Skip to content

Commit

Permalink
merge: #4035
Browse files Browse the repository at this point in the history
4035: fix(lang-js): Add support for connection annotations to SecretDefinitions r=stack72 a=stack72

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()
}
```

Co-authored-by: stack72 <[email protected]>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Jun 24, 2024
2 parents 02d42b4 + b259354 commit b6417fc
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 13 deletions.
51 changes: 39 additions & 12 deletions bin/lang-js/src/asset_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,6 +895,7 @@ export class SecretPropBuilder implements ISecretPropBuilder {
export interface SecretDefinition {
name: string;
props: PropDefinition[];
connectionAnnotations?: string;
}

export interface ISecretDefinitionBuilder {
Expand All @@ -911,6 +912,7 @@ export interface ISecretDefinitionBuilder {
* @example
* const secretDefinition = new SecretDefinitionBuilder()
* .setName("DigitalOcean Token")
* .setConnectionAnnotations("Registry Token")
* .addProp(
* new PropBuilder()
* .setKind("string")
Expand All @@ -931,6 +933,7 @@ export class SecretDefinitionBuilder implements ISecretDefinitionBuilder {
this.definition = <SecretDefinition>{};
this.definition.name = "";
this.definition.props = [];
this.definition.connectionAnnotations = "";
}

/**
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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")
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit b6417fc

Please sign in to comment.