本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
密碼可用於儲存 CodeCatalyst 可在工作流程中參照的敏感資料。您可以將密碼新增至自訂藍圖,並在工作流程中參考它。如需詳細資訊,請參閱 使用秘密遮罩資料。
若要匯入 Amazon CodeCatalyst 藍圖區域類型
在您的blueprint.ts
檔案中,新增下列內容:
import { Secret, SecretDefinition } from '@amazon-codecatalyst/blueprint-component.secrets'
建立密碼
下列範例會建立 UI 元件,提示使用者輸入密碼值和選用說明:
export interface Options extends ParentOptions { ... mySecret: SecretDefinition; } export class Blueprint extends ParentBlueprint { constructor(options_: Options) { new Secret(this, options.secret); }
秘密元件需要name
. 下面的代碼是所需的最小默認形狀:
{ ... "secret": { "name": "secretName" }, }
參考工作流程中的密碼
下列範例藍圖會建立機密和參考密碼值的工作流程。如需詳細資訊,請參閱 在工作流程中參考秘密。
export interface Options extends ParentOptions { ... /** * * @validationRegex /^\w+$/ */ username: string; password: SecretDefinition; } export class Blueprint extends ParentBlueprint { constructor(options_: Options) { const password = new Secret(this, options_.password); const workflowBuilder = new WorkflowBuilder(this, { Name: 'my_workflow', }); workflowBuilder.addBuildAction({ actionName: 'download_files', input: { Sources: ['WorkflowSource'], }, output: { Artifacts: [{ Name: 'download', Files: ['file1'] }], }, steps: [ `curl -u ${options_.username}:${password.reference} https://example.com`, ], }); new Workflow( this, repo, workflowBuilder.getDefinition(), ); }
若要進一步瞭解如何在中使用密碼 CodeCatalyst,請參閱使用秘密遮罩資料。