Skip to content

Commit 9b49a4c

Browse files
committed
Update generator for actions
1 parent eb36de4 commit 9b49a4c

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

internal/generate/servicepackage/main.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ func main() {
6262
v := &visitor{
6363
g: g,
6464

65+
actions: make(map[string]ResourceDatum, 0),
6566
ephemeralResources: make(map[string]ResourceDatum, 0),
6667
frameworkDataSources: make(map[string]ResourceDatum, 0),
6768
frameworkResources: make(map[string]ResourceDatum, 0),
@@ -94,6 +95,7 @@ func main() {
9495
GoV2Package: l.GoV2Package(),
9596
ProviderPackage: p,
9697
ProviderNameUpper: l.ProviderNameUpper(),
98+
Actions: v.actions,
9799
EphemeralResources: v.ephemeralResources,
98100
FrameworkDataSources: v.frameworkDataSources,
99101
FrameworkResources: v.frameworkResources,
@@ -102,6 +104,9 @@ func main() {
102104
}
103105

104106
var imports []goImport
107+
for resource := range maps.Values(v.actions) {
108+
imports = append(imports, resource.goImports...)
109+
}
105110
for resource := range maps.Values(v.ephemeralResources) {
106111
imports = append(imports, resource.goImports...)
107112
}
@@ -232,6 +237,7 @@ type ServiceDatum struct {
232237
GoV2Package string // AWS SDK for Go v2 package name
233238
ProviderPackage string
234239
ProviderNameUpper string
240+
Actions map[string]ResourceDatum
235241
EphemeralResources map[string]ResourceDatum
236242
FrameworkDataSources map[string]ResourceDatum
237243
FrameworkResources map[string]ResourceDatum
@@ -260,6 +266,7 @@ type visitor struct {
260266
functionName string
261267
packageName string
262268

269+
actions map[string]ResourceDatum
263270
ephemeralResources map[string]ResourceDatum
264271
frameworkDataSources map[string]ResourceDatum
265272
frameworkResources map[string]ResourceDatum
@@ -512,6 +519,34 @@ func (v *visitor) processFuncDecl(funcDecl *ast.FuncDecl) {
512519
}
513520

514521
switch annotationName := m[1]; annotationName {
522+
case "Action":
523+
if len(args.Positional) == 0 {
524+
v.errs = append(v.errs, fmt.Errorf("no type name: %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
525+
continue
526+
}
527+
528+
typeName := args.Positional[0]
529+
530+
if !validTypeName.MatchString(typeName) {
531+
v.errs = append(v.errs, fmt.Errorf("invalid type name (%s): %s", typeName, fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
532+
continue
533+
}
534+
535+
if d.Name == "" {
536+
v.errs = append(v.errs, fmt.Errorf("no friendly name: %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
537+
continue
538+
}
539+
540+
if _, ok := v.actions[typeName]; ok {
541+
v.errs = append(v.errs, fmt.Errorf("duplicate Action (%s): %s", typeName, fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
542+
} else {
543+
v.actions[typeName] = d
544+
}
545+
546+
if d.HasV6_0SDKv2Fix {
547+
v.errs = append(v.errs, fmt.Errorf("V60SDKv2Fix not supported for Actions: %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))
548+
}
549+
515550
case "EphemeralResource":
516551
if len(args.Positional) == 0 {
517552
v.errs = append(v.errs, fmt.Errorf("no type name: %s", fmt.Sprintf("%s.%s", v.packageName, v.functionName)))

internal/generate/servicepackage/service_package_gen.go.gtpl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,31 @@ import (
5959

6060
type servicePackage struct {}
6161

62+
{{- if .Actions }}
63+
func (p *servicePackage) Actions(ctx context.Context) []*inttypes.ServicePackageAction {
64+
return []*inttypes.ServicePackageAction {
65+
{{- range $key, $value := .Actions }}
66+
{{- $regionOverrideEnabled := and (not $.IsGlobal) $value.RegionOverrideEnabled }}
67+
{
68+
Factory: {{ $value.FactoryName }},
69+
TypeName: "{{ $key }}",
70+
Name: "{{ $value.Name }}",
71+
{{- if and $regionOverrideEnabled $value.ValidateRegionOverrideInPartition }}
72+
Region: unique.Make(inttypes.ResourceRegionDefault()),
73+
{{- else if not $regionOverrideEnabled }}
74+
Region: unique.Make(inttypes.ResourceRegionDisabled()),
75+
{{- else }}
76+
Region: unique.Make(inttypes.ServicePackageResourceRegion {
77+
IsOverrideEnabled: {{ $regionOverrideEnabled }},
78+
IsValidateOverrideInPartition: {{ $value.ValidateRegionOverrideInPartition }},
79+
}),
80+
{{- end }}
81+
},
82+
{{- end }}
83+
}
84+
}
85+
{{- end }}
86+
6287
{{- if .EphemeralResources }}
6388
func (p *servicePackage) EphemeralResources(ctx context.Context) []*inttypes.ServicePackageEphemeralResource {
6489
return []*inttypes.ServicePackageEphemeralResource {

0 commit comments

Comments
 (0)