Skip to content

Commit bcced1a

Browse files
omerdemirokactions-user
authored andcommitted
chore: remove duplicate type definitions in gcp manual adapters (#1981)
# Cleanup duplicate item type definitions During dynamic adapter development we had to define the item types centrally to prevent import cycling. We need to clean up the ones defined in the individual manual adapter files. GitOrigin-RevId: b2e570b1aa236354994681064b41c31052ce56e5
1 parent 0919ece commit bcced1a

File tree

58 files changed

+260
-418
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+260
-418
lines changed

sources/gcp/dynamic/adapter-listable.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dynamic
33
import (
44
"context"
55
"fmt"
6+
67
"github.com/overmindtech/cli/discovery"
78
"github.com/overmindtech/cli/sdp-go"
89
gcpshared "github.com/overmindtech/cli/sources/gcp/shared"

sources/gcp/dynamic/adapters.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dynamic
22

33
import (
44
"fmt"
5+
56
"github.com/overmindtech/cli/discovery"
67
gcpshared "github.com/overmindtech/cli/sources/gcp/shared"
78
"github.com/overmindtech/cli/sources/shared"

sources/gcp/integration-tests/compute-autoscaler_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ func TestComputeAutoscalerIntegration(t *testing.T) {
114114
}
115115

116116
linkedItem := sdpItem.GetLinkedItemQueries()[0]
117-
if linkedItem.GetQuery().GetType() != manual.ComputeInstanceGroupManager.String() {
118-
t.Fatalf("Expected linked item type to be %s, got: %s", manual.ComputeInstanceGroupManager, linkedItem.GetQuery().GetType())
117+
if linkedItem.GetQuery().GetType() != gcpshared.ComputeInstanceGroupManager.String() {
118+
t.Fatalf("Expected linked item type to be %s, got: %s", gcpshared.ComputeInstanceGroupManager, linkedItem.GetQuery().GetType())
119119
}
120120

121121
if linkedItem.GetQuery().GetQuery() != instanceGroupManagerName {

sources/gcp/integration-tests/compute-instance-group-manager_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ func TestComputeInstanceGroupManagerIntegration(t *testing.T) {
8989

9090
// [SPEC] Ensure Instance Template is present
9191
linkedItem := sdpItem.GetLinkedItemQueries()[0]
92-
if linkedItem.GetQuery().GetType() != manual.ComputeInstanceTemplate.String() {
93-
t.Fatalf("Expected linked item type to be %s, got: %s", manual.ComputeInstanceTemplate, linkedItem.GetQuery().GetType())
92+
if linkedItem.GetQuery().GetType() != gcpshared.ComputeInstanceTemplate.String() {
93+
t.Fatalf("Expected linked item type to be %s, got: %s", gcpshared.ComputeInstanceTemplate, linkedItem.GetQuery().GetType())
9494
}
9595

9696
if linkedItem.GetQuery().GetQuery() != templateName {

sources/gcp/integration-tests/compute-instant-snapshot_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ func TestComputeInstantSnapshotsIntegration(t *testing.T) {
127127

128128
// [SPEC] Ensure Source Disk is linked
129129
linkedItem := sdpItem.GetLinkedItemQueries()[0]
130-
if linkedItem.GetQuery().GetType() != manual.ComputeDisk.String() {
131-
t.Fatalf("Expected linked item type to be %s, got: %s", manual.ComputeDisk, linkedItem.GetQuery().GetType())
130+
if linkedItem.GetQuery().GetType() != gcpshared.ComputeDisk.String() {
131+
t.Fatalf("Expected linked item type to be %s, got: %s", gcpshared.ComputeDisk, linkedItem.GetQuery().GetType())
132132
}
133133

134134
if linkedItem.GetQuery().GetQuery() != diskName {

sources/gcp/integration-tests/compute-node-group_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ func TestComputeNodeGroupIntegration(t *testing.T) {
109109
}
110110

111111
linkedItem := sdpItem.GetLinkedItemQueries()[0]
112-
if linkedItem.GetQuery().GetType() != manual.ComputeNodeTemplate.String() {
113-
t.Fatalf("Expected linked item type to be %s, got: %s", manual.ComputeNodeTemplate.String(), linkedItem.GetQuery().GetType())
112+
if linkedItem.GetQuery().GetType() != gcpshared.ComputeNodeTemplate.String() {
113+
t.Fatalf("Expected linked item type to be %s, got: %s", gcpshared.ComputeNodeTemplate.String(), linkedItem.GetQuery().GetType())
114114
}
115115

116116
if linkedItem.GetQuery().GetQuery() != nodeTemplateName {
@@ -189,7 +189,7 @@ func TestComputeNodeGroupIntegration(t *testing.T) {
189189

190190
queryTests := shared.QueryTests{
191191
{
192-
ExpectedType: manual.ComputeNodeGroup.String(),
192+
ExpectedType: gcpshared.ComputeNodeGroup.String(),
193193
ExpectedMethod: sdp.QueryMethod_SEARCH,
194194
ExpectedQuery: nodeTemplateName,
195195
ExpectedScope: "*",
@@ -203,8 +203,8 @@ func TestComputeNodeGroupIntegration(t *testing.T) {
203203
shared.RunStaticTests(t, nodeTemplateAdapter, sdpItem, queryTests)
204204

205205
linkedItem := sdpItem.GetLinkedItemQueries()[0]
206-
if linkedItem.GetQuery().GetType() != manual.ComputeNodeGroup.String() {
207-
t.Fatalf("Expected linked item type to be %s, got: %s", manual.ComputeNodeGroup.String(), linkedItem.GetQuery().GetType())
206+
if linkedItem.GetQuery().GetType() != gcpshared.ComputeNodeGroup.String() {
207+
t.Fatalf("Expected linked item type to be %s, got: %s", gcpshared.ComputeNodeGroup.String(), linkedItem.GetQuery().GetType())
208208
}
209209

210210
if linkedItem.GetQuery().GetQuery() != nodeTemplateName {

sources/gcp/manual/cloud-kms-crypto-key.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ import (
1414
"github.com/overmindtech/cli/sources/shared"
1515
)
1616

17-
var (
18-
CloudKMSCryptoKey = shared.NewItemType(gcpshared.GCP, gcpshared.CloudKMS, gcpshared.CryptoKey)
19-
20-
CloudKMSCryptoKeyLookupByName = shared.NewItemTypeLookup("name", CloudKMSCryptoKey)
21-
)
17+
var CloudKMSCryptoKeyLookupByName = shared.NewItemTypeLookup("name", gcpshared.CloudKMSCryptoKey)
2218

2319
// cloudKMSCryptoKeyWrapper wraps the KMS CryptoKey client for SDP adaptation.
2420
type cloudKMSCryptoKeyWrapper struct {
@@ -34,7 +30,7 @@ func NewCloudKMSCryptoKey(client gcpshared.CloudKMSCryptoKeyClient, projectID st
3430
ProjectBase: gcpshared.NewProjectBase(
3531
projectID,
3632
sdp.AdapterCategory_ADAPTER_CATEGORY_SECURITY,
37-
CloudKMSCryptoKey,
33+
gcpshared.CloudKMSCryptoKey,
3834
),
3935
}
4036
}
@@ -43,8 +39,8 @@ func NewCloudKMSCryptoKey(client gcpshared.CloudKMSCryptoKeyClient, projectID st
4339
func (c cloudKMSCryptoKeyWrapper) PotentialLinks() map[shared.ItemType]bool {
4440
return shared.NewItemTypesSet(
4541
gcpshared.CloudKMSCryptoKeyVersion,
46-
CloudKMSEKMConnection,
47-
IAMPolicy,
42+
gcpshared.CloudKMSEKMConnection,
43+
gcpshared.IAMPolicy,
4844
)
4945
}
5046

@@ -178,7 +174,7 @@ func (c cloudKMSCryptoKeyWrapper) gcpCryptoKeyToSDPItem(cryptoKey *kmspb.CryptoK
178174
}
179175

180176
sdpItem := &sdp.Item{
181-
Type: CloudKMSCryptoKey.String(),
177+
Type: gcpshared.CloudKMSCryptoKey.String(),
182178
UniqueAttribute: "uniqueAttr",
183179
Attributes: attributes,
184180
Scope: c.DefaultScope(),
@@ -190,7 +186,7 @@ func (c cloudKMSCryptoKeyWrapper) gcpCryptoKeyToSDPItem(cryptoKey *kmspb.CryptoK
190186
// https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings.cryptoKeys/getIamPolicy
191187
sdpItem.LinkedItemQueries = append(sdpItem.LinkedItemQueries, &sdp.LinkedItemQuery{
192188
Query: &sdp.Query{
193-
Type: IAMPolicy.String(),
189+
Type: gcpshared.IAMPolicy.String(),
194190
Method: sdp.QueryMethod_GET,
195191
//TODO(Nauany): "":getIamPolicy" needs to be appended at the end of the URL, ensure team is aware
196192
Query: shared.CompositeLookupKey(location, keyRing, cryptoKeyName),
@@ -235,7 +231,7 @@ func (c cloudKMSCryptoKeyWrapper) gcpCryptoKeyToSDPItem(cryptoKey *kmspb.CryptoK
235231
if len(backendVals) == 2 && backendVals[0] != "" && backendVals[1] != "" {
236232
sdpItem.LinkedItemQueries = append(sdpItem.LinkedItemQueries, &sdp.LinkedItemQuery{
237233
Query: &sdp.Query{
238-
Type: CloudKMSEKMConnection.String(),
234+
Type: gcpshared.CloudKMSEKMConnection.String(),
239235
Method: sdp.QueryMethod_GET,
240236
Query: shared.CompositeLookupKey(backendVals...),
241237
Scope: c.ProjectID(),

sources/gcp/manual/cloud-kms-crypto-key_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func TestCloudKMSCryptoKey(t *testing.T) {
6161
},
6262
},
6363
{
64-
ExpectedType: manual.CloudKMSEKMConnection.String(),
64+
ExpectedType: gcpshared.CloudKMSEKMConnection.String(),
6565
ExpectedMethod: sdp.QueryMethod_GET,
6666
ExpectedQuery: "global|valid-ekm-connection",
6767
ExpectedScope: "test-project-id",
@@ -71,7 +71,7 @@ func TestCloudKMSCryptoKey(t *testing.T) {
7171
},
7272
},
7373
{
74-
ExpectedType: manual.IAMPolicy.String(),
74+
ExpectedType: gcpshared.IAMPolicy.String(),
7575
ExpectedMethod: sdp.QueryMethod_GET,
7676
ExpectedQuery: "global|test-keyring|test-key",
7777
ExpectedScope: "test-project-id",

sources/gcp/manual/cloud-kms-ekm-connection.go

Lines changed: 0 additions & 11 deletions
This file was deleted.

sources/gcp/manual/cloud-kms-key-ring.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@ import (
1515
)
1616

1717
var (
18-
CloudKMSKeyRing = shared.NewItemType(gcpshared.GCP, gcpshared.CloudKMS, gcpshared.KeyRing)
19-
20-
CloudKMSCryptoKeyRingLookupByName = shared.NewItemTypeLookup("name", CloudKMSKeyRing)
21-
CloudKMSCryptoKeyRingLookupByLocation = shared.NewItemTypeLookup("location", CloudKMSKeyRing)
18+
CloudKMSCryptoKeyRingLookupByName = shared.NewItemTypeLookup("name", gcpshared.CloudKMSKeyRing)
19+
CloudKMSCryptoKeyRingLookupByLocation = shared.NewItemTypeLookup("location", gcpshared.CloudKMSKeyRing)
2220
)
2321

2422
// cloudKMSKeyRingWrapper wraps the KMS KeyRing client for SDP adaptation.
@@ -35,15 +33,15 @@ func NewCloudKMSKeyRing(client gcpshared.CloudKMSKeyRingClient, projectID string
3533
ProjectBase: gcpshared.NewProjectBase(
3634
projectID,
3735
sdp.AdapterCategory_ADAPTER_CATEGORY_SECURITY,
38-
CloudKMSKeyRing,
36+
gcpshared.CloudKMSKeyRing,
3937
),
4038
}
4139
}
4240

4341
// PotentialLinks returns the potential links for the kms key ring
4442
func (c cloudKMSKeyRingWrapper) PotentialLinks() map[shared.ItemType]bool {
4543
return shared.NewItemTypesSet(
46-
IAMPolicy,
44+
gcpshared.IAMPolicy,
4745
)
4846
}
4947

@@ -168,7 +166,7 @@ func (c cloudKMSKeyRingWrapper) gcpKeyRingToSDPItem(keyRing *kmspb.KeyRing) (*sd
168166
}
169167

170168
sdpItem := &sdp.Item{
171-
Type: CloudKMSKeyRing.String(),
169+
Type: gcpshared.CloudKMSKeyRing.String(),
172170
UniqueAttribute: "uniqueAttr",
173171
Attributes: attributes,
174172
Scope: c.DefaultScope(),
@@ -179,7 +177,7 @@ func (c cloudKMSKeyRingWrapper) gcpKeyRingToSDPItem(keyRing *kmspb.KeyRing) (*sd
179177
// https://cloud.google.com/kms/docs/reference/rest/v1/projects.locations.keyRings/getIamPolicy
180178
sdpItem.LinkedItemQueries = append(sdpItem.LinkedItemQueries, &sdp.LinkedItemQuery{
181179
Query: &sdp.Query{
182-
Type: IAMPolicy.String(),
180+
Type: gcpshared.IAMPolicy.String(),
183181
Method: sdp.QueryMethod_GET,
184182
//TODO(Nauany): "":getIamPolicy" needs to be appended at the end of the URL, ensure team is aware
185183
Query: shared.CompositeLookupKey(keyRingVals...),

0 commit comments

Comments
 (0)