Skip to content

Commit

Permalink
merge: #2813
Browse files Browse the repository at this point in the history
2813: feat(web,dal,sdf,lang-js): Add Secrets and SecretDefinition to prop tree r=fnichol a=vbustamante

<img src="https://media4.giphy.com/media/f9FOzhKG3qivm/giphy.gif"/>

Co-authored-by: Fletcher Nichol <[email protected]>
  • Loading branch information
si-bors-ng[bot] and fnichol authored Sep 30, 2023
2 parents bddd931 + 8865877 commit 703d4d9
Show file tree
Hide file tree
Showing 29 changed files with 1,006 additions and 169 deletions.
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions app/web/src/components/PropertyEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ import {
PropertyEditorValidation,
} from "@/api/sdf/dal/property_editor";
import { useComponentsStore } from "@/store/components.store";
import { useFeatureFlagsStore } from "@/store/feature_flags.store";
import PropertyWidget from "./PropertyEditor/PropertyWidget.vue";
import WidgetSecret from "./PropertyEditor/WidgetSecret.vue";
const featureFlagsStore = useFeatureFlagsStore();
export interface PropertyEditorContext {
schema: PropertyEditorSchema;
values: PropertyEditorValues;
Expand Down Expand Up @@ -225,6 +228,13 @@ const determineOrder = (
for (const childValueId of childValueIds) {
const child = values.value.values[childValueId];
if (child) {
if (!featureFlagsStore.SECRETS) {
const propName = schemasByPropId.value[child.propId]?.name;
if (propName === "secrets") {
continue;
}
}
order.push(child);
}
const childValuesList = values.value.childValues[childValueId];
Expand Down
156 changes: 148 additions & 8 deletions bin/lang-js/src/asset_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,8 @@ export type PropWidgetDefinitionKind =
| "textArea";

export interface Option {
label: string,
value: string,
label: string;
value: string;
}

export interface PropWidgetDefinition {
Expand All @@ -246,7 +246,8 @@ export interface IPropWidgetDefinitionBuilder {
}

export class PropWidgetDefinitionBuilder
implements IPropWidgetDefinitionBuilder {
implements IPropWidgetDefinitionBuilder
{
propWidget = <PropWidgetDefinition>{};

constructor() {
Expand All @@ -260,7 +261,7 @@ export class PropWidgetDefinitionBuilder

// eslint-disable-next-line @typescript-eslint/no-explicit-any
addOption(key: string, value: string): this {
if (!this.propWidget.options){
if (!this.propWidget.options) {
this.propWidget.options = [];
}

Expand Down Expand Up @@ -330,7 +331,8 @@ export interface ISiPropValueFromDefinitionBuilder {
}

export class SiPropValueFromDefinitionBuilder
implements ISiPropValueFromDefinitionBuilder {
implements ISiPropValueFromDefinitionBuilder
{
definition = <SiPropValueFromDefinition>{};

constructor() {
Expand Down Expand Up @@ -414,7 +416,9 @@ export class PropBuilder implements IPropBuilder {

addChild(child: PropDefinition): this {
if (this.prop.kind !== "object") {
return this;
throw new Error(
"addChild can only be called on props that are objects"
);
}

if (!this.prop.children) {
Expand All @@ -426,8 +430,10 @@ export class PropBuilder implements IPropBuilder {
}

setEntry(entry: PropDefinition): this {
if (this.prop.kind !== "array" && this.prop.kind !== "map") {
return this;
if (this.prop.kind !== "array" && this.prop.kind !== "map") {
throw new Error(
"setEntry can only be called on prop that are arrays or maps"
);
}

this.prop.entry = entry;
Expand Down Expand Up @@ -491,13 +497,123 @@ export class PropBuilder implements IPropBuilder {
}

setWidget(widget: PropWidgetDefinition): this {
if(widget.kind === 'secret') {
throw new Error("Cannot create prop with secret widget. Use addSecretProp() to create those.");
}
this.prop.widget = widget;
return this;
}
}

// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface SecretPropDefinition extends PropDefinition {}

export interface ISecretPropBuilder {
setName(name: string): this;

setSecretKind(kind: string): this;

setDocLinkRef(ref: string): this;

setDocLink(link: string): this;

addValidation(validation: Validation): this;

build(): SecretPropDefinition;
}

export class SecretPropBuilder implements ISecretPropBuilder {
prop = <SecretPropDefinition>{};

constructor() {
this.prop = <SecretPropDefinition>{};
this.prop.kind = "string";
this.prop.widget = {
kind: "secret",
options: [],
};
}
setName(name: string): this {
this.prop.name = name;
return this;
}

setSecretKind(kind: string): this {
this.prop.widget?.options.push({ label: "secretKind", value: kind });
return this;
}

setDocLinkRef(ref: string): this {
this.prop.docLinkRef = ref;
return this;
}

setDocLink(link: string): this {
this.prop.docLink = link;
return this;
}

addValidation(validation: Validation): this {
if (!this.prop.validations) {
this.prop.validations = [];
}
this.prop.validations.push(validation);
return this;
}

build(): SecretPropDefinition {
if (
this.prop.widget?.options?.find(
(option) => option.label === "secretKind"
) === undefined
) {
throw new Error("must call setSecretKind() before build()");
}

return this.prop;
}
}

export interface SecretDefinition {
name: string;
props?: PropDefinition[];
}

export interface ISecretDefinitionBuilder {
addProp(prop: PropDefinition): this;

build(): SecretDefinition;
}

export class SecretDefinitionBuilder implements ISecretDefinitionBuilder {
definition: SecretDefinition;

constructor() {
this.definition = <SecretDefinition>{};
}

setName(name: string): this {
this.definition.name = name;
return this;
}

addProp(prop: PropDefinition): this {
if (!this.definition.props) {
this.definition.props = [];
}
this.definition.props?.push(prop);
return this;
}

build(): SecretDefinition {
return this.definition;
}
}

export interface Asset {
props: PropDefinition[];
secretProps: SecretPropDefinition[];
secretDefinition?: PropDefinition[];
resourceProps: PropDefinition[];
siPropValueFroms: SiPropValueFromDefinition[];
inputSockets: SocketDefinition[];
Expand All @@ -508,6 +624,10 @@ export interface Asset {
export interface IAssetBuilder {
addProp(prop: PropDefinition): this;

addSecretProp(prop: SecretPropDefinition): this;

defineSecret(definition: SecretDefinition): this;

addResourceProp(prop: PropDefinition): this;

addInputSocket(socket: SocketDefinition): this;
Expand Down Expand Up @@ -536,6 +656,26 @@ export class AssetBuilder implements IAssetBuilder {
return this;
}

addSecretProp(prop: SecretPropDefinition) {
if (!this.asset.secretProps) {
this.asset.secretProps = [];
}
this.asset.secretProps?.push(prop);
return this;
}

defineSecret(definition: SecretDefinition): this {
this.asset.secretDefinition = definition.props;
this.addSecretProp(
new SecretPropBuilder()
.setName(definition.name)
.setSecretKind(definition.name)
.build()
);

return this;
}

addResourceProp(prop: PropDefinition) {
if (!this.asset.resourceProps) {
this.asset.resourceProps = [];
Expand Down
2 changes: 2 additions & 0 deletions bin/lang-js/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ function schemaVariantDefinitionSandbox(): Sandbox {
return {
AssetBuilder: assetBuilder.AssetBuilder,
PropBuilder: assetBuilder.PropBuilder,
SecretDefinitionBuilder: assetBuilder.SecretDefinitionBuilder,
SecretPropBuilder: assetBuilder.SecretPropBuilder,
ValidationBuilder: assetBuilder.ValidationBuilder,
ValueFromBuilder: assetBuilder.ValueFromBuilder,
SocketDefinitionBuilder: assetBuilder.SocketDefinitionBuilder,
Expand Down
9 changes: 9 additions & 0 deletions bin/sdf/endpoints.http
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,12 @@ Content-Type: application/json
}


### Check Feature Flags
POST https://e.systeminit.com/decide?v=3
Content-Type: application/json

{
"api_key": "phc_KpehlXOqtU44B2MeW6WjqR09NxRJCYEiUReA58QcAYK",
"distinct_id": "01GW5C5WVQRSS9XP2YWFHKG2P3"
}

6 changes: 6 additions & 0 deletions lib/dal/src/pkg/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,12 @@ impl PkgExporter {
SchemaVariantSpecPropRoot::ResourceValue => {
tree_node.name == "resource_value" && tree_node.path == "/root/"
}
SchemaVariantSpecPropRoot::Secrets => {
tree_node.name == "secrets" && tree_node.path == "/root/"
}
SchemaVariantSpecPropRoot::SecretDefinition => {
tree_node.name == "secret_definition" && tree_node.path == "/root/"
}
}
}) {
Some(root_tree_node) => root_tree_node,
Expand Down
Loading

0 comments on commit 703d4d9

Please sign in to comment.