From f128af564b57a9fd09ccb023909975c8fab3df39 Mon Sep 17 00:00:00 2001 From: Paz Hershberg Date: Mon, 2 Oct 2023 16:23:17 +0300 Subject: [PATCH 1/7] added encryption property to action resource --- internal/cli/models.go | 1 + port/action/model.go | 2 ++ port/action/object.go | 9 ++++++++- port/action/schema.go | 14 ++++++++++++++ port/action/string.go | 16 +++++++++++----- 5 files changed, 36 insertions(+), 6 deletions(-) diff --git a/internal/cli/models.go b/internal/cli/models.go index 4ef393c8..d32b72e5 100644 --- a/internal/cli/models.go +++ b/internal/cli/models.go @@ -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 { diff --git a/port/action/model.go b/port/action/model.go index d60dee4d..a409a0db 100644 --- a/port/action/model.go +++ b/port/action/model.go @@ -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 { @@ -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 { diff --git a/port/action/object.go b/port/action/object.go index b65b7d92..80653e9e 100644 --- a/port/action/object.go +++ b/port/action/object.go @@ -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" ) @@ -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 { @@ -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 } diff --git a/port/action/schema.go b/port/action/schema.go index a5567016..7d55b1fb 100644 --- a/port/action/schema.go +++ b/port/action/schema.go @@ -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()) @@ -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{ diff --git a/port/action/string.go b/port/action/string.go index fa64e9f9..1a9979c7 100644 --- a/port/action/string.go +++ b/port/action/string.go @@ -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) } @@ -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 { From f66b26cac1c8f66ba17e5ebaf5b4366603818f05 Mon Sep 17 00:00:00 2001 From: Paz Hershberg Date: Mon, 2 Oct 2023 16:42:04 +0300 Subject: [PATCH 2/7] added test --- port/action/resource_test.go | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/port/action/resource_test.go b/port/action/resource_test.go index 8655ddac..682415b9 100644 --- a/port/action/resource_test.go +++ b/port/action/resource_test.go @@ -797,3 +797,60 @@ func TestAccPortActionOrderProperties(t *testing.T) { }, }) } + +func TestPortActionEncryption(t *testing.T) { + blueprintIdentifier := utils.GenID() + actionIdentifier := utils.GenID() + var testAccActionConfigCreate = testAccCreateBlueprintConfig(blueprintIdentifier) + fmt.Sprintf(` + resource "port_action" "action1" { + title = "TF Provider Test" + identifier = "%s" + icon = "Terraform" + blueprint = port_blueprint.microservice.id + trigger = "DAY-2" + webhook_method = { + url = "https://getport.io" + } + user_properties = { + "string_props" = { + "encryptedStringProp" = { + "title" = "Encrypted string" + "required" = true + "encryption" = "fernet" + } + } + "object_props" = { + "encryptedObjectProp" = { + "title" = "Encrypted object" + "required" = true + "encryption" = "fernet" + } + } + } + }`, actionIdentifier) + + resource.Test(t, resource.TestCase{ + PreCheck: func() { acctest.TestAccPreCheck(t) }, + ProtoV6ProviderFactories: acctest.TestAccProtoV6ProviderFactories, + + Steps: []resource.TestStep{ + { + Config: acctest.ProviderConfig + testAccActionConfigCreate, + Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("port_action.action1", "title", "TF Provider Test"), + resource.TestCheckResourceAttr("port_action.action1", "identifier", actionIdentifier), + resource.TestCheckResourceAttr("port_action.action1", "icon", "Terraform"), + resource.TestCheckResourceAttr("port_action.action1", "blueprint", blueprintIdentifier), + resource.TestCheckResourceAttr("port_action.action1", "trigger", "DAY-2"), + resource.TestCheckResourceAttr("port_action.action1", "webhook_method.url", "https://getport.io"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.title", "Encrypted string"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.encryption", "fernet"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.title", "Encrypted objectt"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.encryption", "fernet"), + ), + }, + }, + }) +} From 1cb3a464baa7bc80840f69eff9e74f7a2b719169 Mon Sep 17 00:00:00 2001 From: Paz Hershberg Date: Tue, 3 Oct 2023 10:54:27 +0300 Subject: [PATCH 3/7] fix test --- port/action/resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/action/resource_test.go b/port/action/resource_test.go index 682415b9..6b12f611 100644 --- a/port/action/resource_test.go +++ b/port/action/resource_test.go @@ -846,7 +846,7 @@ func TestPortActionEncryption(t *testing.T) { resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.title", "Encrypted string"), resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.required", "true"), resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.encryption", "fernet"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.title", "Encrypted objectt"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.title", "Encrypted object"), resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.required", "true"), resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.encryption", "fernet"), ), From 00129d309c898c54e51a29dd038493755898f4ca Mon Sep 17 00:00:00 2001 From: Paz Hershberg Date: Tue, 3 Oct 2023 10:55:34 +0300 Subject: [PATCH 4/7] improved gitignore --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b3459985..63f337e5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ .vscode/ .env local/ -__debug_bin +__debug_bin* terraform-provider-port-labs \ No newline at end of file From 9562fb6d0841d31004c0188001865c53879ed49e Mon Sep 17 00:00:00 2001 From: Paz Hershberg Date: Tue, 3 Oct 2023 11:02:30 +0300 Subject: [PATCH 5/7] fix tests --- port/action/resource_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/port/action/resource_test.go b/port/action/resource_test.go index 6b12f611..844abd74 100644 --- a/port/action/resource_test.go +++ b/port/action/resource_test.go @@ -846,9 +846,9 @@ func TestPortActionEncryption(t *testing.T) { resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.title", "Encrypted string"), resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.required", "true"), resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedStringProp.encryption", "fernet"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.title", "Encrypted object"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.required", "true"), - resource.TestCheckResourceAttr("port_action.action1", "user_properties.string_props.encryptedObjectProp.encryption", "fernet"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.title", "Encrypted object"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.required", "true"), + resource.TestCheckResourceAttr("port_action.action1", "user_properties.object_props.encryptedObjectProp.encryption", "fernet"), ), }, }, From 93fc29948862164ac81d60da1869f043671d27c3 Mon Sep 17 00:00:00 2001 From: Paz Hershberg Date: Tue, 3 Oct 2023 11:09:22 +0300 Subject: [PATCH 6/7] fix test to match conventions --- port/action/resource_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/port/action/resource_test.go b/port/action/resource_test.go index 844abd74..04007411 100644 --- a/port/action/resource_test.go +++ b/port/action/resource_test.go @@ -798,7 +798,7 @@ func TestAccPortActionOrderProperties(t *testing.T) { }) } -func TestPortActionEncryption(t *testing.T) { +func TestAccPortActionEncryption(t *testing.T) { blueprintIdentifier := utils.GenID() actionIdentifier := utils.GenID() var testAccActionConfigCreate = testAccCreateBlueprintConfig(blueprintIdentifier) + fmt.Sprintf(` From 7bdbe137b007e5bf3e6790b0085643b39f6ba6dd Mon Sep 17 00:00:00 2001 From: Paz Hershberg Date: Tue, 3 Oct 2023 11:22:00 +0300 Subject: [PATCH 7/7] updated docs --- docs/resources/port_action.md | 6 ++++-- docs/resources/port_blueprint.md | 2 -- docs/resources/port_entity.md | 2 -- docs/resources/port_scorecard.md | 6 ++---- docs/resources/port_team.md | 2 -- docs/resources/port_webhook.md | 2 -- 6 files changed, 6 insertions(+), 14 deletions(-) diff --git a/docs/resources/port_action.md b/docs/resources/port_action.md index 82facb85..267a3a83 100644 --- a/docs/resources/port_action.md +++ b/docs/resources/port_action.md @@ -310,6 +310,7 @@ Optional: - `default_jq_query` (String) The default jq query of the object property - `depends_on` (List of String) The properties that this property depends on - `description` (String) The description of the property +- `encryption` (String) The algorithm to encrypt the property with - `icon` (String) The icon of the property - `required` (Boolean) Whether the property is required - `title` (String) The title of the property @@ -357,6 +358,7 @@ Optional: - `default_jq_query` (String) The default jq query of the string property - `depends_on` (List of String) The properties that this property depends on - `description` (String) The description of the property +- `encryption` (String) The algorithm to encrypt the property with - `enum` (List of String) The enum of the string property - `enum_jq_query` (String) The enum jq query of the string property - `format` (String) The format of the string property @@ -410,5 +412,5 @@ Required: Optional: - `agent` (Boolean) Use the agent to invoke the action - - +- `method` (String) The HTTP method to invoke the action +- `synchronized` (Boolean) Synchronize the action diff --git a/docs/resources/port_blueprint.md b/docs/resources/port_blueprint.md index 1b2f9ef2..274a8325 100644 --- a/docs/resources/port_blueprint.md +++ b/docs/resources/port_blueprint.md @@ -242,5 +242,3 @@ Required: Optional: - `agent` (Boolean) The agent of the webhook changelog destination - - diff --git a/docs/resources/port_entity.md b/docs/resources/port_entity.md index a5524c46..5c1535ea 100644 --- a/docs/resources/port_entity.md +++ b/docs/resources/port_entity.md @@ -67,5 +67,3 @@ Optional: - `many_relations` (Map of List of String) The many relation of the entity - `single_relations` (Map of String) The single relation of the entity - - diff --git a/docs/resources/port_scorecard.md b/docs/resources/port_scorecard.md index 1cd17e18..bd9142be 100644 --- a/docs/resources/port_scorecard.md +++ b/docs/resources/port_scorecard.md @@ -10,8 +10,9 @@ description: |- scorecard resource - + + ## Schema ### Required @@ -30,7 +31,6 @@ scorecard resource - `updated_by` (String) The last updater of the scorecard - ### Nested Schema for `rules` Required: @@ -41,7 +41,6 @@ Required: - `title` (String) The title of the rule - ### Nested Schema for `rules.query` Required: @@ -50,7 +49,6 @@ Required: - `conditions` (Attributes List) The conditions of the query (see [below for nested schema](#nestedatt--rules--query--conditions)) - ### Nested Schema for `rules.query.conditions` Required: diff --git a/docs/resources/port_team.md b/docs/resources/port_team.md index aebf4631..fcdeb846 100644 --- a/docs/resources/port_team.md +++ b/docs/resources/port_team.md @@ -30,5 +30,3 @@ Team resource - `id` (String) The ID of this resource. - `provider_name` (String) The provider of the team - `updated_at` (String) The last update date of the team - - diff --git a/docs/resources/port_webhook.md b/docs/resources/port_webhook.md index 0e5c06ca..89654c52 100644 --- a/docs/resources/port_webhook.md +++ b/docs/resources/port_webhook.md @@ -75,5 +75,3 @@ Optional: - `signature_algorithm` (String) The signature algorithm of the webhook - `signature_header_name` (String) The signature header name of the webhook - `signature_prefix` (String) The signature prefix of the webhook - -