Skip to content

Commit 2c7d7b6

Browse files
tomasdembellidylanratcliffe
authored andcommitted
add rest api relation to apigateway adapters
1 parent e4a3f2e commit 2c7d7b6

File tree

6 files changed

+87
-9
lines changed

6 files changed

+87
-9
lines changed

adapters/apigateway-authorizer.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func convertGetAuthorizerOutputToAuthorizer(output *apigateway.GetAuthorizerOutp
2727
}
2828
}
2929

30-
func authorizerOutputMapper(scope string, awsItem *types.Authorizer) (*sdp.Item, error) {
30+
func authorizerOutputMapper(query, scope string, awsItem *types.Authorizer) (*sdp.Item, error) {
3131
attributes, err := adapterhelpers.ToAttributesWithExclude(awsItem, "tags")
3232
if err != nil {
3333
return nil, err
@@ -40,6 +40,20 @@ func authorizerOutputMapper(scope string, awsItem *types.Authorizer) (*sdp.Item,
4040
Scope: scope,
4141
}
4242

43+
item.LinkedItemQueries = append(item.LinkedItemQueries, &sdp.LinkedItemQuery{
44+
Query: &sdp.Query{
45+
Type: "apigateway-rest-api",
46+
Method: sdp.QueryMethod_GET,
47+
Query: strings.Split(query, "/")[0],
48+
Scope: scope,
49+
},
50+
BlastPropagation: &sdp.BlastPropagation{
51+
// They are tightly coupled, so we need to propagate the blast to the linked item
52+
In: true,
53+
Out: true,
54+
},
55+
})
56+
4357
return &item, nil
4458
}
4559

@@ -107,8 +121,8 @@ func NewAPIGatewayAuthorizerAdapter(client *apigateway.Client, accountID string,
107121

108122
return items, nil
109123
},
110-
ItemMapper: func(_, scope string, awsItem *types.Authorizer) (*sdp.Item, error) {
111-
return authorizerOutputMapper(scope, awsItem)
124+
ItemMapper: func(query, scope string, awsItem *types.Authorizer) (*sdp.Item, error) {
125+
return authorizerOutputMapper(query, scope, awsItem)
112126
},
113127
}
114128
}

adapters/apigateway-authorizer_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package adapters
22

33
import (
4+
"github.com/overmindtech/sdp-go"
45
"testing"
56
"time"
67

@@ -24,14 +25,25 @@ func TestAuthorizerOutputMapper(t *testing.T) {
2425
AuthorizerResultTtlInSeconds: aws.Int32(300),
2526
}
2627

27-
item, err := authorizerOutputMapper("scope", awsItem)
28+
item, err := authorizerOutputMapper("rest-api-id", "scope", awsItem)
2829
if err != nil {
2930
t.Fatalf("unexpected error: %v", err)
3031
}
3132

3233
if err := item.Validate(); err != nil {
3334
t.Error(err)
3435
}
36+
37+
tests := adapterhelpers.QueryTests{
38+
{
39+
ExpectedType: "apigateway-rest-api",
40+
ExpectedMethod: sdp.QueryMethod_GET,
41+
ExpectedQuery: "rest-api-id",
42+
ExpectedScope: "scope",
43+
},
44+
}
45+
46+
tests.Execute(t, item)
3547
}
3648

3749
func TestNewAPIGatewayAuthorizerAdapter(t *testing.T) {

adapters/apigateway-deployment.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func convertGetDeploymentOutputToDeployment(output *apigateway.GetDeploymentOutp
2121
}
2222
}
2323

24-
func deploymentOutputMapper(scope string, awsItem *types.Deployment) (*sdp.Item, error) {
24+
func deploymentOutputMapper(query, scope string, awsItem *types.Deployment) (*sdp.Item, error) {
2525
attributes, err := adapterhelpers.ToAttributesWithExclude(awsItem, "tags")
2626
if err != nil {
2727
return nil, err
@@ -34,6 +34,20 @@ func deploymentOutputMapper(scope string, awsItem *types.Deployment) (*sdp.Item,
3434
Scope: scope,
3535
}
3636

37+
item.LinkedItemQueries = append(item.LinkedItemQueries, &sdp.LinkedItemQuery{
38+
Query: &sdp.Query{
39+
Type: "apigateway-rest-api",
40+
Method: sdp.QueryMethod_GET,
41+
Query: strings.Split(query, "/")[0],
42+
Scope: scope,
43+
},
44+
BlastPropagation: &sdp.BlastPropagation{
45+
// They are tightly coupled, so we need to propagate the blast to the linked item
46+
In: true,
47+
Out: true,
48+
},
49+
})
50+
3751
return &item, nil
3852
}
3953

@@ -101,8 +115,8 @@ func NewAPIGatewayDeploymentAdapter(client *apigateway.Client, accountID string,
101115

102116
return items, nil
103117
},
104-
ItemMapper: func(_, scope string, awsItem *types.Deployment) (*sdp.Item, error) {
105-
return deploymentOutputMapper(scope, awsItem)
118+
ItemMapper: func(query, scope string, awsItem *types.Deployment) (*sdp.Item, error) {
119+
return deploymentOutputMapper(query, scope, awsItem)
106120
},
107121
}
108122
}

adapters/apigateway-deployment_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package adapters
22

33
import (
4+
"github.com/overmindtech/sdp-go"
45
"testing"
56
"time"
67

@@ -18,14 +19,25 @@ func TestDeploymentOutputMapper(t *testing.T) {
1819
ApiSummary: map[string]map[string]types.MethodSnapshot{},
1920
}
2021

21-
item, err := deploymentOutputMapper("scope", awsItem)
22+
item, err := deploymentOutputMapper("rest-api-id", "scope", awsItem)
2223
if err != nil {
2324
t.Fatalf("unexpected error: %v", err)
2425
}
2526

2627
if err := item.Validate(); err != nil {
2728
t.Error(err)
2829
}
30+
31+
tests := adapterhelpers.QueryTests{
32+
{
33+
ExpectedType: "apigateway-rest-api",
34+
ExpectedMethod: sdp.QueryMethod_GET,
35+
ExpectedQuery: "rest-api-id",
36+
ExpectedScope: "scope",
37+
},
38+
}
39+
40+
tests.Execute(t, item)
2941
}
3042

3143
func TestNewAPIGatewayDeploymentAdapter(t *testing.T) {

adapters/apigateway-resource.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,20 @@ func resourceOutputMapper(query, scope string, awsItem *types.Resource) (*sdp.It
7373
}
7474
}
7575

76+
item.LinkedItemQueries = append(item.LinkedItemQueries, &sdp.LinkedItemQuery{
77+
Query: &sdp.Query{
78+
Type: "apigateway-rest-api",
79+
Method: sdp.QueryMethod_GET,
80+
Query: restApiID,
81+
Scope: scope,
82+
},
83+
BlastPropagation: &sdp.BlastPropagation{
84+
// They are tightly coupled, so we need to propagate the blast to the linked item
85+
In: true,
86+
Out: true,
87+
},
88+
})
89+
7690
return &item, nil
7791
}
7892

adapters/apigateway-resource_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package adapters
22

33
import (
4+
"github.com/overmindtech/sdp-go"
45
"testing"
56
"time"
67

@@ -152,14 +153,25 @@ func TestResourceOutputMapper(t *testing.T) {
152153
},
153154
}
154155

155-
item, err := resourceOutputMapper("rest-api-13", "scope", resource)
156+
item, err := resourceOutputMapper("rest-api-id", "scope", resource)
156157
if err != nil {
157158
t.Fatal(err)
158159
}
159160

160161
if err := item.Validate(); err != nil {
161162
t.Error(err)
162163
}
164+
165+
tests := adapterhelpers.QueryTests{
166+
{
167+
ExpectedType: "apigateway-rest-api",
168+
ExpectedMethod: sdp.QueryMethod_GET,
169+
ExpectedQuery: "rest-api-id",
170+
ExpectedScope: "scope",
171+
},
172+
}
173+
174+
tests.Execute(t, item)
163175
}
164176

165177
func TestNewAPIGatewayResourceAdapter(t *testing.T) {

0 commit comments

Comments
 (0)