- 概述
- JavaScript 函数
- Python 函数
- 部署并运行
访问平台服务
Orchestrator 资产、存储桶、队列和流程通过 UiPath TypeScript SDK 可供 JavaScript 函数使用,您可以在委派标识和函数标识之间进行选择。
JavaScript 函数通过UiPath TypeScript SDK访问平台资源。包中任何内容均未硬编码:坐标来自ctx.platform ,令牌来自运行时提供的两个身份之一。
import { UiPath } from "@uipath/uipath-typescript/core";
import { Assets } from "@uipath/uipath-typescript/assets";
const { baseUrl, orgId, tenantId } = ctx.platform;
const sdk = new UiPath({
baseUrl,
orgName: orgId,
tenantName: tenantId,
secret: ctx.user.accessToken, // or ctx.robot.accessToken
});
import { UiPath } from "@uipath/uipath-typescript/core";
import { Assets } from "@uipath/uipath-typescript/assets";
const { baseUrl, orgId, tenantId } = ctx.platform;
const sdk = new UiPath({
baseUrl,
orgName: orgId,
tenantName: tenantId,
secret: ctx.user.accessToken, // or ctx.robot.accessToken
});
@uipath/uipath-typescript 属于 dependencies,不属于 devDependencies:已部署函数仅安装生产依赖项。
选择身份
| 模式 | 令牌 | 需要文件夹访问权限的用户 |
|---|---|---|
| 已委派 | ctx.user.accessToken | 调用用户需要访问文件夹 Assets.View |
| 函数 Identity | ctx.robot.accessToken | 仅该函数的服务帐户;调用者不需要任何内容 |
Delegated is the default choice, because the caller's own permissions apply, so the function cannot be used to see more than the caller is entitled to. The function's own identity is for resources that must stay out of the caller's reach — a credential in a restricted folder that only the function may read.
In that case, what the handler fetches must be constrained. A privileged backend that reads a caller-supplied resource name hands over anything its identity can see:
const READABLE = new Set(["PartnerApiCredential"]);
if (!READABLE.has(input.assetName)) {
throw new FunctionError(`"${input.assetName}" is not readable by this function.`, 403);
}
const READABLE = new Set(["PartnerApiCredential"]);
if (!READABLE.has(input.assetName)) {
throw new FunctionError(`"${input.assetName}" is not readable by this function.`, 403);
}
资产
const response = await new Assets(sdk).getAll({
filter: `Name eq 'ApiBaseUrl'`,
folderId: 42,
});
const value = response.items[0]?.value;
const response = await new Assets(sdk).getAll({
filter: `Name eq 'ApiBaseUrl'`,
folderId: 42,
});
const value = response.items[0]?.value;
folderId 为必填项:否则,调用将返回包含空值的元数据。
folderId是文件夹的数字 ID,而不是密钥。由于权限错误,作为folderId传递的密钥会失败。ctx.platform.folderKey将为您提供当前调用的密钥;当调用需要时从中解析数字 ID。
对于任何令牌,这些端点都不会返回凭据资产的用户名和密码。读取其中一个需要函数自己的身份和机器人执行路由,而该路由需要 ctx.robot.key,因此仅适用于已部署的运行。请参阅调用 Orchestrator 。
对于“密码”资产,请读取SecretValue字段中的值。StringValue保存文本资产的值,对于密码为空。
保持资产的AllowDirectApiAccess设置为关闭状态。它使文件夹上的每个具有Assets.View身份均可读取该值,包括使用已登录用户令牌的浏览器读取的身份。请改为使用函数自己的标识读取受限值。
其他服务
同一客户端公开存储桶、队列、作业、流程、实体和 Integration Service 连接。有关完整界面,请参阅SDK 参考。
凭据和安全性
- 密码位于 Orchestrator 资产中,并在运行时读取。切勿将其硬编码或提交到项目中。
- 文件夹级别基于角色的访问控制 (RBAC) 管理每个身份可以读取的内容。使用作为调用者的访问权限的委派模式;函数自己的标识为服务帐户。
- 尽可能返回派生结果,而不是密码,并记录操作,而不是值。