From 70b750f6262317b799172ca474a6849df7fb47dd Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 16 Sep 2024 16:48:00 -0400 Subject: [PATCH 01/15] internal/generate/common: Common generator functionality (from terraform-provider-aws). --- internal/generate/common/generator.go | 212 ++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100644 internal/generate/common/generator.go diff --git a/internal/generate/common/generator.go b/internal/generate/common/generator.go new file mode 100644 index 00000000..c46d94c4 --- /dev/null +++ b/internal/generate/common/generator.go @@ -0,0 +1,212 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package common + +import ( + "bytes" + "fmt" + "go/format" + "maps" + "os" + "path" + "strings" + "text/template" + "unicode" + "unicode/utf8" + + "github.com/hashicorp/cli" + "golang.org/x/text/cases" + "golang.org/x/text/language" +) + +type Generator struct { + ui cli.Ui +} + +func NewGenerator() *Generator { + return &Generator{ + ui: &cli.BasicUi{ + Reader: os.Stdin, + Writer: os.Stdout, + ErrorWriter: os.Stderr, + }, + } +} + +func (g *Generator) UI() cli.Ui { + return g.ui +} + +func (g *Generator) Infof(format string, a ...interface{}) { + g.ui.Info(fmt.Sprintf(format, a...)) +} + +func (g *Generator) Warnf(format string, a ...interface{}) { + g.ui.Warn(fmt.Sprintf(format, a...)) +} + +func (g *Generator) Errorf(format string, a ...interface{}) { + g.ui.Error(fmt.Sprintf(format, a...)) +} + +func (g *Generator) Fatalf(format string, a ...interface{}) { + g.Errorf(format, a...) + os.Exit(1) +} + +type Destination interface { + CreateDirectories() error + Write() error + WriteBytes(body []byte) error + WriteTemplate(templateName, templateBody string, templateData any, funcMaps ...template.FuncMap) error + WriteTemplateSet(templates *template.Template, templateData any) error +} + +func (g *Generator) NewGoFileDestination(filename string) Destination { + return &fileDestination{ + baseDestination: baseDestination{formatter: format.Source}, + filename: filename, + } +} + +func (g *Generator) NewUnformattedFileDestination(filename string) Destination { + return &fileDestination{ + filename: filename, + } +} + +type fileDestination struct { + baseDestination + append bool + filename string +} + +func (d *fileDestination) CreateDirectories() error { + const ( + perm os.FileMode = 0755 + ) + dirname := path.Dir(d.filename) + err := os.MkdirAll(dirname, perm) + + if err != nil { + return fmt.Errorf("creating target directory %s: %w", dirname, err) + } + + return nil +} + +func (d *fileDestination) Write() error { + var flags int + if d.append { + flags = os.O_APPEND | os.O_CREATE | os.O_WRONLY + } else { + flags = os.O_TRUNC | os.O_CREATE | os.O_WRONLY + } + f, err := os.OpenFile(d.filename, flags, 0644) //nolint:mnd // good protection for new files + + if err != nil { + return fmt.Errorf("opening file (%s): %w", d.filename, err) + } + + defer f.Close() + + _, err = f.WriteString(d.buffer.String()) + + if err != nil { + return fmt.Errorf("writing to file (%s): %w", d.filename, err) + } + + return nil +} + +type baseDestination struct { + formatter func([]byte) ([]byte, error) + buffer strings.Builder +} + +func (d *baseDestination) WriteBytes(body []byte) error { + _, err := d.buffer.Write(body) + return err +} + +func (d *baseDestination) WriteTemplate(templateName, templateBody string, templateData any, funcMaps ...template.FuncMap) error { + body, err := parseTemplate(templateName, templateBody, templateData, funcMaps...) + + if err != nil { + return err + } + + body, err = d.format(body) + if err != nil { + return err + } + + return d.WriteBytes(body) +} + +func parseTemplate(templateName, templateBody string, templateData any, funcMaps ...template.FuncMap) ([]byte, error) { + funcMap := template.FuncMap{ + "FirstUpper": FirstUpper, + // Title returns a string with the first character of each word as upper case. + "Title": cases.Title(language.Und, cases.NoLower).String, + } + for _, v := range funcMaps { + maps.Copy(funcMap, v) // Extras overwrite defaults. + } + tmpl, err := template.New(templateName).Funcs(funcMap).Parse(templateBody) + + if err != nil { + return nil, fmt.Errorf("parsing function template: %w", err) + } + + return executeTemplate(tmpl, templateData) +} + +func executeTemplate(tmpl *template.Template, templateData any) ([]byte, error) { + var buffer bytes.Buffer + err := tmpl.Execute(&buffer, templateData) + + if err != nil { + return nil, fmt.Errorf("executing template: %w", err) + } + + return buffer.Bytes(), nil +} + +func (d *baseDestination) WriteTemplateSet(templates *template.Template, templateData any) error { + body, err := executeTemplate(templates, templateData) + if err != nil { + return err + } + + body, err = d.format(body) + if err != nil { + return err + } + + return d.WriteBytes(body) +} + +func (d *baseDestination) format(body []byte) ([]byte, error) { + if d.formatter == nil { + return body, nil + } + + unformattedBody := body + body, err := d.formatter(unformattedBody) + if err != nil { + return nil, fmt.Errorf("formatting parsed template:\n%s\n%w", unformattedBody, err) + } + + return body, nil +} + +// FirstUpper returns a string with the first character as upper case. +func FirstUpper(s string) string { + if s == "" { + return "" + } + r, n := utf8.DecodeRuneInString(s) + return string(unicode.ToUpper(r)) + s[n:] +} From d27cfcf66381a9a3b8924790d8464ed6eb13a811 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Mon, 16 Sep 2024 16:48:35 -0400 Subject: [PATCH 02/15] Add endpoints lookup generator. --- go.mod | 15 ++ go.sum | 65 +++++++ internal/generate/endpoints/endpoints_gen.go | 16 ++ internal/generate/endpoints/generate.go | 6 + internal/generate/endpoints/main.go | 174 +++++++++++++++++++ internal/generate/endpoints/output.go.gtpl | 12 ++ 6 files changed, 288 insertions(+) create mode 100644 internal/generate/endpoints/endpoints_gen.go create mode 100644 internal/generate/endpoints/generate.go create mode 100644 internal/generate/endpoints/main.go create mode 100644 internal/generate/endpoints/output.go.gtpl diff --git a/go.mod b/go.mod index c74ab943..df9af4b0 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/sts v1.30.7 github.com/aws/smithy-go v1.20.4 github.com/google/go-cmp v0.6.0 + github.com/hashicorp/cli v1.1.6 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/terraform-plugin-log v0.9.0 @@ -28,6 +29,10 @@ require ( ) require ( + github.com/Masterminds/goutils v1.1.1 // indirect + github.com/Masterminds/semver/v3 v3.2.0 // indirect + github.com/Masterminds/sprig/v3 v3.2.3 // indirect + github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect @@ -39,16 +44,26 @@ require ( github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19 // indirect github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.17 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.7 // indirect + github.com/bgentry/speakeasy v0.1.0 // indirect github.com/fatih/color v1.17.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.1.2 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect + github.com/huandu/xstrings v1.3.3 // indirect + github.com/imdario/mergo v0.3.11 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect + github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect + github.com/mitchellh/reflectwalk v1.0.0 // indirect + github.com/posener/complete v1.2.3 // indirect + github.com/shopspring/decimal v1.2.0 // indirect + github.com/spf13/cast v1.3.1 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect go.opentelemetry.io/otel/trace v1.30.0 // indirect + golang.org/x/crypto v0.27.0 // indirect golang.org/x/sys v0.25.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index c048a2bc..8adcec67 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,11 @@ +github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= +github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= +github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= +github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= +github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= +github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= +github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g= github.com/aws/aws-sdk-go-v2 v1.30.5/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 h1:70PVAiL15/aBMh5LThwgXdSQorVr91L127ttckI9QQU= @@ -42,6 +50,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.30.7 h1:NKTa1eqZYw8tiHSRGpP0VtTdub/8 github.com/aws/aws-sdk-go-v2/service/sts v1.30.7/go.mod h1:NXi1dIAGteSaRLqYgarlhP/Ij0cFT+qmCwiJqWh/U5o= github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4= github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= +github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= +github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -55,15 +65,25 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= +github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/hashicorp/cli v1.1.6 h1:CMOV+/LJfL1tXCOKrgAX0uRKnzjj/mpmqNXloRSy2K8= +github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ0piz4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= +github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= +github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= +github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= +github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= +github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= @@ -77,16 +97,30 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= +github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= +github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= +github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= +github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= +github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= +github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= +github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.54.0 h1:By10h8DrrjRcZjy10wBEkRdwhe4kOFuNTfprm8RXQQk= go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.54.0/go.mod h1:EtfcBqee4PFJSl+TXvfhg8ADvLWGFXwwX7SYNHG/VGM= go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts= @@ -95,21 +129,52 @@ go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4Q go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ= go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc= go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/generate/endpoints/endpoints_gen.go b/internal/generate/endpoints/endpoints_gen.go new file mode 100644 index 00000000..d969aec1 --- /dev/null +++ b/internal/generate/endpoints/endpoints_gen.go @@ -0,0 +1,16 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by generator/main.go; DO NOT EDIT. + +package endpoints + +const ( + AwsPartitionID = "aws" + AwsCnPartitionID = "aws-cn" + AwsIsoPartitionID = "aws-iso" + AwsIsoBPartitionID = "aws-iso-b" + AwsIsoEPartitionID = "aws-iso-e" + AwsIsoFPartitionID = "aws-iso-f" + AwsUsGovPartitionID = "aws-us-gov" +) diff --git a/internal/generate/endpoints/generate.go b/internal/generate/endpoints/generate.go new file mode 100644 index 00000000..c9c37768 --- /dev/null +++ b/internal/generate/endpoints/generate.go @@ -0,0 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +//go:generate go run main.go -- https://raw.githubusercontent.com/aws/aws-sdk-go-v2/main/codegen/smithy-aws-go-codegen/src/main/resources/software/amazon/smithy/aws/go/codegen/endpoints.json + +package endpoints diff --git a/internal/generate/endpoints/main.go b/internal/generate/endpoints/main.go new file mode 100644 index 00000000..44d3168f --- /dev/null +++ b/internal/generate/endpoints/main.go @@ -0,0 +1,174 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +//go:build generate +// +build generate + +package main + +import ( + _ "embed" + "encoding/json" + "flag" + "fmt" + "html/template" + "io" + "net/http" + "os" + "sort" + "strings" + + "github.com/hashicorp/aws-sdk-go-base/v2/internal/generate/common" + "github.com/hashicorp/aws-sdk-go-base/v2/internal/slices" +) + +type PartitionDatum struct { + ID string + Name string + DNSSuffix string + Regions []RegionDatum +} + +type RegionDatum struct { + ID string + Description string +} + +type TemplateData struct { + Partitions []PartitionDatum +} + +func usage() { + fmt.Fprintf(os.Stderr, "Usage:\n") + fmt.Fprintf(os.Stderr, "\tmain.go \n\n") +} + +func main() { + flag.Usage = usage + flag.Parse() + + args := flag.Args() + + if len(args) < 1 { + flag.Usage() + os.Exit(2) + } + + inputURL := args[0] + outputFilename := `endpoints_gen.go` + target := map[string]any{} + + g := common.NewGenerator() + + if err := readHTTPJSON(inputURL, &target); err != nil { + g.Fatalf("error reading JSON from %s: %s", inputURL, err) + } + + td := TemplateData{} + templateFuncMap := template.FuncMap{ + "IDToConstant": func(s string) (string, error) { + parts := strings.Split(s, "-") + return strings.Join(slices.ApplyToAll(parts, func(s string) string { + return common.FirstUpper(s) + }), ""), nil + }, + } + + if version, ok := target["version"].(float64); ok { + if version != 3.0 { + g.Fatalf("unsupported endpoints document version: %d", int(version)) + } + } else { + g.Fatalf("can't parse endpoints document version") + } + + /* + See https://github.com/aws/aws-sdk-go/blob/main/aws/endpoints/v3model.go. + e.g. + { + "partitions": [{ + "partition": "aws", + "partitionName": "AWS Standard", + "regions" : { + "af-south-1" : { + "description" : "Africa (Cape Town)" + }, + ... + } + ... + }, ...] + } + */ + if partitions, ok := target["partitions"].([]any); ok { + for _, partition := range partitions { + if partition, ok := partition.(map[string]any); ok { + partitionDatum := PartitionDatum{} + + if id, ok := partition["partition"].(string); ok { + partitionDatum.ID = id + } + if name, ok := partition["partitionName"].(string); ok { + partitionDatum.Name = name + } + if regions, ok := partition["regions"].(map[string]any); ok { + for id, region := range regions { + regionDatum := RegionDatum{ + ID: id, + } + + if region, ok := region.(map[string]any); ok { + if description, ok := region["description"].(string); ok { + regionDatum.Description = description + } + } + + partitionDatum.Regions = append(partitionDatum.Regions, regionDatum) + } + } + + td.Partitions = append(td.Partitions, partitionDatum) + } + } + } + + sort.SliceStable(td.Partitions, func(i, j int) bool { + return td.Partitions[i].ID < td.Partitions[j].ID + }) + + d := g.NewGoFileDestination(outputFilename) + + if err := d.WriteTemplate("endpoints", tmpl, td, templateFuncMap); err != nil { + g.Fatalf("error generating endpoint resolver: %s", err) + } + + if err := d.Write(); err != nil { + g.Fatalf("generating file (%s): %s", outputFilename, err) + } +} + +func readHTTPJSON(url string, to any) error { + r, err := http.Get(url) + if err != nil { + return err + } + defer r.Body.Close() + + return decodeFromReader(r.Body, to) +} + +func decodeFromReader(r io.Reader, to any) error { + dec := json.NewDecoder(r) + + for { + if err := dec.Decode(to); err == io.EOF { + break + } else if err != nil { + return err + } + } + + return nil +} + +//go:embed output.go.gtpl +var tmpl string diff --git a/internal/generate/endpoints/output.go.gtpl b/internal/generate/endpoints/output.go.gtpl new file mode 100644 index 00000000..2391676b --- /dev/null +++ b/internal/generate/endpoints/output.go.gtpl @@ -0,0 +1,12 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +// Code generated by generator/main.go; DO NOT EDIT. + +package endpoints + +const ( +{{- range .Partitions }} + {{ .ID | IDToConstant}}PartitionID = "{{ .ID }}" +{{- end }} +) \ No newline at end of file From 9dcf735730a833a8c93ab2f9cc511a37b6ec28eb Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 12:09:18 -0400 Subject: [PATCH 03/15] New top-level endpoints package. --- {internal/generate/endpoints => endpoints}/endpoints_gen.go | 0 endpoints/generate.go | 6 ++++++ internal/generate/endpoints/generate.go | 6 ------ internal/generate/endpoints/main.go | 3 ++- internal/generate/endpoints/output.go.gtpl | 2 +- 5 files changed, 9 insertions(+), 8 deletions(-) rename {internal/generate/endpoints => endpoints}/endpoints_gen.go (100%) create mode 100644 endpoints/generate.go delete mode 100644 internal/generate/endpoints/generate.go diff --git a/internal/generate/endpoints/endpoints_gen.go b/endpoints/endpoints_gen.go similarity index 100% rename from internal/generate/endpoints/endpoints_gen.go rename to endpoints/endpoints_gen.go diff --git a/endpoints/generate.go b/endpoints/generate.go new file mode 100644 index 00000000..296b8921 --- /dev/null +++ b/endpoints/generate.go @@ -0,0 +1,6 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +//go:generate go run ../internal/generate/endpoints/main.go -- https://raw.githubusercontent.com/aws/aws-sdk-go-v2/main/codegen/smithy-aws-go-codegen/src/main/resources/software/amazon/smithy/aws/go/codegen/endpoints.json + +package endpoints diff --git a/internal/generate/endpoints/generate.go b/internal/generate/endpoints/generate.go deleted file mode 100644 index c9c37768..00000000 --- a/internal/generate/endpoints/generate.go +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -//go:generate go run main.go -- https://raw.githubusercontent.com/aws/aws-sdk-go-v2/main/codegen/smithy-aws-go-codegen/src/main/resources/software/amazon/smithy/aws/go/codegen/endpoints.json - -package endpoints diff --git a/internal/generate/endpoints/main.go b/internal/generate/endpoints/main.go index 44d3168f..af9df844 100644 --- a/internal/generate/endpoints/main.go +++ b/internal/generate/endpoints/main.go @@ -66,7 +66,8 @@ func main() { td := TemplateData{} templateFuncMap := template.FuncMap{ - "IDToConstant": func(s string) (string, error) { + // KebabToTitle splits a kebab case string and returns a string with each part title cased. + "KebabToTitle": func(s string) (string, error) { parts := strings.Split(s, "-") return strings.Join(slices.ApplyToAll(parts, func(s string) string { return common.FirstUpper(s) diff --git a/internal/generate/endpoints/output.go.gtpl b/internal/generate/endpoints/output.go.gtpl index 2391676b..46b2ab0d 100644 --- a/internal/generate/endpoints/output.go.gtpl +++ b/internal/generate/endpoints/output.go.gtpl @@ -7,6 +7,6 @@ package endpoints const ( {{- range .Partitions }} - {{ .ID | IDToConstant}}PartitionID = "{{ .ID }}" + {{ .ID | KebabToTitle}}PartitionID = "{{ .ID }}" {{- end }} ) \ No newline at end of file From e0af50976220a7382a6a8327a49f1d472cc10262 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 14:01:03 -0400 Subject: [PATCH 04/15] endpoints: Generate IDs and lookup table. --- endpoints/endpoints.go | 8 + endpoints/endpoints_gen.go | 301 ++++++++++++++++++++- endpoints/partition.go | 31 +++ endpoints/region.go | 22 ++ go.mod | 3 +- go.sum | 6 +- internal/generate/endpoints/main.go | 21 +- internal/generate/endpoints/output.go.gtpl | 47 +++- 8 files changed, 422 insertions(+), 17 deletions(-) create mode 100644 endpoints/endpoints.go create mode 100644 endpoints/partition.go create mode 100644 endpoints/region.go diff --git a/endpoints/endpoints.go b/endpoints/endpoints.go new file mode 100644 index 00000000..68a29284 --- /dev/null +++ b/endpoints/endpoints.go @@ -0,0 +1,8 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package endpoints + +const ( + AwsGlobalRegionID = "aws-global" // AWS Standard global region. +) diff --git a/endpoints/endpoints_gen.go b/endpoints/endpoints_gen.go index d969aec1..6232a612 100644 --- a/endpoints/endpoints_gen.go +++ b/endpoints/endpoints_gen.go @@ -1,16 +1,301 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -// Code generated by generator/main.go; DO NOT EDIT. +// Code generated by internal/generate/endpoints/main.go; DO NOT EDIT. package endpoints +import ( + "github.com/YakDriver/regexache" +) + +// All known partition IDs. +const ( + AwsPartitionID = "aws" // AWS Standard + AwsCnPartitionID = "aws-cn" // AWS China + AwsIsoPartitionID = "aws-iso" // AWS ISO (US) + AwsIsoBPartitionID = "aws-iso-b" // AWS ISOB (US) + AwsIsoEPartitionID = "aws-iso-e" // AWS ISOE (Europe) + AwsIsoFPartitionID = "aws-iso-f" // AWS ISOF + AwsUsGovPartitionID = "aws-us-gov" // AWS GovCloud (US) +) + +// All known Region IDs. const ( - AwsPartitionID = "aws" - AwsCnPartitionID = "aws-cn" - AwsIsoPartitionID = "aws-iso" - AwsIsoBPartitionID = "aws-iso-b" - AwsIsoEPartitionID = "aws-iso-e" - AwsIsoFPartitionID = "aws-iso-f" - AwsUsGovPartitionID = "aws-us-gov" + // AWS Standard partition's Regions. + AfSouth1RegionID = "af-south-1" // Africa (Cape Town) + ApEast1RegionID = "ap-east-1" // Asia Pacific (Hong Kong) + ApNortheast1RegionID = "ap-northeast-1" // Asia Pacific (Tokyo) + ApNortheast2RegionID = "ap-northeast-2" // Asia Pacific (Seoul) + ApNortheast3RegionID = "ap-northeast-3" // Asia Pacific (Osaka) + ApSouth1RegionID = "ap-south-1" // Asia Pacific (Mumbai) + ApSouth2RegionID = "ap-south-2" // Asia Pacific (Hyderabad) + ApSoutheast1RegionID = "ap-southeast-1" // Asia Pacific (Singapore) + ApSoutheast2RegionID = "ap-southeast-2" // Asia Pacific (Sydney) + ApSoutheast3RegionID = "ap-southeast-3" // Asia Pacific (Jakarta) + ApSoutheast4RegionID = "ap-southeast-4" // Asia Pacific (Melbourne) + ApSoutheast5RegionID = "ap-southeast-5" // Asia Pacific (Malaysia) + CaCentral1RegionID = "ca-central-1" // Canada (Central) + CaWest1RegionID = "ca-west-1" // Canada West (Calgary) + EuCentral1RegionID = "eu-central-1" // Europe (Frankfurt) + EuCentral2RegionID = "eu-central-2" // Europe (Zurich) + EuNorth1RegionID = "eu-north-1" // Europe (Stockholm) + EuSouth1RegionID = "eu-south-1" // Europe (Milan) + EuSouth2RegionID = "eu-south-2" // Europe (Spain) + EuWest1RegionID = "eu-west-1" // Europe (Ireland) + EuWest2RegionID = "eu-west-2" // Europe (London) + EuWest3RegionID = "eu-west-3" // Europe (Paris) + IlCentral1RegionID = "il-central-1" // Israel (Tel Aviv) + MeCentral1RegionID = "me-central-1" // Middle East (UAE) + MeSouth1RegionID = "me-south-1" // Middle East (Bahrain) + SaEast1RegionID = "sa-east-1" // South America (Sao Paulo) + UsEast1RegionID = "us-east-1" // US East (N. Virginia) + UsEast2RegionID = "us-east-2" // US East (Ohio) + UsWest1RegionID = "us-west-1" // US West (N. California) + UsWest2RegionID = "us-west-2" // US West (Oregon) + // AWS China partition's Regions. + CnNorth1RegionID = "cn-north-1" // China (Beijing) + CnNorthwest1RegionID = "cn-northwest-1" // China (Ningxia) + // AWS ISO (US) partition's Regions. + UsIsoEast1RegionID = "us-iso-east-1" // US ISO East + UsIsoWest1RegionID = "us-iso-west-1" // US ISO WEST + // AWS ISOB (US) partition's Regions. + UsIsobEast1RegionID = "us-isob-east-1" // US ISOB East (Ohio) + // AWS ISOE (Europe) partition's Regions. + EuIsoeWest1RegionID = "eu-isoe-west-1" // EU ISOE West + // AWS ISOF partition's Regions. + // AWS GovCloud (US) partition's Regions. + UsGovEast1RegionID = "us-gov-east-1" // AWS GovCloud (US-East) + UsGovWest1RegionID = "us-gov-west-1" // AWS GovCloud (US-West) +) + +type partitionAndRegions struct { + partition Partition + regions map[string]Region +} + +var ( + partitionsAndRegions = map[string]partitionAndRegions{ + AwsPartitionID: { + partition: Partition{ + id: AwsPartitionID, + name: "AWS Standard", + dnsSuffix: "amazonaws.com", + regionRegex: regexache.MustCompile(`^(us|eu|ap|sa|ca|me|af|il|mx)\-\w+\-\d+$`), + }, + regions: map[string]Region{ + AfSouth1RegionID: { + id: AfSouth1RegionID, + description: "Africa (Cape Town)", + }, + ApEast1RegionID: { + id: ApEast1RegionID, + description: "Asia Pacific (Hong Kong)", + }, + ApNortheast1RegionID: { + id: ApNortheast1RegionID, + description: "Asia Pacific (Tokyo)", + }, + ApNortheast2RegionID: { + id: ApNortheast2RegionID, + description: "Asia Pacific (Seoul)", + }, + ApNortheast3RegionID: { + id: ApNortheast3RegionID, + description: "Asia Pacific (Osaka)", + }, + ApSouth1RegionID: { + id: ApSouth1RegionID, + description: "Asia Pacific (Mumbai)", + }, + ApSouth2RegionID: { + id: ApSouth2RegionID, + description: "Asia Pacific (Hyderabad)", + }, + ApSoutheast1RegionID: { + id: ApSoutheast1RegionID, + description: "Asia Pacific (Singapore)", + }, + ApSoutheast2RegionID: { + id: ApSoutheast2RegionID, + description: "Asia Pacific (Sydney)", + }, + ApSoutheast3RegionID: { + id: ApSoutheast3RegionID, + description: "Asia Pacific (Jakarta)", + }, + ApSoutheast4RegionID: { + id: ApSoutheast4RegionID, + description: "Asia Pacific (Melbourne)", + }, + ApSoutheast5RegionID: { + id: ApSoutheast5RegionID, + description: "Asia Pacific (Malaysia)", + }, + CaCentral1RegionID: { + id: CaCentral1RegionID, + description: "Canada (Central)", + }, + CaWest1RegionID: { + id: CaWest1RegionID, + description: "Canada West (Calgary)", + }, + EuCentral1RegionID: { + id: EuCentral1RegionID, + description: "Europe (Frankfurt)", + }, + EuCentral2RegionID: { + id: EuCentral2RegionID, + description: "Europe (Zurich)", + }, + EuNorth1RegionID: { + id: EuNorth1RegionID, + description: "Europe (Stockholm)", + }, + EuSouth1RegionID: { + id: EuSouth1RegionID, + description: "Europe (Milan)", + }, + EuSouth2RegionID: { + id: EuSouth2RegionID, + description: "Europe (Spain)", + }, + EuWest1RegionID: { + id: EuWest1RegionID, + description: "Europe (Ireland)", + }, + EuWest2RegionID: { + id: EuWest2RegionID, + description: "Europe (London)", + }, + EuWest3RegionID: { + id: EuWest3RegionID, + description: "Europe (Paris)", + }, + IlCentral1RegionID: { + id: IlCentral1RegionID, + description: "Israel (Tel Aviv)", + }, + MeCentral1RegionID: { + id: MeCentral1RegionID, + description: "Middle East (UAE)", + }, + MeSouth1RegionID: { + id: MeSouth1RegionID, + description: "Middle East (Bahrain)", + }, + SaEast1RegionID: { + id: SaEast1RegionID, + description: "South America (Sao Paulo)", + }, + UsEast1RegionID: { + id: UsEast1RegionID, + description: "US East (N. Virginia)", + }, + UsEast2RegionID: { + id: UsEast2RegionID, + description: "US East (Ohio)", + }, + UsWest1RegionID: { + id: UsWest1RegionID, + description: "US West (N. California)", + }, + UsWest2RegionID: { + id: UsWest2RegionID, + description: "US West (Oregon)", + }, + }, + }, + AwsCnPartitionID: { + partition: Partition{ + id: AwsCnPartitionID, + name: "AWS China", + dnsSuffix: "amazonaws.com.cn", + regionRegex: regexache.MustCompile(`^cn\-\w+\-\d+$`), + }, + regions: map[string]Region{ + CnNorth1RegionID: { + id: CnNorth1RegionID, + description: "China (Beijing)", + }, + CnNorthwest1RegionID: { + id: CnNorthwest1RegionID, + description: "China (Ningxia)", + }, + }, + }, + AwsIsoPartitionID: { + partition: Partition{ + id: AwsIsoPartitionID, + name: "AWS ISO (US)", + dnsSuffix: "c2s.ic.gov", + regionRegex: regexache.MustCompile(`^us\-iso\-\w+\-\d+$`), + }, + regions: map[string]Region{ + UsIsoEast1RegionID: { + id: UsIsoEast1RegionID, + description: "US ISO East", + }, + UsIsoWest1RegionID: { + id: UsIsoWest1RegionID, + description: "US ISO WEST", + }, + }, + }, + AwsIsoBPartitionID: { + partition: Partition{ + id: AwsIsoBPartitionID, + name: "AWS ISOB (US)", + dnsSuffix: "sc2s.sgov.gov", + regionRegex: regexache.MustCompile(`^us\-isob\-\w+\-\d+$`), + }, + regions: map[string]Region{ + UsIsobEast1RegionID: { + id: UsIsobEast1RegionID, + description: "US ISOB East (Ohio)", + }, + }, + }, + AwsIsoEPartitionID: { + partition: Partition{ + id: AwsIsoEPartitionID, + name: "AWS ISOE (Europe)", + dnsSuffix: "cloud.adc-e.uk", + regionRegex: regexache.MustCompile(`^eu\-isoe\-\w+\-\d+$`), + }, + regions: map[string]Region{ + EuIsoeWest1RegionID: { + id: EuIsoeWest1RegionID, + description: "EU ISOE West", + }, + }, + }, + AwsIsoFPartitionID: { + partition: Partition{ + id: AwsIsoFPartitionID, + name: "AWS ISOF", + dnsSuffix: "csp.hci.ic.gov", + regionRegex: regexache.MustCompile(`^us\-isof\-\w+\-\d+$`), + }, + regions: map[string]Region{}, + }, + AwsUsGovPartitionID: { + partition: Partition{ + id: AwsUsGovPartitionID, + name: "AWS GovCloud (US)", + dnsSuffix: "amazonaws.com", + regionRegex: regexache.MustCompile(`^us\-gov\-\w+\-\d+$`), + }, + regions: map[string]Region{ + UsGovEast1RegionID: { + id: UsGovEast1RegionID, + description: "AWS GovCloud (US-East)", + }, + UsGovWest1RegionID: { + id: UsGovWest1RegionID, + description: "AWS GovCloud (US-West)", + }, + }, + }, + } ) diff --git a/endpoints/partition.go b/endpoints/partition.go new file mode 100644 index 00000000..9af61ce8 --- /dev/null +++ b/endpoints/partition.go @@ -0,0 +1,31 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package endpoints + +import ( + "regexp" +) + +type Partition struct { + id string + name string + dnsSuffix string + regionRegex *regexp.Regexp +} + +func (p *Partition) ID() string { + return p.id +} + +func (p *Partition) Name() string { + return p.name +} + +func (p *Partition) DNSSuffix() string { + return p.dnsSuffix +} + +func (p *Partition) RegionRegex() *regexp.Regexp { + return p.regionRegex +} diff --git a/endpoints/region.go b/endpoints/region.go new file mode 100644 index 00000000..251889d1 --- /dev/null +++ b/endpoints/region.go @@ -0,0 +1,22 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package endpoints + +type Region struct { + id string + description string + partitionID string +} + +func (r *Region) ID() string { + return r.id +} + +func (r *Region) Description() string { + return r.description +} + +func (r *Region) PartitionID() string { + return r.partitionID +} diff --git a/go.mod b/go.mod index df9af4b0..de06177d 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.22 toolchain go1.22.7 require ( + github.com/YakDriver/regexache v0.24.0 github.com/aws/aws-sdk-go-v2 v1.30.5 github.com/aws/aws-sdk-go-v2/config v1.27.33 github.com/aws/aws-sdk-go-v2/credentials v1.17.32 @@ -48,7 +49,7 @@ require ( github.com/fatih/color v1.17.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/google/uuid v1.1.2 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/huandu/xstrings v1.3.3 // indirect github.com/imdario/mergo v0.3.11 // indirect diff --git a/go.sum b/go.sum index 8adcec67..1b7e9940 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,8 @@ github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7Y github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= +github.com/YakDriver/regexache v0.24.0 h1:zUKaixelkswzdqsqPc2sveiV//Mi/msJn0teG8zBDiA= +github.com/YakDriver/regexache v0.24.0/go.mod h1:awcd8uBj614F3ScW06JqlfSGqq2/7vdJHy+RiKzVC+g= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g= @@ -66,8 +68,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.1.2 h1:EVhdT+1Kseyi1/pUmXKaFxYsDNy9RQYkMWRH68J/W7Y= -github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/cli v1.1.6 h1:CMOV+/LJfL1tXCOKrgAX0uRKnzjj/mpmqNXloRSy2K8= github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ0piz4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= diff --git a/internal/generate/endpoints/main.go b/internal/generate/endpoints/main.go index af9df844..d9663978 100644 --- a/internal/generate/endpoints/main.go +++ b/internal/generate/endpoints/main.go @@ -23,10 +23,11 @@ import ( ) type PartitionDatum struct { - ID string - Name string - DNSSuffix string - Regions []RegionDatum + ID string + Name string + DNSSuffix string + RegionRegex string + Regions []RegionDatum } type RegionDatum struct { @@ -111,6 +112,12 @@ func main() { if name, ok := partition["partitionName"].(string); ok { partitionDatum.Name = name } + if dnsSuffix, ok := partition["dnsSuffix"].(string); ok { + partitionDatum.DNSSuffix = dnsSuffix + } + if regionRegex, ok := partition["regionRegex"].(string); ok { + partitionDatum.RegionRegex = regionRegex + } if regions, ok := partition["regions"].(map[string]any); ok { for id, region := range regions { regionDatum := RegionDatum{ @@ -136,6 +143,12 @@ func main() { return td.Partitions[i].ID < td.Partitions[j].ID }) + for i := 0; i < len(td.Partitions); i++ { + sort.SliceStable(td.Partitions[i].Regions, func(j, k int) bool { + return td.Partitions[i].Regions[j].ID < td.Partitions[i].Regions[k].ID + }) + } + d := g.NewGoFileDestination(outputFilename) if err := d.WriteTemplate("endpoints", tmpl, td, templateFuncMap); err != nil { diff --git a/internal/generate/endpoints/output.go.gtpl b/internal/generate/endpoints/output.go.gtpl index 46b2ab0d..0dccbb4b 100644 --- a/internal/generate/endpoints/output.go.gtpl +++ b/internal/generate/endpoints/output.go.gtpl @@ -1,12 +1,55 @@ // Copyright (c) HashiCorp, Inc. // SPDX-License-Identifier: MPL-2.0 -// Code generated by generator/main.go; DO NOT EDIT. +// Code generated by internal/generate/endpoints/main.go; DO NOT EDIT. package endpoints +import ( + "github.com/YakDriver/regexache" +) + +// All known partition IDs. +const ( +{{- range .Partitions }} + {{ .ID | KebabToTitle}}PartitionID = "{{ .ID }}" // {{ .Name }} +{{- end }} +) + +// All known Region IDs. const ( {{- range .Partitions }} - {{ .ID | KebabToTitle}}PartitionID = "{{ .ID }}" + // {{ .Name }} partition's Regions. + {{- range .Regions }} + {{ .ID | KebabToTitle}}RegionID = "{{ .ID }}" // {{ .Description }} + {{- end }} +{{- end }} +) + +type partitionAndRegions struct { + partition Partition + regions map[string]Region +} + +var ( + partitionsAndRegions = map[string]partitionAndRegions{ +{{- range .Partitions }} + {{ .ID | KebabToTitle}}PartitionID: { + partition: Partition{ + id: {{ .ID | KebabToTitle}}PartitionID, + name: "{{ .Name }}", + dnsSuffix: "{{ .DNSSuffix }}", + regionRegex: regexache.MustCompile(`{{ .RegionRegex }}`), + }, + regions: map[string]Region{ + {{- range .Regions }} + {{ .ID | KebabToTitle}}RegionID: { + id: {{ .ID | KebabToTitle}}RegionID, + description: "{{ .Description }}", + }, + {{- end }} + }, + }, {{- end }} + } ) \ No newline at end of file From 092a8bbe9d1c0a60693bdd5d7744d0779626689b Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 14:22:31 -0400 Subject: [PATCH 05/15] Add 'endpoints.DefaultPartitions'. --- endpoints/partition.go | 25 +++++++++++++++++++++---- endpoints/partition_test.go | 19 +++++++++++++++++++ endpoints/region.go | 13 ++++++------- 3 files changed, 46 insertions(+), 11 deletions(-) create mode 100644 endpoints/partition_test.go diff --git a/endpoints/partition.go b/endpoints/partition.go index 9af61ce8..fcafdb0e 100644 --- a/endpoints/partition.go +++ b/endpoints/partition.go @@ -7,6 +7,8 @@ import ( "regexp" ) +// Partition represents an AWS partition. +// See https://docs.aws.amazon.com/whitepapers/latest/aws-fault-isolation-boundaries/partitions.html. type Partition struct { id string name string @@ -14,18 +16,33 @@ type Partition struct { regionRegex *regexp.Regexp } -func (p *Partition) ID() string { +// ID returns the identifier of the partition. +func (p Partition) ID() string { return p.id } -func (p *Partition) Name() string { +// Name returns the name of the partition. +func (p Partition) Name() string { return p.name } -func (p *Partition) DNSSuffix() string { +// DNSSuffix returns the base domain name of the partition. +func (p Partition) DNSSuffix() string { return p.dnsSuffix } -func (p *Partition) RegionRegex() *regexp.Regexp { +// RegionRegex return the regular expression that matches Region IDs for the partition. +func (p Partition) RegionRegex() *regexp.Regexp { return p.regionRegex } + +// DefaultPartitions returns a list of the partitions. +func DefaultPartitions() []Partition { + partitions := make([]Partition, len(partitionsAndRegions)) + + for _, v := range partitionsAndRegions { + partitions = append(partitions, v.partition) + } + + return partitions +} diff --git a/endpoints/partition_test.go b/endpoints/partition_test.go new file mode 100644 index 00000000..01db7c7e --- /dev/null +++ b/endpoints/partition_test.go @@ -0,0 +1,19 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package endpoints_test + +import ( + "testing" + + "github.com/hashicorp/aws-sdk-go-base/v2/endpoints" +) + +func TestDefaultPartitions(t *testing.T) { + t.Parallel() + + got := endpoints.DefaultPartitions() + if len(got) == 0 { + t.Fatalf("expected partitions, got none") + } +} diff --git a/endpoints/region.go b/endpoints/region.go index 251889d1..e2741b50 100644 --- a/endpoints/region.go +++ b/endpoints/region.go @@ -3,20 +3,19 @@ package endpoints +// Region represents an AWS Region. +// See https://docs.aws.amazon.com/whitepapers/latest/aws-fault-isolation-boundaries/regions.html. type Region struct { id string description string - partitionID string } -func (r *Region) ID() string { +// ID returns the Region's identifier. +func (r Region) ID() string { return r.id } -func (r *Region) Description() string { +// Description returns the Region's description. +func (r Region) Description() string { return r.description } - -func (r *Region) PartitionID() string { - return r.partitionID -} From 80d4e38eee45f8842d4f5cd17ea1b2f4b4976171 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 14:49:07 -0400 Subject: [PATCH 06/15] Add 'endpoints.PartitionForRegion'. --- endpoints/partition.go | 33 +++++++++++++++++++++++++++++--- endpoints/partition_test.go | 38 +++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 3 deletions(-) diff --git a/endpoints/partition.go b/endpoints/partition.go index fcafdb0e..44423776 100644 --- a/endpoints/partition.go +++ b/endpoints/partition.go @@ -4,6 +4,7 @@ package endpoints import ( + "maps" "regexp" ) @@ -36,13 +37,39 @@ func (p Partition) RegionRegex() *regexp.Regexp { return p.regionRegex } +// Regions returns a map of Regions for the partition, indexed by their ID. +func (p Partition) Regions() map[string]Region { + partitionAndRegion, ok := partitionsAndRegions[p.id] + if !ok { + return nil + } + + return maps.Clone(partitionAndRegion.regions) +} + // DefaultPartitions returns a list of the partitions. func DefaultPartitions() []Partition { - partitions := make([]Partition, len(partitionsAndRegions)) + ps := make([]Partition, len(partitionsAndRegions)) for _, v := range partitionsAndRegions { - partitions = append(partitions, v.partition) + ps = append(ps, v.partition) + } + + return ps +} + +// PartitionForRegion returns the first partition which includes the specific Region. +func PartitionForRegion(ps []Partition, regionID string) (Partition, bool) { + for _, p := range ps { + partitionAndRegion, ok := partitionsAndRegions[p.id] + if !ok { + continue + } + + if _, ok := partitionAndRegion.regions[regionID]; ok || partitionAndRegion.partition.regionRegex.MatchString(regionID) { + return p, true + } } - return partitions + return Partition{}, false } diff --git a/endpoints/partition_test.go b/endpoints/partition_test.go index 01db7c7e..9705571c 100644 --- a/endpoints/partition_test.go +++ b/endpoints/partition_test.go @@ -17,3 +17,41 @@ func TestDefaultPartitions(t *testing.T) { t.Fatalf("expected partitions, got none") } } + +func TestPartitionForRegion(t *testing.T) { + t.Parallel() + + testcases := map[string]struct { + expectedFound bool + expectedID string + }{ + "us-east-1": { + expectedFound: true, + expectedID: "aws", + }, + "us-gov-west-1": { + expectedFound: true, + expectedID: "aws-us-gov", + }, + "not-found": { + expectedFound: false, + }, + "us-east-17": { + expectedFound: true, + expectedID: "aws", + }, + } + + ps := endpoints.DefaultPartitions() + for region, testcase := range testcases { + gotID, gotFound := endpoints.PartitionForRegion(ps, region) + + if gotFound != testcase.expectedFound { + t.Errorf("expected PartitionFound %t for Region %q, got %t", testcase.expectedFound, region, gotFound) + } + if gotID.ID() != testcase.expectedID { + t.Errorf("expected PartitionID %q for Region %q, got %q", testcase.expectedID, region, gotID.ID()) + } + } + +} From 1b1dd671dbe499d0b8a79a7ad5319b481c94e7e6 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 14:54:06 -0400 Subject: [PATCH 07/15] Add 'TestPartitionRegions'. --- endpoints/partition_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/endpoints/partition_test.go b/endpoints/partition_test.go index 9705571c..b7bc87f9 100644 --- a/endpoints/partition_test.go +++ b/endpoints/partition_test.go @@ -53,5 +53,31 @@ func TestPartitionForRegion(t *testing.T) { t.Errorf("expected PartitionID %q for Region %q, got %q", testcase.expectedID, region, gotID.ID()) } } +} + +func TestPartitionRegions(t *testing.T) { + t.Parallel() + + testcases := map[string]struct { + expectedRegions bool + }{ + "us-east-1": { + expectedRegions: true, + }, + "us-gov-west-1": { + expectedRegions: true, + }, + "not-found": { + expectedRegions: false, + }, + } + ps := endpoints.DefaultPartitions() + for region, testcase := range testcases { + gotID, _ := endpoints.PartitionForRegion(ps, region) + + if got, want := len(gotID.Regions()) > 0, testcase.expectedRegions; got != want { + t.Errorf("expected Regions %t for Region %q, got %t", want, region, got) + } + } } From 94d0344d6346c770640ed9628319399751dda5c0 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 15:04:59 -0400 Subject: [PATCH 08/15] Replace 'internal/endpoints' with top-level 'endpoints' package. --- aws_config.go | 6 +- internal/endpoints/endpoints.go | 129 --------------------------- internal/endpoints/endpoints_test.go | 37 -------- validation/region.go | 16 ++-- 4 files changed, 12 insertions(+), 176 deletions(-) delete mode 100644 internal/endpoints/endpoints.go delete mode 100644 internal/endpoints/endpoints_test.go diff --git a/aws_config.go b/aws_config.go index 069cf26b..eba1b817 100644 --- a/aws_config.go +++ b/aws_config.go @@ -24,9 +24,9 @@ import ( "github.com/aws/aws-sdk-go-v2/feature/ec2/imds" "github.com/aws/smithy-go/middleware" "github.com/hashicorp/aws-sdk-go-base/v2/diag" + "github.com/hashicorp/aws-sdk-go-base/v2/endpoints" "github.com/hashicorp/aws-sdk-go-base/v2/internal/awsconfig" "github.com/hashicorp/aws-sdk-go-base/v2/internal/constants" - "github.com/hashicorp/aws-sdk-go-base/v2/internal/endpoints" "github.com/hashicorp/aws-sdk-go-base/v2/logging" "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -337,7 +337,9 @@ func GetAwsAccountIDAndPartition(ctx context.Context, awsConfig aws.Config, c *C "Errors: %w", err)) } - return "", endpoints.PartitionForRegion(awsConfig.Region), nil + partition, _ := endpoints.PartitionForRegion(endpoints.DefaultPartitions(), awsConfig.Region) + + return "", partition.ID(), nil } func commonLoadOptions(ctx context.Context, c *Config) ([]func(*config.LoadOptions) error, error) { diff --git a/internal/endpoints/endpoints.go b/internal/endpoints/endpoints.go deleted file mode 100644 index e98bf508..00000000 --- a/internal/endpoints/endpoints.go +++ /dev/null @@ -1,129 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package endpoints - -import ( - "regexp" -) - -func Partitions() []Partition { - ps := make([]Partition, len(partitions)) - for i := 0; i < len(partitions); i++ { - ps[i] = partitions[i].Partition() - } - return ps -} - -type Partition struct { - id string - p *partition -} - -func (p Partition) Regions() []string { - rs := make([]string, len(p.p.regions)) - copy(rs, p.p.regions) - return rs -} - -func PartitionForRegion(regionID string) string { - for _, p := range partitions { - if p.regionRegex.MatchString(regionID) { - return p.id - } - } - - return "" -} - -type partition struct { - id string - regionRegex *regexp.Regexp - regions []string -} - -func (p partition) Partition() Partition { - return Partition{ - id: p.id, - p: &p, - } -} - -// TODO: this should be generated from the AWS SDK source data -// Data from https://github.com/aws/aws-sdk-go/blob/main/models/endpoints/endpoints.json. -var partitions = []partition{ - { - id: "aws", - regionRegex: regexp.MustCompile(`^(us|eu|ap|sa|ca|me|af|il)\-\w+\-\d+$`), - regions: []string{ - "af-south-1", // Africa (Cape Town). - "ap-east-1", // Asia Pacific (Hong Kong). - "ap-northeast-1", // Asia Pacific (Tokyo). - "ap-northeast-2", // Asia Pacific (Seoul). - "ap-northeast-3", // Asia Pacific (Osaka). - "ap-south-1", // Asia Pacific (Mumbai). - "ap-south-2", // Asia Pacific (Hyderabad). - "ap-southeast-1", // Asia Pacific (Singapore). - "ap-southeast-2", // Asia Pacific (Sydney). - "ap-southeast-3", // Asia Pacific (Jakarta). - "ap-southeast-4", // Asia Pacific (Melbourne). - "ap-southeast-5", // Asia Pacific (Malaysia). - "ca-central-1", // Canada (Central). - "ca-west-1", // Canada (Calgary). - "eu-central-1", // Europe (Frankfurt). - "eu-central-2", // Europe (Zurich). - "eu-north-1", // Europe (Stockholm). - "eu-south-1", // Europe (Milan). - "eu-south-2", // Europe (Spain). - "eu-west-1", // Europe (Ireland). - "eu-west-2", // Europe (London). - "eu-west-3", // Europe (Paris). - "il-central-1", // Israel (Tel Aviv). - "me-central-1", // Middle East (UAE). - "me-south-1", // Middle East (Bahrain). - "sa-east-1", // South America (Sao Paulo). - "us-east-1", // US East (N. Virginia). - "us-east-2", // US East (Ohio). - "us-west-1", // US West (N. California). - "us-west-2", // US West (Oregon). - }, - }, - { - id: "aws-cn", - regionRegex: regexp.MustCompile(`^cn\-\w+\-\d+$`), - regions: []string{ - "cn-north-1", // China (Beijing). - "cn-northwest-1", // China (Ningxia). - }, - }, - { - id: "aws-us-gov", - regionRegex: regexp.MustCompile(`^us\-gov\-\w+\-\d+$`), - regions: []string{ - "us-gov-east-1", // AWS GovCloud (US-East). - "us-gov-west-1", // AWS GovCloud (US-West). - }, - }, - { - id: "aws-iso", - regionRegex: regexp.MustCompile(`^us\-iso\-\w+\-\d+$`), - regions: []string{ - "us-iso-east-1", // US ISO East. - "us-iso-west-1", // US ISO WEST. - }, - }, - { - id: "aws-iso-b", - regionRegex: regexp.MustCompile(`^us\-isob\-\w+\-\d+$`), - regions: []string{ - "us-isob-east-1", // US ISOB East (Ohio). - }, - }, - { - id: "aws-iso-e", - regionRegex: regexp.MustCompile(`^eu\-isoe\-\w+\-\d+$`), - regions: []string{ - "eu-isoe-west-1", // EU ISOE West. - }, - }, -} diff --git a/internal/endpoints/endpoints_test.go b/internal/endpoints/endpoints_test.go deleted file mode 100644 index fcd892e8..00000000 --- a/internal/endpoints/endpoints_test.go +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) HashiCorp, Inc. -// SPDX-License-Identifier: MPL-2.0 - -package endpoints_test - -import ( - "testing" - - "github.com/hashicorp/aws-sdk-go-base/v2/internal/endpoints" -) - -func TestPartitionForRegion(t *testing.T) { - testcases := map[string]struct { - expected string - }{ - "us-east-1": { - expected: "aws", - }, - "me-central-1": { - expected: "aws", - }, - "cn-north-1": { - expected: "aws-cn", - }, - "us-gov-west-1": { - expected: "aws-us-gov", - }, - } - - for region, testcase := range testcases { - got := endpoints.PartitionForRegion(region) - - if got != testcase.expected { - t.Errorf("expected Partition %q for Region %q, got %q", testcase.expected, region, got) - } - } -} diff --git a/validation/region.go b/validation/region.go index 4241a665..cd6aa651 100644 --- a/validation/region.go +++ b/validation/region.go @@ -5,8 +5,9 @@ package validation import ( "fmt" + "slices" - "github.com/hashicorp/aws-sdk-go-base/v2/internal/endpoints" + "github.com/hashicorp/aws-sdk-go-base/v2/endpoints" ) type InvalidRegionError struct { @@ -14,17 +15,16 @@ type InvalidRegionError struct { } func (e *InvalidRegionError) Error() string { - return fmt.Sprintf("Invalid AWS Region: %s", e.region) + return fmt.Sprintf("invalid AWS Region: %s", e.region) } // SupportedRegion checks if the given region is a valid AWS region. func SupportedRegion(region string) error { - for _, partition := range endpoints.Partitions() { - for _, partitionRegion := range partition.Regions() { - if region == partitionRegion { - return nil - } - } + if slices.ContainsFunc(endpoints.DefaultPartitions(), func(p endpoints.Partition) bool { + _, ok := p.Regions()[region] + return ok + }) { + return nil } return &InvalidRegionError{ From e5e5626cb54e4ee036f567767353048ebaaffdcf Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 15:12:42 -0400 Subject: [PATCH 09/15] Add CHANGELOG entry. --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e8ab17bf..eeaede29 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,10 @@ # v2.0.0 (Unreleased) +ENHANCEMENTS + +* Adds top-level `endpoints` package containing AWS partition and Region metadata ([#1176](https://github.com/hashicorp/aws-sdk-go-base/pull/1176)) + # v2.0.0-beta.56 (2024-09-11) ENHANCEMENTS From ca95b81443d0652a080cb39bf7f8b74b9daf3758 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 15:33:45 -0400 Subject: [PATCH 10/15] Run 'go work sync'. --- go.mod | 6 ++++-- go.sum | 8 ++++++-- v2/awsv1shim/go.mod | 2 ++ v2/awsv1shim/go.sum | 2 ++ 4 files changed, 14 insertions(+), 4 deletions(-) diff --git a/go.mod b/go.mod index abae7843..afe10750 100644 --- a/go.mod +++ b/go.mod @@ -31,7 +31,7 @@ require ( require ( github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.2.0 // indirect + github.com/Masterminds/semver/v3 v3.3.0 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect @@ -54,14 +54,16 @@ require ( github.com/huandu/xstrings v1.3.3 // indirect github.com/imdario/mergo v0.3.11 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect + github.com/kr/pretty v0.3.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/reflectwalk v1.0.0 // indirect github.com/posener/complete v1.2.3 // indirect + github.com/rogpeppe/go-internal v1.12.0 // indirect github.com/shopspring/decimal v1.2.0 // indirect - github.com/spf13/cast v1.3.1 // indirect + github.com/spf13/cast v1.5.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect go.opentelemetry.io/otel/trace v1.30.0 // indirect golang.org/x/crypto v0.27.0 // indirect diff --git a/go.sum b/go.sum index 7e962283..02324f60 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,7 @@ github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.2.0 h1:3MEsd0SM6jqZojhjLWWeBY+Kcjy9i6MQAeY7YgDP83g= github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= +github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= github.com/YakDriver/regexache v0.24.0 h1:zUKaixelkswzdqsqPc2sveiV//Mi/msJn0teG8zBDiA= @@ -60,6 +60,7 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= +github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -90,6 +91,8 @@ github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9Y github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -111,10 +114,11 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= +github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= diff --git a/v2/awsv1shim/go.mod b/v2/awsv1shim/go.mod index b0d6ee03..80c0b1ea 100644 --- a/v2/awsv1shim/go.mod +++ b/v2/awsv1shim/go.mod @@ -20,6 +20,7 @@ require ( ) require ( + github.com/YakDriver/regexache v0.24.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect @@ -40,6 +41,7 @@ require ( github.com/fatih/color v1.17.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect diff --git a/v2/awsv1shim/go.sum b/v2/awsv1shim/go.sum index a71e3b22..60a33e22 100644 --- a/v2/awsv1shim/go.sum +++ b/v2/awsv1shim/go.sum @@ -1,3 +1,4 @@ +github.com/YakDriver/regexache v0.24.0 h1:zUKaixelkswzdqsqPc2sveiV//Mi/msJn0teG8zBDiA= github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU= github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g= @@ -57,6 +58,7 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= From 27fccd4d09ae65b915aefba69b7a4466d3158bc1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Tue, 17 Sep 2024 15:34:32 -0400 Subject: [PATCH 11/15] Run 'go mod tidy'. --- go.sum | 9 +++++++++ v2/awsv1shim/go.sum | 2 ++ 2 files changed, 11 insertions(+) diff --git a/go.sum b/go.sum index 02324f60..fece635f 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,7 @@ github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJ github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= +github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= github.com/YakDriver/regexache v0.24.0 h1:zUKaixelkswzdqsqPc2sveiV//Mi/msJn0teG8zBDiA= @@ -54,6 +55,7 @@ github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4= github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -61,6 +63,7 @@ github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYF github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= +github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -92,7 +95,9 @@ github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHW github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= +github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -110,15 +115,19 @@ github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJ github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= +github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= +github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= diff --git a/v2/awsv1shim/go.sum b/v2/awsv1shim/go.sum index 60a33e22..612df5cf 100644 --- a/v2/awsv1shim/go.sum +++ b/v2/awsv1shim/go.sum @@ -1,4 +1,5 @@ github.com/YakDriver/regexache v0.24.0 h1:zUKaixelkswzdqsqPc2sveiV//Mi/msJn0teG8zBDiA= +github.com/YakDriver/regexache v0.24.0/go.mod h1:awcd8uBj614F3ScW06JqlfSGqq2/7vdJHy+RiKzVC+g= github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU= github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g= @@ -59,6 +60,7 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= +github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= From ed9722f637568b3b216dc951688024f63f627dff Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 18 Sep 2024 08:22:28 -0400 Subject: [PATCH 12/15] Use golang stdlib 'regexp', not 'regexache'. --- endpoints/endpoints_gen.go | 16 ++++++++-------- go.mod | 1 - go.sum | 2 -- internal/generate/endpoints/output.go.gtpl | 4 ++-- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/endpoints/endpoints_gen.go b/endpoints/endpoints_gen.go index 6232a612..891e5634 100644 --- a/endpoints/endpoints_gen.go +++ b/endpoints/endpoints_gen.go @@ -6,7 +6,7 @@ package endpoints import ( - "github.com/YakDriver/regexache" + "regexp" ) // All known partition IDs. @@ -81,7 +81,7 @@ var ( id: AwsPartitionID, name: "AWS Standard", dnsSuffix: "amazonaws.com", - regionRegex: regexache.MustCompile(`^(us|eu|ap|sa|ca|me|af|il|mx)\-\w+\-\d+$`), + regionRegex: regexp.MustCompile(`^(us|eu|ap|sa|ca|me|af|il|mx)\-\w+\-\d+$`), }, regions: map[string]Region{ AfSouth1RegionID: { @@ -211,7 +211,7 @@ var ( id: AwsCnPartitionID, name: "AWS China", dnsSuffix: "amazonaws.com.cn", - regionRegex: regexache.MustCompile(`^cn\-\w+\-\d+$`), + regionRegex: regexp.MustCompile(`^cn\-\w+\-\d+$`), }, regions: map[string]Region{ CnNorth1RegionID: { @@ -229,7 +229,7 @@ var ( id: AwsIsoPartitionID, name: "AWS ISO (US)", dnsSuffix: "c2s.ic.gov", - regionRegex: regexache.MustCompile(`^us\-iso\-\w+\-\d+$`), + regionRegex: regexp.MustCompile(`^us\-iso\-\w+\-\d+$`), }, regions: map[string]Region{ UsIsoEast1RegionID: { @@ -247,7 +247,7 @@ var ( id: AwsIsoBPartitionID, name: "AWS ISOB (US)", dnsSuffix: "sc2s.sgov.gov", - regionRegex: regexache.MustCompile(`^us\-isob\-\w+\-\d+$`), + regionRegex: regexp.MustCompile(`^us\-isob\-\w+\-\d+$`), }, regions: map[string]Region{ UsIsobEast1RegionID: { @@ -261,7 +261,7 @@ var ( id: AwsIsoEPartitionID, name: "AWS ISOE (Europe)", dnsSuffix: "cloud.adc-e.uk", - regionRegex: regexache.MustCompile(`^eu\-isoe\-\w+\-\d+$`), + regionRegex: regexp.MustCompile(`^eu\-isoe\-\w+\-\d+$`), }, regions: map[string]Region{ EuIsoeWest1RegionID: { @@ -275,7 +275,7 @@ var ( id: AwsIsoFPartitionID, name: "AWS ISOF", dnsSuffix: "csp.hci.ic.gov", - regionRegex: regexache.MustCompile(`^us\-isof\-\w+\-\d+$`), + regionRegex: regexp.MustCompile(`^us\-isof\-\w+\-\d+$`), }, regions: map[string]Region{}, }, @@ -284,7 +284,7 @@ var ( id: AwsUsGovPartitionID, name: "AWS GovCloud (US)", dnsSuffix: "amazonaws.com", - regionRegex: regexache.MustCompile(`^us\-gov\-\w+\-\d+$`), + regionRegex: regexp.MustCompile(`^us\-gov\-\w+\-\d+$`), }, regions: map[string]Region{ UsGovEast1RegionID: { diff --git a/go.mod b/go.mod index afe10750..33dae101 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,6 @@ go 1.22 toolchain go1.22.7 require ( - github.com/YakDriver/regexache v0.24.0 github.com/aws/aws-sdk-go-v2 v1.30.5 github.com/aws/aws-sdk-go-v2/config v1.27.35 github.com/aws/aws-sdk-go-v2/credentials v1.17.33 diff --git a/go.sum b/go.sum index fece635f..f5726210 100644 --- a/go.sum +++ b/go.sum @@ -5,8 +5,6 @@ github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+ github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= -github.com/YakDriver/regexache v0.24.0 h1:zUKaixelkswzdqsqPc2sveiV//Mi/msJn0teG8zBDiA= -github.com/YakDriver/regexache v0.24.0/go.mod h1:awcd8uBj614F3ScW06JqlfSGqq2/7vdJHy+RiKzVC+g= github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g= diff --git a/internal/generate/endpoints/output.go.gtpl b/internal/generate/endpoints/output.go.gtpl index 0dccbb4b..127351c1 100644 --- a/internal/generate/endpoints/output.go.gtpl +++ b/internal/generate/endpoints/output.go.gtpl @@ -6,7 +6,7 @@ package endpoints import ( - "github.com/YakDriver/regexache" + "regexp" ) // All known partition IDs. @@ -39,7 +39,7 @@ var ( id: {{ .ID | KebabToTitle}}PartitionID, name: "{{ .Name }}", dnsSuffix: "{{ .DNSSuffix }}", - regionRegex: regexache.MustCompile(`{{ .RegionRegex }}`), + regionRegex: regexp.MustCompile(`{{ .RegionRegex }}`), }, regions: map[string]Region{ {{- range .Regions }} From d5b2b08540a68645f12291023f30f40dc493e8ae Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 18 Sep 2024 08:31:49 -0400 Subject: [PATCH 13/15] internal/generate/common: No need to use 'hashicorp/cli'. --- go.mod | 17 ------ go.sum | 78 --------------------------- internal/generate/common/generator.go | 29 ++++------ internal/generate/endpoints/main.go | 7 +-- 4 files changed, 15 insertions(+), 116 deletions(-) diff --git a/go.mod b/go.mod index 33dae101..a139f615 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,6 @@ require ( github.com/aws/aws-sdk-go-v2/service/sts v1.30.8 github.com/aws/smithy-go v1.20.4 github.com/google/go-cmp v0.6.0 - github.com/hashicorp/cli v1.1.6 github.com/hashicorp/go-hclog v1.6.3 github.com/hashicorp/go-multierror v1.1.1 github.com/hashicorp/terraform-plugin-log v0.9.0 @@ -29,10 +28,6 @@ require ( ) require ( - github.com/Masterminds/goutils v1.1.1 // indirect - github.com/Masterminds/semver/v3 v3.3.0 // indirect - github.com/Masterminds/sprig/v3 v3.2.3 // indirect - github.com/armon/go-radix v1.0.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect @@ -44,28 +39,16 @@ require ( github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.19 // indirect github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.17 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.26.8 // indirect - github.com/bgentry/speakeasy v0.1.0 // indirect github.com/fatih/color v1.17.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect - github.com/huandu/xstrings v1.3.3 // indirect - github.com/imdario/mergo v0.3.11 // indirect github.com/jmespath/go-jmespath v0.4.0 // indirect - github.com/kr/pretty v0.3.1 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mitchellh/copystructure v1.0.0 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect - github.com/mitchellh/reflectwalk v1.0.0 // indirect - github.com/posener/complete v1.2.3 // indirect - github.com/rogpeppe/go-internal v1.12.0 // indirect - github.com/shopspring/decimal v1.2.0 // indirect - github.com/spf13/cast v1.5.0 // indirect go.opentelemetry.io/otel/metric v1.30.0 // indirect go.opentelemetry.io/otel/trace v1.30.0 // indirect - golang.org/x/crypto v0.27.0 // indirect golang.org/x/sys v0.25.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect ) diff --git a/go.sum b/go.sum index f5726210..54aa9a10 100644 --- a/go.sum +++ b/go.sum @@ -1,12 +1,3 @@ -github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= -github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= -github.com/Masterminds/semver/v3 v3.2.0/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ= -github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0= -github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= -github.com/Masterminds/sprig/v3 v3.2.3 h1:eL2fZNezLomi0uOLqjQoN6BfsDD+fyLtgbJMAj9n6YA= -github.com/Masterminds/sprig/v3 v3.2.3/go.mod h1:rXcFaZ2zZbLRJv/xSysmlgIM1u11eBaRMhvYXJNkGuM= -github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI= -github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g= github.com/aws/aws-sdk-go-v2 v1.30.5/go.mod h1:CT+ZPWXbYrci8chcARI3OmI/qgd+f6WtuLOoaIA8PR0= github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 h1:70PVAiL15/aBMh5LThwgXdSQorVr91L127ttckI9QQU= @@ -51,17 +42,12 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.30.8 h1:bAi+4p5EKnni+jrfcAhb7iHFQ24b github.com/aws/aws-sdk-go-v2/service/sts v1.30.8/go.mod h1:NXi1dIAGteSaRLqYgarlhP/Ij0cFT+qmCwiJqWh/U5o= github.com/aws/smithy-go v1.20.4 h1:2HK1zBdPgRbjFOHlfeQZfpC4r72MOb9bZkiFwggKO+4= github.com/aws/smithy-go v1.20.4/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg= -github.com/bgentry/speakeasy v0.1.0 h1:ByYyxL9InA1OWqxJqqp2A5pYHUrCiAL6K3J+LKSsQkY= -github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= -github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4= github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI= -github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE= -github.com/frankban/quicktest v1.14.3/go.mod h1:mgiwOwqx65TmIk1wJ6Q7wvnVMocbUorkibMOrVTHZps= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -69,33 +55,19 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/hashicorp/cli v1.1.6 h1:CMOV+/LJfL1tXCOKrgAX0uRKnzjj/mpmqNXloRSy2K8= -github.com/hashicorp/cli v1.1.6/go.mod h1:MPon5QYlgjjo0BSoAiN0ESeT5fRzDjVRp+uioJ0piz4= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k= github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/terraform-plugin-log v0.9.0 h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0= github.com/hashicorp/terraform-plugin-log v0.9.0/go.mod h1:rKL8egZQ/eXSyDqzLUuwUYLVdlYeamldAHSxjUFADow= -github.com/huandu/xstrings v1.3.3 h1:/Gcsuc1x8JVbJ9/rlye4xZnVAbEkGauT8lbebqcQws4= -github.com/huandu/xstrings v1.3.3/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE= -github.com/imdario/mergo v0.3.11 h1:3tnifQM4i+fbajXKBHXWEH+KvNHqojZ778UH75j3bGA= -github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg= github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo= github.com/jmespath/go-jmespath/internal/testify v1.5.1 h1:shLQSRRSCCPj3f2gpwzGwWFoC7ycTf1rcQZHOlsJ6N8= github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U= -github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= -github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= -github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= -github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/mattn/go-colorable v0.1.9/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -105,35 +77,16 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ= -github.com/mitchellh/copystructure v1.0.0/go.mod h1:SNtv71yrdKgLRyLFxmLdkAbkKEFWgYaq1OVrnRcwhnw= github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/mitchellh/go-testing-interface v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU= github.com/mitchellh/go-testing-interface v1.14.1/go.mod h1:gfgS7OtZj6MA4U1UrDRp04twqAjfvlZyCfX3sDjEym8= -github.com/mitchellh/reflectwalk v1.0.0 h1:9D+8oIskB4VJBN5SFlmc27fSlIBZaov1Wpk/IfikLNY= -github.com/mitchellh/reflectwalk v1.0.0/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw= -github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo= -github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s= -github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= -github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8= -github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4= -github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ= -github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o= -github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= -github.com/spf13/cast v1.5.0 h1:rj3WzYc11XZaIZMPKmwP96zkFEnnAmV8s6XbB2aY32w= -github.com/spf13/cast v1.5.0/go.mod h1:SpXXQ5YoyJw6s3/6cMTQuxvgRl3PCJiyaX9p6b155UU= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= -github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.55.0 h1:MnAevUB0SFfKALzF5ApgrArdvHZduRT3/e59L/lNYKE= go.opentelemetry.io/contrib/instrumentation/github.com/aws/aws-sdk-go-v2/otelaws v0.55.0/go.mod h1:MHPbT1EvQOZMGbKeuCovYWcyM9iaxcltRf7+GsU8ziE= go.opentelemetry.io/otel v1.30.0 h1:F2t8sK4qf1fAmY9ua4ohFS/K+FUuOPemHUIXHtktrts= @@ -142,52 +95,21 @@ go.opentelemetry.io/otel/metric v1.30.0 h1:4xNulvn9gjzo4hjg+wzIKG7iNFEaBMX00Qd4Q go.opentelemetry.io/otel/metric v1.30.0/go.mod h1:aXTfST94tswhWEb+5QjlSqG+cZlmyXy/u8jFpor3WqQ= go.opentelemetry.io/otel/trace v1.30.0 h1:7UBkkYzeg3C7kQX8VAidWh2biiQbtAKjyIML8dQ9wmc= go.opentelemetry.io/otel/trace v1.30.0/go.mod h1:5EyKqTzzmyqB9bwtCCq6pDLktPK6fmGf/Dph+8VI02o= -golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.3.0/go.mod h1:hebNnKkNXi2UzZN1eVRvBB7co0a+JxK6XbPiWVs/3J4= -golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= -golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= -golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= -golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= -golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= -golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= -golang.org/x/term v0.2.0/go.mod h1:TVmDHMZPmdnySmBfhjOoOdhjzdE1h4u1VwSiw2l1Nuc= -golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= -golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= -golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= -golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= -golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= -golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/internal/generate/common/generator.go b/internal/generate/common/generator.go index c46d94c4..2f08b570 100644 --- a/internal/generate/common/generator.go +++ b/internal/generate/common/generator.go @@ -7,6 +7,7 @@ import ( "bytes" "fmt" "go/format" + "io" "maps" "os" "path" @@ -15,39 +16,26 @@ import ( "unicode" "unicode/utf8" - "github.com/hashicorp/cli" "golang.org/x/text/cases" "golang.org/x/text/language" ) -type Generator struct { - ui cli.Ui -} +type Generator struct{} func NewGenerator() *Generator { - return &Generator{ - ui: &cli.BasicUi{ - Reader: os.Stdin, - Writer: os.Stdout, - ErrorWriter: os.Stderr, - }, - } -} - -func (g *Generator) UI() cli.Ui { - return g.ui + return &Generator{} } func (g *Generator) Infof(format string, a ...interface{}) { - g.ui.Info(fmt.Sprintf(format, a...)) + g.output(os.Stdout, format, a...) } func (g *Generator) Warnf(format string, a ...interface{}) { - g.ui.Warn(fmt.Sprintf(format, a...)) + g.Errorf(format, a...) } func (g *Generator) Errorf(format string, a ...interface{}) { - g.ui.Error(fmt.Sprintf(format, a...)) + g.output(os.Stderr, format, a...) } func (g *Generator) Fatalf(format string, a ...interface{}) { @@ -55,6 +43,11 @@ func (g *Generator) Fatalf(format string, a ...interface{}) { os.Exit(1) } +func (g *Generator) output(w io.Writer, format string, a ...interface{}) { + fmt.Fprintf(w, format, a...) + fmt.Fprint(w, "\n") +} + type Destination interface { CreateDirectories() error Write() error diff --git a/internal/generate/endpoints/main.go b/internal/generate/endpoints/main.go index d9663978..d08c942f 100644 --- a/internal/generate/endpoints/main.go +++ b/internal/generate/endpoints/main.go @@ -56,10 +56,11 @@ func main() { } inputURL := args[0] - outputFilename := `endpoints_gen.go` + filename := `endpoints_gen.go` target := map[string]any{} g := common.NewGenerator() + g.Infof("Generating endpoints/%s", filename) if err := readHTTPJSON(inputURL, &target); err != nil { g.Fatalf("error reading JSON from %s: %s", inputURL, err) @@ -149,14 +150,14 @@ func main() { }) } - d := g.NewGoFileDestination(outputFilename) + d := g.NewGoFileDestination(filename) if err := d.WriteTemplate("endpoints", tmpl, td, templateFuncMap); err != nil { g.Fatalf("error generating endpoint resolver: %s", err) } if err := d.Write(); err != nil { - g.Fatalf("generating file (%s): %s", outputFilename, err) + g.Fatalf("generating file (%s): %s", filename, err) } } From 5e4c48fe58937ee412ab9e6ca7bfe912109d19b4 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 18 Sep 2024 08:56:38 -0400 Subject: [PATCH 14/15] endpoints: Simplify generate code. --- endpoints/endpoints_gen.go | 79 ++++++++-------------- endpoints/partition.go | 21 ++---- internal/generate/endpoints/output.go.gtpl | 17 ++--- 3 files changed, 41 insertions(+), 76 deletions(-) diff --git a/endpoints/endpoints_gen.go b/endpoints/endpoints_gen.go index 891e5634..ceb98e58 100644 --- a/endpoints/endpoints_gen.go +++ b/endpoints/endpoints_gen.go @@ -69,20 +69,13 @@ const ( UsGovWest1RegionID = "us-gov-west-1" // AWS GovCloud (US-West) ) -type partitionAndRegions struct { - partition Partition - regions map[string]Region -} - var ( - partitionsAndRegions = map[string]partitionAndRegions{ + partitions = map[string]Partition{ AwsPartitionID: { - partition: Partition{ - id: AwsPartitionID, - name: "AWS Standard", - dnsSuffix: "amazonaws.com", - regionRegex: regexp.MustCompile(`^(us|eu|ap|sa|ca|me|af|il|mx)\-\w+\-\d+$`), - }, + id: AwsPartitionID, + name: "AWS Standard", + dnsSuffix: "amazonaws.com", + regionRegex: regexp.MustCompile(`^(us|eu|ap|sa|ca|me|af|il|mx)\-\w+\-\d+$`), regions: map[string]Region{ AfSouth1RegionID: { id: AfSouth1RegionID, @@ -207,12 +200,10 @@ var ( }, }, AwsCnPartitionID: { - partition: Partition{ - id: AwsCnPartitionID, - name: "AWS China", - dnsSuffix: "amazonaws.com.cn", - regionRegex: regexp.MustCompile(`^cn\-\w+\-\d+$`), - }, + id: AwsCnPartitionID, + name: "AWS China", + dnsSuffix: "amazonaws.com.cn", + regionRegex: regexp.MustCompile(`^cn\-\w+\-\d+$`), regions: map[string]Region{ CnNorth1RegionID: { id: CnNorth1RegionID, @@ -225,12 +216,10 @@ var ( }, }, AwsIsoPartitionID: { - partition: Partition{ - id: AwsIsoPartitionID, - name: "AWS ISO (US)", - dnsSuffix: "c2s.ic.gov", - regionRegex: regexp.MustCompile(`^us\-iso\-\w+\-\d+$`), - }, + id: AwsIsoPartitionID, + name: "AWS ISO (US)", + dnsSuffix: "c2s.ic.gov", + regionRegex: regexp.MustCompile(`^us\-iso\-\w+\-\d+$`), regions: map[string]Region{ UsIsoEast1RegionID: { id: UsIsoEast1RegionID, @@ -243,12 +232,10 @@ var ( }, }, AwsIsoBPartitionID: { - partition: Partition{ - id: AwsIsoBPartitionID, - name: "AWS ISOB (US)", - dnsSuffix: "sc2s.sgov.gov", - regionRegex: regexp.MustCompile(`^us\-isob\-\w+\-\d+$`), - }, + id: AwsIsoBPartitionID, + name: "AWS ISOB (US)", + dnsSuffix: "sc2s.sgov.gov", + regionRegex: regexp.MustCompile(`^us\-isob\-\w+\-\d+$`), regions: map[string]Region{ UsIsobEast1RegionID: { id: UsIsobEast1RegionID, @@ -257,12 +244,10 @@ var ( }, }, AwsIsoEPartitionID: { - partition: Partition{ - id: AwsIsoEPartitionID, - name: "AWS ISOE (Europe)", - dnsSuffix: "cloud.adc-e.uk", - regionRegex: regexp.MustCompile(`^eu\-isoe\-\w+\-\d+$`), - }, + id: AwsIsoEPartitionID, + name: "AWS ISOE (Europe)", + dnsSuffix: "cloud.adc-e.uk", + regionRegex: regexp.MustCompile(`^eu\-isoe\-\w+\-\d+$`), regions: map[string]Region{ EuIsoeWest1RegionID: { id: EuIsoeWest1RegionID, @@ -271,21 +256,17 @@ var ( }, }, AwsIsoFPartitionID: { - partition: Partition{ - id: AwsIsoFPartitionID, - name: "AWS ISOF", - dnsSuffix: "csp.hci.ic.gov", - regionRegex: regexp.MustCompile(`^us\-isof\-\w+\-\d+$`), - }, - regions: map[string]Region{}, + id: AwsIsoFPartitionID, + name: "AWS ISOF", + dnsSuffix: "csp.hci.ic.gov", + regionRegex: regexp.MustCompile(`^us\-isof\-\w+\-\d+$`), + regions: map[string]Region{}, }, AwsUsGovPartitionID: { - partition: Partition{ - id: AwsUsGovPartitionID, - name: "AWS GovCloud (US)", - dnsSuffix: "amazonaws.com", - regionRegex: regexp.MustCompile(`^us\-gov\-\w+\-\d+$`), - }, + id: AwsUsGovPartitionID, + name: "AWS GovCloud (US)", + dnsSuffix: "amazonaws.com", + regionRegex: regexp.MustCompile(`^us\-gov\-\w+\-\d+$`), regions: map[string]Region{ UsGovEast1RegionID: { id: UsGovEast1RegionID, diff --git a/endpoints/partition.go b/endpoints/partition.go index 44423776..ddc20a01 100644 --- a/endpoints/partition.go +++ b/endpoints/partition.go @@ -15,6 +15,7 @@ type Partition struct { name string dnsSuffix string regionRegex *regexp.Regexp + regions map[string]Region } // ID returns the identifier of the partition. @@ -39,20 +40,15 @@ func (p Partition) RegionRegex() *regexp.Regexp { // Regions returns a map of Regions for the partition, indexed by their ID. func (p Partition) Regions() map[string]Region { - partitionAndRegion, ok := partitionsAndRegions[p.id] - if !ok { - return nil - } - - return maps.Clone(partitionAndRegion.regions) + return maps.Clone(p.regions) } // DefaultPartitions returns a list of the partitions. func DefaultPartitions() []Partition { - ps := make([]Partition, len(partitionsAndRegions)) + ps := make([]Partition, 0, len(partitions)) - for _, v := range partitionsAndRegions { - ps = append(ps, v.partition) + for _, p := range partitions { + ps = append(ps, p) } return ps @@ -61,12 +57,7 @@ func DefaultPartitions() []Partition { // PartitionForRegion returns the first partition which includes the specific Region. func PartitionForRegion(ps []Partition, regionID string) (Partition, bool) { for _, p := range ps { - partitionAndRegion, ok := partitionsAndRegions[p.id] - if !ok { - continue - } - - if _, ok := partitionAndRegion.regions[regionID]; ok || partitionAndRegion.partition.regionRegex.MatchString(regionID) { + if _, ok := p.regions[regionID]; ok || p.regionRegex.MatchString(regionID) { return p, true } } diff --git a/internal/generate/endpoints/output.go.gtpl b/internal/generate/endpoints/output.go.gtpl index 127351c1..481e71fb 100644 --- a/internal/generate/endpoints/output.go.gtpl +++ b/internal/generate/endpoints/output.go.gtpl @@ -26,21 +26,14 @@ const ( {{- end }} ) -type partitionAndRegions struct { - partition Partition - regions map[string]Region -} - var ( - partitionsAndRegions = map[string]partitionAndRegions{ + partitions = map[string]Partition{ {{- range .Partitions }} {{ .ID | KebabToTitle}}PartitionID: { - partition: Partition{ - id: {{ .ID | KebabToTitle}}PartitionID, - name: "{{ .Name }}", - dnsSuffix: "{{ .DNSSuffix }}", - regionRegex: regexp.MustCompile(`{{ .RegionRegex }}`), - }, + id: {{ .ID | KebabToTitle}}PartitionID, + name: "{{ .Name }}", + dnsSuffix: "{{ .DNSSuffix }}", + regionRegex: regexp.MustCompile(`{{ .RegionRegex }}`), regions: map[string]Region{ {{- range .Regions }} {{ .ID | KebabToTitle}}RegionID: { From 95086f477712e84680966e512bf0721aedf321ca Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 18 Sep 2024 09:19:21 -0400 Subject: [PATCH 15/15] Run 'make cleantidy'. --- v2/awsv1shim/go.mod | 2 -- v2/awsv1shim/go.sum | 4 ---- 2 files changed, 6 deletions(-) diff --git a/v2/awsv1shim/go.mod b/v2/awsv1shim/go.mod index 80c0b1ea..b0d6ee03 100644 --- a/v2/awsv1shim/go.mod +++ b/v2/awsv1shim/go.mod @@ -20,7 +20,6 @@ require ( ) require ( - github.com/YakDriver/regexache v0.24.0 // indirect github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.4 // indirect github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.17 // indirect github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.17 // indirect @@ -41,7 +40,6 @@ require ( github.com/fatih/color v1.17.0 // indirect github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect - github.com/google/uuid v1.6.0 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect diff --git a/v2/awsv1shim/go.sum b/v2/awsv1shim/go.sum index 612df5cf..a71e3b22 100644 --- a/v2/awsv1shim/go.sum +++ b/v2/awsv1shim/go.sum @@ -1,5 +1,3 @@ -github.com/YakDriver/regexache v0.24.0 h1:zUKaixelkswzdqsqPc2sveiV//Mi/msJn0teG8zBDiA= -github.com/YakDriver/regexache v0.24.0/go.mod h1:awcd8uBj614F3ScW06JqlfSGqq2/7vdJHy+RiKzVC+g= github.com/aws/aws-sdk-go v1.55.5 h1:KKUZBfBoyqy5d3swXyiC7Q76ic40rYcbqH7qjh59kzU= github.com/aws/aws-sdk-go v1.55.5/go.mod h1:eRwEWoyTWFMVYVQzKMNHWP5/RV4xIUGMQfXQHfHkpNU= github.com/aws/aws-sdk-go-v2 v1.30.5 h1:mWSRTwQAb0aLE17dSzztCVJWI9+cRMgqebndjwDyK0g= @@ -59,8 +57,6 @@ github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= -github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=