Skip to content

Commit a049149

Browse files
authored
Merge pull request #5 from port-labs/danielsinai-v1-support
Added support for new V1 routes
2 parents a6a52f0 + 4c084b8 commit a049149

File tree

7 files changed

+22
-17
lines changed

7 files changed

+22
-17
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.vscode/
2+
.env

port/cli/blueprint.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ import (
88

99
func (c *PortClient) ReadBlueprint(ctx context.Context, id string) (*Blueprint, error) {
1010
pb := &PortBody{}
11-
url := "v0.1/blueprints/{identifier}"
11+
url := "v1/blueprints/{identifier}"
1212
resp, err := c.Client.R().
1313
SetContext(ctx).
1414
SetHeader("Accept", "application/json").
15-
SetQueryParam("exclude_mirror_properties", "true").
15+
SetQueryParam("exclude_calculated_properties", "true").
1616
SetResult(pb).
1717
SetPathParam("identifier", id).
1818
Get(url)
@@ -26,7 +26,7 @@ func (c *PortClient) ReadBlueprint(ctx context.Context, id string) (*Blueprint,
2626
}
2727

2828
func (c *PortClient) CreateBlueprint(ctx context.Context, b *Blueprint) (*Blueprint, error) {
29-
url := "v0.1/blueprints"
29+
url := "v1/blueprints"
3030
resp, err := c.Client.R().
3131
SetBody(b).
3232
SetContext(ctx).
@@ -46,7 +46,7 @@ func (c *PortClient) CreateBlueprint(ctx context.Context, b *Blueprint) (*Bluepr
4646
}
4747

4848
func (c *PortClient) UpdateBlueprint(ctx context.Context, b *Blueprint, id string) (*Blueprint, error) {
49-
url := "v0.1/blueprints/{identifier}"
49+
url := "v1/blueprints/{identifier}"
5050
resp, err := c.Client.R().
5151
SetBody(b).
5252
SetContext(ctx).
@@ -67,7 +67,7 @@ func (c *PortClient) UpdateBlueprint(ctx context.Context, b *Blueprint, id strin
6767
}
6868

6969
func (c *PortClient) DeleteBlueprint(ctx context.Context, id string) error {
70-
url := "v0.1/blueprints/{identifier}"
70+
url := "v1/blueprints/{identifier}"
7171
resp, err := c.Client.R().
7272
SetContext(ctx).
7373
SetHeader("Accept", "application/json").

port/cli/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func New(baseURL string, opts ...Option) (*PortClient, error) {
4242
}
4343

4444
func (c *PortClient) Authenticate(ctx context.Context, clientID, clientSecret string) (string, error) {
45-
url := "v0.1/auth/access_token"
45+
url := "v1/auth/access_token"
4646
resp, err := c.Client.R().
4747
SetContext(ctx).
4848
SetQueryParam("client_id", clientID).

port/cli/entity.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import (
66
"fmt"
77
)
88

9-
func (c *PortClient) ReadEntity(ctx context.Context, id string) (*Entity, error) {
10-
url := "v0.1/entities/{identifier}"
9+
func (c *PortClient) ReadEntity(ctx context.Context, id string, blueprint string) (*Entity, error) {
10+
url := "v1/blueprints/{blueprint}/entities/{identifier}"
1111
resp, err := c.Client.R().
1212
SetHeader("Accept", "application/json").
13-
SetQueryParam("exclude_mirror_properties", "true").
13+
SetQueryParam("exclude_calculated_properties", "true").
14+
SetPathParam(("blueprint"), blueprint).
1415
SetPathParam("identifier", id).
1516
Get(url)
1617
if err != nil {
@@ -25,10 +26,11 @@ func (c *PortClient) ReadEntity(ctx context.Context, id string) (*Entity, error)
2526
}
2627

2728
func (c *PortClient) CreateEntity(ctx context.Context, e *Entity) (*Entity, error) {
28-
url := "v0.1/entities"
29+
url := "v1/blueprints/{blueprint}/entities"
2930
pb := &PortBody{}
3031
resp, err := c.Client.R().
3132
SetBody(e).
33+
SetPathParam(("blueprint"), e.Blueprint).
3234
SetQueryParam("upsert", "true").
3335
SetResult(&pb).
3436
Post(url)
@@ -41,11 +43,12 @@ func (c *PortClient) CreateEntity(ctx context.Context, e *Entity) (*Entity, erro
4143
return &pb.Entity, nil
4244
}
4345

44-
func (c *PortClient) DeleteEntity(ctx context.Context, id string) error {
45-
url := "v0.1/entities/{identifier}"
46+
func (c *PortClient) DeleteEntity(ctx context.Context, id string, blueprint string) error {
47+
url := "v1/blueprints/{blueprint}/entities/{identifier}"
4648
pb := &PortBody{}
4749
resp, err := c.Client.R().
4850
SetHeader("Accept", "application/json").
51+
SetPathParam("blueprint", blueprint).
4952
SetPathParam("identifier", id).
5053
SetResult(pb).
5154
Delete(url)

port/cli/permission.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func (c *PortClient) CreatePermissions(ctx context.Context, clientID string, scopes ...string) error {
10-
url := "v0.1/apps/{app_id}/permissions"
10+
url := "v1/apps/{app_id}/permissions"
1111
resp, err := c.Client.R().
1212
SetContext(ctx).
1313
SetHeader("Accept", "application/json").

port/cli/relation.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
)
77

88
func (c *PortClient) CreateRelation(ctx context.Context, bpID string, r *Relation) (string, error) {
9-
url := "v0.1/blueprints/{identifier}/relations"
9+
url := "v1/blueprints/{identifier}/relations"
1010
result := map[string]interface{}{}
1111
resp, err := c.Client.R().
1212
SetBody(r).
@@ -24,7 +24,7 @@ func (c *PortClient) CreateRelation(ctx context.Context, bpID string, r *Relatio
2424
}
2525

2626
func (c *PortClient) ReadRelations(ctx context.Context, blueprintID string) ([]*Relation, error) {
27-
url := "v0.1/relations"
27+
url := "v1/relations"
2828
result := map[string]interface{}{}
2929
resp, err := c.Client.R().
3030
SetContext(ctx).

port/resource_port_entity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func newEntityResource() *schema.Resource {
111111
func deleteEntity(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
112112
var diags diag.Diagnostics
113113
c := m.(*cli.PortClient)
114-
err := c.DeleteEntity(ctx, d.Id())
114+
err := c.DeleteEntity(ctx, d.Id(), d.Get("blueprint").(string))
115115
if err != nil {
116116
return diag.FromErr(err)
117117
}
@@ -245,7 +245,7 @@ func createEntity(ctx context.Context, d *schema.ResourceData, m interface{}) di
245245
func readEntity(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
246246
var diags diag.Diagnostics
247247
c := m.(*cli.PortClient)
248-
e, err := c.ReadEntity(ctx, d.Id())
248+
e, err := c.ReadEntity(ctx, d.Id(), d.Get("blueprint").(string))
249249
if err != nil {
250250
return diag.FromErr(err)
251251
}

0 commit comments

Comments
 (0)