Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/s.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ resources:
# id: xxxxx
# description: test
# resourceGroupId:

armsConfiguration:
enableArms: false
# armsLicenseKey:

endpoints:
- name: production
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@
"publish": "npm i && npm run build && s registry publish"
},
"dependencies": {
"@alicloud/agentrun20250910": "^5.3.9",
"@alicloud/agentrun20250910": "^5.7.3",
"@alicloud/arms20190808": "^10.0.6",
"@alicloud/fc2": "^2.6.6",
"@alicloud/fc20230330": "^4.6.3",
"@alicloud/openapi-client": "^0.4.9",
"@alicloud/tea-typescript": "^1.8.0",
"@alicloud/tea-util": "^1.4.8",
"@alicloud/fc2": "^2.6.6",
"@alicloud/fc20230330": "^4.6.3",
"@serverless-cd/srm-aliyun-sls20201230": "0.0.4",
"@serverless-devs/component-interface": "^0.0.4",
"@serverless-devs/logger": "^0.0.5",
"@serverless-devs/load-component": "*",
"@serverless-devs/logger": "^0.0.5",
"@serverless-devs/utils": "^0.0.15",
"@serverless-devs/zip": "^0.0.3-beta.8",
"ajv": "^8.13.0",
Expand All @@ -61,4 +62,4 @@
"ts-node": "^10.9.2",
"typescript": "^5.4.5"
}
}
}
49 changes: 47 additions & 2 deletions src/impl/agentrun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ import Client, {
ListWorkspacesRequest,
CreateWorkspaceRequest,
CreateWorkspaceInput,
ArmsConfiguration,
GetWorkspaceRequest,
DeleteAgentRuntimeEndpointRequest,
DeleteAgentRuntimeRequest,
} from "@alicloud/agentrun20250910";
import { agentRunRegionEndpoints } from "../common/constant";
import { verify, verifyDelete } from "../utils/verify";
Expand All @@ -53,6 +57,7 @@ import axios from "axios";
import fs from "fs";
import zip from "@serverless-devs/zip";
import Sls from "./sls";
import Arms from "./arms";

// 常量定义
const FC_CLIENT_READ_TIMEOUT = 60000;
Expand Down Expand Up @@ -209,6 +214,7 @@ export class AgentRun {
environmentVariables: config.environmentVariables,
executionRoleArn: config.role, // 保存原始值,稍后在需要时转换
credentialName: config.credentialName,
armsConfiguration: config.armsConfiguration,
};

// 处理代码配置
Expand Down Expand Up @@ -368,6 +374,23 @@ export class AgentRun {
return normalized as AgentRuntimeConfig;
}

private async normalizeArmsLicenseKey(): Promise<ArmsConfiguration> {
const { armsLicenseKey: localArmsLicenseKey } =
this.agentRuntimeConfig.armsConfiguration;
let resolvedArmsLicenseKey: string;
if (!localArmsLicenseKey) {
const credentials = await this.inputs.getCredential();
const armsClient = new Arms(this.region, credentials);
resolvedArmsLicenseKey = await armsClient.DescribeTraceLicenseKey();
} else {
resolvedArmsLicenseKey = localArmsLicenseKey;
}
return new ArmsConfiguration({
...this.agentRuntimeConfig.armsConfiguration,
armsLicenseKey: resolvedArmsLicenseKey,
});
}

