From 4c084b889ed8bfcd6823b827afe89604abec73d5 Mon Sep 17 00:00:00 2001 From: danielsinai Date: Sun, 28 Aug 2022 18:48:38 +0300 Subject: [PATCH] Added support for new V1 routes --- .gitignore | 2 ++ port/cli/blueprint.go | 10 +++++----- port/cli/client.go | 2 +- port/cli/entity.go | 15 +++++++++------ port/cli/permission.go | 2 +- port/cli/relation.go | 4 ++-- port/resource_port_entity.go | 4 ++-- 7 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..a091954c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.vscode/ +.env \ No newline at end of file diff --git a/port/cli/blueprint.go b/port/cli/blueprint.go index e1b8c4bf..093fff68 100644 --- a/port/cli/blueprint.go +++ b/port/cli/blueprint.go @@ -8,11 +8,11 @@ import ( func (c *PortClient) ReadBlueprint(ctx context.Context, id string) (*Blueprint, error) { pb := &PortBody{} - url := "v0.1/blueprints/{identifier}" + url := "v1/blueprints/{identifier}" resp, err := c.Client.R(). SetContext(ctx). SetHeader("Accept", "application/json"). - SetQueryParam("exclude_mirror_properties", "true"). + SetQueryParam("exclude_calculated_properties", "true"). SetResult(pb). SetPathParam("identifier", id). Get(url) @@ -26,7 +26,7 @@ func (c *PortClient) ReadBlueprint(ctx context.Context, id string) (*Blueprint, } func (c *PortClient) CreateBlueprint(ctx context.Context, b *Blueprint) (*Blueprint, error) { - url := "v0.1/blueprints" + url := "v1/blueprints" resp, err := c.Client.R(). SetBody(b). SetContext(ctx). @@ -46,7 +46,7 @@ func (c *PortClient) CreateBlueprint(ctx context.Context, b *Blueprint) (*Bluepr } func (c *PortClient) UpdateBlueprint(ctx context.Context, b *Blueprint, id string) (*Blueprint, error) { - url := "v0.1/blueprints/{identifier}" + url := "v1/blueprints/{identifier}" resp, err := c.Client.R(). SetBody(b). SetContext(ctx). @@ -67,7 +67,7 @@ func (c *PortClient) UpdateBlueprint(ctx context.Context, b *Blueprint, id strin } func (c *PortClient) DeleteBlueprint(ctx context.Context, id string) error { - url := "v0.1/blueprints/{identifier}" + url := "v1/blueprints/{identifier}" resp, err := c.Client.R(). SetContext(ctx). SetHeader("Accept", "application/json"). diff --git a/port/cli/client.go b/port/cli/client.go index 908a22f1..a8474b8f 100644 --- a/port/cli/client.go +++ b/port/cli/client.go @@ -42,7 +42,7 @@ func New(baseURL string, opts ...Option) (*PortClient, error) { } func (c *PortClient) Authenticate(ctx context.Context, clientID, clientSecret string) (string, error) { - url := "v0.1/auth/access_token" + url := "v1/auth/access_token" resp, err := c.Client.R(). SetContext(ctx). SetQueryParam("client_id", clientID). diff --git a/port/cli/entity.go b/port/cli/entity.go index 5e3fc5c6..927a2df7 100644 --- a/port/cli/entity.go +++ b/port/cli/entity.go @@ -6,11 +6,12 @@ import ( "fmt" ) -func (c *PortClient) ReadEntity(ctx context.Context, id string) (*Entity, error) { - url := "v0.1/entities/{identifier}" +func (c *PortClient) ReadEntity(ctx context.Context, id string, blueprint string) (*Entity, error) { + url := "v1/blueprints/{blueprint}/entities/{identifier}" resp, err := c.Client.R(). SetHeader("Accept", "application/json"). - SetQueryParam("exclude_mirror_properties", "true"). + SetQueryParam("exclude_calculated_properties", "true"). + SetPathParam(("blueprint"), blueprint). SetPathParam("identifier", id). Get(url) if err != nil { @@ -25,10 +26,11 @@ func (c *PortClient) ReadEntity(ctx context.Context, id string) (*Entity, error) } func (c *PortClient) CreateEntity(ctx context.Context, e *Entity) (*Entity, error) { - url := "v0.1/entities" + url := "v1/blueprints/{blueprint}/entities" pb := &PortBody{} resp, err := c.Client.R(). SetBody(e). + SetPathParam(("blueprint"), e.Blueprint). SetQueryParam("upsert", "true"). SetResult(&pb). Post(url) @@ -41,11 +43,12 @@ func (c *PortClient) CreateEntity(ctx context.Context, e *Entity) (*Entity, erro return &pb.Entity, nil } -func (c *PortClient) DeleteEntity(ctx context.Context, id string) error { - url := "v0.1/entities/{identifier}" +func (c *PortClient) DeleteEntity(ctx context.Context, id string, blueprint string) error { + url := "v1/blueprints/{blueprint}/entities/{identifier}" pb := &PortBody{} resp, err := c.Client.R(). SetHeader("Accept", "application/json"). + SetPathParam("blueprint", blueprint). SetPathParam("identifier", id). SetResult(pb). Delete(url) diff --git a/port/cli/permission.go b/port/cli/permission.go index 29b6a3cb..6881f623 100644 --- a/port/cli/permission.go +++ b/port/cli/permission.go @@ -7,7 +7,7 @@ import ( ) func (c *PortClient) CreatePermissions(ctx context.Context, clientID string, scopes ...string) error { - url := "v0.1/apps/{app_id}/permissions" + url := "v1/apps/{app_id}/permissions" resp, err := c.Client.R(). SetContext(ctx). SetHeader("Accept", "application/json"). diff --git a/port/cli/relation.go b/port/cli/relation.go index 711fcd2e..82720c05 100644 --- a/port/cli/relation.go +++ b/port/cli/relation.go @@ -6,7 +6,7 @@ import ( ) func (c *PortClient) CreateRelation(ctx context.Context, bpID string, r *Relation) (string, error) { - url := "v0.1/blueprints/{identifier}/relations" + url := "v1/blueprints/{identifier}/relations" result := map[string]interface{}{} resp, err := c.Client.R(). SetBody(r). @@ -24,7 +24,7 @@ func (c *PortClient) CreateRelation(ctx context.Context, bpID string, r *Relatio } func (c *PortClient) ReadRelations(ctx context.Context, blueprintID string) ([]*Relation, error) { - url := "v0.1/relations" + url := "v1/relations" result := map[string]interface{}{} resp, err := c.Client.R(). SetContext(ctx). diff --git a/port/resource_port_entity.go b/port/resource_port_entity.go index 2a822879..40049d86 100644 --- a/port/resource_port_entity.go +++ b/port/resource_port_entity.go @@ -111,7 +111,7 @@ func newEntityResource() *schema.Resource { func deleteEntity(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics c := m.(*cli.PortClient) - err := c.DeleteEntity(ctx, d.Id()) + err := c.DeleteEntity(ctx, d.Id(), d.Get("blueprint").(string)) if err != nil { return diag.FromErr(err) } @@ -245,7 +245,7 @@ func createEntity(ctx context.Context, d *schema.ResourceData, m interface{}) di func readEntity(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { var diags diag.Diagnostics c := m.(*cli.PortClient) - e, err := c.ReadEntity(ctx, d.Id()) + e, err := c.ReadEntity(ctx, d.Id(), d.Get("blueprint").(string)) if err != nil { return diag.FromErr(err) }