Class ResourcePath
- Namespace
- FoundationaLLM.Common.Models.ResourceProviders
- Assembly
- FoundationaLLM.Common.dll
Provides the logic for handling FoundationaLLM resource identifiers.
public class ResourcePath
- Inheritance
-
ResourcePath
- Inherited Members
- Extension Methods
Constructors
ResourcePath(string, ImmutableList<string>, Dictionary<string, ResourceTypeDescriptor>, bool)
Creates a new resource identifier from a resource path optionally allowing an action.
public ResourcePath(string resourcePath, ImmutableList<string> allowedResourceProviders, Dictionary<string, ResourceTypeDescriptor> allowedResourceTypes, bool allowAction = true)
Parameters
resourcePath
stringThe resource path used to create the resource identifier.
allowedResourceProviders
ImmutableList<string>Provides a list of allowed resource providers.
allowedResourceTypes
Dictionary<string, ResourceTypeDescriptor>Provides a dictionary of ResourceTypeDescriptor used to validate resource types.
allowAction
boolOptional parameter that indicates whether an action name is allowed as part of the resource identifier.
Properties
Action
Gets the action (if any) specified in the resource path.
public string? Action { get; }
Property Value
HasAction
Indicates whether the resource path contains a valid action or not.
public bool HasAction { get; }
Property Value
HasResourceId
Indicates whether the resource path contains a valid resource id or not.
public bool HasResourceId { get; }
Property Value
HasSubordinateResourceId
A flag denoting if the resource path contains subordinate resources or not.
public bool HasSubordinateResourceId { get; }
Property Value
InstanceId
The instance id of the resource identifier. Can be null if the resource path does not contain an instance id.
public string? InstanceId { get; }
Property Value
IsInstancePath
Indicates whether the resource path is an instance path or not (i.e., only contains the FoundationaLLM instance identifier).
public bool IsInstancePath { get; }
Property Value
IsResourceTypePath
Indicates whether the resource path refers to a resource type (does not contain a resource name).
public bool IsResourceTypePath { get; }
Property Value
IsRootPath
Indicates whether the resource path is a root path ("/") or not.
public bool IsRootPath { get; }
Property Value
MainResourceId
Gets the resource id of the main resource type of the path.
public string? MainResourceId { get; }
Property Value
MainResourceType
Gets the object type of the main resource type of the path.
public Type? MainResourceType { get; }
Property Value
Remarks
The main resource type is the first resource type in the path. In the case of nested resources, this will be the resource type of the main resource.
MainResourceTypeName
Gets the name of the main resource type of the path.
public string? MainResourceTypeName { get; }
Property Value
Remarks
The main resource type is the first resource type in the path. In the case of nested resources, this will be the resource type of the main resource.
ObjectId
Gets the resource object identifier associated with the resource path.
public string? ObjectId { get; }
Property Value
Remarks
Only fully qualified resource paths can be converted to object identifiers.
RawResourcePath
Gets the raw resource path which was used to create the resource path object.
public string RawResourcePath { get; }
Property Value
ResourceId
Gets the resource id of the resource identified by the path.
public string? ResourceId { get; }
Property Value
Remarks
This is the last resource id in the path. If the path refers to nested resources, this will be the resource id of the last resource. Otherwise, it will be the resource id of the main resource (and hence identical to MainResourceId).
ResourceProvider
The resource provider of the resource identifier. Can be null if the resource path does not contain a resource provider.
public string? ResourceProvider { get; }
Property Value
ResourceType
Gets the resource type of the resource identified by the path.
public Type? ResourceType { get; }
Property Value
Remarks
This is the last resource type in the path. If the path refers to nested resources, this will be the resource type of the last resource. Otherwise, it will be the resource type of the main resource (and hence identical to MainResourceType).
ResourceTypeInstances
The resource type instances of the resource identifier.
public List<ResourceTypeInstance> ResourceTypeInstances { get; }
Property Value
ResourceTypeName
Gets the resource type name of the resource identified by the path.
public string? ResourceTypeName { get; }
Property Value
Remarks
This is the last resource type name in the path. If the path refers to nested resources, this will be the resource type name of the last resource. Otherwise, it will be the resource type name of the main resource (and hence identical to MainResourceTypeName).
Methods
GetAllowedResourceTypes(string)
Retrieves the allowed resource types for a specified resource provider.
public static Dictionary<string, ResourceTypeDescriptor> GetAllowedResourceTypes(string resourceProvider)
Parameters
resourceProvider
stringThe name of the resource provider.
Returns
GetObjectId(string?, string?)
Computes the object id of the resource identifier.
public string GetObjectId(string? instanceId, string? resourceProvider)
Parameters
instanceId
stringThe FoundationaLLM instance id. Provide this if the resource does not have a fully-qualified resource identifier.
resourceProvider
stringThe name of the resource provider. Provide this if the resource does not have a fully-qualified resource identifier.
Returns
- string
The object id.
GetObjectId(string, string, string, string)
Computes the object id of the resource identifier.
public static string GetObjectId(string instanceId, string resourceProviderName, string resourceTypeName, string resourceName)
Parameters
instanceId
stringThe FoundationaLLM instance id.
resourceProviderName
stringThe name of the resource provider.
resourceTypeName
stringThe name of the resource type.
resourceName
stringThe name of the resource.
Returns
- string
The object id.
GetObjectId(string, string, string, string, string, string)
Computes the object id of the resource identifier.
public static string GetObjectId(string instanceId, string resourceProviderName, string mainResourceTypeName, string mainResourceName, string resourceTypeName, string resourceName)
Parameters
instanceId
stringThe FoundationaLLM instance id.
resourceProviderName
stringThe name of the resource provider.
mainResourceTypeName
stringThe name of the main resource type.
mainResourceName
stringThe name of the main resource.
resourceTypeName
stringThe name of the resource type.
resourceName
stringThe name of the resource.
Returns
- string
The object id.
GetResourcePath(string)
Parses a resource path.
public static ResourcePath GetResourcePath(string resourcePath)
Parameters
resourcePath
stringThe resource path to be parsed.
Returns
- ResourcePath
A ResourcePath object containing the parsed resource path.
GetResourceTypeObjectId()
Computes the object id of the resource type associated with the resource identifier.
public string GetResourceTypeObjectId()
Returns
- string
The resource type object id.
Exceptions
IncludesResourcePath(ResourcePath, bool)
Determines whether the resource path includes another specified resource path.
public bool IncludesResourcePath(ResourcePath other, bool allowEqual = true)
Parameters
other
ResourcePathThe ResourcePath to check for inclusion.
allowEqual
boolIndicates whether an equal resource path is considered to be included or not.
Returns
- bool
True if the specified resource path is included in the resource path.
MatchesResourceTypes(ResourcePath)
Determines whether the resource path matches exactly (including order) the resource types of another specified resource path.
public bool MatchesResourceTypes(ResourcePath other)
Parameters
other
ResourcePathThe ResourcePath to be matched.
Returns
- bool
True if the resource path matches exactly (including order) the resource types of the other resource path.
TryParse(string, ImmutableList<string>, Dictionary<string, ResourceTypeDescriptor>, bool, out ResourcePath?)
Tries to parse a resource path and create a resource identifier from it.
public static bool TryParse(string resourcePath, ImmutableList<string> allowedResourceProviders, Dictionary<string, ResourceTypeDescriptor> allowedResourceTypes, bool allowAction, out ResourcePath? resourcePathInstance)
Parameters
resourcePath
stringThe resource path used to create the resource identifier.
allowedResourceProviders
ImmutableList<string>Provides a list of allowed resource providers.
allowedResourceTypes
Dictionary<string, ResourceTypeDescriptor>Provides a dictionary of ResourceTypeDescriptor used to validate resource types.
allowAction
boolOptional parameter that indicates whether an action name is allowed as part of the resource identifier.
resourcePathInstance
ResourcePathThe parsed resource path.
Returns
- bool
True if the resource path is parsed successfully.
TryParseInstanceId(string, out string?)
Tries to retrieve the identifier of the FoundationaLLM instance from a resource path.
public static bool TryParseInstanceId(string resourcePath, out string? instanceId)
Parameters
resourcePath
stringThe resource path to analyze.
instanceId
stringThe FoundationaLLM instance identifier.
Returns
- bool
True if a valid intance identifier is retrieved successfully.
TryParseResourceProvider(string, out string?)
Tries to retrieve the name of the resource provider from a resource path.
public static bool TryParseResourceProvider(string resourcePath, out string? resourceProvider)
Parameters
resourcePath
stringThe resource path to analyze.
resourceProvider
stringThe resource provider name.
Returns
- bool
True if a valid resource provider name is retrieved successfully.