From b2593543cb115b00aa03560f20029172d521e76c Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 24 Jun 2024 21:36:52 +0100 Subject: [PATCH] fix(lang-js): Add support for connection annotations to SecretDefinitions This will add the specified connection annotation to the generated output socket ``` function main() { const credential = new SecretDefinitionBuilder() .setName("GHCR Credential") .setConnectionAnnotation("Docker Hub Credential") .addProp( new PropBuilder() .setName("Username") .setKind("string") .setWidget( new PropWidgetDefinitionBuilder() .setKind("password") .build() ).build()) .build(); return new AssetBuilder() .defineSecret(credential) .build() } ``` --- bin/lang-js/src/asset_builder.ts | 51 ++++++++++++++----- .../ts_types/asset_types_with_secrets.d.ts | 17 ++++++- 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/bin/lang-js/src/asset_builder.ts b/bin/lang-js/src/asset_builder.ts index 28aca94679..5fd45db8ba 100644 --- a/bin/lang-js/src/asset_builder.ts +++ b/bin/lang-js/src/asset_builder.ts @@ -895,6 +895,7 @@ export class SecretPropBuilder implements ISecretPropBuilder { export interface SecretDefinition { name: string; props: PropDefinition[]; + connectionAnnotations?: string; } export interface ISecretDefinitionBuilder { @@ -911,6 +912,7 @@ export interface ISecretDefinitionBuilder { * @example * const secretDefinition = new SecretDefinitionBuilder() * .setName("DigitalOcean Token") + * .setConnectionAnnotations("Registry Token") * .addProp( * new PropBuilder() * .setKind("string") @@ -931,6 +933,7 @@ export class SecretDefinitionBuilder implements ISecretDefinitionBuilder { this.definition = {}; this.definition.name = ""; this.definition.props = []; + this.definition.connectionAnnotations = ""; } /** @@ -967,6 +970,21 @@ export class SecretDefinitionBuilder implements ISecretDefinitionBuilder { return this; } + /** + * Adds the specified connection annotations to the output socket for the secret + * + * @param {string} connectionAnnotations - the connection annotations to create for the output socket. + * + * @returns this + * + * @example + * .setConnectionAnnotation("Registry Token") + */ + setConnectionAnnotation(connectionAnnotations: string): this { + this.definition.connectionAnnotations = connectionAnnotations; + return this; + } + build(): SecretDefinition { const def = this.definition; @@ -1070,18 +1088,27 @@ export class AssetBuilder implements IAssetBuilder { .build(), ); - this.addOutputSocket( - new SocketDefinitionBuilder() - .setArity("one") - .setName(definition.name) - .setValueFrom( - new ValueFromBuilder() - .setKind("prop") - .setPropPath(["root", "secrets", definition.name]) - .build(), - ) - .build(), - ); + const outputSocketBuilder = new SocketDefinitionBuilder() + .setArity("one") + .setName(definition.name) + .setValueFrom( + new ValueFromBuilder() + .setKind("prop") + .setPropPath(["root", "secrets", definition.name]) + .build(), + ); + + if ( + definition.connectionAnnotations + && definition.connectionAnnotations !== "" + ) { + outputSocketBuilder.setConnectionAnnotation( + definition.connectionAnnotations, + ); + } + + const outputSocket = outputSocketBuilder.build(); + this.addOutputSocket(outputSocket); return this; } diff --git a/lib/dal/src/func/authoring/data/ts_types/asset_types_with_secrets.d.ts b/lib/dal/src/func/authoring/data/ts_types/asset_types_with_secrets.d.ts index 0d454bb595..82fdce40f4 100644 --- a/lib/dal/src/func/authoring/data/ts_types/asset_types_with_secrets.d.ts +++ b/lib/dal/src/func/authoring/data/ts_types/asset_types_with_secrets.d.ts @@ -686,10 +686,12 @@ declare class SecretPropBuilder implements ISecretPropBuilder { interface SecretDefinition { name: string; props: PropDefinition[]; + connectionAnnotations?: string; } interface ISecretDefinitionBuilder { addProp(prop: PropDefinition): this; + setName(name: string): this; build(): SecretDefinition; } @@ -699,7 +701,8 @@ interface ISecretDefinitionBuilder { * * @example * const secretDefinition = new SecretDefinitionBuilder() - * .setName("DigitalOcean Token") + * .setName("DigitalOcean Token") + * .setConnectionAnnotations("Registry Token") * .addProp( * new PropBuilder() * .setKind("string") @@ -746,6 +749,18 @@ declare class SecretDefinitionBuilder implements ISecretDefinitionBuilder { */ addProp(prop: PropDefinition): this; + /** + * Adds the specified connection annotations to the output socket for the secret + * + * @param {string} connectionAnnotations - the connection annotations to create for the output socket. + * + * @returns this + * + * @example + * .setConnectionAnnotation("Registry Token") + */ + setConnectionAnnotation(connectionAnnotations: string): this; + build(): SecretDefinition; }