From 84dc8477cedb3b2c3b3da613e8eef72f871bea21 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Thu, 21 Sep 2023 16:18:41 +0800 Subject: [PATCH] Add restore pat supports Signed-off-by: Ryan Wang --- ...-run-v1alpha1-personal-access-token-api.ts | 123 ++++++++++++++++++ .../api-client/src/models/pat-spec.ts | 6 +- console/src/locales/en.yaml | 3 + console/src/locales/zh-CN.yaml | 3 + console/src/locales/zh-TW.yaml | 3 + .../PersonalAccessTokenListItem.vue | 11 +- 6 files changed, 145 insertions(+), 4 deletions(-) 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 index 2ae67b63be2..cff7334b18d 100644 --- 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 @@ -261,6 +261,60 @@ export const ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiAxiosParamCr 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.console.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 @@ -424,6 +478,29 @@ export const ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFp = 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 @@ -517,6 +594,20 @@ export const ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiFactory = .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. @@ -576,6 +667,20 @@ export interface ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiObtainPa 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 @@ -665,6 +770,24 @@ export class ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApi extends Bas .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. diff --git a/console/packages/api-client/src/models/pat-spec.ts b/console/packages/api-client/src/models/pat-spec.ts index 72ede25da09..f0929811b5d 100644 --- a/console/packages/api-client/src/models/pat-spec.ts +++ b/console/packages/api-client/src/models/pat-spec.ts @@ -41,7 +41,7 @@ export interface PatSpec { * @type {string} * @memberof PatSpec */ - name?: string; + name: string; /** * * @type {boolean} @@ -71,11 +71,11 @@ export interface PatSpec { * @type {string} * @memberof PatSpec */ - tokenId?: string; + tokenId: string; /** * * @type {string} * @memberof PatSpec */ - username?: string; + username: string; } diff --git a/console/src/locales/en.yaml b/console/src/locales/en.yaml index 6adfadd8a38..4879d9b7bc4 100644 --- a/console/src/locales/en.yaml +++ b/console/src/locales/en.yaml @@ -899,6 +899,9 @@ core: 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 diff --git a/console/src/locales/zh-CN.yaml b/console/src/locales/zh-CN.yaml index 023f71005f5..d11b0eefd87 100644 --- a/console/src/locales/zh-CN.yaml +++ b/console/src/locales/zh-CN.yaml @@ -899,6 +899,9 @@ core: toast_success: 撤销成功 copy: title: 请立即复制并保存,Token 将仅显示一次。 + restore: + button: 恢复 + toast_success: 恢复成功 list: empty: title: 当前没有创建个人令牌 diff --git a/console/src/locales/zh-TW.yaml b/console/src/locales/zh-TW.yaml index 00ba408ebc7..ccd6695eda4 100644 --- a/console/src/locales/zh-TW.yaml +++ b/console/src/locales/zh-TW.yaml @@ -899,6 +899,9 @@ core: toast_success: 撤銷成功 copy: title: 請立即複製並保存,令牌僅顯示一次。 + restore: + button: 還原 + toast_success: 還原成功 list: empty: title: 目前尚未建立個人令牌 diff --git a/console/src/modules/system/users/components/PersonalAccessTokenListItem.vue b/console/src/modules/system/users/components/PersonalAccessTokenListItem.vue index ca6dd0c8980..f4792d382cf 100644 --- a/console/src/modules/system/users/components/PersonalAccessTokenListItem.vue +++ b/console/src/modules/system/users/components/PersonalAccessTokenListItem.vue @@ -55,6 +55,13 @@ function handleRevoke() { }); } +async function handleRestore() { + await apiClient.pat.restorePat({ name: props.token.metadata.name }); + + Toast.success(t("core.user.pat.operations.restore.toast_success")); + queryClient.invalidateQueries({ queryKey: ["personal-access-tokens"] }); +} + const statusText = computed(() => { const { expiresAt } = props.token.spec || {}; if (expiresAt && new Date(expiresAt) < new Date()) { @@ -130,7 +137,9 @@ const statusTheme = computed(() => { > {{ $t("core.user.pat.operations.revoke.button") }} - 恢复 + + {{ $t("core.user.pat.operations.restore.button") }} + {{ $t("core.common.buttons.delete") }}