Skip to content

Commit e563ebe

Browse files
author
Nicholas Thomson
committed
Move SDK operations into operations package
1 parent 427eca0 commit e563ebe

File tree

15 files changed

+128
-125
lines changed

15 files changed

+128
-125
lines changed

pkg/generate/ack/controller.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config"
2323
"github.com/aws-controllers-k8s/code-generator/pkg/generate/templateset"
2424
ackmodel "github.com/aws-controllers-k8s/code-generator/pkg/model"
25-
acksdk "github.com/aws-controllers-k8s/code-generator/pkg/sdk"
25+
ackoperations "github.com/aws-controllers-k8s/code-generator/pkg/operations"
2626
awssdkmodel "github.com/aws/aws-sdk-go/private/model/api"
2727
)
2828

@@ -61,16 +61,16 @@ var (
6161
return code.CheckExceptionMessage(r.Config(), r, httpStatusCode)
6262
},
6363
"GoCodeSetReadOneOutput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
64-
return code.SetResource(r.Config(), r, acksdk.OpTypeGet, sourceVarName, targetVarName, indentLevel)
64+
return code.SetResource(r.Config(), r, ackoperations.OpTypeGet, sourceVarName, targetVarName, indentLevel)
6565
},
6666
"GoCodeSetReadOneInput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
67-
return code.SetSDK(r.Config(), r, acksdk.OpTypeGet, sourceVarName, targetVarName, indentLevel)
67+
return code.SetSDK(r.Config(), r, ackoperations.OpTypeGet, sourceVarName, targetVarName, indentLevel)
6868
},
6969
"GoCodeSetReadManyOutput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
70-
return code.SetResource(r.Config(), r, acksdk.OpTypeList, sourceVarName, targetVarName, indentLevel)
70+
return code.SetResource(r.Config(), r, ackoperations.OpTypeList, sourceVarName, targetVarName, indentLevel)
7171
},
7272
"GoCodeSetReadManyInput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
73-
return code.SetSDK(r.Config(), r, acksdk.OpTypeList, sourceVarName, targetVarName, indentLevel)
73+
return code.SetSDK(r.Config(), r, ackoperations.OpTypeList, sourceVarName, targetVarName, indentLevel)
7474
},
7575
"GoCodeGetAttributesSetInput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
7676
return code.SetSDKGetAttributes(r.Config(), r, sourceVarName, targetVarName, indentLevel)
@@ -82,19 +82,19 @@ var (
8282
return code.SetResourceGetAttributes(r.Config(), r, sourceVarName, targetVarName, indentLevel)
8383
},
8484
"GoCodeSetCreateOutput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
85-
return code.SetResource(r.Config(), r, acksdk.OpTypeCreate, sourceVarName, targetVarName, indentLevel)
85+
return code.SetResource(r.Config(), r, ackoperations.OpTypeCreate, sourceVarName, targetVarName, indentLevel)
8686
},
8787
"GoCodeSetCreateInput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
88-
return code.SetSDK(r.Config(), r, acksdk.OpTypeCreate, sourceVarName, targetVarName, indentLevel)
88+
return code.SetSDK(r.Config(), r, ackoperations.OpTypeCreate, sourceVarName, targetVarName, indentLevel)
8989
},
9090
"GoCodeSetUpdateOutput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
91-
return code.SetResource(r.Config(), r, acksdk.OpTypeUpdate, sourceVarName, targetVarName, indentLevel)
91+
return code.SetResource(r.Config(), r, ackoperations.OpTypeUpdate, sourceVarName, targetVarName, indentLevel)
9292
},
9393
"GoCodeSetUpdateInput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
94-
return code.SetSDK(r.Config(), r, acksdk.OpTypeUpdate, sourceVarName, targetVarName, indentLevel)
94+
return code.SetSDK(r.Config(), r, ackoperations.OpTypeUpdate, sourceVarName, targetVarName, indentLevel)
9595
},
9696
"GoCodeSetDeleteInput": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
97-
return code.SetSDK(r.Config(), r, acksdk.OpTypeDelete, sourceVarName, targetVarName, indentLevel)
97+
return code.SetSDK(r.Config(), r, ackoperations.OpTypeDelete, sourceVarName, targetVarName, indentLevel)
9898
},
9999
"GoCodeSetSDKForStruct": func(r *ackmodel.CRD, targetFieldName string, targetVarName string, targetShapeRef *awssdkmodel.ShapeRef, sourceFieldPath string, sourceVarName string, indentLevel int) string {
100100
return code.SetSDKForStruct(r.Config(), r, targetFieldName, targetVarName, targetShapeRef, sourceFieldPath, sourceVarName, indentLevel)
@@ -109,16 +109,16 @@ var (
109109
return strings.TrimSpace(subject) == ""
110110
},
111111
"GoCodeRequiredFieldsMissingFromReadOneInput": func(r *ackmodel.CRD, koVarName string, indentLevel int) string {
112-
return code.CheckRequiredFieldsMissingFromShape(r, acksdk.OpTypeGet, koVarName, indentLevel)
112+
return code.CheckRequiredFieldsMissingFromShape(r, ackoperations.OpTypeGet, koVarName, indentLevel)
113113
},
114114
"GoCodeRequiredFieldsMissingFromReadManyInput": func(r *ackmodel.CRD, koVarName string, indentLevel int) string {
115-
return code.CheckRequiredFieldsMissingFromShape(r, acksdk.OpTypeList, koVarName, indentLevel)
115+
return code.CheckRequiredFieldsMissingFromShape(r, ackoperations.OpTypeList, koVarName, indentLevel)
116116
},
117117
"GoCodeRequiredFieldsMissingFromGetAttributesInput": func(r *ackmodel.CRD, koVarName string, indentLevel int) string {
118-
return code.CheckRequiredFieldsMissingFromShape(r, acksdk.OpTypeGetAttributes, koVarName, indentLevel)
118+
return code.CheckRequiredFieldsMissingFromShape(r, ackoperations.OpTypeGetAttributes, koVarName, indentLevel)
119119
},
120120
"GoCodeRequiredFieldsMissingFromSetAttributesInput": func(r *ackmodel.CRD, koVarName string, indentLevel int) string {
121-
return code.CheckRequiredFieldsMissingFromShape(r, acksdk.OpTypeSetAttributes, koVarName, indentLevel)
121+
return code.CheckRequiredFieldsMissingFromShape(r, ackoperations.OpTypeSetAttributes, koVarName, indentLevel)
122122
},
123123
"GoCodeSetResourceIdentifiers": func(r *ackmodel.CRD, sourceVarName string, targetVarName string, indentLevel int) string {
124124
return code.SetResourceIdentifiers(r.Config(), r, sourceVarName, targetVarName, indentLevel)

pkg/generate/code/check.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config"
2323
"github.com/aws-controllers-k8s/code-generator/pkg/model"
24-
"github.com/aws-controllers-k8s/code-generator/pkg/sdk"
24+
"github.com/aws-controllers-k8s/code-generator/pkg/operations"
2525
)
2626

2727
// CheckExceptionMessage returns Go code that contains a condition to
@@ -66,21 +66,21 @@ func CheckExceptionMessage(
6666
// return r.ko.Spec.APIID == nil || r.ko.Status.RouteID == nil
6767
func CheckRequiredFieldsMissingFromShape(
6868
r *model.CRD,
69-
opType sdk.OpType,
69+
opType operations.OpType,
7070
koVarName string,
7171
indentLevel int,
7272
) string {
7373
var op *awssdkmodel.Operation
7474
switch opType {
75-
case sdk.OpTypeGet:
75+
case operations.OpTypeGet:
7676
op = r.Ops.ReadOne
77-
case sdk.OpTypeList:
77+
case operations.OpTypeList:
7878
op = r.Ops.ReadMany
7979
return checkRequiredFieldsMissingFromShapeReadMany(
8080
r, koVarName, indentLevel, op, op.InputRef.Shape)
81-
case sdk.OpTypeGetAttributes:
81+
case operations.OpTypeGetAttributes:
8282
op = r.Ops.GetAttributes
83-
case sdk.OpTypeSetAttributes:
83+
case operations.OpTypeSetAttributes:
8484
op = r.Ops.SetAttributes
8585
default:
8686
return ""

pkg/generate/code/check_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/stretchr/testify/require"
2222

2323
"github.com/aws-controllers-k8s/code-generator/pkg/generate/code"
24-
"github.com/aws-controllers-k8s/code-generator/pkg/sdk"
24+
"github.com/aws-controllers-k8s/code-generator/pkg/operations"
2525
"github.com/aws-controllers-k8s/code-generator/pkg/testutil"
2626
)
2727

@@ -47,7 +47,7 @@ func TestCheckRequiredFields_Attributes_ARNField(t *testing.T) {
4747
strings.TrimSpace(expReqFieldsInShape),
4848
strings.TrimSpace(
4949
code.CheckRequiredFieldsMissingFromShape(
50-
crd, sdk.OpTypeGetAttributes, "ko", 1,
50+
crd, operations.OpTypeGetAttributes, "ko", 1,
5151
),
5252
),
5353
)
@@ -66,7 +66,7 @@ func TestCheckRequiredFields_Attributes_StatusField(t *testing.T) {
6666
return r.ko.Status.QueueURL == nil
6767
`
6868
gotCode := code.CheckRequiredFieldsMissingFromShape(
69-
crd, sdk.OpTypeGetAttributes, "r.ko", 1,
69+
crd, operations.OpTypeGetAttributes, "r.ko", 1,
7070
)
7171
assert.Equal(
7272
strings.TrimSpace(expRequiredFieldsCode),
@@ -87,7 +87,7 @@ func TestCheckRequiredFields_Attributes_StatusAndSpecField(t *testing.T) {
8787
return r.ko.Spec.APIID == nil || r.ko.Status.RouteID == nil
8888
`
8989
gotCode := code.CheckRequiredFieldsMissingFromShape(
90-
crd, sdk.OpTypeGet, "r.ko", 1,
90+
crd, operations.OpTypeGet, "r.ko", 1,
9191
)
9292
assert.Equal(
9393
strings.TrimSpace(expRequiredFieldsCode),
@@ -108,7 +108,7 @@ func TestCheckRequiredFields_RenamedSpecField(t *testing.T) {
108108
return r.ko.Spec.ClusterName == nil || r.ko.Spec.Name == nil
109109
`
110110
gotCode := code.CheckRequiredFieldsMissingFromShape(
111-
crd, sdk.OpTypeGet, "r.ko", 1,
111+
crd, operations.OpTypeGet, "r.ko", 1,
112112
)
113113
assert.Equal(
114114
strings.TrimSpace(expRequiredFieldsCode),
@@ -129,7 +129,7 @@ func TestCheckRequiredFields_StatusField_ReadMany(t *testing.T) {
129129
return r.ko.Status.VPCID == nil
130130
`
131131
gotCode := code.CheckRequiredFieldsMissingFromShape(
132-
crd, sdk.OpTypeList, "r.ko", 1,
132+
crd, operations.OpTypeList, "r.ko", 1,
133133
)
134134
assert.Equal(
135135
strings.TrimSpace(expRequiredFieldsCode),

pkg/generate/code/set_resource.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323
ackgenconfig "github.com/aws-controllers-k8s/code-generator/pkg/generate/config"
2424
"github.com/aws-controllers-k8s/code-generator/pkg/model"
2525
"github.com/aws-controllers-k8s/code-generator/pkg/names"
26-
"github.com/aws-controllers-k8s/code-generator/pkg/sdk"
26+
"github.com/aws-controllers-k8s/code-generator/pkg/operations"
2727
"github.com/aws-controllers-k8s/code-generator/pkg/util"
2828
)
2929

@@ -76,7 +76,7 @@ func SetResource(
7676
cfg *ackgenconfig.Config,
7777
r *model.CRD,
7878
// The type of operation to look for the Output shape
79-
opType sdk.OpType,
79+
opType operations.OpType,
8080
// String representing the name of the variable that we will grab the
8181
// Output shape from. This will likely be "resp" since in the templates
8282
// that call this method, the "source variable" is the response struct
@@ -92,18 +92,18 @@ func SetResource(
9292
) string {
9393
var op *awssdkmodel.Operation
9494
switch opType {
95-
case sdk.OpTypeCreate:
95+
case operations.OpTypeCreate:
9696
op = r.Ops.Create
97-
case sdk.OpTypeGet:
97+
case operations.OpTypeGet:
9898
op = r.Ops.ReadOne
99-
case sdk.OpTypeList:
99+
case operations.OpTypeList:
100100
return setResourceReadMany(
101101
cfg, r,
102102
r.Ops.ReadMany, sourceVarName, targetVarName, indentLevel,
103103
)
104-
case sdk.OpTypeUpdate:
104+
case operations.OpTypeUpdate:
105105
op = r.Ops.Update
106-
case sdk.OpTypeDelete:
106+
case operations.OpTypeDelete:
107107
op = r.Ops.Delete
108108
default:
109109
return ""

pkg/generate/code/set_resource_test.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"github.com/stretchr/testify/require"
2121

2222
"github.com/aws-controllers-k8s/code-generator/pkg/generate/code"
23-
"github.com/aws-controllers-k8s/code-generator/pkg/sdk"
23+
"github.com/aws-controllers-k8s/code-generator/pkg/operations"
2424
"github.com/aws-controllers-k8s/code-generator/pkg/testutil"
2525
)
2626

@@ -122,7 +122,7 @@ func TestSetResource_APIGWv2_Route_Create(t *testing.T) {
122122
`
123123
assert.Equal(
124124
expected,
125-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
125+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
126126
)
127127
}
128128

@@ -224,7 +224,7 @@ func TestSetResource_APIGWv2_Route_ReadOne(t *testing.T) {
224224
`
225225
assert.Equal(
226226
expected,
227-
code.SetResource(crd.Config(), crd, sdk.OpTypeGet, "resp", "ko", 1),
227+
code.SetResource(crd.Config(), crd, operations.OpTypeGet, "resp", "ko", 1),
228228
)
229229
}
230230

@@ -278,7 +278,7 @@ func TestSetResource_DynamoDB_Backup_ReadOne(t *testing.T) {
278278
`
279279
assert.Equal(
280280
expected,
281-
code.SetResource(crd.Config(), crd, sdk.OpTypeGet, "resp", "ko", 1),
281+
code.SetResource(crd.Config(), crd, operations.OpTypeGet, "resp", "ko", 1),
282282
)
283283
}
284284

@@ -304,7 +304,7 @@ func TestSetResource_CodeDeploy_Deployment_Create(t *testing.T) {
304304
`
305305
assert.Equal(
306306
expected,
307-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
307+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
308308
)
309309
}
310310

@@ -652,7 +652,7 @@ func TestSetResource_DynamoDB_Table_ReadOne(t *testing.T) {
652652
`
653653
assert.Equal(
654654
expected,
655-
code.SetResource(crd.Config(), crd, sdk.OpTypeGet, "resp", "ko", 1),
655+
code.SetResource(crd.Config(), crd, operations.OpTypeGet, "resp", "ko", 1),
656656
)
657657
}
658658

@@ -718,7 +718,7 @@ func TestSetResource_EC2_LaunchTemplate_Create(t *testing.T) {
718718
`
719719
assert.Equal(
720720
expected,
721-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
721+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
722722
)
723723
}
724724

@@ -779,7 +779,7 @@ func TestSetResource_ECR_Repository_Create(t *testing.T) {
779779
`
780780
assert.Equal(
781781
expected,
782-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
782+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
783783
)
784784
}
785785

@@ -855,7 +855,7 @@ func TestSetResource_ECR_Repository_ReadMany(t *testing.T) {
855855
`
856856
assert.Equal(
857857
expected,
858-
code.SetResource(crd.Config(), crd, sdk.OpTypeList, "resp", "ko", 1),
858+
code.SetResource(crd.Config(), crd, operations.OpTypeList, "resp", "ko", 1),
859859
)
860860
}
861861

@@ -1203,7 +1203,7 @@ func TestSetResource_Elasticache_ReplicationGroup_Create(t *testing.T) {
12031203
`
12041204
assert.Equal(
12051205
expected,
1206-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
1206+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
12071207
)
12081208
}
12091209

@@ -1559,7 +1559,7 @@ func TestSetResource_Elasticache_ReplicationGroup_ReadMany(t *testing.T) {
15591559
`
15601560
assert.Equal(
15611561
expected,
1562-
code.SetResource(crd.Config(), crd, sdk.OpTypeList, "resp", "ko", 1),
1562+
code.SetResource(crd.Config(), crd, operations.OpTypeList, "resp", "ko", 1),
15631563
)
15641564
}
15651565

@@ -2113,7 +2113,7 @@ func TestSetResource_RDS_DBInstance_Create(t *testing.T) {
21132113
`
21142114
assert.Equal(
21152115
expected,
2116-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
2116+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
21172117
)
21182118
}
21192119

@@ -2678,7 +2678,7 @@ func TestSetResource_RDS_DBInstance_ReadMany(t *testing.T) {
26782678
`
26792679
assert.Equal(
26802680
expected,
2681-
code.SetResource(crd.Config(), crd, sdk.OpTypeList, "resp", "ko", 1),
2681+
code.SetResource(crd.Config(), crd, operations.OpTypeList, "resp", "ko", 1),
26822682
)
26832683
}
26842684

@@ -2700,7 +2700,7 @@ func TestSetResource_S3_Bucket_Create(t *testing.T) {
27002700
`
27012701
assert.Equal(
27022702
expected,
2703-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
2703+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
27042704
)
27052705
}
27062706

@@ -2735,7 +2735,7 @@ func TestSetResource_S3_Bucket_ReadMany(t *testing.T) {
27352735
`
27362736
assert.Equal(
27372737
expected,
2738-
code.SetResource(crd.Config(), crd, sdk.OpTypeList, "resp", "ko", 1),
2738+
code.SetResource(crd.Config(), crd, operations.OpTypeList, "resp", "ko", 1),
27392739
)
27402740
}
27412741

@@ -2765,7 +2765,7 @@ func TestSetResource_SNS_Topic_Create(t *testing.T) {
27652765
`
27662766
assert.Equal(
27672767
expected,
2768-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
2768+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
27692769
)
27702770
}
27712771

@@ -2819,7 +2819,7 @@ func TestSetResource_SQS_Queue_Create(t *testing.T) {
28192819
`
28202820
assert.Equal(
28212821
expected,
2822-
code.SetResource(crd.Config(), crd, sdk.OpTypeCreate, "resp", "ko", 1),
2822+
code.SetResource(crd.Config(), crd, operations.OpTypeCreate, "resp", "ko", 1),
28232823
)
28242824
}
28252825

@@ -2934,7 +2934,7 @@ func TestSetResource_RDS_DBSubnetGroup_ReadMany(t *testing.T) {
29342934
`
29352935
assert.Equal(
29362936
expected,
2937-
code.SetResource(crd.Config(), crd, sdk.OpTypeList, "resp", "ko", 1),
2937+
code.SetResource(crd.Config(), crd, operations.OpTypeList, "resp", "ko", 1),
29382938
)
29392939
}
29402940

0 commit comments

Comments
 (0)