Skip to content

Commit

Permalink
Add CheckName action for APIEndpointConfiguration resources
Browse files Browse the repository at this point in the history
  • Loading branch information
joelhulen committed Jan 21, 2025
1 parent b26ac55 commit 6f30e87
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public static class ConfigurationResourceProviderMetadata
new ResourceTypeAllowedTypes(HttpMethod.Delete.Method, AuthorizableOperations.Delete, [], [], []),
],
Actions = [
new ResourceTypeAction(ResourceProviderActions.CheckName, false, true, [
new ResourceTypeAllowedTypes(HttpMethod.Post.Method, AuthorizableOperations.Read, [], [typeof(ResourceName)], [typeof(ResourceNameCheckResult)])
])
]
new ResourceTypeAction(ResourceProviderActions.CheckName, false, true, [
new ResourceTypeAllowedTypes(HttpMethod.Post.Method, AuthorizableOperations.Read, [], [typeof(ResourceName)], [typeof(ResourceNameCheckResult)])
])
]
}
}
,
Expand All @@ -44,6 +44,11 @@ public static class ConfigurationResourceProviderMetadata
new ResourceTypeAllowedTypes(HttpMethod.Get.Method, AuthorizableOperations.Read, [], [], [typeof(ResourceProviderGetResult<APIEndpointConfiguration>)]),
new ResourceTypeAllowedTypes(HttpMethod.Post.Method, AuthorizableOperations.Write, [], [typeof(APIEndpointConfiguration)], [typeof(ResourceProviderUpsertResult)]),
new ResourceTypeAllowedTypes(HttpMethod.Delete.Method, AuthorizableOperations.Delete, [], [], []),
],
Actions = [
new ResourceTypeAction(ResourceProviderActions.CheckName, false, true, [
new ResourceTypeAllowedTypes(HttpMethod.Post.Method, AuthorizableOperations.Read, [], [typeof(ResourceName)], [typeof(ResourceNameCheckResult)])
])
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
using FoundationaLLM.Common.Models.Configuration.Instance;
using FoundationaLLM.Common.Models.Events;
using FoundationaLLM.Common.Models.ResourceProviders;
using FoundationaLLM.Common.Models.ResourceProviders.Agent.AgentAccessTokens;
using FoundationaLLM.Common.Models.ResourceProviders.Agent;
using FoundationaLLM.Common.Models.ResourceProviders.Configuration;
using FoundationaLLM.Common.Services;
using FoundationaLLM.Common.Services.ResourceProviders;
Expand Down Expand Up @@ -130,6 +132,24 @@ protected override async Task DeleteResourceAsync(ResourcePath resourcePath, Uni
};
}

/// <inheritdoc/>
protected override async Task<object> ExecuteActionAsync(
ResourcePath resourcePath,
ResourcePathAuthorizationResult authorizationResult,
string serializedAction,
UnifiedUserIdentity userIdentity) =>
resourcePath.ResourceTypeName switch
{
ConfigurationResourceTypeNames.APIEndpointConfigurations => resourcePath.Action switch
{
ResourceProviderActions.CheckName => await CheckResourceName<APIEndpointConfiguration>(
JsonSerializer.Deserialize<ResourceName>(serializedAction)!),
_ => throw new ResourceProviderException($"The action {resourcePath.Action} is not supported by the {_name} resource provider.",
StatusCodes.Status400BadRequest)
},
_ => throw new ResourceProviderException()
};

#endregion

#region Resource provider strongly typed operations
Expand Down

0 comments on commit 6f30e87

Please sign in to comment.