Skip to content

Commit

Permalink
merge: #2974
Browse files Browse the repository at this point in the history
2974: Add support for Secrets Snippets and TypeHints r=stack72 a=stack72



Co-authored-by: stack72 <[email protected]>
  • Loading branch information
si-bors-ng[bot] and stack72 authored Nov 23, 2023
2 parents 2204781 + 3d57b81 commit 293876c
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 2 deletions.
5 changes: 5 additions & 0 deletions app/web/src/components/FuncEditor/FuncDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
/>

<VButton
v-if="
funcStore.selectedFuncDetails &&
funcStore.selectedFuncDetails?.associations?.type !==
'authentication'
"
class="--tone-success"
icon="save"
size="md"
Expand Down
32 changes: 32 additions & 0 deletions app/web/src/utils/typescriptLinterSnippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,38 @@ export const snippets = [
},
),

// new secret prop
snippetCompletion(
`const \${secretPropName} = new SecretPropBuilder()
.setName("\${name}")
.setSecretKind("\${Secret Kind}")
.build();`,
{
label: "New Secret Prop Snippet",
type: "function",
},
),

// new secret definition
snippetCompletion(
`const \${secretDefinition} = new SecretDefinitionBuilder()
.setName("\${name}")
.addProp(
new PropBuilder()
.setName("\${value}")
.setKind("\${string}")
.setWidget(
new PropWidgetDefinitionBuilder()
.setKind("password")
.build()
).build()
).build();`,
{
label: "New Secret Definition",
type: "function",
},
),

