From 647fd94ac9b51a375191ff8cccae6b37b1573e68 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 | 63 ++++++++++++++----- .../ts_types/asset_types_with_secrets.d.ts | 31 +++++++-- 2 files changed, 71 insertions(+), 23 deletions(-) diff --git a/bin/lang-js/src/asset_builder.ts b/bin/lang-js/src/asset_builder.ts index 28aca94679..930b740f73 100644 --- a/bin/lang-js/src/asset_builder.ts +++ b/bin/lang-js/src/asset_builder.ts @@ -62,8 +62,8 @@ export class ValueFromBuilder implements IValueFromBuilder { */ setSocketName(name: string): this { if ( - this.valueFrom.kind !== "inputSocket" - && this.valueFrom.kind !== "outputSocket" + this.valueFrom.kind !== "inputSocket" && + this.valueFrom.kind !== "outputSocket" ) { return this; } @@ -301,7 +301,8 @@ export interface IPropWidgetDefinitionBuilder { * .build() */ export class PropWidgetDefinitionBuilder -implements IPropWidgetDefinitionBuilder { + implements IPropWidgetDefinitionBuilder +{ propWidget = {}; constructor() { @@ -449,7 +450,8 @@ export interface ISiPropValueFromDefinitionBuilder { } export class SiPropValueFromDefinitionBuilder -implements ISiPropValueFromDefinitionBuilder { + implements ISiPropValueFromDefinitionBuilder +{ definition = {}; constructor() { @@ -895,6 +897,7 @@ export class SecretPropBuilder implements ISecretPropBuilder { export interface SecretDefinition { name: string; props: PropDefinition[]; + connectionAnnotations?: string; } export interface ISecretDefinitionBuilder { @@ -910,7 +913,8 @@ export interface ISecretDefinitionBuilder { * * @example * const secretDefinition = new SecretDefinitionBuilder() - * .setName("DigitalOcean Token") + * .setName("DigitalOcean Token") + * .setConnectionAnnotations("Registry Token") * .addProp( * new PropBuilder() * .setKind("string") @@ -931,6 +935,7 @@ export class SecretDefinitionBuilder implements ISecretDefinitionBuilder { this.definition = {}; this.definition.name = ""; this.definition.props = []; + this.definition.connectionAnnotations = ""; } /** @@ -967,6 +972,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 +1090,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..a36f761bd3 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 @@ -196,7 +196,7 @@ declare class SocketDefinitionBuilder implements ISocketDefinitionBuilder { } type PropWidgetDefinitionKind = - "array" + | "array" | "checkbox" | "codeEditor" | "color" @@ -235,7 +235,9 @@ interface IPropWidgetDefinitionBuilder { * .setKind("text") * .build() */ -declare class PropWidgetDefinitionBuilder implements IPropWidgetDefinitionBuilder { +declare class PropWidgetDefinitionBuilder + implements IPropWidgetDefinitionBuilder +{ propWidget: PropWidgetDefinition; constructor(); @@ -351,7 +353,9 @@ interface ISiPropValueFromDefinitionBuilder { build(): SiPropValueFromDefinition; } -declare class SiPropValueFromDefinitionBuilder implements ISiPropValueFromDefinitionBuilder { +declare class SiPropValueFromDefinitionBuilder + implements ISiPropValueFromDefinitionBuilder +{ definition: SiPropValueFromDefinition; constructor(); @@ -370,7 +374,7 @@ declare class SiPropValueFromDefinitionBuilder implements ISiPropValueFromDefini } type PropDefinitionKind = - "array" + | "array" | "boolean" | "integer" | "map" @@ -686,10 +690,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 +705,8 @@ interface ISecretDefinitionBuilder { * * @example * const secretDefinition = new SecretDefinitionBuilder() - * .setName("DigitalOcean Token") + * .setName("DigitalOcean Token") + * .setConnectionAnnotations("Registry Token") * .addProp( * new PropBuilder() * .setKind("string") @@ -746,6 +753,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; } @@ -802,4 +821,4 @@ declare class AssetBuilder implements IAssetBuilder { addDocLink(key: string, value: string): this; build(): Asset; -} \ No newline at end of file +}