From 1e1285e572a815b3b4488bcab269daf142adccd7 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Fri, 22 Sep 2023 12:00:19 +0800 Subject: [PATCH] Support managing PAT at console --- .../api-client/src/.openapi-generator/FILES | 5 +- console/packages/api-client/src/api.ts | 3 +- ...-run-v1alpha1-personal-access-token-api.ts | 808 +++++++++++++++++ ...-run-v1alpha1-personal-access-token-api.ts | 846 ++++++++++++++++++ .../packages/api-client/src/models/index.ts | 2 +- .../api-client/src/models/pat-spec.ts | 81 ++ .../src/models/personal-access-token.ts | 6 +- .../api-client/src/models/user-permission.ts | 6 + console/src/constants/annotations.ts | 5 + console/src/locales/en.yaml | 41 + console/src/locales/zh-CN.yaml | 41 + console/src/locales/zh-TW.yaml | 41 + .../src/modules/system/roles/RoleDetail.vue | 15 +- .../roles/components/RoleEditingModal.vue | 18 +- .../system/roles/composables/use-role.ts | 29 +- .../system/users/PersonalAccessTokens.vue | 361 ++------ .../PersonalAccessTokenCreationModal.vue | 279 ++++++ .../PersonalAccessTokenListItem.vue | 149 +++ .../users/layouts/UserProfileLayout.vue | 33 +- console/src/stores/role.ts | 1 + console/src/utils/api-client.ts | 18 +- console/vite.config.ts | 6 +- 22 files changed, 2466 insertions(+), 328 deletions(-) create mode 100644 console/packages/api-client/src/api/api-console-security-halo-run-v1alpha1-personal-access-token-api.ts create mode 100644 console/packages/api-client/src/api/security-halo-run-v1alpha1-personal-access-token-api.ts create mode 100644 console/packages/api-client/src/models/pat-spec.ts create mode 100644 console/src/modules/system/users/components/PersonalAccessTokenCreationModal.vue create mode 100644 console/src/modules/system/users/components/PersonalAccessTokenListItem.vue diff --git a/console/packages/api-client/src/.openapi-generator/FILES b/console/packages/api-client/src/.openapi-generator/FILES index c0989d7452..54693000ea 100644 --- a/console/packages/api-client/src/.openapi-generator/FILES +++ b/console/packages/api-client/src/.openapi-generator/FILES @@ -14,6 +14,7 @@ api/api-console-halo-run-v1alpha1-system-api.ts api/api-console-halo-run-v1alpha1-theme-api.ts api/api-console-halo-run-v1alpha1-user-api.ts api/api-console-migration-halo-run-v1alpha1-migration-api.ts +api/api-console-security-halo-run-v1alpha1-personal-access-token-api.ts api/api-content-halo-run-v1alpha1-category-api.ts api/api-content-halo-run-v1alpha1-post-api.ts api/api-content-halo-run-v1alpha1-single-page-api.ts @@ -42,6 +43,7 @@ api/plugin-halo-run-v1alpha1-extension-point-definition-api.ts api/plugin-halo-run-v1alpha1-plugin-api.ts api/plugin-halo-run-v1alpha1-reverse-proxy-api.ts api/plugin-halo-run-v1alpha1-search-engine-api.ts +api/security-halo-run-v1alpha1-personal-access-token-api.ts api/storage-halo-run-v1alpha1-attachment-api.ts api/storage-halo-run-v1alpha1-group-api.ts api/storage-halo-run-v1alpha1-policy-api.ts @@ -52,7 +54,6 @@ api/v1alpha1-cache-api.ts api/v1alpha1-config-map-api.ts api/v1alpha1-menu-api.ts api/v1alpha1-menu-item-api.ts -api/v1alpha1-personal-access-token-api.ts api/v1alpha1-role-api.ts api/v1alpha1-role-binding-api.ts api/v1alpha1-secret-api.ts @@ -157,8 +158,8 @@ models/menu.ts models/metadata.ts models/navigation-post-vo.ts models/owner-info.ts +models/pat-spec.ts models/personal-access-token-list.ts -models/personal-access-token-spec.ts models/personal-access-token.ts models/plugin-author.ts models/plugin-list.ts diff --git a/console/packages/api-client/src/api.ts b/console/packages/api-client/src/api.ts index e7f9b9a08c..23a8c25752 100644 --- a/console/packages/api-client/src/api.ts +++ b/console/packages/api-client/src/api.ts @@ -25,6 +25,7 @@ export * from "./api/api-console-halo-run-v1alpha1-system-api"; export * from "./api/api-console-halo-run-v1alpha1-theme-api"; export * from "./api/api-console-halo-run-v1alpha1-user-api"; export * from "./api/api-console-migration-halo-run-v1alpha1-migration-api"; +export * from "./api/api-console-security-halo-run-v1alpha1-personal-access-token-api"; export * from "./api/api-content-halo-run-v1alpha1-category-api"; export * from "./api/api-content-halo-run-v1alpha1-post-api"; export * from "./api/api-content-halo-run-v1alpha1-single-page-api"; @@ -53,6 +54,7 @@ export * from "./api/plugin-halo-run-v1alpha1-extension-point-definition-api"; export * from "./api/plugin-halo-run-v1alpha1-plugin-api"; export * from "./api/plugin-halo-run-v1alpha1-reverse-proxy-api"; export * from "./api/plugin-halo-run-v1alpha1-search-engine-api"; +export * from "./api/security-halo-run-v1alpha1-personal-access-token-api"; export * from "./api/storage-halo-run-v1alpha1-attachment-api"; export * from "./api/storage-halo-run-v1alpha1-group-api"; export * from "./api/storage-halo-run-v1alpha1-policy-api"; @@ -63,7 +65,6 @@ export * from "./api/v1alpha1-cache-api"; export * from "./api/v1alpha1-config-map-api"; export * from "./api/v1alpha1-menu-api"; export * from "./api/v1alpha1-menu-item-api"; -export * from "./api/v1alpha1-personal-access-token-api"; export * from "./api/v1alpha1-role-api"; export * from "./api/v1alpha1-role-binding-api"; export * from "./api/v1alpha1-secret-api"; diff --git a/console/packages/api-client/src/api/api-console-security-halo-run-v1alpha1-personal-access-token-api.ts b/console/packages/api-client/src/api/api-console-security-halo-run-v1alpha1-personal-access-token-api.ts new file mode 100644 index 0000000000..2bb9e7e0bf --- /dev/null +++ b/console/packages/api-client/src/api/api-console-security-halo-run-v1alpha1-personal-access-token-api.ts @@ -0,0 +1,808 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Halo Next API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 2.0.0 + * + * + * 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, AxiosRequestConfig } 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, +} from "../base"; +// @ts-ignore +import { PersonalAccessToken } from "../models"; +/** + * ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi - axios parameter creator + * @export + */ +export const ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiAxiosParamCreator = + function (configuration?: Configuration) { + return { + /** + * Delete a PAT + * @param {string} name + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + deletePat: async ( + name: string, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists("deletePat", "name", name); + const localVarPath = + `/apis/api.security.halo.run/v1alpha1/users/-/personalaccesstokens/{name}`.replace( + `{${"name"}}`, + encodeURIComponent(String(name)) + ); + // 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: "DELETE", + ...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, + }; + }, + /** + * Generate a PAT. + * @param {PersonalAccessToken} personalAccessToken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + generatePat: async ( + personalAccessToken: PersonalAccessToken, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'personalAccessToken' is not null or undefined + assertParamExists( + "generatePat", + "personalAccessToken", + personalAccessToken + ); + const localVarPath = `/apis/api.security.halo.run/v1alpha1/users/-/personalaccesstokens`; + // 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: "POST", + ...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( + personalAccessToken, + localVarRequestOptions, + configuration + ); + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Obtain a PAT. + * @param {string} name + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + obtainPat: async ( + name: string, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists("obtainPat", "name", name); + const localVarPath = + `/apis/api.security.halo.run/v1alpha1/users/-/personalaccesstokens/{name}`.replace( + `{${"name"}}`, + encodeURIComponent(String(name)) + ); + // 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, + }; + }, + /** + * Obtain PAT list. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + obtainPats: async ( + options: AxiosRequestConfig = {} + ): Promise => { + const localVarPath = `/apis/api.security.halo.run/v1alpha1/users/-/personalaccesstokens`; + // 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, + }; + }, + /** + * Restore a PAT. + * @param {string} name + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + restorePat: async ( + name: string, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists("restorePat", "name", name); + const localVarPath = + `/apis/api.security.halo.run/v1alpha1/users/-/personalaccesstokens/{name}/actions/restoration`.replace( + `{${"name"}}`, + encodeURIComponent(String(name)) + ); + // 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); + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Revoke a PAT + * @param {string} name + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + revokePat: async ( + name: string, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists("revokePat", "name", name); + const localVarPath = + `/apis/api.security.halo.run/v1alpha1/users/-/personalaccesstokens/{name}/actions/revocation`.replace( + `{${"name"}}`, + encodeURIComponent(String(name)) + ); + // 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); + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + }; + }; + +/** + * ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi - functional programming interface + * @export + */ +export const ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp = + function (configuration?: Configuration) { + const localVarAxiosParamCreator = + ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiAxiosParamCreator( + configuration + ); + return { + /** + * Delete a PAT + * @param {string} name + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async deletePat( + name: string, + options?: AxiosRequestConfig + ): Promise< + (axios?: AxiosInstance, basePath?: string) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.deletePat( + name, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * Generate a PAT. + * @param {PersonalAccessToken} personalAccessToken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async generatePat( + personalAccessToken: PersonalAccessToken, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.generatePat( + personalAccessToken, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * Obtain a PAT. + * @param {string} name + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async obtainPat( + name: string, + options?: AxiosRequestConfig + ): Promise< + (axios?: AxiosInstance, basePath?: string) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.obtainPat( + name, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * Obtain PAT list. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async obtainPats( + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise> + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.obtainPats( + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * Restore a PAT. + * @param {string} name + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async restorePat( + name: string, + options?: AxiosRequestConfig + ): Promise< + (axios?: AxiosInstance, basePath?: string) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.restorePat( + name, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * Revoke a PAT + * @param {string} name + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async revokePat( + name: string, + options?: AxiosRequestConfig + ): Promise< + (axios?: AxiosInstance, basePath?: string) => AxiosPromise + > { + const localVarAxiosArgs = await localVarAxiosParamCreator.revokePat( + name, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + }; + }; + +/** + * ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi - factory interface + * @export + */ +export const ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFactory = + function ( + configuration?: Configuration, + basePath?: string, + axios?: AxiosInstance + ) { + const localVarFp = + ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp(configuration); + return { + /** + * Delete a PAT + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiDeletePatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + deletePat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiDeletePatRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .deletePat(requestParameters.name, options) + .then((request) => request(axios, basePath)); + }, + /** + * Generate a PAT. + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiGeneratePatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + generatePat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiGeneratePatRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .generatePat(requestParameters.personalAccessToken, options) + .then((request) => request(axios, basePath)); + }, + /** + * Obtain a PAT. + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiObtainPatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + obtainPat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiObtainPatRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .obtainPat(requestParameters.name, options) + .then((request) => request(axios, basePath)); + }, + /** + * Obtain PAT list. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + obtainPats( + options?: AxiosRequestConfig + ): AxiosPromise> { + return localVarFp + .obtainPats(options) + .then((request) => request(axios, basePath)); + }, + /** + * Restore a PAT. + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRestorePatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + restorePat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRestorePatRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .restorePat(requestParameters.name, options) + .then((request) => request(axios, basePath)); + }, + /** + * Revoke a PAT + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRevokePatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + revokePat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRevokePatRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .revokePat(requestParameters.name, options) + .then((request) => request(axios, basePath)); + }, + }; + }; + +/** + * Request parameters for deletePat operation in ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiDeletePatRequest + */ +export interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiDeletePatRequest { + /** + * + * @type {string} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiDeletePat + */ + readonly name: string; +} + +/** + * Request parameters for generatePat operation in ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiGeneratePatRequest + */ +export interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiGeneratePatRequest { + /** + * + * @type {PersonalAccessToken} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiGeneratePat + */ + readonly personalAccessToken: PersonalAccessToken; +} + +/** + * Request parameters for obtainPat operation in ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiObtainPatRequest + */ +export interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiObtainPatRequest { + /** + * + * @type {string} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiObtainPat + */ + readonly name: string; +} + +/** + * Request parameters for restorePat operation in ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRestorePatRequest + */ +export interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRestorePatRequest { + /** + * + * @type {string} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRestorePat + */ + readonly name: string; +} + +/** + * Request parameters for revokePat operation in ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRevokePatRequest + */ +export interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRevokePatRequest { + /** + * + * @type {string} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRevokePat + */ + readonly name: string; +} + +/** + * ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi - object-oriented interface + * @export + * @class ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi + * @extends {BaseAPI} + */ +export class ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi extends BaseAPI { + /** + * Delete a PAT + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiDeletePatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public deletePat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiDeletePatRequest, + options?: AxiosRequestConfig + ) { + return ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp( + this.configuration + ) + .deletePat(requestParameters.name, options) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Generate a PAT. + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiGeneratePatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public generatePat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiGeneratePatRequest, + options?: AxiosRequestConfig + ) { + return ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp( + this.configuration + ) + .generatePat(requestParameters.personalAccessToken, options) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Obtain a PAT. + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiObtainPatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public obtainPat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiObtainPatRequest, + options?: AxiosRequestConfig + ) { + return ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp( + this.configuration + ) + .obtainPat(requestParameters.name, options) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Obtain PAT list. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public obtainPats(options?: AxiosRequestConfig) { + return ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp( + this.configuration + ) + .obtainPats(options) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Restore a PAT. + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRestorePatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public restorePat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRestorePatRequest, + options?: AxiosRequestConfig + ) { + return ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp( + this.configuration + ) + .restorePat(requestParameters.name, options) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Revoke a PAT + * @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRevokePatRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public revokePat( + requestParameters: ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRevokePatRequest, + options?: AxiosRequestConfig + ) { + return ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp( + this.configuration + ) + .revokePat(requestParameters.name, options) + .then((request) => request(this.axios, this.basePath)); + } +} diff --git a/console/packages/api-client/src/api/security-halo-run-v1alpha1-personal-access-token-api.ts b/console/packages/api-client/src/api/security-halo-run-v1alpha1-personal-access-token-api.ts new file mode 100644 index 0000000000..9f1ef7c44d --- /dev/null +++ b/console/packages/api-client/src/api/security-halo-run-v1alpha1-personal-access-token-api.ts @@ -0,0 +1,846 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Halo Next API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 2.0.0 + * + * + * 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, AxiosRequestConfig } 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, +} from "../base"; +// @ts-ignore +import { PersonalAccessToken } from "../models"; +// @ts-ignore +import { PersonalAccessTokenList } from "../models"; +/** + * SecurityHaloRunV1alpha1PersonalAccessTokenApi - axios parameter creator + * @export + */ +export const SecurityHaloRunV1alpha1PersonalAccessTokenApiAxiosParamCreator = + function (configuration?: Configuration) { + return { + /** + * Create security.halo.run/v1alpha1/PersonalAccessToken + * @param {PersonalAccessToken} [personalAccessToken] Fresh personalaccesstoken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createsecurityHaloRunV1alpha1PersonalAccessToken: async ( + personalAccessToken?: PersonalAccessToken, + options: AxiosRequestConfig = {} + ): Promise => { + const localVarPath = `/apis/security.halo.run/v1alpha1/personalaccesstokens`; + // 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: "POST", + ...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( + personalAccessToken, + localVarRequestOptions, + configuration + ); + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Delete security.halo.run/v1alpha1/PersonalAccessToken + * @param {string} name Name of personalaccesstoken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + deletesecurityHaloRunV1alpha1PersonalAccessToken: async ( + name: string, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists( + "deletesecurityHaloRunV1alpha1PersonalAccessToken", + "name", + name + ); + const localVarPath = + `/apis/security.halo.run/v1alpha1/personalaccesstokens/{name}`.replace( + `{${"name"}}`, + encodeURIComponent(String(name)) + ); + // 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: "DELETE", + ...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, + }; + }, + /** + * Get security.halo.run/v1alpha1/PersonalAccessToken + * @param {string} name Name of personalaccesstoken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getsecurityHaloRunV1alpha1PersonalAccessToken: async ( + name: string, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists( + "getsecurityHaloRunV1alpha1PersonalAccessToken", + "name", + name + ); + const localVarPath = + `/apis/security.halo.run/v1alpha1/personalaccesstokens/{name}`.replace( + `{${"name"}}`, + encodeURIComponent(String(name)) + ); + // 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, + }; + }, + /** + * List security.halo.run/v1alpha1/PersonalAccessToken + * @param {Array} [fieldSelector] Field selector for filtering. + * @param {Array} [labelSelector] Label selector for filtering. + * @param {number} [page] The page number. Zero indicates no page. + * @param {number} [size] Size of one page. Zero indicates no limit. + * @param {Array} [sort] Sort property and direction of the list result. Support sorting based on attribute name path. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listsecurityHaloRunV1alpha1PersonalAccessToken: async ( + fieldSelector?: Array, + labelSelector?: Array, + page?: number, + size?: number, + sort?: Array, + options: AxiosRequestConfig = {} + ): Promise => { + const localVarPath = `/apis/security.halo.run/v1alpha1/personalaccesstokens`; + // 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); + + if (fieldSelector) { + localVarQueryParameter["fieldSelector"] = fieldSelector; + } + + if (labelSelector) { + localVarQueryParameter["labelSelector"] = labelSelector; + } + + if (page !== undefined) { + localVarQueryParameter["page"] = page; + } + + if (size !== undefined) { + localVarQueryParameter["size"] = size; + } + + if (sort) { + localVarQueryParameter["sort"] = Array.from(sort); + } + + setSearchParams(localVarUrlObj, localVarQueryParameter); + let headersFromBaseOptions = + baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = { + ...localVarHeaderParameter, + ...headersFromBaseOptions, + ...options.headers, + }; + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + /** + * Update security.halo.run/v1alpha1/PersonalAccessToken + * @param {string} name Name of personalaccesstoken + * @param {PersonalAccessToken} [personalAccessToken] Updated personalaccesstoken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updatesecurityHaloRunV1alpha1PersonalAccessToken: async ( + name: string, + personalAccessToken?: PersonalAccessToken, + options: AxiosRequestConfig = {} + ): Promise => { + // verify required parameter 'name' is not null or undefined + assertParamExists( + "updatesecurityHaloRunV1alpha1PersonalAccessToken", + "name", + name + ); + const localVarPath = + `/apis/security.halo.run/v1alpha1/personalaccesstokens/{name}`.replace( + `{${"name"}}`, + encodeURIComponent(String(name)) + ); + // 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( + personalAccessToken, + localVarRequestOptions, + configuration + ); + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, + }; + }; + +/** + * SecurityHaloRunV1alpha1PersonalAccessTokenApi - functional programming interface + * @export + */ +export const SecurityHaloRunV1alpha1PersonalAccessTokenApiFp = function ( + configuration?: Configuration +) { + const localVarAxiosParamCreator = + SecurityHaloRunV1alpha1PersonalAccessTokenApiAxiosParamCreator( + configuration + ); + return { + /** + * Create security.halo.run/v1alpha1/PersonalAccessToken + * @param {PersonalAccessToken} [personalAccessToken] Fresh personalaccesstoken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async createsecurityHaloRunV1alpha1PersonalAccessToken( + personalAccessToken?: PersonalAccessToken, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = + await localVarAxiosParamCreator.createsecurityHaloRunV1alpha1PersonalAccessToken( + personalAccessToken, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * Delete security.halo.run/v1alpha1/PersonalAccessToken + * @param {string} name Name of personalaccesstoken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async deletesecurityHaloRunV1alpha1PersonalAccessToken( + name: string, + options?: AxiosRequestConfig + ): Promise< + (axios?: AxiosInstance, basePath?: string) => AxiosPromise + > { + const localVarAxiosArgs = + await localVarAxiosParamCreator.deletesecurityHaloRunV1alpha1PersonalAccessToken( + name, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * Get security.halo.run/v1alpha1/PersonalAccessToken + * @param {string} name Name of personalaccesstoken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async getsecurityHaloRunV1alpha1PersonalAccessToken( + name: string, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = + await localVarAxiosParamCreator.getsecurityHaloRunV1alpha1PersonalAccessToken( + name, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * List security.halo.run/v1alpha1/PersonalAccessToken + * @param {Array} [fieldSelector] Field selector for filtering. + * @param {Array} [labelSelector] Label selector for filtering. + * @param {number} [page] The page number. Zero indicates no page. + * @param {number} [size] Size of one page. Zero indicates no limit. + * @param {Array} [sort] Sort property and direction of the list result. Support sorting based on attribute name path. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async listsecurityHaloRunV1alpha1PersonalAccessToken( + fieldSelector?: Array, + labelSelector?: Array, + page?: number, + size?: number, + sort?: Array, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = + await localVarAxiosParamCreator.listsecurityHaloRunV1alpha1PersonalAccessToken( + fieldSelector, + labelSelector, + page, + size, + sort, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + /** + * Update security.halo.run/v1alpha1/PersonalAccessToken + * @param {string} name Name of personalaccesstoken + * @param {PersonalAccessToken} [personalAccessToken] Updated personalaccesstoken + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async updatesecurityHaloRunV1alpha1PersonalAccessToken( + name: string, + personalAccessToken?: PersonalAccessToken, + options?: AxiosRequestConfig + ): Promise< + ( + axios?: AxiosInstance, + basePath?: string + ) => AxiosPromise + > { + const localVarAxiosArgs = + await localVarAxiosParamCreator.updatesecurityHaloRunV1alpha1PersonalAccessToken( + name, + personalAccessToken, + options + ); + return createRequestFunction( + localVarAxiosArgs, + globalAxios, + BASE_PATH, + configuration + ); + }, + }; +}; + +/** + * SecurityHaloRunV1alpha1PersonalAccessTokenApi - factory interface + * @export + */ +export const SecurityHaloRunV1alpha1PersonalAccessTokenApiFactory = function ( + configuration?: Configuration, + basePath?: string, + axios?: AxiosInstance +) { + const localVarFp = + SecurityHaloRunV1alpha1PersonalAccessTokenApiFp(configuration); + return { + /** + * Create security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiCreatesecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + createsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiCreatesecurityHaloRunV1alpha1PersonalAccessTokenRequest = {}, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .createsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.personalAccessToken, + options + ) + .then((request) => request(axios, basePath)); + }, + /** + * Delete security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiDeletesecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + deletesecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiDeletesecurityHaloRunV1alpha1PersonalAccessTokenRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .deletesecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.name, + options + ) + .then((request) => request(axios, basePath)); + }, + /** + * Get security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiGetsecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + getsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiGetsecurityHaloRunV1alpha1PersonalAccessTokenRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .getsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.name, + options + ) + .then((request) => request(axios, basePath)); + }, + /** + * List security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + listsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessTokenRequest = {}, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .listsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.fieldSelector, + requestParameters.labelSelector, + requestParameters.page, + requestParameters.size, + requestParameters.sort, + options + ) + .then((request) => request(axios, basePath)); + }, + /** + * Update security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiUpdatesecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + updatesecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiUpdatesecurityHaloRunV1alpha1PersonalAccessTokenRequest, + options?: AxiosRequestConfig + ): AxiosPromise { + return localVarFp + .updatesecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.name, + requestParameters.personalAccessToken, + options + ) + .then((request) => request(axios, basePath)); + }, + }; +}; + +/** + * Request parameters for createsecurityHaloRunV1alpha1PersonalAccessToken operation in SecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface SecurityHaloRunV1alpha1PersonalAccessTokenApiCreatesecurityHaloRunV1alpha1PersonalAccessTokenRequest + */ +export interface SecurityHaloRunV1alpha1PersonalAccessTokenApiCreatesecurityHaloRunV1alpha1PersonalAccessTokenRequest { + /** + * Fresh personalaccesstoken + * @type {PersonalAccessToken} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiCreatesecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly personalAccessToken?: PersonalAccessToken; +} + +/** + * Request parameters for deletesecurityHaloRunV1alpha1PersonalAccessToken operation in SecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface SecurityHaloRunV1alpha1PersonalAccessTokenApiDeletesecurityHaloRunV1alpha1PersonalAccessTokenRequest + */ +export interface SecurityHaloRunV1alpha1PersonalAccessTokenApiDeletesecurityHaloRunV1alpha1PersonalAccessTokenRequest { + /** + * Name of personalaccesstoken + * @type {string} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiDeletesecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly name: string; +} + +/** + * Request parameters for getsecurityHaloRunV1alpha1PersonalAccessToken operation in SecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface SecurityHaloRunV1alpha1PersonalAccessTokenApiGetsecurityHaloRunV1alpha1PersonalAccessTokenRequest + */ +export interface SecurityHaloRunV1alpha1PersonalAccessTokenApiGetsecurityHaloRunV1alpha1PersonalAccessTokenRequest { + /** + * Name of personalaccesstoken + * @type {string} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiGetsecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly name: string; +} + +/** + * Request parameters for listsecurityHaloRunV1alpha1PersonalAccessToken operation in SecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessTokenRequest + */ +export interface SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessTokenRequest { + /** + * Field selector for filtering. + * @type {Array} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly fieldSelector?: Array; + + /** + * Label selector for filtering. + * @type {Array} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly labelSelector?: Array; + + /** + * The page number. Zero indicates no page. + * @type {number} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly page?: number; + + /** + * Size of one page. Zero indicates no limit. + * @type {number} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly size?: number; + + /** + * Sort property and direction of the list result. Support sorting based on attribute name path. + * @type {Array} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly sort?: Array; +} + +/** + * Request parameters for updatesecurityHaloRunV1alpha1PersonalAccessToken operation in SecurityHaloRunV1alpha1PersonalAccessTokenApi. + * @export + * @interface SecurityHaloRunV1alpha1PersonalAccessTokenApiUpdatesecurityHaloRunV1alpha1PersonalAccessTokenRequest + */ +export interface SecurityHaloRunV1alpha1PersonalAccessTokenApiUpdatesecurityHaloRunV1alpha1PersonalAccessTokenRequest { + /** + * Name of personalaccesstoken + * @type {string} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiUpdatesecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly name: string; + + /** + * Updated personalaccesstoken + * @type {PersonalAccessToken} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApiUpdatesecurityHaloRunV1alpha1PersonalAccessToken + */ + readonly personalAccessToken?: PersonalAccessToken; +} + +/** + * SecurityHaloRunV1alpha1PersonalAccessTokenApi - object-oriented interface + * @export + * @class SecurityHaloRunV1alpha1PersonalAccessTokenApi + * @extends {BaseAPI} + */ +export class SecurityHaloRunV1alpha1PersonalAccessTokenApi extends BaseAPI { + /** + * Create security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiCreatesecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public createsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiCreatesecurityHaloRunV1alpha1PersonalAccessTokenRequest = {}, + options?: AxiosRequestConfig + ) { + return SecurityHaloRunV1alpha1PersonalAccessTokenApiFp(this.configuration) + .createsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.personalAccessToken, + options + ) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Delete security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiDeletesecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public deletesecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiDeletesecurityHaloRunV1alpha1PersonalAccessTokenRequest, + options?: AxiosRequestConfig + ) { + return SecurityHaloRunV1alpha1PersonalAccessTokenApiFp(this.configuration) + .deletesecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.name, + options + ) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Get security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiGetsecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public getsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiGetsecurityHaloRunV1alpha1PersonalAccessTokenRequest, + options?: AxiosRequestConfig + ) { + return SecurityHaloRunV1alpha1PersonalAccessTokenApiFp(this.configuration) + .getsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.name, + options + ) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * List security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public listsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiListsecurityHaloRunV1alpha1PersonalAccessTokenRequest = {}, + options?: AxiosRequestConfig + ) { + return SecurityHaloRunV1alpha1PersonalAccessTokenApiFp(this.configuration) + .listsecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.fieldSelector, + requestParameters.labelSelector, + requestParameters.page, + requestParameters.size, + requestParameters.sort, + options + ) + .then((request) => request(this.axios, this.basePath)); + } + + /** + * Update security.halo.run/v1alpha1/PersonalAccessToken + * @param {SecurityHaloRunV1alpha1PersonalAccessTokenApiUpdatesecurityHaloRunV1alpha1PersonalAccessTokenRequest} requestParameters Request parameters. + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof SecurityHaloRunV1alpha1PersonalAccessTokenApi + */ + public updatesecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters: SecurityHaloRunV1alpha1PersonalAccessTokenApiUpdatesecurityHaloRunV1alpha1PersonalAccessTokenRequest, + options?: AxiosRequestConfig + ) { + return SecurityHaloRunV1alpha1PersonalAccessTokenApiFp(this.configuration) + .updatesecurityHaloRunV1alpha1PersonalAccessToken( + requestParameters.name, + requestParameters.personalAccessToken, + options + ) + .then((request) => request(this.axios, this.basePath)); + } +} diff --git a/console/packages/api-client/src/models/index.ts b/console/packages/api-client/src/models/index.ts index 6e100e14f8..88262a54b6 100644 --- a/console/packages/api-client/src/models/index.ts +++ b/console/packages/api-client/src/models/index.ts @@ -91,9 +91,9 @@ export * from "./menu-vo"; export * from "./metadata"; export * from "./navigation-post-vo"; export * from "./owner-info"; +export * from "./pat-spec"; export * from "./personal-access-token"; export * from "./personal-access-token-list"; -export * from "./personal-access-token-spec"; export * from "./plugin"; export * from "./plugin-author"; export * from "./plugin-list"; diff --git a/console/packages/api-client/src/models/pat-spec.ts b/console/packages/api-client/src/models/pat-spec.ts new file mode 100644 index 0000000000..f0929811b5 --- /dev/null +++ b/console/packages/api-client/src/models/pat-spec.ts @@ -0,0 +1,81 @@ +/* tslint:disable */ +/* eslint-disable */ +/** + * Halo Next API + * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + * + * The version of the OpenAPI document: 2.0.0 + * + * + * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech). + * https://openapi-generator.tech + * Do not edit the class manually. + */ + +/** + * + * @export + * @interface PatSpec + */ +export interface PatSpec { + /** + * + * @type {string} + * @memberof PatSpec + */ + description?: string; + /** + * + * @type {string} + * @memberof PatSpec + */ + expiresAt?: string; + /** + * + * @type {string} + * @memberof PatSpec + */ + lastUsed?: string; + /** + * + * @type {string} + * @memberof PatSpec + */ + name: string; + /** + * + * @type {boolean} + * @memberof PatSpec + */ + revoked?: boolean; + /** + * + * @type {string} + * @memberof PatSpec + */ + revokesAt?: string; + /** + * + * @type {Array} + * @memberof PatSpec + */ + roles?: Array; + /** + * + * @type {Array} + * @memberof PatSpec + */ + scopes?: Array; + /** + * + * @type {string} + * @memberof PatSpec + */ + tokenId: string; + /** + * + * @type {string} + * @memberof PatSpec + */ + username: string; +} diff --git a/console/packages/api-client/src/models/personal-access-token.ts b/console/packages/api-client/src/models/personal-access-token.ts index 12c33fc330..08385810b4 100644 --- a/console/packages/api-client/src/models/personal-access-token.ts +++ b/console/packages/api-client/src/models/personal-access-token.ts @@ -17,7 +17,7 @@ import { Metadata } from "./metadata"; // May contain unused imports in some cases // @ts-ignore -import { PersonalAccessTokenSpec } from "./personal-access-token-spec"; +import { PatSpec } from "./pat-spec"; /** * @@ -45,8 +45,8 @@ export interface PersonalAccessToken { metadata: Metadata; /** * - * @type {PersonalAccessTokenSpec} + * @type {PatSpec} * @memberof PersonalAccessToken */ - spec?: PersonalAccessTokenSpec; + spec?: PatSpec; } diff --git a/console/packages/api-client/src/models/user-permission.ts b/console/packages/api-client/src/models/user-permission.ts index 7439be2a0a..e057a1745c 100644 --- a/console/packages/api-client/src/models/user-permission.ts +++ b/console/packages/api-client/src/models/user-permission.ts @@ -22,6 +22,12 @@ import { Role } from "./role"; * @interface UserPermission */ export interface UserPermission { + /** + * + * @type {Array} + * @memberof UserPermission + */ + permissions: Array; /** * * @type {Array} diff --git a/console/src/constants/annotations.ts b/console/src/constants/annotations.ts index c3c16a56f9..76ae27bab3 100644 --- a/console/src/constants/annotations.ts +++ b/console/src/constants/annotations.ts @@ -18,3 +18,8 @@ export enum rbacAnnotations { export enum contentAnnotations { PREFERRED_EDITOR = "content.halo.run/preferred-editor", } + +// pat +export enum patAnnotations { + ACCESS_TOKEN = "security.halo.run/access-token", +} diff --git a/console/src/locales/en.yaml b/console/src/locales/en.yaml index 2215f7cedf..4879d9b7bc 100644 --- a/console/src/locales/en.yaml +++ b/console/src/locales/en.yaml @@ -852,6 +852,7 @@ core: title: User detail tabs: detail: Detail + pat: Personal Access Tokens actions: update_profile: title: Update profile @@ -886,6 +887,46 @@ core: flip_horizontal: Flip Horizontal flip_vertical: Flip Vertical reset: Reset + pat: + operations: + delete: + title: Delete Personal Access Token + description: Are you sure you want to delete this personal access token? + revoke: + button: Revoke + title: Revoke Personal Access Token + description: Are you sure you want to revoke this personal access token? + toast_success: Revocation succeeded + copy: + title: Please copy and save immediately, Token will only be displayed once. + restore: + button: Restore + toast_success: Restore successfully + list: + empty: + title: No personal access tokens have been created + message: You can try refreshing or creating a new personal access token + fields: + expiresAt: + dynamic: "Expires on {expiresAt}" + forever: Never expires + status: + normal: Normal + revoked: Revoked + expired: Expired + creation_modal: + title: Create Personal Access Token + groups: + general: General + permissions: Permissions + fields: + name: + label: Name + expiresAt: + label: Expiration Time + help: Leave empty for no expiration + description: + label: Description role: title: Roles common: diff --git a/console/src/locales/zh-CN.yaml b/console/src/locales/zh-CN.yaml index 093a353daf..d11b0eefd8 100644 --- a/console/src/locales/zh-CN.yaml +++ b/console/src/locales/zh-CN.yaml @@ -852,6 +852,7 @@ core: title: 用户详情 tabs: detail: 详情 + pat: 个人令牌 actions: update_profile: title: 修改资料 @@ -886,6 +887,46 @@ core: flip_horizontal: 水平翻转 flip_vertical: 垂直翻转 reset: 重置 + pat: + operations: + delete: + title: 删除个人令牌 + description: 确定要删除该个人令牌吗? + revoke: + button: 撤销 + title: 撤销个人令牌 + description: 确定要撤销该个人令牌吗? + toast_success: 撤销成功 + copy: + title: 请立即复制并保存,Token 将仅显示一次。 + restore: + button: 恢复 + toast_success: 恢复成功 + list: + empty: + title: 当前没有创建个人令牌 + message: 你可以尝试刷新或者新建个人令牌 + fields: + expiresAt: + dynamic: "{expiresAt}失效" + forever: 永久有效 + status: + normal: 正常 + revoked: 已撤销 + expired: 已过期 + creation_modal: + title: 创建个人令牌 + groups: + general: 基本信息 + permissions: 权限 + fields: + name: + label: 名称 + expiresAt: + label: 过期时间 + help: 不设置代表永不过期 + description: + label: 描述 role: title: 角色 common: diff --git a/console/src/locales/zh-TW.yaml b/console/src/locales/zh-TW.yaml index 4f79c03e82..ccd6695eda 100644 --- a/console/src/locales/zh-TW.yaml +++ b/console/src/locales/zh-TW.yaml @@ -852,6 +852,7 @@ core: title: 用戶詳情 tabs: detail: 詳情 + pat: 個人令牌 actions: update_profile: title: 修改資料 @@ -886,6 +887,46 @@ core: flip_horizontal: 水平翻轉 flip_vertical: 垂直翻轉 reset: 重置 + pat: + operations: + delete: + title: 刪除個人令牌 + description: 您確定要刪除此個人令牌嗎? + revoke: + button: 撤銷 + title: 撤銷個人令牌 + description: 您確定要撤銷此個人令牌嗎? + toast_success: 撤銷成功 + copy: + title: 請立即複製並保存,令牌僅顯示一次。 + restore: + button: 還原 + toast_success: 還原成功 + list: + empty: + title: 目前尚未建立個人令牌 + message: 您可以嘗試重新整理或建立新的個人令牌 + fields: + expiresAt: + dynamic: "到期於 {expiresAt}" + forever: 永久有效 + status: + normal: 正常 + revoked: 已撤銷 + expired: 已過期 + creation_modal: + title: 建立個人令牌 + groups: + general: 基本資訊 + permissions: 權限 + fields: + name: + label: 名稱 + expiresAt: + label: 到期時間 + help: 留空代表永不過期 + description: + label: 描述 role: title: 角色 common: diff --git a/console/src/modules/system/roles/RoleDetail.vue b/console/src/modules/system/roles/RoleDetail.vue index df69468aeb..2e19b91d2c 100644 --- a/console/src/modules/system/roles/RoleDetail.vue +++ b/console/src/modules/system/roles/RoleDetail.vue @@ -22,14 +22,27 @@ import { import { SUPER_ROLE_NAME } from "@/constants/constants"; import { useI18n } from "vue-i18n"; import { formatDatetime } from "@/utils/date"; +import { useQuery } from "@tanstack/vue-query"; const route = useRoute(); const { t } = useI18n(); const tabActiveId = ref("detail"); +const { data: roleTemplates } = useQuery({ + queryKey: ["role-templates"], + queryFn: async () => { + const { data } = await apiClient.extension.role.listv1alpha1Role({ + page: 0, + size: 0, + labelSelector: [`${roleLabels.TEMPLATE}=true`, "!halo.run/hidden"], + }); + return data.items; + }, +}); + const { roleTemplateGroups, handleRoleTemplateSelect, selectedRoleTemplates } = - useRoleTemplateSelection(); + useRoleTemplateSelection(roleTemplates); const { formState, saving, handleCreateOrUpdate } = useRoleForm(); diff --git a/console/src/modules/system/roles/components/RoleEditingModal.vue b/console/src/modules/system/roles/components/RoleEditingModal.vue index aa468171fb..743a77b6af 100644 --- a/console/src/modules/system/roles/components/RoleEditingModal.vue +++ b/console/src/modules/system/roles/components/RoleEditingModal.vue @@ -11,8 +11,10 @@ import { import cloneDeep from "lodash.clonedeep"; import { reset } from "@formkit/core"; import { setFocus } from "@/formkit/utils/focus"; -import { pluginLabels } from "@/constants/labels"; +import { pluginLabels, roleLabels } from "@/constants/labels"; import { useI18n } from "vue-i18n"; +import { apiClient } from "@/utils/api-client"; +import { useQuery } from "@tanstack/vue-query"; const { t } = useI18n(); @@ -32,8 +34,20 @@ const emit = defineEmits<{ (event: "close"): void; }>(); +const { data: roleTemplates } = useQuery({ + queryKey: ["role-templates"], + queryFn: async () => { + const { data } = await apiClient.extension.role.listv1alpha1Role({ + page: 0, + size: 0, + labelSelector: [`${roleLabels.TEMPLATE}=true`, "!halo.run/hidden"], + }); + return data.items; + }, +}); + const { roleTemplateGroups, handleRoleTemplateSelect, selectedRoleTemplates } = - useRoleTemplateSelection(); + useRoleTemplateSelection(roleTemplates); const { formState, diff --git a/console/src/modules/system/roles/composables/use-role.ts b/console/src/modules/system/roles/composables/use-role.ts index 4b8d643ab6..480bd8c1a2 100644 --- a/console/src/modules/system/roles/composables/use-role.ts +++ b/console/src/modules/system/roles/composables/use-role.ts @@ -43,7 +43,6 @@ interface useRoleFormReturn { interface useRoleTemplateSelectionReturn { selectedRoleTemplates: Ref>; - roleTemplates: Ref; roleTemplateGroups: ComputedRef; handleRoleTemplateSelect: (e: Event) => void; } @@ -157,8 +156,9 @@ export function useRoleForm(): useRoleFormReturn { * * @returns {useRoleTemplateSelectionReturn} */ -export function useRoleTemplateSelection(): useRoleTemplateSelectionReturn { - const roleTemplates = ref([] as Role[]); +export function useRoleTemplateSelection( + roleTemplates: Ref +): useRoleTemplateSelectionReturn { const selectedRoleTemplates = ref>(new Set()); /** @@ -246,7 +246,7 @@ export function useRoleTemplateSelection(): useRoleTemplateSelectionReturn { */ const roleTemplateGroups = computed(() => { const groups: RoleTemplateGroup[] = []; - roleTemplates.value.forEach((role) => { + roleTemplates.value?.forEach((role) => { const group = groups.find( (group) => group.module === role.metadata.annotations?.[rbacAnnotations.MODULE] @@ -263,28 +263,12 @@ export function useRoleTemplateSelection(): useRoleTemplateSelectionReturn { return groups; }); - /** - * Get all role templates based on the condition that `metadata.labels.[halo.run/role-template] = 'true'` and `!halo.run/hidden` - */ - const handleFetchRoles = async () => { - try { - const { data } = await apiClient.extension.role.listv1alpha1Role({ - page: 0, - size: 0, - labelSelector: [`${roleLabels.TEMPLATE}=true`, "!halo.run/hidden"], - }); - roleTemplates.value = data.items; - } catch (e) { - console.error(e); - } - }; - const handleRoleTemplateSelect = async (e: Event) => { const { checked, value } = e.target as HTMLInputElement; if (!checked) { return; } - const role = roleTemplates.value.find( + const role = roleTemplates.value?.find( (role) => role.metadata.name === value ); const dependencies = @@ -298,11 +282,8 @@ export function useRoleTemplateSelection(): useRoleTemplateSelectionReturn { }); }; - onMounted(handleFetchRoles); - return { selectedRoleTemplates, - roleTemplates, roleTemplateGroups, handleRoleTemplateSelect, }; diff --git a/console/src/modules/system/users/PersonalAccessTokens.vue b/console/src/modules/system/users/PersonalAccessTokens.vue index 7a39f94d8b..55a3275470 100644 --- a/console/src/modules/system/users/PersonalAccessTokens.vue +++ b/console/src/modules/system/users/PersonalAccessTokens.vue @@ -1,292 +1,103 @@ diff --git a/console/src/modules/system/users/components/PersonalAccessTokenCreationModal.vue b/console/src/modules/system/users/components/PersonalAccessTokenCreationModal.vue new file mode 100644 index 0000000000..8655f522ac --- /dev/null +++ b/console/src/modules/system/users/components/PersonalAccessTokenCreationModal.vue @@ -0,0 +1,279 @@ + + + diff --git a/console/src/modules/system/users/components/PersonalAccessTokenListItem.vue b/console/src/modules/system/users/components/PersonalAccessTokenListItem.vue new file mode 100644 index 0000000000..f4792d382c --- /dev/null +++ b/console/src/modules/system/users/components/PersonalAccessTokenListItem.vue @@ -0,0 +1,149 @@ + + + diff --git a/console/src/modules/system/users/layouts/UserProfileLayout.vue b/console/src/modules/system/users/layouts/UserProfileLayout.vue index 24c2de8bb1..eaeaf367cb 100644 --- a/console/src/modules/system/users/layouts/UserProfileLayout.vue +++ b/console/src/modules/system/users/layouts/UserProfileLayout.vue @@ -53,18 +53,13 @@ const { currentUserHasPermission } = usePermission(); const userStore = useUserStore(); const { t } = useI18n(); -const tabs = [ +const tabs = ref([ { id: "detail", label: t("core.user.detail.tabs.detail"), routeName: "UserDetail", }, - // { - // id: "tokens", - // label: "个人令牌", - // routeName: "PersonalAccessTokens", - // }, -]; +]); const editingModal = ref(false); const passwordChangeModal = ref(false); @@ -122,6 +117,20 @@ const isCurrentUser = computed(() => { provide>("user", user); provide>("isCurrentUser", isCurrentUser); +// fixme: refactor this component to simplify the logic +watch( + () => isCurrentUser.value, + (value) => { + if (value) { + tabs.value.push({ + id: "tokens", + label: t("core.user.detail.tabs.pat"), + routeName: "PersonalAccessTokens", + }); + } + } +); + const activeTab = ref(); const route = useRoute(); @@ -129,20 +138,20 @@ const router = useRouter(); // set default active tab onMounted(() => { - const tab = tabs.find((tab) => tab.routeName === route.name); - activeTab.value = tab ? tab.id : tabs[0].id; + const tab = tabs.value.find((tab) => tab.routeName === route.name); + activeTab.value = tab ? tab.id : tabs.value[0].id; }); watch( () => route.name, async (newRouteName) => { - const tab = tabs.find((tab) => tab.routeName === newRouteName); - activeTab.value = tab ? tab.id : tabs[0].id; + const tab = tabs.value.find((tab) => tab.routeName === newRouteName); + activeTab.value = tab ? tab.id : tabs.value[0].id; } ); const handleTabChange = (id: string) => { - const tab = tabs.find((tab) => tab.id === id); + const tab = tabs.value.find((tab) => tab.id === id); if (tab) { router.push({ name: tab.routeName }); } diff --git a/console/src/stores/role.ts b/console/src/stores/role.ts index 208b976c17..26af3a9bfc 100644 --- a/console/src/stores/role.ts +++ b/console/src/stores/role.ts @@ -5,6 +5,7 @@ import { ref } from "vue"; export const useRoleStore = defineStore("role", () => { const permissions = ref({ roles: [], + permissions: [], uiPermissions: [], }); diff --git a/console/src/utils/api-client.ts b/console/src/utils/api-client.ts index 52eb57261f..7c0d5dacc0 100644 --- a/console/src/utils/api-client.ts +++ b/console/src/utils/api-client.ts @@ -28,7 +28,6 @@ import { V1alpha1ConfigMapApi, V1alpha1MenuApi, V1alpha1MenuItemApi, - V1alpha1PersonalAccessTokenApi, V1alpha1RoleApi, V1alpha1RoleBindingApi, V1alpha1SettingApi, @@ -41,6 +40,8 @@ import { ApiHaloRunV1alpha1UserApi, MigrationHaloRunV1alpha1BackupApi, ApiConsoleMigrationHaloRunV1alpha1MigrationApi, + ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi, + SecurityHaloRunV1alpha1PersonalAccessTokenApi, } from "@halo-dev/api-client"; import type { AxiosError, AxiosInstance } from "axios"; import axios from "axios"; @@ -117,11 +118,6 @@ function setupApiClient(axios: AxiosInstance) { return { extension: { configMap: new V1alpha1ConfigMapApi(undefined, baseURL, axios), - personalAccessToken: new V1alpha1PersonalAccessTokenApi( - undefined, - baseURL, - axios - ), roleBinding: new V1alpha1RoleBindingApi(undefined, baseURL, axios), role: new V1alpha1RoleApi(undefined, baseURL, axios), setting: new V1alpha1SettingApi(undefined, baseURL, axios), @@ -184,6 +180,11 @@ function setupApiClient(axios: AxiosInstance) { axios ), backup: new MigrationHaloRunV1alpha1BackupApi(undefined, baseURL, axios), + pat: new SecurityHaloRunV1alpha1PersonalAccessTokenApi( + undefined, + baseURL, + axios + ), }, // custom endpoints user: new ApiConsoleHaloRunV1alpha1UserApi(undefined, baseURL, axios), @@ -220,6 +221,11 @@ function setupApiClient(axios: AxiosInstance) { axios ), system: new ApiConsoleHaloRunV1alpha1SystemApi(undefined, baseURL, axios), + pat: new ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi( + undefined, + baseURL, + axios + ), }; } diff --git a/console/vite.config.ts b/console/vite.config.ts index af4e2a21b5..b741bbccf3 100644 --- a/console/vite.config.ts +++ b/console/vite.config.ts @@ -11,7 +11,11 @@ import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite"; import GzipPlugin from "rollup-plugin-gzip"; export const sharedPlugins = [ - Vue(), + Vue({ + script: { + defineModel: true, + }, + }), VueJsx(), GzipPlugin() as Plugin, Icons({