Class ResourceProviderServiceBase<TResourceReference>
- Namespace
- FoundationaLLM.Common.Services.ResourceProviders
- Assembly
- FoundationaLLM.Common.dll
Implements basic resource provider functionality
public class ResourceProviderServiceBase<TResourceReference> : IResourceProviderService, IManagementProviderService where TResourceReference : ResourceReference
Type Parameters
TResourceReferenceThe type of the resource reference used by the resource provider.
- Inheritance
-
ResourceProviderServiceBase<TResourceReference>
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
ResourceProviderServiceBase(InstanceSettings, ResourceProviderCacheSettings, IAuthorizationServiceClient, IStorageService, IEventService, IResourceValidatorFactory, IServiceProvider, ILogger, List<string>?, bool, bool)
Creates a new instance of the resource provider.
public ResourceProviderServiceBase(InstanceSettings instanceSettings, ResourceProviderCacheSettings cacheSettings, IAuthorizationServiceClient authorizationServiceClient, IStorageService storageService, IEventService eventService, IResourceValidatorFactory resourceValidatorFactory, IServiceProvider serviceProvider, ILogger logger, List<string>? eventTypesToSubscribe = null, bool useInternalReferencesStore = false, bool proxyMode = false)
Parameters
instanceSettingsInstanceSettingsThe InstanceSettings that provides instance-wide settings.
cacheSettingsResourceProviderCacheSettingsThe ResourceProviderCacheSettings that provides settings for the resource provider cache.
authorizationServiceClientIAuthorizationServiceClientThe IAuthorizationServiceClient providing authorization services to the resource provider.
storageServiceIStorageServiceThe IStorageService providing storage services to the resource provider.
eventServiceIEventServiceThe IEventService providing event services to the resource provider.
resourceValidatorFactoryIResourceValidatorFactoryThe IResourceValidatorFactory providing services to instantiate resource validators.
serviceProviderIServiceProviderThe IServiceProvider of the main dependency injection container.
loggerILoggerThe logger used for logging.
eventTypesToSubscribeList<string>The list of Event Service event namespaces to subscribe to for local event processing.
useInternalReferencesStoreboolIndicates whether the resource provider should use the internal resource references store or provide one of its own.
proxyModeboolIndicates whether the resource provider is running in proxy mode.
Fields
_authorizationServiceClient
The IAuthorizationServiceClient providing authorization services to the resource provider.
protected readonly IAuthorizationServiceClient _authorizationServiceClient
Field Value
_eventService
The IEventService providing event services to the resource provider.
protected readonly IEventService _eventService
Field Value
_instanceSettings
The InstanceSettings that provides instance-wide settings.
protected readonly InstanceSettings _instanceSettings
Field Value
_logger
The logger used for logging.
protected readonly ILogger _logger
Field Value
_proxyMode
Indicates whether the resource provider is running in proxy mode. When running in proxy mode, the resource provider will use a remote service to manage resources instead of managing them locally.
protected readonly bool _proxyMode
Field Value
_resourceReferenceStore
The resource reference store used by the resource provider.
protected ResourceProviderResourceReferenceStore<TResourceReference>? _resourceReferenceStore
Field Value
- ResourceProviderResourceReferenceStore<TResourceReference>
_resourceValidatorFactory
The IResourceValidatorFactory providing services to instantiate resource validators.
protected readonly IResourceValidatorFactory _resourceValidatorFactory
Field Value
_serviceProvider
The IServiceProvider tha provides dependency injection services.
protected readonly IServiceProvider _serviceProvider
Field Value
_storageService
The IStorageService providing storage services to the resource provider.
protected readonly IStorageService _storageService
Field Value
_validator
The standard validator used to validate resources.
protected readonly StandardValidator _validator
Field Value
Properties
AllowedResourceTypes
The metadata describing the resource types allowed by the resource provider.
public Dictionary<string, ResourceTypeDescriptor> AllowedResourceTypes { get; }
Property Value
InitializationTask
The task that is executed when the resource provider is initialized.
public Task InitializationTask { get; }
Property Value
Remarks
This task enables the consumers of the resource provider to wait for the initialization to be completed.
IsInitialized
Indicates whether the resource provider is initialized or not.
public bool IsInitialized { get; }
Property Value
Name
The name of the resource provider.
public string Name { get; }
Property Value
StorageAccountName
The name of the storage account used by the resource provider.
public string StorageAccountName { get; }
Property Value
StorageContainerName
The name of the storage account container used by the resource provider.
public string StorageContainerName { get; }
Property Value
StorageRootPath
Gets the optional storage root path used by the resource provider.
public string? StorageRootPath { get; }
Property Value
_name
The name of the resource provider. Must be overridden in derived classes.
protected virtual string _name { get; }
Property Value
_serializerSettings
Default JSON serialization settings.
protected virtual JsonSerializerOptions _serializerSettings { get; }
Property Value
_storageContainerName
The name of the storage container name used by the resource provider to store its internal data.
protected virtual string _storageContainerName { get; }
Property Value
_storageRootPath
The optional root path used by the resource provider to store its internal data.
protected virtual string? _storageRootPath { get; }
Property Value
Methods
CheckResourceName<T>(ResourceName)
Checks if a resource name is available.
protected Task<ResourceNameCheckResult> CheckResourceName<T>(ResourceName resourceName)
Parameters
resourceNameResourceNameThe ResourceName providing the name to be checked for availability.
Returns
- Task<ResourceNameCheckResult>
A ResourceNameCheckResult indicating the outcome of the operation.
Type Parameters
TThe type of resource for which the name check is performed.
CreateResource(TResourceReference, Stream, string?)
Creates a resource based on a resource reference and the resource itself.
protected Task CreateResource(TResourceReference resourceReference, Stream content, string? contentType)
Parameters
resourceReferenceTResourceReferenceThe resource reference used to identify the resource.
contentStreamThe resource itself.
contentTypestringThe resource content type, if applicable.
Returns
Exceptions
CreateResource<T>(TResourceReference, T)
Creates a resource based on a resource reference and the resource itself.
protected Task CreateResource<T>(TResourceReference resourceReference, T resource) where T : ResourceBase
Parameters
resourceReferenceTResourceReferenceThe resource reference used to identify the resource.
resourceTThe resource itself.
Returns
Type Parameters
TThe type of resource to create.
Exceptions
CreateResources<T1, T2>(TResourceReference, T1, TResourceReference, T2)
Creates two resources based on their resource references and the resources themselves.
protected Task CreateResources<T1, T2>(TResourceReference resourceReference1, T1 resource1, TResourceReference resourceReference2, T2 resource2) where T1 : ResourceBase where T2 : ResourceBase
Parameters
resourceReference1TResourceReferenceThe resource reference used to identify the first resource.
resource1T1The first resource to create.
resourceReference2TResourceReferenceThe resource reference used to identify the second resource.
resource2T2The second resource to create.
Returns
Type Parameters
T1The type of the first resource to create.
T2The type of the second resource to create.
Exceptions
DeleteResourceAsync(ResourcePath, UnifiedUserIdentity)
The internal implementation of DeleteResourceAsync. Must be overridden in derived classes.
protected virtual Task DeleteResourceAsync(ResourcePath resourcePath, UnifiedUserIdentity userIdentity)
Parameters
resourcePathResourcePathA ResourcePath containing information about the resource path.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
Returns
DeleteResourceAsyncInternal<T>(ResourcePath, ResourcePathAuthorizationResult, UnifiedUserIdentity)
The internal implementation of DeleteResourceAsync. Must be overridden in derived classes.
protected virtual Task DeleteResourceAsyncInternal<T>(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, UnifiedUserIdentity userIdentity) where T : ResourceBase
Parameters
resourcePathResourcePathThe ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity providing information about the calling user identity.
Returns
Type Parameters
TThe type of the resource being deleted.
Exceptions
DeleteResourceAsync<T>(string, string, UnifiedUserIdentity)
Deletes logically a resource based on its logical path.
public Task DeleteResourceAsync<T>(string instanceId, string resourceName, UnifiedUserIdentity userIdentity) where T : ResourceBase
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
resourceNamestringThe name of the resource being logically deleted.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity providing information about the calling user identity.
Returns
Type Parameters
TThe type of the resource.
DeleteResource<T>(ResourcePath)
Deletes a resource.
protected Task DeleteResource<T>(ResourcePath resourcePath)
Parameters
resourcePathResourcePathThe ResourcePath identifying the resource to delete.
Returns
Type Parameters
TThe type of resource to delete.
Remarks
The operation is a logical delete. The resource reference is marked deleted, but the resource content remains in storage. To fully remove a resource, the delete operation must be followed by a purge operation.
Exceptions
EnsureAndValidatePolicyDefinitions(ResourcePath, ResourcePathAuthorizationResult)
public PolicyDefinition EnsureAndValidatePolicyDefinitions(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult)
Parameters
resourcePathResourcePathauthorizationResultResourcePathAuthorizationResult
Returns
ExecuteActionAsync(ResourcePath, ResourcePathAuthorizationResult, string, UnifiedUserIdentity, Func<object, bool>?)
The internal implementation of ExecuteActionAsync. Must be overriden in derived classes.
protected virtual Task<object> ExecuteActionAsync(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, string serializedAction, UnifiedUserIdentity userIdentity, Func<object, bool>? requestPayloadValidator = null)
Parameters
resourcePathResourcePathA ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
serializedActionstringThe serialized details of the action being executed.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
requestPayloadValidatorFunc<object, bool>An optional validator used to perform additional validation on the action payload after deserialization.
Returns
Remarks
In the special case of the filter action, the override must handle the authorization result and return
the appropriate response as follows:
- The read action is authorized for the resource path itself. In this case, all matching resources must be returned according to the PBAC policies specified by the authorization result (if any).
- The read action is denied for the resource path itself. In this case, only the matching resources specified in the subordinate authorized resource paths list of the authorization result should be returned (if any).
ExecuteManagementAction(ResourcePath, ResourcePathAuthorizationResult, string)
Executes a management action on the resource provider.
protected Task<ResourceProviderActionResult> ExecuteManagementAction(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, string serializedAction)
Parameters
resourcePathResourcePathA ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
serializedActionstringThe serialized details of the action being executed.
Returns
ExecuteResourceActionAsyncInternal<T, TAction, TResult>(ResourcePath, ResourcePathAuthorizationResult, TAction, UnifiedUserIdentity)
The internal implementation of ExecuteResourceActionAsync. Must be overridden in derived classes.
protected virtual Task<TResult> ExecuteResourceActionAsyncInternal<T, TAction, TResult>(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, TAction actionPayload, UnifiedUserIdentity userIdentity) where T : ResourceBase where TAction : class? where TResult : ResourceProviderActionResult
Parameters
resourcePathResourcePathA ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
actionPayloadTActionThe
TActionobject containing details about the action to be executed.userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
Returns
- Task<TResult>
A
TResultobject with the result of the action.
Type Parameters
TTActionTResult
Remarks
In the special case of the filter action, the override must handle the authorization result and return
the appropriate response as follows:
- The read action is authorized for the resource path itself. In this case, all matching resources must be returned according to the PBAC policies specified by the authorization result (if any).
- The read action is denied for the resource path itself. In this case, only the matching resources specified in the subordinate authorized resource paths list of the authorization result should be returned (if any).
ExecuteResourceActionAsync<T, TAction, TResult>(string, string, string, TAction, UnifiedUserIdentity, ResourceBase?)
Executes an action on a resource.
public Task<TResult> ExecuteResourceActionAsync<T, TAction, TResult>(string instanceId, string resourceName, string actionName, TAction actionPayload, UnifiedUserIdentity userIdentity, ResourceBase? parentResourceInstance = null) where T : ResourceBase where TAction : class? where TResult : ResourceProviderActionResult
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
resourceNamestringThe name of the resource on which the action is executed.
actionNamestringThe name of the action being executed.
actionPayloadTActionThe payload of the action providing details about it.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
parentResourceInstanceResourceBaseThe optional parent resource of the resource identified by
instanceIdandresourceName.
Returns
- Task<TResult>
Type Parameters
TThe type of the resource.
TActionThe type of the action payload providing details about the action to be executed.
TResultThe type of the result returned.
Remarks
When the parent resource instance is provided, and it specifies inheritable authorizable actions, the parent resource instance is used to authorize the request for any of those actions.
ExecuteResourceActionAsync<TMain, TSubordinate, TAction, TResult>(string, string, string, string, TAction, UnifiedUserIdentity, ResourceBase?)
Executes an action on a main resource and it subordinate resource.
public Task<TResult> ExecuteResourceActionAsync<TMain, TSubordinate, TAction, TResult>(string instanceId, string mainResourceName, string resourceName, string actionName, TAction actionPayload, UnifiedUserIdentity userIdentity, ResourceBase? parentResourceInstance = null) where TMain : ResourceBase where TSubordinate : ResourceBase where TAction : class? where TResult : ResourceProviderActionResult
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
mainResourceNamestringThe name of the main resource on which the action is executed.
resourceNamestringThe name of the subordinate resource on which the action is executed.
actionNamestringThe name of the action being executed.
actionPayloadTActionThe payload of the action providing details about it.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
parentResourceInstanceResourceBaseThe optional parent resource of the resource identified by
instanceIdandresourceName.
Returns
- Task<TResult>
Type Parameters
TMainThe type of the main resource.
TSubordinateThe type of the subordinate resource.
TActionThe type of the action payload providing details about the action to be executed.
TResultThe type of the result returned.
Remarks
When the parent resource instance is provided, and it specifies inheritable authorizable actions, the parent resource instance is used to authorize the request for any of those actions.
FilterResources<T>(ResourcePath, ResourceFilter, ResourcePathAuthorizationResult, ResourceProviderGetOptions?, Func<TResourceReference, bool, Task<T>>?, Func<T, bool>?)
Loads a list of resources filtered based on object IDs.
protected Task<IEnumerable<T>> FilterResources<T>(ResourcePath resourcePath, ResourceFilter filter, ResourcePathAuthorizationResult authorizationResult, ResourceProviderGetOptions? options = null, Func<TResourceReference, bool, Task<T>>? customResourceLoader = null, Func<T, bool>? customResourceFilter = null) where T : ResourceBase
Parameters
resourcePathResourcePathThe ResourcePath resource type path to filter.
filterResourceFilterThe ResourceFilter used to filter the resources.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
optionsResourceProviderGetOptionsThe ResourceProviderGetOptions which provides operation parameters.
customResourceLoaderFunc<TResourceReference, bool, Task<T>>An optional function that loads the resource used to override the default resource loading mechanism.
customResourceFilterFunc<T, bool>An optional function that filters the list of loaded resources.
Returns
- Task<IEnumerable<T>>
A list of objects of type
T.
Type Parameters
TThe type of resources to load.
GetParsedResourcePath(string, bool)
Gets a ResourcePath object for the specified string resource path.
protected ResourcePath GetParsedResourcePath(string resourcePath, bool allowAction = true)
Parameters
resourcePathstringThe resource path.
allowActionboolIndicates whether actions are allowed in the resource path.
Returns
- ResourcePath
A ResourcePath object.
GetResourceAsyncInternal<T>(ResourcePath, ResourcePathAuthorizationResult, UnifiedUserIdentity, ResourceProviderGetOptions?, ResourceBase?)
The internal implementation of GetResource. Must be overridden in derived classes.
protected virtual Task<T> GetResourceAsyncInternal<T>(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, UnifiedUserIdentity userIdentity, ResourceProviderGetOptions? options = null, ResourceBase? parentResourceInstance = null) where T : ResourceBase
Parameters
resourcePathResourcePathA ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity providing information about the calling user identity.
optionsResourceProviderGetOptionsThe ResourceProviderGetOptions which provides operation parameters.
parentResourceInstanceResourceBaseThe optional parent resource of the resource identified by
resourcePath.
Returns
- Task<T>
Type Parameters
T
Remarks
When the parent resource instance is provided, and it specifies inheritable authorizable actions, the parent resource instance is used to authorize the request for any of those actions.
GetResourceAsync<T>(string, UnifiedUserIdentity, ResourceProviderGetOptions?, ResourceBase?)
Gets a resource based on its logical path.
public Task<T> GetResourceAsync<T>(string resourcePath, UnifiedUserIdentity userIdentity, ResourceProviderGetOptions? options = null, ResourceBase? parentResourceInstance = null) where T : ResourceBase
Parameters
resourcePathstringThe logical path of the resource.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
optionsResourceProviderGetOptionsThe ResourceProviderGetOptions which provides operation parameters.
parentResourceInstanceResourceBaseThe optional parent resource of the resource identified by
resourcePath.
Returns
- Task<T>
The instance of the resource corresponding to the specified logical path.
Type Parameters
TThe type of the resource.
Remarks
When the parent resource instance is provided, and it specifies inheritable authorizable actions, the parent resource instance is used to authorize the request for any of those actions.
GetResourceAsync<T>(string, string, UnifiedUserIdentity, ResourceProviderGetOptions?, ResourceBase?)
Gets a resource based on its name.
public Task<T> GetResourceAsync<T>(string instanceId, string resourceName, UnifiedUserIdentity userIdentity, ResourceProviderGetOptions? options = null, ResourceBase? parentResourceInstance = null) where T : ResourceBase
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
resourceNamestringThe logical path of the resource.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
optionsResourceProviderGetOptionsThe ResourceProviderGetOptions which provides operation parameters.
parentResourceInstanceResourceBaseThe optional parent resource of the resource identified by
instanceIdandresourceName.
Returns
- Task<T>
The instance of the resource corresponding to the specified logical path.
Type Parameters
TThe type of the resource.
Remarks
When the parent resource instance is provided, and it specifies inheritable authorizable actions, the parent resource instance is used to authorize the request for any of those actions.
GetResourcePath(string, Type, string?, string?)
Get the fully qualified resource path for a specified resource.
protected (string ResourcePath, ResourceTypeDescriptor ResourceTypeDescriptor) GetResourcePath(string instanceId, Type resourceType, string? resourceName = null, string? actionName = null)
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
resourceTypeTypeThe type of the resource.
resourceNamestringThe name of the resource.
actionNamestringThe name of the action.
Returns
GetResourcePath(string, Type, string, Type, string?, string?)
Get the fully qualified resource path for a specified resource and subordinate resource.
protected (string ResourcePath, ResourceTypeDescriptor ResourceTypeDescriptor) GetResourcePath(string instanceId, Type mainResourceType, string mainResourceName, Type resourceType, string? resourceName = null, string? actionName = null)
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
mainResourceTypeTypeThe type of the main resource.
mainResourceNamestringThe name of the main resource.
resourceTypeTypeThe type of the resource.
resourceNamestringThe name of the resource.
actionNamestringThe name of the action.
Returns
GetResourceProviderServiceByName(string)
Gets a resource provider service by name.
protected IResourceProviderService GetResourceProviderServiceByName(string name)
Parameters
namestringThe name of the resource provider.
Returns
- IResourceProviderService
The IResourceProviderService used to interact with the resource provider.
GetResourceProviderState()
Gets the resource provider state.
protected virtual Task<BinaryData> GetResourceProviderState()
Returns
- Task<BinaryData>
The resource provider state in binary format.
GetResourceTypes()
Gets the details about the resource types managed by the resource provider.
protected virtual Dictionary<string, ResourceTypeDescriptor> GetResourceTypes()
Returns
- Dictionary<string, ResourceTypeDescriptor>
A dictionary of ResourceTypeDescriptor objects with details about the resource types.
GetResourcesAsync(ResourcePath, ResourcePathAuthorizationResult, UnifiedUserIdentity, ResourceProviderGetOptions?)
The internal implementation of GetResourcesAsync. Must be overridden in derived classes.
protected virtual Task<object> GetResourcesAsync(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, UnifiedUserIdentity userIdentity, ResourceProviderGetOptions? options = null)
Parameters
resourcePathResourcePathA ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
optionsResourceProviderGetOptionsThe ResourceProviderGetOptions which provides operation parameters.
Returns
Remarks
The override implementation should return a list of resources or a single resource, depending on the resource path. It also must handle the authorization result and return the appropriate response as follows:
- The resource path refers to a single resource. In this case, the authorization is already confirmed and the specific resource should be returned.
- The resource path refers to a resource type and the read action is authorized for the resource path itself. In this case, all resources must be returned according to the PBAC policies specified by the authorization result (if any).
- The resource path refers to a resource type and the read action is denied for the resource path itself. In this case, only the resources specified in the subordinate authorized resource paths list of the authorization result should be returned (if any).
GetResourcesAsync<T>(string, UnifiedUserIdentity, ResourceProviderGetOptions?)
Gets resources of a specific type.
public Task<List<ResourceProviderGetResult<T>>> GetResourcesAsync<T>(string instanceId, UnifiedUserIdentity userIdentity, ResourceProviderGetOptions? options = null) where T : ResourceBase
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
optionsResourceProviderGetOptionsThe ResourceProviderGetOptions which provides operation parameters.
Returns
- Task<List<ResourceProviderGetResult<T>>>
A list of ResourceProviderGetResult<T> containing the loaded resources.
Type Parameters
TThe type of resource to return.
HandleCacheResetCommand()
Handles the cache reset command.
protected virtual Task HandleCacheResetCommand()
Returns
HandleDeleteAsync(string, UnifiedUserIdentity, Func<HttpMethod, ResourcePath, bool>?)
Handles a HTTP DELETE request for a specified resource path.
public Task HandleDeleteAsync(string resourcePath, UnifiedUserIdentity userIdentity, Func<HttpMethod, ResourcePath, bool>? resourcePathAvailabilityChecker = null)
Parameters
resourcePathstringThe resource path.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
resourcePathAvailabilityCheckerFunc<HttpMethod, ResourcePath, bool>An optional resource path availability checker used to block certain resource providers and resource types.
Returns
HandleEventsInternal(EventTypeEventArgs)
Handles events received from the IEventService when they are dequeued locally.
protected virtual Task HandleEventsInternal(EventTypeEventArgs e)
Parameters
eEventTypeEventArgsThe EventTypeEventArgs containing the event type and the actual events.
Returns
HandleGetAsync(string, UnifiedUserIdentity, ResourceProviderGetOptions?, Func<HttpMethod, ResourcePath, bool>?)
Handles a HTTP GET request for a specified resource path.
public Task<object> HandleGetAsync(string resourcePath, UnifiedUserIdentity userIdentity, ResourceProviderGetOptions? options = null, Func<HttpMethod, ResourcePath, bool>? resourcePathAvailabilityChecker = null)
Parameters
resourcePathstringThe resource path.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
optionsResourceProviderGetOptionsThe ResourceProviderGetOptions which provides operation parameters.
resourcePathAvailabilityCheckerFunc<HttpMethod, ResourcePath, bool>An optional resource path availability checker used to block certain resource providers and resource types.
Returns
HandlePostAsync(string, string?, ResourceProviderFormFile?, UnifiedUserIdentity, Func<HttpMethod, ResourcePath, bool>?, Func<object, bool>?)
Handles a HTTP POST request for a specified resource path.
public Task<object> HandlePostAsync(string resourcePath, string? serializedResource, ResourceProviderFormFile? formFile, UnifiedUserIdentity userIdentity, Func<HttpMethod, ResourcePath, bool>? resourcePathAvailabilityChecker = null, Func<object, bool>? requestPayloadValidator = null)
Parameters
resourcePathstringThe resource path.
serializedResourcestringformFileResourceProviderFormFileThe optional file attached to the request.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
resourcePathAvailabilityCheckerFunc<HttpMethod, ResourcePath, bool>An optional resource path availability checker used to block certain resource providers and resource types.
requestPayloadValidatorFunc<object, bool>An optional function to validate the request payload after deserialization.
Returns
Initialize()
Initializes the resource provider.
public Task Initialize()
Returns
InitializeInternal()
The internal implementation of Initialize. Must be overridden in derived classes.
protected virtual Task InitializeInternal()
Returns
LoadResource<T>(string)
Loads a resource based on its name.
protected Task<T?> LoadResource<T>(string resourceName) where T : ResourceBase
Parameters
resourceNamestringThe name of the resource.
Returns
- Task<T>
The loaded resource.
Type Parameters
TThe type of resource to load.
Exceptions
LoadResource<T>(TResourceReference)
Loads a resource based on its resource reference.
protected Task<T?> LoadResource<T>(TResourceReference resourceReference) where T : ResourceBase
Parameters
resourceReferenceTResourceReferenceThe type of resource reference used to indetify the resource to load.
Returns
- Task<T>
The loaded resource.
Type Parameters
TThe type of resource to load.
Remarks
Always ensure this method is called within a lock to avoid unexpected racing conditions.
Exceptions
LoadResources<T>(ResourceTypeInstance, ResourcePathAuthorizationResult, ResourceProviderGetOptions?, Func<TResourceReference, bool, Task<T>>?)
Loads one or more resources of a specific type.
protected Task<List<ResourceProviderGetResult<T>>> LoadResources<T>(ResourceTypeInstance instance, ResourcePathAuthorizationResult authorizationResult, ResourceProviderGetOptions? options = null, Func<TResourceReference, bool, Task<T>>? customResourceLoader = null) where T : ResourceBase
Parameters
instanceResourceTypeInstanceThe ResourceTypeInstance that indicates a specific resource to load.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
optionsResourceProviderGetOptionsThe ResourceProviderGetOptions which provides operation parameters.
customResourceLoaderFunc<TResourceReference, bool, Task<T>>An optional function that loads the resource used to override the default resource loading mechanism.
Returns
- Task<List<ResourceProviderGetResult<T>>>
A list of ResourceProviderGetResult<T> objects.
Type Parameters
TThe type of resources to load.
PurgeResource<T>(ResourcePath)
Purges a deleted resource.
protected Task<ResourceProviderActionResult> PurgeResource<T>(ResourcePath resourcePath)
Parameters
resourcePathResourcePathThe ResourcePath identifying the resource to purge.
Returns
- Task<ResourceProviderActionResult>
A ResourceProviderActionResult indicating the outcome of the operation.
Type Parameters
TThe type of the resource to purge.
Remarks
The operation can only be applied to a resource that has been logically deleted.
Exceptions
ResourceExistsAsyncInternal<T>(ResourcePath, ResourcePathAuthorizationResult, UnifiedUserIdentity)
The internal implementation of ResourceExistsAsync. Must be overridden in derived classes.
protected virtual Task<(bool Exists, bool Deleted)> ResourceExistsAsyncInternal<T>(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, UnifiedUserIdentity userIdentity) where T : ResourceBase
Parameters
resourcePathResourcePathThe ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity providing information about the calling user identity.
Returns
- Task<(bool Exists, bool Deleted)>
A tuple indicating whether the resource exists or not and whether it is logically deleted or not.
Type Parameters
TThe type of resource being checked.
Remarks
If a resource was logically deleted but not purged, this method will return True, indicating the existence of the resource.
ResourceExistsAsync<T>(string, string, UnifiedUserIdentity)
Checks if a resource exists.
public Task<(bool Exists, bool Deleted)> ResourceExistsAsync<T>(string instanceId, string resourceName, UnifiedUserIdentity userIdentity) where T : ResourceBase
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
resourceNamestringThe resource name being checked.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity providing information about the calling user identity.
Returns
- Task<(bool Exists, bool Deleted)>
A tuple indicating whether the resource exists or not and whether it is logically deleted or not.
Type Parameters
TThe type of the resource.
Remarks
If a resource was logically deleted but not purged, this method will return True, indicating the existence of the resource.
SaveResource<T>(TResourceReference, T)
Saves a resource based on its resource reference and the resource itself.
protected Task SaveResource<T>(TResourceReference resourceReference, T resource) where T : ResourceBase
Parameters
resourceReferenceTResourceReferenceThe resource reference used to identify the resource.
resourceTThe resource to be saved.
Returns
Type Parameters
TThe type of resource to save.
SaveResource<T>(T)
Saves a resource.
protected Task SaveResource<T>(T resource) where T : ResourceBase
Parameters
resourceTThe resource to be saved.
Returns
Type Parameters
TThe type of resource to save.
SendResourceProviderEvent(string, string?, object?, bool)
Sends a resource provider event to the event service.
protected Task SendResourceProviderEvent(string eventType, string? targetServiceName = null, object? data = null, bool forceLocalProcessing = false)
Parameters
eventTypestringThe type of the event to send.
targetServiceNamestringOptional name of the target service to which the event is sent. If null, the event is sent to all services.
dataobjectThe optional data to send with the event.
forceLocalProcessingboolIndicates whether the event should be processed on the service instance that created it as well.
Returns
Remarks
See EventTypes for a list of event types.
SetDefaultResource<T>(ResourcePath)
Sets a resource as the default for its resource type.
protected Task<ResourceProviderActionResult> SetDefaultResource<T>(ResourcePath resourcePath)
Parameters
resourcePathResourcePathThe ResourcePath identifying the resource to which the default resource name should be set.
Returns
- Task<ResourceProviderActionResult>
A ResourceProviderActionResult indicating the outcome of the operation.
Type Parameters
TThe resource type.
Exceptions
UpdateBaseProperties(ResourceBase, UnifiedUserIdentity, bool)
Updates the base properties of an object derived from ResourceBase.
protected void UpdateBaseProperties(ResourceBase resource, UnifiedUserIdentity userIdentity, bool isNew = false)
Parameters
resourceResourceBaseThe ResourceBase object to be updated.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity providing the information about the identity of the user that performed a create or update operation on the resource.
isNewboolIndicates whether the resource is new or being updated.
UpdateBaseProperties(ResourceBase, string, bool)
Updates the base properties of an object derived from ResourceBase.
protected void UpdateBaseProperties(ResourceBase resource, string userIdentity, bool isNew = false)
Parameters
resourceResourceBaseThe ResourceBase object to be updated.
userIdentitystringTheidentity of the user that performed a create or update operation on the resource.
isNewboolIndicates whether the resource is new or being updated.
UpdateResourcePropertiesAsyncInternal<T, TResult>(ResourcePath, ResourcePathAuthorizationResult, Dictionary<string, object>, UnifiedUserIdentity)
The internal implementation of UpdateResourcePropertiesAsync. Must be overridden in derived classes.
protected virtual Task<TResult> UpdateResourcePropertiesAsyncInternal<T, TResult>(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, Dictionary<string, object> propertyValues, UnifiedUserIdentity userIdentity) where T : ResourceBase where TResult : ResourceProviderUpsertResult<T>
Parameters
resourcePathResourcePathThe ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
propertyValuesDictionary<string, object>The dictionary with propery names and values to update.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity providing information about the calling user identity.
Returns
- Task<TResult>
Type Parameters
TThe type of the resource being updated.
TResultThe type of the result returned.
UpdateResourcePropertiesAsync<T, TResult>(string, string, Dictionary<string, object?>, UnifiedUserIdentity)
Updates a subset of the properties of a resource.
public Task<TResult> UpdateResourcePropertiesAsync<T, TResult>(string instanceId, string resourceName, Dictionary<string, object?> propertyValues, UnifiedUserIdentity userIdentity) where T : ResourceBase where TResult : ResourceProviderUpsertResult<T>
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
resourceNamestringThe name of the resource being updated.
propertyValuesDictionary<string, object>The dictionary with propery names and values to update.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
Returns
- Task<TResult>
Type Parameters
TThe type of the resource.
TResultThe type of the result returned.
UpsertResourceAsync(ResourcePath, string?, ResourceProviderFormFile?, ResourcePathAuthorizationResult, UnifiedUserIdentity, Func<object, bool>?)
The internal implementation of UpsertResourceAsync. Must be overridden in derived classes.
protected virtual Task<object> UpsertResourceAsync(ResourcePath resourcePath, string? serializedResource, ResourceProviderFormFile? formFile, ResourcePathAuthorizationResult authorizationResult, UnifiedUserIdentity userIdentity, Func<object, bool>? requestPayloadValidator = null)
Parameters
resourcePathResourcePathA ResourcePath containing information about the resource path.
serializedResourcestringThe optional serialized resource being created or updated.
formFileResourceProviderFormFileThe optional file attached to the request.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
requestPayloadValidatorFunc<object, bool>An optional validator used to perform additional validation on the serialized resource after deserialization.
Returns
UpsertResourceAsyncInternal<T, TResult>(ResourcePath, ResourcePathAuthorizationResult, T, UnifiedUserIdentity, ResourceProviderUpsertOptions?)
The internal implementation of UpsertResourceAsync. Must be overridden in derived classes.
protected virtual Task<TResult> UpsertResourceAsyncInternal<T, TResult>(ResourcePath resourcePath, ResourcePathAuthorizationResult authorizationResult, T resource, UnifiedUserIdentity userIdentity, ResourceProviderUpsertOptions? options = null) where T : ResourceBase where TResult : ResourceProviderUpsertResult<T>
Parameters
resourcePathResourcePathA ResourcePath containing information about the resource path.
authorizationResultResourcePathAuthorizationResultThe ResourcePathAuthorizationResult containing the result of the resource path authorization request.
resourceTThe instance of the resource being created or updated.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity providing information about the calling user identity.
optionsResourceProviderUpsertOptionsThe ResourceProviderUpsertOptions which provides operation parameters.
Returns
- Task<TResult>
Type Parameters
TThe type of the resource being created or updated.
TResultThe type of the result returned.
UpsertResourceAsync<T, TResult>(string, T, UnifiedUserIdentity, ResourceProviderUpsertOptions?)
Creates or updates a resource based on its logical path.
public Task<TResult> UpsertResourceAsync<T, TResult>(string instanceId, T resource, UnifiedUserIdentity userIdentity, ResourceProviderUpsertOptions? options = null) where T : ResourceBase where TResult : ResourceProviderUpsertResult<T>
Parameters
instanceIdstringThe FoundationaLLM instance identifier.
resourceTThe instance of the resource being created or updated.
userIdentityUnifiedUserIdentityThe UnifiedUserIdentity with details about the identity of the user.
optionsResourceProviderUpsertOptionsThe ResourceProviderUpsertOptions which provides operation parameters.
Returns
- Task<TResult>
The object id of the resource.
Type Parameters
TThe type of the resource.
TResultThe type of the result returned
WaitForInitialization()
Waits for the resource provider service to be initialized.
public Task WaitForInitialization()