Skip to content

Commit 3248b7c

Browse files
omerdemirokactions-user
authored andcommitted
Make manual adapter framework cloud-provider agnostic by moving PredefinedRole to GCP-specific interface (#2799)
GitOrigin-RevId: 1a1ef38828617466ef56ec15383f15d76559fc0e
1 parent 3fccec8 commit 3248b7c

File tree

7 files changed

+43
-49
lines changed

7 files changed

+43
-49
lines changed

sources/aws/apigateway-api-key.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@ type apiGatewayKeyWrapper struct {
2525
*Base
2626
}
2727

28-
func (d *apiGatewayKeyWrapper) PredefinedRole() string {
29-
// TODO: https://linear.app/overmind/issue/ENG-1526/ensure-the-manual-adapter-framework-is-cloud-provider-agnostic
30-
return ""
31-
}
32-
3328
// NewApiGatewayAPIKey creates a new apiGatewayKeyWrapper for AWS API Gateway API Key
3429
func NewApiGatewayAPIKey(client *apigateway.Client, accountID, region string) sources.SearchableListableWrapper {
3530
return &apiGatewayKeyWrapper{

sources/aws/apigateway-stage.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,3 @@ func convertGetStageOutputToStage(output *apigateway.GetStageOutput) types.Stage
213213
Tags: output.Tags,
214214
}
215215
}
216-
217-
func (d *apiGatewayStageWrapper) PredefinedRole() string {
218-
// TODO: https://linear.app/overmind/issue/ENG-1526/ensure-the-manual-adapter-framework-is-cloud-provider-agnostic
219-
return ""
220-
}

sources/example/custom_searchable_listable.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,3 @@ func (d *customComputeInstanceWrapper) IAMPermissions() []string {
173173
"compute.instances.list",
174174
}
175175
}
176-
177-
func (d *customComputeInstanceWrapper) PredefinedRole() string {
178-
return "roles/compute.viewer"
179-
}

sources/example/standard_searchable_listable.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,3 @@ func (d *computeInstanceWrapper) IAMPermissions() []string {
194194
"compute.instances.list",
195195
}
196196
}
197-
198-
func (d *computeInstanceWrapper) PredefinedRole() string {
199-
return "roles/compute.viewer"
200-
}

