mirror of
https://github.com/certd/certd.git
synced 2026-05-16 21:27:34 +08:00
chore: 补充其他access的测试按钮
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import {AccessInput, BaseAccess, IsAccess} from '@certd/pipeline';
|
||||
import { AccessInput, BaseAccess, IsAccess } from '@certd/pipeline';
|
||||
import { VolcengineClient } from './ve-client.js';
|
||||
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
@@ -18,7 +19,7 @@ export class VolcengineAccess extends BaseAccess {
|
||||
component: {
|
||||
placeholder: 'AccessKeyID',
|
||||
},
|
||||
helper:"[获取密钥](https://console.volcengine.com/iam/keymanage/)",
|
||||
helper: "[获取密钥](https://console.volcengine.com/iam/keymanage/)",
|
||||
required: true,
|
||||
})
|
||||
accessKeyId = '';
|
||||
@@ -32,6 +33,50 @@ export class VolcengineAccess extends BaseAccess {
|
||||
})
|
||||
secretAccessKey = '';
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "onTestRequest",
|
||||
},
|
||||
helper: "点击测试接口看是否正常",
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getCallerIdentity();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
async getCallerIdentity() {
|
||||
const veClient = new VolcengineClient({
|
||||
access: this,
|
||||
logger: this.ctx.logger,
|
||||
http: this.ctx.http,
|
||||
});
|
||||
const service = await veClient.getStsService();
|
||||
|
||||
const res = await service.request({
|
||||
action: "GetCallerIdentity",
|
||||
});
|
||||
|
||||
const result = res.Result || {};
|
||||
this.ctx.logger.info("✅ 密钥有效!");
|
||||
this.ctx.logger.info(` 账户ID: ${result.AccountId}`);
|
||||
this.ctx.logger.info(` ARN: ${result.Trn}`);
|
||||
this.ctx.logger.info(` 用户ID: ${result.IdentityId}`);
|
||||
|
||||
return {
|
||||
valid: true,
|
||||
accountId: result.AccountId,
|
||||
arn: result.Trn,
|
||||
userId: result.IdentityId
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
new VolcengineAccess();
|
||||
|
||||
@@ -113,6 +113,19 @@ export class VolcengineClient {
|
||||
return service;
|
||||
}
|
||||
|
||||
async getStsService() {
|
||||
const CommonService = await this.getServiceCls();
|
||||
|
||||
const service = new CommonService({
|
||||
serviceName: "sts",
|
||||
defaultVersion: "2018-01-01"
|
||||
});
|
||||
service.setAccessKeyId(this.opts.access.accessKeyId);
|
||||
service.setSecretKey(this.opts.access.secretAccessKey);
|
||||
service.setRegion("cn-north-1");
|
||||
return service;
|
||||
}
|
||||
|
||||
async getServiceCls() {
|
||||
if (this.CommonService) {
|
||||
return this.CommonService;
|
||||
|
||||
Reference in New Issue
Block a user