Skip to content

Commit

Permalink
Merge pull request #5 from port-labs/danielsinai-v1-support
Browse files Browse the repository at this point in the history
Added support for new V1 routes
  • Loading branch information
danielsinai authored Aug 29, 2022
2 parents a6a52f0 + 4c084b8 commit a049149
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/
.env
10 changes: 5 additions & 5 deletions port/cli/blueprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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).
Expand All @@ -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).
Expand All @@ -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").
Expand Down
2 changes: 1 addition & 1 deletion port/cli/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
15 changes: 9 additions & 6 deletions port/cli/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion port/cli/permission.go
Original file line number Diff line number Diff line change
Expand Up @@ -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").
Expand Down
4 changes: 2 additions & 2 deletions port/cli/relation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -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).
Expand Down
4 changes: 2 additions & 2 deletions port/resource_port_entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit a049149

Please sign in to comment.