sources/gcp/shared/base.go

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import (
1111
// It adds the project ID and zone to the base struct
1212
// and makes them available to concrete wrapper implementations.
1313
type ZoneBase struct {
14-
projectID string
15-
zone string
14+
GCPBase
15+
zone string
1616

1717
*shared.Base
1818
}
@@ -25,8 +25,10 @@ func NewZoneBase(
2525
item shared.ItemType,
2626
) *ZoneBase {
2727
return &ZoneBase{
28-
projectID: projectID,
29-
zone: zone,
28+
GCPBase: GCPBase{
29+
projectID: projectID,
30+
},
31+
zone: zone,
3032
Base: shared.NewBase(
3133
category,
3234
item,
@@ -35,11 +37,6 @@ func NewZoneBase(
3537
}
3638
}
3739

38-
// ProjectID returns the project ID
39-
func (m *ZoneBase) ProjectID() string {
40-
return m.projectID
41-
}
42-
4340
// Zone returns the zone
4441
func (m *ZoneBase) Zone() string {
4542
return m.zone
@@ -55,8 +52,8 @@ func (m *ZoneBase) DefaultScope() string {
5552
// It adds the project ID and region to the base struct
5653
// and makes them available to concrete wrapper implementations.
5754
type RegionBase struct {
58-
projectID string
59-
region string
55+
GCPBase
56+
region string
6057

6158
*shared.Base
6259
}
@@ -69,8 +66,10 @@ func NewRegionBase(
6966
item shared.ItemType,
7067
) *RegionBase {
7168
return &RegionBase{
72-
projectID: projectID,
73-
region: region,
69+
GCPBase: GCPBase{
70+
projectID: projectID,
71+
},
72+
region: region,
7473
Base: shared.NewBase(
7574
category,
7675
item,
@@ -79,11 +78,6 @@ func NewRegionBase(
7978
}
8079
}
8180

82-
// ProjectID returns the project ID
83-
func (m *RegionBase) ProjectID() string {
84-
return m.projectID
85-
}
86-
8781
// Region returns the region
8882
func (m *RegionBase) Region() string {
8983
return m.region
@@ -99,7 +93,7 @@ func (m *RegionBase) DefaultScope() string {
9993
// It adds the project ID to the base struct
10094
// and makes them available to concrete wrapper implementations.
10195
type ProjectBase struct {
102-
projectID string
96+
GCPBase
10397

10498
*shared.Base
10599
}
@@ -111,7 +105,9 @@ func NewProjectBase(
111105
item shared.ItemType,
112106
) *ProjectBase {
113107
return &ProjectBase{
114-
projectID: projectID,
108+
GCPBase: GCPBase{
109+
projectID: projectID,
110+
},
115111
Base: shared.NewBase(
116112
category,
117113
item,
@@ -120,13 +116,20 @@ func NewProjectBase(
120116
}
121117
}
122118

123-
// ProjectID returns the project ID
124-
func (m *ProjectBase) ProjectID() string {
125-
return m.projectID
126-
}
127-
128119
// DefaultScope returns the default scope
129120
// Project ID is used to create the default scope.
130121
func (m *ProjectBase) DefaultScope() string {
131122
return m.Scopes()[0]
132123
}
124+
125+
type GCPBase struct {
126+
projectID string
127+
}
128+
129+
func (g *GCPBase) PredefinedRole() string {
130+
panic("Predefined role not implemented")
131+
}
132+
133+
func (g *GCPBase) ProjectID() string {
134+
return g.projectID
135+
}

sources/gcp/shared/predefined-roles.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package shared
22

3+
type WithPredefinedRole interface {
4+
PredefinedRole() string
5+
}
6+
37
type role struct {
48
Role string
59
Link string

sources/transformer.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ type Wrapper interface {
4141
PotentialLinks() map[shared.ItemType]bool
4242
AdapterMetadata() *sdp.AdapterMetadata
4343
IAMPermissions() []string
44-
PredefinedRole() string
4544
}
4645

4746
// ListableWrapper defines an optional interface for resources that support listing.
@@ -826,18 +825,24 @@ func expectedSearchQueryFormat(keywords []ItemTypeLookups) string {
826825

827826
// validatePredefinedRole validates that the wrapper's predefined role and IAM permissions are consistent
828827
func validatePredefinedRole(wrapper Wrapper) error {
829-
predefinedRole := wrapper.PredefinedRole()
828+
pdr, ok := wrapper.(gcpshared.WithPredefinedRole)
829+
if !ok {
830+
return fmt.Errorf("gcp predefined role not supported")
831+
}
832+
833+
pRole := pdr.PredefinedRole()
834+
830835
iamPermissions := wrapper.IAMPermissions()
831836

832837
// Predefined role must be specified
833-
if predefinedRole == "" {
838+
if pRole == "" {
834839
return fmt.Errorf("wrapper %s must specify a predefined role", wrapper.Type())
835840
}
836841

837842
// Check if the predefined role exists in the map
838-
role, exists := gcpshared.PredefinedRoles[predefinedRole]
843+
role, exists := gcpshared.PredefinedRoles[pRole]
839844
if !exists {
840-
return fmt.Errorf("predefined role %s is not found in PredefinedRoles map", predefinedRole)
845+
return fmt.Errorf("predefined role %s is not found in PredefinedRoles map", pRole)
841846
}
842847

843848
// Check if all IAM permissions from the wrapper exist in the predefined role's IAMPermissions
@@ -850,7 +855,7 @@ func validatePredefinedRole(wrapper Wrapper) error {
850855
}
851856
}
852857
if !found {
853-
return fmt.Errorf("IAM permission %s from wrapper is not included in predefined role %s IAMPermissions", perm, predefinedRole)
858+
return fmt.Errorf("IAM permission %s from wrapper is not included in predefined role %s IAMPermissions", perm, pRole)
854859
}
855860
}
856861

0 commit comments

Comments
 (0)