From 7604044d1e8601e907c075eba86283e4a440a14b Mon Sep 17 00:00:00 2001 From: talsabagport Date: Thu, 13 Apr 2023 19:07:37 +0300 Subject: [PATCH] Add support for blueprint items in array property --- docs/resources/action.md | 4 +++- docs/resources/blueprint.md | 3 ++- port/cli/client.go | 2 +- port/cli/models.go | 1 + port/resource_port_blueprint.go | 15 ++++++++++++++- port/resource_port_blueprint_test.go | 12 +++++++++--- 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/docs/resources/action.md b/docs/resources/action.md index 15c9de76..3a86ecfc 100644 --- a/docs/resources/action.md +++ b/docs/resources/action.md @@ -19,7 +19,7 @@ Port action - `blueprint_identifier` (String) The identifier of the blueprint - `identifier` (String) The identifier of the action -- `invocation_method` (Block List, Min: 1, Max: 1) The methods the action is dispatched in. Supports WEBHOOK, KAFKA and GITHUB (see [below for nested schema](#nestedblock--invocation_method)) +- `invocation_method` (Block List, Min: 1, Max: 1) The methods the action is dispatched in. Supports WEBHOOK, KAFKA, GITHUB and AZURE-DEVOPS (see [below for nested schema](#nestedblock--invocation_method)) - `title` (String) The display name of the action - `trigger` (String) The type of the action, one of CREATE, DAY-2, DELETE @@ -43,12 +43,14 @@ Required: Optional: - `agent` (Boolean) Relevant only when selecting type WEBHOOK. The flag that controls if the port execution agent will handle the action +- `azure_org` (String) Required when selecting type AZURE-DEVOPS. The Azure Devops org that the webhook belongs to - `omit_payload` (Boolean) Relevant only when selecting type GITHUB. The flag that controls if to omit Port's payload from workflow's dispatch input - `omit_user_inputs` (Boolean) Relevant only when selecting type GITHUB. The flag that controls if to omit user inputs from workflow's dispatch input - `org` (String) Required when selecting type GITHUB. The GitHub org that the workflow belongs to - `repo` (String) Required when selecting type GITHUB. The GitHub repository that the workflow belongs to - `report_workflow_status` (Boolean) Relevant only when selecting type GITHUB. The flag that controls if to report the action status when the workflow completes - `url` (String) Required when selecting type WEBHOOK. The URL to which the action is dispatched +- `webhook` (String) Required when selecting type AZURE-DEVOPS. The Azure Devops webhook id - `workflow` (String) Required when selecting type GITHUB. The GitHub workflow id or the workflow file name diff --git a/docs/resources/blueprint.md b/docs/resources/blueprint.md index f8fcda04..5146cb2e 100644 --- a/docs/resources/blueprint.md +++ b/docs/resources/blueprint.md @@ -23,7 +23,7 @@ Port blueprint ### Optional -- `calculation_properties` (Block Set) A set of properties that are calculated upon Entitys regular properties. (see [below for nested schema](#nestedblock--calculation_properties)) +- `calculation_properties` (Block Set) A set of properties that are calculated upon entity's regular properties. (see [below for nested schema](#nestedblock--calculation_properties)) - `changelog_destination` (Block List, Max: 1) Blueprints changelog destination, Supports WEBHOOK and KAFKA (see [below for nested schema](#nestedblock--changelog_destination)) - `data_source` (String, Deprecated) The data source for entities of this blueprint - `description` (String) The description of the blueprint @@ -57,6 +57,7 @@ Optional: - `enum_colors` (Map of String) A map of colors for the enum values - `format` (String) The format of the Property - `icon` (String) The icon of the property +- `items` (Map of String) A metadata of an array's items, in case the type is an array - `required` (Boolean) Whether or not the property is required - `spec` (String) The specification of the property, one of "async-api", "open-api", "embedded-url" diff --git a/port/cli/client.go b/port/cli/client.go index d2cd7db9..3d9779d8 100644 --- a/port/cli/client.go +++ b/port/cli/client.go @@ -45,7 +45,7 @@ func (c *PortClient) Authenticate(ctx context.Context, clientID, clientSecret st url := "v1/auth/access_token" resp, err := c.Client.R(). SetBody(map[string]interface{}{ - "clientId": clientID, + "clientId": clientID, "clientSecret": clientSecret, }). SetContext(ctx). diff --git a/port/cli/models.go b/port/cli/models.go index dc51d60e..7cb5e71b 100644 --- a/port/cli/models.go +++ b/port/cli/models.go @@ -32,6 +32,7 @@ type ( Type string `json:"type,omitempty"` Title string `json:"title,omitempty"` Identifier string `json:"identifier,omitempty"` + Items map[string]any `json:"items,omitempty"` Default interface{} `json:"default,omitempty"` Icon string `json:"icon,omitempty"` Format string `json:"format,omitempty"` diff --git a/port/resource_port_blueprint.go b/port/resource_port_blueprint.go index 95fd13fb..bf9eb66d 100644 --- a/port/resource_port_blueprint.go +++ b/port/resource_port_blueprint.go @@ -106,6 +106,11 @@ func newBlueprintResource() *schema.Resource { Required: true, Description: "The type of the property", }, + "items": { + Type: schema.TypeMap, + Optional: true, + Description: "A metadata of an array's items, in case the type is an array", + }, "description": { Type: schema.TypeString, Optional: true, @@ -186,7 +191,7 @@ func newBlueprintResource() *schema.Resource { }, "calculation_properties": { Type: schema.TypeSet, - Description: "A set of properties that are calculated upon Entitys regular properties.", + Description: "A set of properties that are calculated upon entity's regular properties.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ "identifier": { @@ -329,6 +334,7 @@ func writeBlueprintFieldsToResource(d *schema.ResourceData, b *cli.Blueprint) { p["identifier"] = k p["title"] = v.Title p["type"] = v.Type + p["items"] = v.Items p["description"] = v.Description p["format"] = v.Format p["icon"] = v.Icon @@ -456,6 +462,13 @@ func blueprintResourceToBody(d *schema.ResourceData) (*cli.Blueprint, error) { if d, ok := p["default_items"]; ok && d != nil { propFields.Default = d } + if i, ok := p["items"]; ok && i != nil { + items := make(map[string]any) + for key, value := range i.(map[string]any) { + items[key] = value.(string) + } + propFields.Items = items + } case "object": if d, ok := p["default"]; ok && d.(string) != "" { defaultObj := make(map[string]interface{}) diff --git a/port/resource_port_blueprint_test.go b/port/resource_port_blueprint_test.go index 6c03f71c..f1c89cd1 100644 --- a/port/resource_port_blueprint_test.go +++ b/port/resource_port_blueprint_test.go @@ -45,8 +45,12 @@ func TestAccPortBlueprint(t *testing.T) { properties { identifier = "array" type = "array" + items = { + type = "string" + format = "url" + } title = "array" - default_items = [1, 2, 3] + default_items = ["https://getport.io", "https://app.getport.io"] } properties { identifier = "text" @@ -70,8 +74,10 @@ func TestAccPortBlueprint(t *testing.T) { { Config: testAccActionConfigCreate, Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.default_items.0", "1"), - resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.default_items.#", "3"), + resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.default_items.0", "https://getport.io"), + resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.default_items.#", "2"), + resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.items.type", "string"), + resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.0.items.format", "url"), resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.1.default", "1"), resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.2.identifier", "text"), resource.TestCheckResourceAttr("port-labs_blueprint.microservice", "properties.2.enum.0", "a"),