Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

r/aws_efs_file_system: Fix sweeper crash #28234

Merged
merged 2 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions internal/generate/listpages/function.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ func {{ .Name }}PagesWithContext(ctx context.Context, conn {{ .RecvType }}, inpu
return err
}

lastPage := aws.StringValue(output.{{ .Paginator }}) == ""
lastPage := aws.StringValue(output.{{ .OutputPaginator }}) == ""
if !fn(output, lastPage) || lastPage {
break
}

input.{{ .Paginator }} = output.{{ .Paginator }}
input.{{ .InputPaginator }} = output.{{ .OutputPaginator }}
}
return nil
}
80 changes: 41 additions & 39 deletions internal/generate/listpages/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ const (
)

var (
listOps = flag.String("ListOps", "", "ListOps")
paginator = flag.String("Paginator", "NextToken", "name of the pagination token field")
export = flag.Bool("Export", false, "whether to export the list functions")
inputPaginator = flag.String("InputPaginator", "", "name of the input pagination token field")
listOps = flag.String("ListOps", "", "ListOps")
outputPaginator = flag.String("OutputPaginator", "", "name of the output pagination token field")
paginator = flag.String("Paginator", "NextToken", "name of the pagination token field")
export = flag.Bool("Export", false, "whether to export the list functions")
)

func usage() {
Expand All @@ -38,20 +40,23 @@ func usage() {
flag.PrintDefaults()
}

type TemplateData struct {
AWSService string
ServicePackage string

ListOps string
Paginator string
}

func main() {
log.SetPrefix("generate/listpage: ")
log.SetFlags(0)
flag.Usage = usage
flag.Parse()

if (*inputPaginator != "" && *outputPaginator == "") || (*inputPaginator == "" && *outputPaginator != "") {
log.Fatal("both InputPaginator and OutputPaginator must be specified if one is")
}

if *inputPaginator == "" {
*inputPaginator = *paginator
}
if *outputPaginator == "" {
*outputPaginator = *paginator
}

filename := defaultFilename
if args := flag.Args(); len(args) > 0 {
filename = args[0]
Expand All @@ -72,27 +77,21 @@ func main() {
log.Fatalf("encountered: %s", err)
}

templateData := TemplateData{
AWSService: awsService,
ServicePackage: servicePackage,
ListOps: *listOps,
Paginator: *paginator,
}

functions := strings.Split(templateData.ListOps, ",")
functions := strings.Split(*listOps, ",")
sort.Strings(functions)

g := Generator{
paginator: templateData.Paginator,
tmpl: template.Must(template.New("function").Parse(functionTemplate)),
tmpl: template.Must(template.New("function").Parse(functionTemplate)),
inputPaginator: *inputPaginator,
outputPaginator: *outputPaginator,
}

sourcePackage := fmt.Sprintf("github.com/aws/aws-sdk-go/service/%s", templateData.AWSService)
sourcePackage := fmt.Sprintf("github.com/aws/aws-sdk-go/service/%s", awsService)
g.parsePackage(sourcePackage)

g.printHeader(HeaderInfo{
Parameters: strings.Join(os.Args[1:], " "),
DestinationPackage: templateData.ServicePackage,
DestinationPackage: servicePackage,
SourcePackage: sourcePackage,
})

Expand Down Expand Up @@ -121,10 +120,11 @@ type HeaderInfo struct {
}

type Generator struct {
buf bytes.Buffer
pkg *Package
tmpl *template.Template
paginator string
buf bytes.Buffer
pkg *Package
tmpl *template.Template
inputPaginator string
outputPaginator string
}

func (g *Generator) Printf(format string, args ...interface{}) {
Expand Down Expand Up @@ -176,12 +176,13 @@ func (g *Generator) addPackage(pkg *packages.Package) {
}

type FuncSpec struct {
Name string
AWSName string
RecvType string
ParamType string
ResultType string
Paginator string
Name string
AWSName string
RecvType string
ParamType string
ResultType string
InputPaginator string
OutputPaginator string
}

func (g *Generator) generateFunction(functionName, awsService string, export bool) {
Expand Down Expand Up @@ -215,12 +216,13 @@ func (g *Generator) generateFunction(functionName, awsService string, export boo
}

funcSpec := FuncSpec{
Name: fixUpFuncName(funcName, awsService),
AWSName: function.Name.Name,
RecvType: g.expandTypeField(function.Recv),
ParamType: g.expandTypeField(function.Type.Params), // Assumes there is a single input parameter
ResultType: g.expandTypeField(function.Type.Results), // Assumes we can take the first return parameter
Paginator: g.paginator,
Name: fixUpFuncName(funcName, awsService),
AWSName: function.Name.Name,
RecvType: g.expandTypeField(function.Recv),
ParamType: g.expandTypeField(function.Type.Params), // Assumes there is a single input parameter
ResultType: g.expandTypeField(function.Type.Results), // Assumes we can take the first return parameter
InputPaginator: g.inputPaginator,
OutputPaginator: g.outputPaginator,
}

err := g.tmpl.Execute(&g.buf, funcSpec)
Expand Down
1 change: 1 addition & 0 deletions internal/service/efs/generate.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:generate go run ../../generate/listpages/main.go -ListOps=DescribeMountTargets -InputPaginator=Marker -OutputPaginator=NextMarker
//go:generate go run ../../generate/tags/main.go -ListTags -ListTagsOp=DescribeTags -ListTagsInIDElem=FileSystemId -ServiceTagsSlice -TagInIDElem=ResourceId -UpdateTags
// ONLY generate directives and package declaration! Do not add anything else to this file.

Expand Down
31 changes: 31 additions & 0 deletions internal/service/efs/list_pages_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading