Skip to content

Commit

Permalink
Add restore pat supports
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Wang <[email protected]>
  • Loading branch information
ruibaby committed Sep 21, 2023
1 parent ead98f3 commit 84dc847
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestArgs> => {
// 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
Expand Down Expand Up @@ -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<void>
> {
const localVarAxiosArgs = await localVarAxiosParamCreator.restorePat(
name,
options
);
return createRequestFunction(
localVarAxiosArgs,
globalAxios,
BASE_PATH,
configuration
);
},
/**
* Revoke a PAT
* @param {string} name
Expand Down Expand Up @@ -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<void> {
return localVarFp
.restorePat(requestParameters.name, options)
.then((request) => request(axios, basePath));
},
/**
* Revoke a PAT
* @param {ApiConsoleSecurityHaloRunV1alpha1PersonalAccessTokenApiRevokePatRequest} requestParameters Request parameters.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions console/packages/api-client/src/models/pat-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export interface PatSpec {
* @type {string}
* @memberof PatSpec
*/
name?: string;
name: string;
/**
*
* @type {boolean}
Expand Down Expand Up @@ -71,11 +71,11 @@ export interface PatSpec {
* @type {string}
* @memberof PatSpec
*/
tokenId?: string;
tokenId: string;
/**
*
* @type {string}
* @memberof PatSpec
*/
username?: string;
username: string;
}
3 changes: 3 additions & 0 deletions console/src/locales/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions console/src/locales/zh-CN.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,9 @@ core:
toast_success: 撤销成功
copy:
title: 请立即复制并保存,Token 将仅显示一次。
restore:
button: 恢复
toast_success: 恢复成功
list:
empty:
title: 当前没有创建个人令牌
Expand Down
3 changes: 3 additions & 0 deletions console/src/locales/zh-TW.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,9 @@ core:
toast_success: 撤銷成功
copy:
title: 請立即複製並保存,令牌僅顯示一次。
restore:
button: 還原
toast_success: 還原成功
list:
empty:
title: 目前尚未建立個人令牌
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -130,7 +137,9 @@ const statusTheme = computed(() => {
>
{{ $t("core.user.pat.operations.revoke.button") }}
</VDropdownItem>
<VDropdownItem v-else @click="handleDelete">恢复</VDropdownItem>
<VDropdownItem v-else @click="handleRestore">
{{ $t("core.user.pat.operations.restore.button") }}
</VDropdownItem>
<VDropdownDivider />
<VDropdownItem type="danger" @click="handleDelete">
{{ $t("core.common.buttons.delete") }}
Expand Down

0 comments on commit 84dc847

Please sign in to comment.