diff --git a/api-docs/openapi/v3_0/aggregated.json b/api-docs/openapi/v3_0/aggregated.json index 226a503fc..85a8b22ff 100644 --- a/api-docs/openapi/v3_0/aggregated.json +++ b/api-docs/openapi/v3_0/aggregated.json @@ -7408,6 +7408,89 @@ ] } }, + "/apis/console.api.storage.halo.run/v1alpha1/policies/{name}/configs/{group}": { + "get": { + "description": "Get policy config by group", + "operationId": "getPolicyConfigByGroup", + "parameters": [ + { + "description": "Name of the policy", + "in": "path", + "name": "name", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "Name of the group", + "in": "path", + "name": "group", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "default": { + "content": { + "*/*": { + "schema": { + "$ref": "#/components/schemas/JsonNode" + } + } + }, + "description": "default response" + } + }, + "tags": [ + "PolicyAlpha1Console" + ] + }, + "put": { + "description": "Update policy config by group", + "operationId": "updatePolicyConfigByGroup", + "parameters": [ + { + "description": "Name of the policy", + "in": "path", + "name": "name", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "Name of the group", + "in": "path", + "name": "group", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/JsonNode" + } + } + }, + "required": true + }, + "responses": { + "204": { + "description": "No Content" + } + }, + "tags": [ + "PolicyAlpha1Console" + ] + } + }, "/apis/content.halo.run/v1alpha1/categories": { "get": { "description": "List Category", diff --git a/api-docs/openapi/v3_0/apis_console.api_v1alpha1.json b/api-docs/openapi/v3_0/apis_console.api_v1alpha1.json index 52ba4a557..d3d6c3b36 100644 --- a/api-docs/openapi/v3_0/apis_console.api_v1alpha1.json +++ b/api-docs/openapi/v3_0/apis_console.api_v1alpha1.json @@ -3284,6 +3284,89 @@ "UserV1alpha1Console" ] } + }, + "/apis/console.api.storage.halo.run/v1alpha1/policies/{name}/configs/{group}": { + "get": { + "description": "Get policy config by group", + "operationId": "getPolicyConfigByGroup", + "parameters": [ + { + "description": "Name of the policy", + "in": "path", + "name": "name", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "Name of the group", + "in": "path", + "name": "group", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "default": { + "content": { + "*/*": { + "schema": { + "$ref": "#/components/schemas/JsonNode" + } + } + }, + "description": "default response" + } + }, + "tags": [ + "PolicyAlpha1Console" + ] + }, + "put": { + "description": "Update policy config by group", + "operationId": "updatePolicyConfigByGroup", + "parameters": [ + { + "description": "Name of the policy", + "in": "path", + "name": "name", + "required": true, + "schema": { + "type": "string" + } + }, + { + "description": "Name of the group", + "in": "path", + "name": "group", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/JsonNode" + } + } + }, + "required": true + }, + "responses": { + "204": { + "description": "No Content" + } + }, + "tags": [ + "PolicyAlpha1Console" + ] + } } }, "components": { @@ -4326,6 +4409,9 @@ } } }, + "JsonNode": { + "type": "object" + }, "JsonPatch": { "minItems": 1, "uniqueItems": true, diff --git a/application/src/main/java/run/halo/app/core/attachment/endpoint/PolicyEndpoint.java b/application/src/main/java/run/halo/app/core/attachment/endpoint/PolicyEndpoint.java new file mode 100644 index 000000000..bb118f102 --- /dev/null +++ b/application/src/main/java/run/halo/app/core/attachment/endpoint/PolicyEndpoint.java @@ -0,0 +1,183 @@ +package run.halo.app.core.attachment.endpoint; + +import static org.springdoc.core.fn.builders.apiresponse.Builder.responseBuilder; +import static org.springdoc.core.fn.builders.parameter.Builder.parameterBuilder; +import static org.springdoc.core.fn.builders.requestbody.Builder.requestBodyBuilder; +import static org.springframework.http.HttpStatus.NO_CONTENT; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import io.swagger.v3.oas.annotations.enums.ParameterIn; +import java.util.HashMap; +import java.util.Objects; +import org.springdoc.webflux.core.fn.SpringdocRouteBuilder; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.transaction.ReactiveTransactionManager; +import org.springframework.transaction.reactive.TransactionalOperator; +import org.springframework.util.StringUtils; +import org.springframework.web.reactive.function.server.RequestPredicates; +import org.springframework.web.reactive.function.server.RouterFunction; +import org.springframework.web.reactive.function.server.ServerRequest; +import org.springframework.web.reactive.function.server.ServerResponse; +import org.springframework.web.server.ServerWebInputException; +import reactor.core.publisher.Mono; +import run.halo.app.core.extension.attachment.Policy; +import run.halo.app.core.extension.endpoint.CustomEndpoint; +import run.halo.app.extension.ConfigMap; +import run.halo.app.extension.GroupVersion; +import run.halo.app.extension.Metadata; +import run.halo.app.extension.ReactiveExtensionClient; + +@Component +class PolicyEndpoint implements CustomEndpoint { + + private final ReactiveExtensionClient client; + + private final ObjectMapper mapper; + + private final ReactiveTransactionManager txManager; + + PolicyEndpoint(ReactiveExtensionClient client, ObjectMapper mapper, + ReactiveTransactionManager txManager) { + this.client = client; + this.mapper = mapper; + this.txManager = txManager; + } + + @Override + public RouterFunction endpoint() { + var tag = "PolicyAlpha1Console"; + return SpringdocRouteBuilder.route() + .GET( + "/policies/{name}/configs/{group}", + this::getPolicyConfigByGroup, + builder -> builder.operationId("getPolicyConfigByGroup") + .description("Get policy config by group") + .tag(tag) + .parameter(parameterBuilder() + .in(ParameterIn.PATH) + .name("name") + .description("Name of the policy") + .required(true) + .implementation(String.class) + ) + .parameter(parameterBuilder() + .in(ParameterIn.PATH) + .name("group") + .description("Name of the group") + .required(true) + .implementation(String.class) + ) + .response(responseBuilder().implementation(JsonNode.class)) + ) + .PUT( + "/policies/{name}/configs/{group}", + RequestPredicates.contentType(MediaType.APPLICATION_JSON), + this::updatePolicyConfigByGroup, + builder -> builder.operationId("updatePolicyConfigByGroup") + .description("Update policy config by group") + .tag(tag) + .parameter(parameterBuilder() + .in(ParameterIn.PATH) + .name("name") + .description("Name of the policy") + .required(true) + .implementation(String.class) + ) + .parameter(parameterBuilder() + .in(ParameterIn.PATH) + .name("group") + .description("Name of the group") + .required(true) + .implementation(String.class) + ) + .requestBody( + requestBodyBuilder().required(true).implementation(JsonNode.class)) + .response( + responseBuilder().responseCode(String.valueOf(NO_CONTENT.value())) + ) + ) + .build(); + } + + private Mono updatePolicyConfigByGroup(ServerRequest serverRequest) { + var policyName = serverRequest.pathVariable("name"); + var configGroup = serverRequest.pathVariable("group"); + return serverRequest.bodyToMono(JsonNode.class) + .switchIfEmpty(Mono.error(() -> new ServerWebInputException( + "Request body is required.") + )) + .flatMap(jsonNode -> { + var tx = TransactionalOperator.create(txManager); + return client.get(Policy.class, policyName) + .flatMap(policy -> Mono.justOrEmpty(policy.getSpec()) + .mapNotNull(Policy.PolicySpec::getConfigMapName) + .filter(StringUtils::hasText) + .flatMap(cmName -> client.fetch(ConfigMap.class, cmName)) + .switchIfEmpty(Mono.fromSupplier(() -> { + // create a new configmap + var cm = new ConfigMap(); + cm.setMetadata(new Metadata()); + cm.getMetadata().setGenerateName(policyName + "-config-"); + return cm; + })) + .flatMap(cm -> Mono.fromCallable(() -> { + if (cm.getData() == null) { + cm.setData(new HashMap<>()); + } + var oldJson = cm.getData().get(configGroup); + if (StringUtils.hasText(oldJson) + && Objects.equals(jsonNode, mapper.readTree(oldJson))) { + // skip if no change + return null; + } + var newJson = mapper.writeValueAsString(jsonNode); + cm.getData().put(configGroup, newJson); + return cm; + })) + .flatMap(cm -> { + if (cm.getMetadata().getVersion() != null) { + return client.update(cm); + } + return client.create(cm); + }) + .flatMap(cm -> { + var cmName = cm.getMetadata().getName(); + if (policy.getSpec() != null + && Objects.equals(policy.getSpec().getConfigMapName(), cmName)) { + return Mono.just(cm); + } + if (policy.getSpec() == null) { + policy.setSpec(new Policy.PolicySpec()); + } + policy.getSpec().setConfigMapName(cmName); + return client.update(policy); + }) + ) + .as(tx::transactional); + }) + .then(ServerResponse.noContent().build()); + } + + private Mono getPolicyConfigByGroup(ServerRequest serverRequest) { + var policyName = serverRequest.pathVariable("name"); + var configGroup = serverRequest.pathVariable("group"); + + return client.get(Policy.class, policyName) + .filter(p -> p.getSpec() != null) + .map(p -> p.getSpec().getConfigMapName()) + .filter(StringUtils::hasText) + .flatMap(cmName -> client.fetch(ConfigMap.class, cmName)) + .filter(cm -> cm.getData() != null && cm.getData().containsKey(configGroup)) + .map(cm -> cm.getData().get(configGroup)) + .flatMap(json -> Mono.fromCallable(() -> mapper.readTree(json))) + .defaultIfEmpty(mapper.nullNode()) + .flatMap(config -> ServerResponse.ok().bodyValue(config)); + } + + @Override + public GroupVersion groupVersion() { + return GroupVersion.parseAPIVersion("console.api.storage.halo.run/v1alpha1"); + } +} diff --git a/application/src/main/java/run/halo/app/extension/exception/ExtensionNotFoundException.java b/application/src/main/java/run/halo/app/extension/exception/ExtensionNotFoundException.java index a298704fe..cacdbd9d8 100644 --- a/application/src/main/java/run/halo/app/extension/exception/ExtensionNotFoundException.java +++ b/application/src/main/java/run/halo/app/extension/exception/ExtensionNotFoundException.java @@ -1,13 +1,18 @@ package run.halo.app.extension.exception; +import java.net.URI; import org.springframework.http.HttpStatus; import run.halo.app.extension.GroupVersionKind; public class ExtensionNotFoundException extends ExtensionException { + public static final URI TYPE = + URI.create("https://www.halo.run/api/errors/extension-not-found"); + public ExtensionNotFoundException(GroupVersionKind gvk, String name) { super(HttpStatus.NOT_FOUND, "Extension " + gvk + "/" + name + " was not found.", null, null, new Object[] {gvk, name}); + setType(TYPE); } } diff --git a/application/src/test/java/run/halo/app/core/attachment/endpoint/PolicyEndpointTest.java b/application/src/test/java/run/halo/app/core/attachment/endpoint/PolicyEndpointTest.java new file mode 100644 index 000000000..9b91d27db --- /dev/null +++ b/application/src/test/java/run/halo/app/core/attachment/endpoint/PolicyEndpointTest.java @@ -0,0 +1,230 @@ +package run.halo.app.core.attachment.endpoint; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.assertArg; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.json.JsonMapper; +import java.util.HashMap; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Spy; +import org.mockito.junit.jupiter.MockitoExtension; +import org.skyscreamer.jsonassert.JSONAssert; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; +import org.springframework.transaction.ReactiveTransaction; +import org.springframework.transaction.ReactiveTransactionManager; +import reactor.core.publisher.Mono; +import run.halo.app.core.extension.attachment.Policy; +import run.halo.app.extension.ConfigMap; +import run.halo.app.extension.Metadata; +import run.halo.app.extension.ReactiveExtensionClient; +import run.halo.app.extension.Scheme; +import run.halo.app.extension.exception.ExtensionNotFoundException; + +@ExtendWith(MockitoExtension.class) +class PolicyEndpointTest { + + @Mock + ReactiveExtensionClient client; + + @Spy + ObjectMapper mapper = JsonMapper.builder().build(); + + @Mock + ReactiveTransactionManager txManager; + + @InjectMocks + PolicyEndpoint endpoint; + + WebTestClient webClient; + + @BeforeEach + void setUp() { + webClient = WebTestClient.bindToRouterFunction(endpoint.endpoint()) + .build(); + } + + @Test + void shouldRespondNotFoundIfPolicyNotFound() { + // Implement test logic here + var policyScheme = Scheme.buildFromType(Policy.class); + when(client.get(Policy.class, "fake-policy")) + .thenReturn(Mono.error(() -> new ExtensionNotFoundException( + policyScheme.groupVersionKind(), "fake-policy") + )); + webClient.get().uri("/policies/fake-policy/configs/fake-group") + .exchange() + .expectStatus().isNotFound(); + } + + @Test + void shouldRespondNullIfNoConfigFound() { + when(client.get(Policy.class, "fake-policy")).thenReturn(Mono.fromSupplier(() -> { + var policy = new Policy(); + policy.setSpec(new Policy.PolicySpec()); + policy.getSpec().setConfigMapName("fake-config-map"); + return policy; + })); + + when(client.fetch(ConfigMap.class, "fake-config-map")) + .thenReturn(Mono.empty()); + + webClient.get().uri("/policies/fake-policy/configs/fake-group") + .exchange() + .expectStatus().isOk() + .expectBody(String.class) + .isEqualTo("null"); + } + + @Test + void shouldRespondNullIfGroupNotFound() { + when(client.get(Policy.class, "fake-policy")).thenReturn(Mono.fromSupplier(() -> { + var policy = new Policy(); + policy.setSpec(new Policy.PolicySpec()); + policy.getSpec().setConfigMapName("fake-config-map"); + return policy; + })); + + when(client.fetch(ConfigMap.class, "fake-config-map")) + .thenReturn(Mono.fromSupplier(() -> { + var cm = new ConfigMap(); + cm.setData(new HashMap<>()); + return cm; + })); + + webClient.get().uri("/policies/fake-policy/configs/fake-group") + .exchange() + .expectStatus().isOk() + .expectBody(String.class) + .isEqualTo("null"); + } + + @Test + void shouldRespondConfigIfGroupFound() { + when(client.get(Policy.class, "fake-policy")).thenReturn(Mono.fromSupplier(() -> { + var policy = new Policy(); + policy.setSpec(new Policy.PolicySpec()); + policy.getSpec().setConfigMapName("fake-config-map"); + return policy; + })); + + when(client.fetch(ConfigMap.class, "fake-config-map")) + .thenReturn(Mono.fromSupplier(() -> { + var cm = new ConfigMap(); + cm.setData(new HashMap<>()); + cm.getData().put("fake-group", """ + { + "halo": "awesome" + }"""); + return cm; + })); + + webClient.get().uri("/policies/fake-policy/configs/fake-group") + .exchange() + .expectStatus().isOk() + .expectBody() + .jsonPath("$.halo").isEqualTo("awesome"); + } + + + @Test + void shouldUpdateConfigIfPresent() { + when(client.get(Policy.class, "fake-policy")).thenReturn(Mono.fromSupplier(() -> { + var policy = new Policy(); + policy.setSpec(new Policy.PolicySpec()); + policy.getSpec().setConfigMapName("fake-config-map"); + return policy; + })); + + var cm = new ConfigMap(); + cm.setMetadata(new Metadata()); + cm.getMetadata().setName("fake-config-map"); + cm.getMetadata().setVersion(1L); + cm.setData(new HashMap<>()); + cm.getData().put("fake-group", """ + { + "halo": "awesome" + }"""); + when(client.fetch(ConfigMap.class, "fake-config-map")) + .thenReturn(Mono.just(cm)); + + var tx = mock(ReactiveTransaction.class); + when(txManager.getReactiveTransaction(any())).thenReturn(Mono.just(tx)); + when(txManager.commit(tx)).thenReturn(Mono.empty()); + + when(client.update(cm)).thenReturn(Mono.just(cm)); + + var body = """ + { + "halo": "nice", + "key": "value" + }"""; + + webClient.put().uri("/policies/fake-policy/configs/fake-group") + .contentType(MediaType.APPLICATION_JSON) + .bodyValue(body) + .exchange() + .expectStatus().isNoContent(); + + verify(client).update(assertArg(gotCm -> { + var data = gotCm.getData(); + JSONAssert.assertEquals(body, data.get("fake-group"), true); + })); + } + + @Test + void shouldCreateConfigIfAbsent() { + var policy = new Policy(); + policy.setSpec(new Policy.PolicySpec()); + when(client.get(Policy.class, "fake-policy")).thenReturn(Mono.just(policy)); + + + var tx = mock(ReactiveTransaction.class); + when(txManager.getReactiveTransaction(any())).thenReturn(Mono.just(tx)); + when(txManager.commit(tx)).thenReturn(Mono.empty()); + + var cm = new ConfigMap(); + cm.setMetadata(new Metadata()); + cm.getMetadata().setName("fake-config-map"); + cm.getMetadata().setVersion(1L); + cm.setData(new HashMap<>()); + cm.getData().put("fake-group", """ + { + "halo": "nice", + "key": "value" + }\ + """); + when(client.create(any(ConfigMap.class))).thenReturn(Mono.just(cm)); + when(client.update(policy)).thenReturn(Mono.just(policy)); + + var body = """ + { + "halo": "nice", + "key": "value" + }"""; + + webClient.put().uri("/policies/fake-policy/configs/fake-group") + .contentType(MediaType.APPLICATION_JSON) + .bodyValue(body) + .exchange() + .expectStatus().isNoContent(); + + verify(client).create(assertArg(gotCm -> { + var data = gotCm.getData(); + JSONAssert.assertEquals(body, data.get("fake-group"), true); + })); + + verify(client).update(assertArg( + gotPolicy -> assertEquals("fake-config-map", gotPolicy.getSpec().getConfigMapName()) + )); + } +} diff --git a/ui/packages/api-client/entry/api-client.ts b/ui/packages/api-client/entry/api-client.ts index 4834fa280..ed994c7c2 100644 --- a/ui/packages/api-client/entry/api-client.ts +++ b/ui/packages/api-client/entry/api-client.ts @@ -66,6 +66,7 @@ import { UserV1alpha1Api, UserV1alpha1ConsoleApi, UserPreferenceV1alpha1UcApi, + PolicyAlpha1ConsoleApi, } from "../src"; const defaultAxiosInstance = axios.create({ @@ -281,6 +282,7 @@ function createConsoleApiClient(axiosInstance: AxiosInstance) { baseURL, axiosInstance ), + policy: new PolicyAlpha1ConsoleApi(undefined, baseURL, axiosInstance), }, auth: { authProvider: new AuthProviderV1alpha1ConsoleApi( diff --git a/ui/packages/api-client/src/.openapi-generator/FILES b/ui/packages/api-client/src/.openapi-generator/FILES index 56337f3ef..677de08db 100644 --- a/ui/packages/api-client/src/.openapi-generator/FILES +++ b/ui/packages/api-client/src/.openapi-generator/FILES @@ -42,6 +42,7 @@ api/personal-access-token-v1alpha1-uc-api.ts api/plugin-v1alpha1-api.ts api/plugin-v1alpha1-console-api.ts api/plugin-v1alpha1-public-api.ts +api/policy-alpha1-console-api.ts api/policy-template-v1alpha1-api.ts api/policy-v1alpha1-api.ts api/post-v1alpha1-api.ts diff --git a/ui/packages/api-client/src/api.ts b/ui/packages/api-client/src/api.ts index 76699bb42..17994c755 100644 --- a/ui/packages/api-client/src/api.ts +++ b/ui/packages/api-client/src/api.ts @@ -54,6 +54,7 @@ export * from './api/personal-access-token-v1alpha1-uc-api'; export * from './api/plugin-v1alpha1-api'; export * from './api/plugin-v1alpha1-console-api'; export * from './api/plugin-v1alpha1-public-api'; +export * from './api/policy-alpha1-console-api'; export * from './api/policy-template-v1alpha1-api'; export * from './api/policy-v1alpha1-api'; export * from './api/post-v1alpha1-api'; diff --git a/ui/packages/api-client/src/api/policy-alpha1-console-api.ts b/ui/packages/api-client/src/api/policy-alpha1-console-api.ts new file mode 100644 index 000000000..1014a56e5 --- /dev/null +++ b/ui/packages/api-client/src/api/policy-alpha1-console-api.ts @@ -0,0 +1,272 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Halo + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 2.21.0-SNAPSHOT + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + + +import type { Configuration } from '../configuration'; +import type { AxiosPromise, AxiosInstance, RawAxiosRequestConfig } from 'axios'; +import globalAxios from 'axios'; +// Some imports not used depending on template conditions +// @ts-ignore +import { DUMMY_BASE_URL, assertParamExists, setApiKeyToObject, setBasicAuthToObject, setBearerAuthToObject, setOAuthToObject, setSearchParams, serializeDataIfNeeded, toPathString, createRequestFunction } from '../common'; +// @ts-ignore +import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError, operationServerMap } from '../base'; +/** + * PolicyAlpha1ConsoleApi - axios parameter creator + * @export + */ +export const PolicyAlpha1ConsoleApiAxiosParamCreator = function (configuration?: Configuration) { + return { + /** + * Get policy config by group + * @param {string} name Name of the policy + * @param {string} group Name of the group + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getPolicyConfigByGroup: async (name: string, group: string, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists('getPolicyConfigByGroup', 'name', name) + // verify required parameter 'group' is not null or undefined + assertParamExists('getPolicyConfigByGroup', 'group', group) + const localVarPath = `/apis/console.api.storage.halo.run/v1alpha1/policies/{name}/configs/{group}` + .replace(`{${"name"}}`, encodeURIComponent(String(name))) + .replace(`{${"group"}}`, encodeURIComponent(String(group))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication basicAuth required + // http basic authentication required + setBasicAuthToObject(localVarRequestOptions, configuration) + + // authentication bearerAuth required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Update policy config by group + * @param {string} name Name of the policy + * @param {string} group Name of the group + * @param {object} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updatePolicyConfigByGroup: async (name: string, group: string, body: object, options: RawAxiosRequestConfig = {}): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists('updatePolicyConfigByGroup', 'name', name) + // verify required parameter 'group' is not null or undefined + assertParamExists('updatePolicyConfigByGroup', 'group', group) + // verify required parameter 'body' is not null or undefined + assertParamExists('updatePolicyConfigByGroup', 'body', body) + const localVarPath = `/apis/console.api.storage.halo.run/v1alpha1/policies/{name}/configs/{group}` + .replace(`{${"name"}}`, encodeURIComponent(String(name))) + .replace(`{${"group"}}`, encodeURIComponent(String(group))); + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'PUT', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + // authentication basicAuth required + // http basic authentication required + setBasicAuthToObject(localVarRequestOptions, configuration) + + // authentication bearerAuth required + // http bearer authentication required + await setBearerAuthToObject(localVarHeaderParameter, configuration) + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(body, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + } +}; + +/** + * PolicyAlpha1ConsoleApi - functional programming interface + * @export + */ +export const PolicyAlpha1ConsoleApiFp = function(configuration?: Configuration) { + const localVarAxiosParamCreator = PolicyAlpha1ConsoleApiAxiosParamCreator(configuration) + return { + /** + * Get policy config by group + * @param {string} name Name of the policy + * @param {string} group Name of the group + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getPolicyConfigByGroup(name: string, group: string, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.getPolicyConfigByGroup(name, group, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['PolicyAlpha1ConsoleApi.getPolicyConfigByGroup']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + /** + * Update policy config by group + * @param {string} name Name of the policy + * @param {string} group Name of the group + * @param {object} body + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async updatePolicyConfigByGroup(name: string, group: string, body: object, options?: RawAxiosRequestConfig): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.updatePolicyConfigByGroup(name, group, body, options); + const localVarOperationServerIndex = configuration?.serverIndex ?? 0; + const localVarOperationServerBasePath = operationServerMap['PolicyAlpha1ConsoleApi.updatePolicyConfigByGroup']?.[localVarOperationServerIndex]?.url; + return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath); + }, + } +}; + +/** + * PolicyAlpha1ConsoleApi - factory interface + * @export + */ +export const PolicyAlpha1ConsoleApiFactory = function (configuration?: Configuration, basePath?: string, axios?: AxiosInstance) { + const localVarFp = PolicyAlpha1ConsoleApiFp(configuration) + return { + /** + * Get policy config by group + * @param {PolicyAlpha1ConsoleApiGetPolicyConfigByGroupRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getPolicyConfigByGroup(requestParameters: PolicyAlpha1ConsoleApiGetPolicyConfigByGroupRequest, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.getPolicyConfigByGroup(requestParameters.name, requestParameters.group, options).then((request) => request(axios, basePath)); + }, + /** + * Update policy config by group + * @param {PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroupRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updatePolicyConfigByGroup(requestParameters: PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroupRequest, options?: RawAxiosRequestConfig): AxiosPromise { + return localVarFp.updatePolicyConfigByGroup(requestParameters.name, requestParameters.group, requestParameters.body, options).then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * Request parameters for getPolicyConfigByGroup operation in PolicyAlpha1ConsoleApi. + * @export + * @interface PolicyAlpha1ConsoleApiGetPolicyConfigByGroupRequest + */ +export interface PolicyAlpha1ConsoleApiGetPolicyConfigByGroupRequest { + /** + * Name of the policy + * @type {string} + * @memberof PolicyAlpha1ConsoleApiGetPolicyConfigByGroup + */ + readonly name: string + + /** + * Name of the group + * @type {string} + * @memberof PolicyAlpha1ConsoleApiGetPolicyConfigByGroup + */ + readonly group: string +} + +/** + * Request parameters for updatePolicyConfigByGroup operation in PolicyAlpha1ConsoleApi. + * @export + * @interface PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroupRequest + */ +export interface PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroupRequest { + /** + * Name of the policy + * @type {string} + * @memberof PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroup + */ + readonly name: string + + /** + * Name of the group + * @type {string} + * @memberof PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroup + */ + readonly group: string + + /** + * + * @type {object} + * @memberof PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroup + */ + readonly body: object +} + +/** + * PolicyAlpha1ConsoleApi - object-oriented interface + * @export + * @class PolicyAlpha1ConsoleApi + * @extends {BaseAPI} + */ +export class PolicyAlpha1ConsoleApi extends BaseAPI { + /** + * Get policy config by group + * @param {PolicyAlpha1ConsoleApiGetPolicyConfigByGroupRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PolicyAlpha1ConsoleApi + */ + public getPolicyConfigByGroup(requestParameters: PolicyAlpha1ConsoleApiGetPolicyConfigByGroupRequest, options?: RawAxiosRequestConfig) { + return PolicyAlpha1ConsoleApiFp(this.configuration).getPolicyConfigByGroup(requestParameters.name, requestParameters.group, options).then((request) => request(this.axios, this.basePath)); + } + + /** + * Update policy config by group + * @param {PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroupRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof PolicyAlpha1ConsoleApi + */ + public updatePolicyConfigByGroup(requestParameters: PolicyAlpha1ConsoleApiUpdatePolicyConfigByGroupRequest, options?: RawAxiosRequestConfig) { + return PolicyAlpha1ConsoleApiFp(this.configuration).updatePolicyConfigByGroup(requestParameters.name, requestParameters.group, requestParameters.body, options).then((request) => request(this.axios, this.basePath)); + } +} +