// basic socket
snippetCompletion(
`const \${socketName} = new SocketDefinitionBuilder()
Expand Down
82 changes: 81 additions & 1 deletion bin/lang-js/src/asset_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ implements IPropWidgetDefinitionBuilder {
/**
* The type of widget
*
* @param {string} kind [array | checkbox | color | comboBox | header | map | secret | select | text | textArea | codeEditor]
* @param {string} kind [array | checkbox | color | comboBox | header | map | select | text | textArea | codeEditor | password]
*
* @returns this
*
Expand Down Expand Up @@ -895,6 +895,15 @@ export interface ISecretPropBuilder {
build(): SecretPropDefinition;
}

/**
* Creates a prop [and a socket] in an asset with which to connect a secret
*
* @example
* const secretPropName = new SecretPropBuilder()
* .setName("credential")
* .setSecretKind("DigitalOcean Credential")
* .build();
*/
export class SecretPropBuilder implements ISecretPropBuilder {
prop = <SecretPropDefinition>{};

Expand All @@ -908,11 +917,31 @@ export class SecretPropBuilder implements ISecretPropBuilder {
this.prop.hasInputSocket = true;
}

/**
* The secret prop name. This will appear in the model UI and can be any value
*
* @param {string} name - the name of the secret prop
*
* @returns this
*
* @example
* .setName("token")
*/
setName(name: string): this {
this.prop.name = name;
return this;
}

/**
* The type of the secret - relates to the Secret Definition Name
*
* @param {any} value
*
* @returns this
*
* @example
* .setSecretKind("DigitalOcean Credential")
*/
setSecretKind(kind: string): this {
this.prop.widget?.options.push({ label: "secretKind", value: kind });
return this;
Expand All @@ -936,6 +965,14 @@ export class SecretPropBuilder implements ISecretPropBuilder {
return this;
}

/**
* Whether the prop should disable the auto-creation of an input socket
*
* @returns this
*
* @example
* .skipInputSocket()
*/
skipInputSocket(): this {
this.prop.hasInputSocket = false;
return this;
Expand Down Expand Up @@ -965,6 +1002,25 @@ export interface ISecretDefinitionBuilder {
build(): SecretDefinition;
}

/**
* Creates a secret to be used with a set of assets
*
* @example
* const secretDefinition = new SecretDefinitionBuilder()
* .setName("DigitalOcean Token")
* .addProp(
* new PropBuilder()
* .setKind("string")
* .setName("token")
* .setWidget(
* new PropWidgetDefinitionBuilder()
* .setKind("password")
* .build()
* )
* .build()
* )
* .build();
*/
export class SecretDefinitionBuilder implements ISecretDefinitionBuilder {
definition: SecretDefinition;

Expand All @@ -974,11 +1030,35 @@ export class SecretDefinitionBuilder implements ISecretDefinitionBuilder {
this.definition.props = [];
}

/**
* The secret name. This corresponds to the kind of secret
*
* @param {string} name - the name of the secret kind
*
* @returns this
*
* @example
* .setName("DigitalOcean Token")
*/
setName(name: string): this {
this.definition.name = name;
return this;
}

/**
* Adds a Prop to the secret definition. These define the form fields for the secret input
*
* @param {PropDefinition} child
*
* @returns this
*
* @example
* .addProp(new PropBuilder()
* .setName("token")
* .setKind("string")
* .setWidget(new PropWidgetDefinitionBuilder().setKind("password").build())
* .build())
*/
addProp(prop: PropDefinition): this {
this.definition.props?.push(prop);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ interface PropDefinition {
kind: PropDefinitionKind;
docLinkRef?: string;
docLink?: string;
documentation? string;
documentation?: string;
children?: PropDefinition[];
entry?: PropDefinition;
widget?: PropWidgetDefinition;
Expand Down Expand Up @@ -546,14 +546,51 @@ interface ISecretPropBuilder {
skipInputSocket(): this;
build(): SecretPropDefinition;
}
/**
* Creates a prop [and a socket] in an asset with which to connect a secret
*
* @example
* const secretPropName = new SecretPropBuilder()
* .setName("credential")
* .setSecretKind("DigitalOcean Credential")
* .build();
*/
declare class SecretPropBuilder implements ISecretPropBuilder {
prop: SecretPropDefinition;
constructor();
/**
* The secret prop name. This will appear in the model UI and can be any value
*
* @param {string} name - the name of the secret prop
*
* @returns this
*
* @example
* .setName("token")
*/
setName(name: string): this;
/**
* The type of the secret - relates to the Secret Definition Name
*
* @param {any} value
*
* @returns this
*
* @example
* .setSecretKind("DigitalOcean Credential")
*/
setSecretKind(kind: string): this;
setDocLinkRef(ref: string): this;
setDocLink(link: string): this;
addValidation(validation: Validation): this;
/**
* Whether the prop should disable the auto-creation of an input socket
*
* @returns this
*
* @example
* .skipInputSocket()
*/
skipInputSocket(): this;
build(): SecretPropDefinition;
}
Expand All @@ -565,10 +602,53 @@ interface ISecretDefinitionBuilder {
addProp(prop: PropDefinition): this;
build(): SecretDefinition;
}
/**
* Creates a secret to be used with a set of assets
*
* @example
* const secretDefinition = new SecretDefinitionBuilder()
* .setName("DigitalOcean Token")
* .addProp(
* new PropBuilder()
* .setKind("string")
* .setName("token")
* .setWidget(
* new PropWidgetDefinitionBuilder()
* .setKind("password")
* .build()
* )
* .build()
* )
* .build();
*/
declare class SecretDefinitionBuilder implements ISecretDefinitionBuilder {
definition: SecretDefinition;
constructor();
/**
* The secret name. This corresponds to the kind of secret
*
* @param {string} name - the name of the secret kind
*
* @returns this
*
* @example
* .setName("DigitalOcean Token")
*/
setName(name: string): this;
/**
* Adds a Prop to the secret definition. These define the form fields for the secret input
*
* @param {PropDefinition} child
*
* @returns this
*
* @example
* .addProp(new PropBuilder()
* .setName("token")
* .setKind("string")
* .setWidget(new PropWidgetDefinitionBuilder().setKind("password").build())
* .build())
*/
addProp(prop: PropDefinition): this;
build(): SecretDefinition;
}
Expand Down

0 comments on commit 293876c

Please sign in to comment.