Skip to content

Commit

Permalink
added encryption property to action resource
Browse files Browse the repository at this point in the history
  • Loading branch information
pazhersh committed Oct 2, 2023
1 parent b636416 commit f128af5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 6 deletions.
1 change: 1 addition & 0 deletions internal/cli/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type (
EnumColors map[string]string `json:"enumColors,omitempty"`
DependsOn []string `json:"dependsOn,omitempty"`
Dataset *Dataset `json:"dataset,omitempty"`
Encryption *string `json:"encryption,omitempty"`
}

SpecAuthentication struct {
Expand Down
2 changes: 2 additions & 0 deletions port/action/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ type StringPropModel struct {
Dataset *DatasetModel `tfsdk:"dataset"`
DefaultJqQuery types.String `tfsdk:"default_jq_query"`
EnumJqQuery types.String `tfsdk:"enum_jq_query"`
Encryption types.String `tfsdk:"encryption"`
}

type NumberPropModel struct {
Expand Down Expand Up @@ -117,6 +118,7 @@ type ObjectPropModel struct {
DependsOn types.List `tfsdk:"depends_on"`
Dataset *DatasetModel `tfsdk:"dataset"`
DefaultJqQuery types.String `tfsdk:"default_jq_query"`
Encryption types.String `tfsdk:"encryption"`
}

type StringItems struct {
Expand Down
9 changes: 8 additions & 1 deletion port/action/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"

"github.com/port-labs/terraform-provider-port-labs/internal/cli"
"github.com/port-labs/terraform-provider-port-labs/internal/flex"
"github.com/port-labs/terraform-provider-port-labs/internal/utils"
)

Expand Down Expand Up @@ -55,7 +56,11 @@ func objectPropResourceToBody(ctx context.Context, d *ActionModel, props map[str
return err
}
property.DependsOn = utils.InterfaceToStringArray(dependsOn)
}

if !prop.Encryption.IsNull() {
encryption := prop.Encryption.ValueString()
property.Encryption = &encryption
}

if prop.Dataset != nil {
Expand All @@ -73,7 +78,9 @@ func objectPropResourceToBody(ctx context.Context, d *ActionModel, props map[str
}

func addObjectPropertiesToResource(v *cli.ActionProperty) *ObjectPropModel {
objectProp := &ObjectPropModel{}
objectProp := &ObjectPropModel{
Encryption: flex.GoStringToFramework(v.Encryption),
}

return objectProp
}
14 changes: 14 additions & 0 deletions port/action/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,13 @@ func StringPropertySchema() schema.Attribute {
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("enum")),
},
},
"encryption": schema.StringAttribute{
MarkdownDescription: "The algorithm to encrypt the property with",
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("fernet"),
},
},
}

utils.CopyMaps(stringPropertySchema, MetadataProperties())
Expand Down Expand Up @@ -415,6 +422,13 @@ func ObjectPropertySchema() schema.Attribute {
stringvalidator.ConflictsWith(path.MatchRelative().AtParent().AtName("default")),
},
},
"encryption": schema.StringAttribute{
MarkdownDescription: "The algorithm to encrypt the property with",
Optional: true,
Validators: []validator.String{
stringvalidator.OneOf("fernet"),
},
},
}
utils.CopyMaps(objectPropertySchema, MetadataProperties())
return schema.MapNestedAttribute{
Expand Down
16 changes: 11 additions & 5 deletions port/action/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ func stringPropResourceToBody(ctx context.Context, d *ActionModel, props map[str
property.DependsOn = utils.InterfaceToStringArray(dependsOn)
}

if !prop.Encryption.IsNull() {
encryption := prop.Encryption.ValueString()
property.Encryption = &encryption
}

if prop.Dataset != nil {
property.Dataset = actionDataSetToPortBody(prop.Dataset)
}
Expand All @@ -109,11 +114,12 @@ func stringPropResourceToBody(ctx context.Context, d *ActionModel, props map[str

func addStringPropertiesToResource(ctx context.Context, v *cli.ActionProperty) *StringPropModel {
stringProp := &StringPropModel{
MinLength: flex.GoInt64ToFramework(v.MinLength),
MaxLength: flex.GoInt64ToFramework(v.MaxLength),
Pattern: flex.GoStringToFramework(v.Pattern),
Format: flex.GoStringToFramework(v.Format),
Blueprint: flex.GoStringToFramework(v.Blueprint),
MinLength: flex.GoInt64ToFramework(v.MinLength),
MaxLength: flex.GoInt64ToFramework(v.MaxLength),
Pattern: flex.GoStringToFramework(v.Pattern),
Format: flex.GoStringToFramework(v.Format),
Blueprint: flex.GoStringToFramework(v.Blueprint),
Encryption: flex.GoStringToFramework(v.Encryption),
}

if v.Enum != nil {
Expand Down

0 comments on commit f128af5

Please sign in to comment.