Skip to content

Commit e52978b

Browse files
authored
aws/endpoints: Workaround CloudHSMv2 signing name not modeled (#111)
Provides a endpoint customization as a workaround CloudHSMv2 not modeling the service's signing name correctly. When the model is eventually updated this change should be removed. V2 port of aws/aws-sdk-go#1751
1 parent 3ef3d9b commit e52978b

File tree

5 files changed

+176
-1
lines changed

5 files changed

+176
-1
lines changed

aws/endpoints/decode.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"encoding/json"
55
"fmt"
66
"io"
7+
"os"
78

89
"github.com/aws/aws-sdk-go-v2/aws/awserr"
910
)
@@ -84,11 +85,34 @@ func decodeV3Endpoints(modelDef modelDefinition, opts DecodeModelOptions) (*Reso
8485
custAddEC2Metadata(p)
8586
custAddS3DualStack(p)
8687
custSetUnresolveServices(p)
88+
89+
custFixCloudHSMv2SigningName(p)
8790
}
8891

8992
return &Resolver{partitions: ps}, nil
9093
}
9194

95+
func custFixCloudHSMv2SigningName(p *partition) {
96+
// Workaround for aws/aws-sdk-go#1745 until the endpoint model can be
97+
// fixed upstream. TODO remove this once the endpoints model is updated.
98+
99+
s, ok := p.Services["cloudhsmv2"]
100+
if !ok {
101+
return
102+
}
103+
104+
if len(s.Defaults.CredentialScope.Service) != 0 {
105+
fmt.Fprintf(os.Stderr, "cloudhsmv2 signing name already set, ignoring override.\n")
106+
// If the value is already set don't override
107+
return
108+
}
109+
110+
s.Defaults.CredentialScope.Service = "cloudhsm"
111+
fmt.Fprintf(os.Stderr, "cloudhsmv2 signing name not set, overriding.\n")
112+
113+
p.Services["cloudhsmv2"] = s
114+
}
115+
92116
func custAddS3DualStack(p *partition) {
93117
if p.ID != "aws" {
94118
return

aws/endpoints/decode_test.go

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,126 @@ func TestDecodeModelOptionsSet(t *testing.T) {
115115
t.Errorf("expect %v options got %v", expect, actual)
116116
}
117117
}
118+
119+
func TestDecode_CustFixCloudHSMv2SigningName(t *testing.T) {
120+
cases := []struct {
121+
Doc string
122+
Expect string
123+
}{
124+
{
125+
Doc: `
126+
{
127+
"version": 3,
128+
"partitions": [
129+
{
130+
"defaults": {
131+
"hostname": "{service}.{region}.{dnsSuffix}",
132+
"protocols": [
133+
"https"
134+
],
135+
"signatureVersions": [
136+
"v4"
137+
]
138+
},
139+
"dnsSuffix": "amazonaws.com",
140+
"partition": "aws",
141+
"partitionName": "AWS Standard",
142+
"regionRegex": "^(us|eu|ap|sa|ca)\\-\\w+\\-\\d+$",
143+
"regions": {
144+
"ap-northeast-1": {
145+
"description": "Asia Pacific (Tokyo)"
146+
},
147+
"us-east-1": {
148+
"description": "US East (N. Virginia)"
149+
}
150+
},
151+
"services": {
152+
"cloudhsmv2": {
153+
"endpoints": {
154+
"us-east-1": {}
155+
}
156+
},
157+
"s3": {
158+
"endpoints": {
159+
"ap-northeast-1": {}
160+
}
161+
}
162+
}
163+
}
164+
]
165+
}`,
166+
Expect: "cloudhsm",
167+
},
168+
{
169+
Doc: `
170+
{
171+
"version": 3,
172+
"partitions": [
173+
{
174+
"defaults": {
175+
"hostname": "{service}.{region}.{dnsSuffix}",
176+
"protocols": [
177+
"https"
178+
],
179+
"signatureVersions": [
180+
"v4"
181+
]
182+
},
183+
"dnsSuffix": "amazonaws.com",
184+
"partition": "aws",
185+
"partitionName": "AWS Standard",
186+
"regionRegex": "^(us|eu|ap|sa|ca)\\-\\w+\\-\\d+$",
187+
"regions": {
188+
"ap-northeast-1": {
189+
"description": "Asia Pacific (Tokyo)"
190+
},
191+
"us-east-1": {
192+
"description": "US East (N. Virginia)"
193+
}
194+
},
195+
"services": {
196+
"cloudhsmv2": {
197+
"defaults": {
198+
"credentialScope": {
199+
"service": "coolSigningName"
200+
}
201+
},
202+
"endpoints": {
203+
"us-east-1": {}
204+
}
205+
},
206+
"s3": {
207+
"endpoints": {
208+
"ap-northeast-1": {}
209+
}
210+
}
211+
}
212+
}
213+
]
214+
}`,
215+
Expect: "coolSigningName",
216+
},
217+
}
218+
219+
for i, c := range cases {
220+
resolver, err := DecodeModel(strings.NewReader(c.Doc))
221+
if err != nil {
222+
t.Fatalf("%d, expected no error, got %v", i, err)
223+
}
224+
225+
p := resolver.partitions[0]
226+
defaults := p.Services["cloudhsmv2"].Defaults
227+
if e, a := c.Expect, defaults.CredentialScope.Service; e != a {
228+
t.Errorf("%d, expect %v, got %v", i, e, a)
229+
}
230+
231+
endpoint, err := resolver.ResolveEndpoint("cloudhsmv2", "us-east-1")
232+
if err != nil {
233+
t.Fatalf("%d, failed to resolve endpoint, %v", i, err)
234+
}
235+
236+
if e, a := c.Expect, endpoint.SigningName; e != a {
237+
t.Errorf("%d, expected %q go %q", i, e, a)
238+
}
239+
}
240+
}

aws/endpoints/defaults.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// +build integration
2+
3+
//Package cloudhsmv2 provides gucumber integration tests support.
4+
package cloudhsmv2
5+
6+
import (
7+
"github.com/aws/aws-sdk-go-v2/internal/awstesting/integration"
8+
_ "github.com/aws/aws-sdk-go-v2/internal/awstesting/integration/smoke"
9+
"github.com/aws/aws-sdk-go-v2/service/cloudhsmv2"
10+
"github.com/gucumber/gucumber"
11+
)
12+
13+
func init() {
14+
gucumber.Before("@cloudhsmv2", func() {
15+
gucumber.World["client"] = cloudhsmv2.New(integration.Config())
16+
})
17+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# language: en
2+
@cloudhsmv2 @client
3+
Feature: Amazon CloudHSMv2
4+
5+
Scenario: Making a request
6+
When I call the "DescribeBackups" API
7+
Then the request should be successful

0 commit comments

Comments
 (0)