private async initClient(command: string) {
const {
AccessKeyID: accessKeyId,
Expand Down Expand Up @@ -727,6 +750,13 @@ logConfig:
createInput.port = this.agentRuntimeConfig.port;
createInput.workspaceId = workspaceId;

if (!_.isEmpty(this.agentRuntimeConfig.armsConfiguration)) {
logger.debug(
`Arms configuration: ${JSON.stringify(this.agentRuntimeConfig.armsConfiguration)}`,
);
createInput.armsConfiguration = await this.normalizeArmsLicenseKey();
}

if (
this.agentRuntimeConfig.sessionConcurrencyLimitPerInstance !== undefined
) {
Expand Down Expand Up @@ -911,6 +941,13 @@ logConfig:
updateInput.artifactType = this.agentRuntimeConfig.artifactType;
updateInput.workspaceId = workspaceId;

if (!_.isEmpty(this.agentRuntimeConfig.armsConfiguration)) {
logger.debug(
`Arms configuration: ${JSON.stringify(this.agentRuntimeConfig.armsConfiguration)}`,
);
updateInput.armsConfiguration = await this.normalizeArmsLicenseKey();
}

if (
this.agentRuntimeConfig.sessionConcurrencyLimitPerInstance !== undefined
) {
Expand Down Expand Up @@ -1220,7 +1257,8 @@ logConfig:
}
let isCreateWorkspace = true;
if (id) {
await this.agentRuntimeClient.getWorkspace(id);
const getWorkspaceRequest = new GetWorkspaceRequest({});
await this.agentRuntimeClient.getWorkspace(id, getWorkspaceRequest);
isCreateWorkspace = false;
workspaceId = id;
} else {
Expand Down Expand Up @@ -1305,10 +1343,13 @@ logConfig:
logger.info(`found ${endpoints.length} endpoint(s), deleting...`);
for (const endpoint of endpoints) {
try {
const deleteAgentRuntimeEndpoint =
new DeleteAgentRuntimeEndpointRequest({});
const deleteEndpointResp =
await this.agentRuntimeClient.deleteAgentRuntimeEndpoint(
runtimeId,
endpoint.agentRuntimeEndpointId || "",
deleteAgentRuntimeEndpoint,
);
if (
deleteEndpointResp.statusCode != 200 &&
Expand All @@ -1331,7 +1372,11 @@ logConfig:
}
}

const resp = await this.agentRuntimeClient.deleteAgentRuntime(runtimeId);
const deleteAgentRunRequest = new DeleteAgentRuntimeRequest({});
const resp = await this.agentRuntimeClient.deleteAgentRuntime(
runtimeId,
deleteAgentRunRequest,
);
if (
resp.statusCode != 200 &&
resp.statusCode != 202 &&
Expand Down
44 changes: 44 additions & 0 deletions src/impl/arms.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { ICredentials } from "@serverless-devs/component-interface";
import { Config } from "@alicloud/openapi-client";
import GLogger from "../common/logger";
import Arms20210422, {
DescribeDispatchRuleRequest,
} from "@alicloud/arms20190808";
import * as $Util from "@alicloud/tea-util";

export default class Arms {
readonly client: Arms20210422;

constructor(region: string, credentials: ICredentials) {
const config = new Config({
accessKeyId: credentials.AccessKeyID,
accessKeySecret: credentials.AccessKeySecret,
securityToken: credentials.SecurityToken,
endpoint: `arms.${region}.aliyuncs.com`,
regionId: region,
readTimeout: 60000,
connectTimeout: 5000,
});
GLogger.getLogger().debug(
`Init arms client with config: ${JSON.stringify(config)}`,
);
this.client = new Arms20210422(config);
}

async DescribeTraceLicenseKey() {
const request = new DescribeDispatchRuleRequest({});
GLogger.getLogger().debug(
`DescribeTraceLicenseKey request: ${JSON.stringify(request)}`,
);
let runtime = new $Util.RuntimeOptions({});
const response = await this.client.describeTraceLicenseKeyWithOptions(
request,
runtime,
);
GLogger.getLogger().debug(
"DescribeTraceLicenseKey response: %j",
JSON.stringify(response),
);
return response.body.licenseKey;
}
}
5 changes: 5 additions & 0 deletions src/interface/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ArmsConfiguration } from "@alicloud/agentrun20250910";
import { IInputs as _IInputs } from "@serverless-devs/component-interface";

export interface IInputs extends _IInputs {
Expand Down Expand Up @@ -81,6 +82,9 @@ export interface AgentConfig {

// 工作空间配置
workspace?: WorkspaceConfig;

// 阿里云arms配置
armsConfiguration?: ArmsConfiguration;
}

// 代码配置(必须是对象,包含 src 或 OSS 配置)
Expand Down Expand Up @@ -267,6 +271,7 @@ export interface AgentRuntimeConfig {
protocolConfiguration?: ProtocolConfiguration;
healthCheckConfiguration?: HealthCheckConfiguration;
endpoints?: EndpointConfigInternal[];
armsConfiguration?: ArmsConfiguration;
}

export interface CodeConfiguration {
Expand Down