Skip to content

Commit 5ac8f26

Browse files
authored
private/model/api: Backfill authtype, STS and Cognito Identity (#293)
Backfills the authtype=none modeled trait for STS and Cognito Identity services. This removes the in code customization for these two services' APIs that should not be signed. If the service API models are updated this customization to the code generation can be removed. V2 SDK port of: aws/aws-sdk-go#2477
1 parent bb1c293 commit 5ac8f26

File tree

7 files changed

+97
-61
lines changed

7 files changed

+97
-61
lines changed

private/model/api/customization_passes.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
package api
44

55
import (
6+
"fmt"
67
"io/ioutil"
8+
"os"
79
"path/filepath"
810
"strings"
911
)
@@ -50,6 +52,19 @@ func (a *API) customizationPasses() {
5052
// MTurk smoke test is invalid. The service requires AWS account to be
5153
// linked to Amazon Mechanical Turk Account.
5254
"mturk": supressSmokeTest,
55+
56+
// Backfill the authentication type for cognito identity and sts.
57+
// Removes the need for the customizations in these services.
58+
"cognitoidentity": backfillAuthType("none",
59+
"GetId",
60+
"GetOpenIdToken",
61+
"UnlinkIdentity",
62+
"GetCredentialsForIdentity",
63+
),
64+
"sts": backfillAuthType("none",
65+
"AssumeRoleWithSAML",
66+
"AssumeRoleWithWebIdentity",
67+
),
5368
}
5469

5570
for k := range mergeServices {
@@ -211,3 +226,19 @@ func rdsCustomizations(a *API) {
211226
}
212227
}
213228
}
229+
func backfillAuthType(typ string, opNames ...string) func(*API) {
230+
return func(a *API) {
231+
for _, opName := range opNames {
232+
op, ok := a.Operations[opName]
233+
if !ok {
234+
panic("unable to backfill auth-type for unknown operation " + opName)
235+
}
236+
if v := op.AuthType; len(v) != 0 {
237+
fmt.Fprintf(os.Stderr, "unable to backfill auth-type for %s, already set, %s", opName, v)
238+
continue
239+
}
240+
241+
op.AuthType = typ
242+
}
243+
}
244+
}

service/cognitoidentity/api.go

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/cognitoidentity/customizations.go

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 59 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// +build go1.8
2+
13
package cognitoidentity_test
24

35
import (
@@ -10,47 +12,68 @@ import (
1012

1113
var svc = cognitoidentity.New(unit.Config())
1214

13-
func TestUnsignedRequest_GetID(t *testing.T) {
14-
req := svc.GetIdRequest(&cognitoidentity.GetIdInput{
15-
IdentityPoolId: aws.String("IdentityPoolId"),
16-
})
17-
18-
err := req.Sign()
19-
if err != nil {
20-
t.Errorf("expected no error, but received %v", err)
21-
}
22-
23-
if e, a := "", req.HTTPRequest.Header.Get("Authorization"); e != a {
24-
t.Errorf("expected empty value '%v', but received, %v", e, a)
25-
}
26-
}
27-
28-
func TestUnsignedRequest_GetOpenIDToken(t *testing.T) {
29-
req := svc.GetOpenIdTokenRequest(&cognitoidentity.GetOpenIdTokenInput{
30-
IdentityId: aws.String("IdentityId"),
31-
})
32-
33-
err := req.Sign()
34-
if err != nil {
35-
t.Errorf("expected no error, but received %v", err)
15+
func TestUnsignedRequests(t *testing.T) {
16+
type reqSigner interface {
17+
Sign() error
3618
}
3719

38-
if e, a := "", req.HTTPRequest.Header.Get("Authorization"); e != a {
39-
t.Errorf("expected empty value '%v', but received, %v", e, a)
20+
cases := map[string]struct {
21+
ReqFn func() reqSigner
22+
}{
23+
"GetId": {
24+
ReqFn: func() reqSigner {
25+
req := svc.GetIdRequest(&cognitoidentity.GetIdInput{
26+
IdentityPoolId: aws.String("IdentityPoolId"),
27+
})
28+
return req
29+
},
30+
},
31+
"GetOpenIdToken": {
32+
ReqFn: func() reqSigner {
33+
req := svc.GetOpenIdTokenRequest(&cognitoidentity.GetOpenIdTokenInput{
34+
IdentityId: aws.String("IdentityId"),
35+
})
36+
return req
37+
},
38+
},
39+
"UnlinkIdentity": {
40+
ReqFn: func() reqSigner {
41+
req := svc.UnlinkIdentityRequest(&cognitoidentity.UnlinkIdentityInput{
42+
IdentityId: aws.String("IdentityId"),
43+
Logins: map[string]string{},
44+
LoginsToRemove: []string{},
45+
})
46+
return req
47+
},
48+
},
49+
"GetCredentialsForIdentity": {
50+
ReqFn: func() reqSigner {
51+
req := svc.GetCredentialsForIdentityRequest(&cognitoidentity.GetCredentialsForIdentityInput{
52+
IdentityId: aws.String("IdentityId"),
53+
})
54+
return req
55+
},
56+
},
4057
}
41-
}
4258

43-
func TestUnsignedRequest_GetCredentialsForIdentity(t *testing.T) {
44-
req := svc.GetCredentialsForIdentityRequest(&cognitoidentity.GetCredentialsForIdentityInput{
45-
IdentityId: aws.String("IdentityId"),
46-
})
59+
for cn, c := range cases {
60+
t.Run(cn, func(t *testing.T) {
61+
req := c.ReqFn()
62+
err := req.Sign()
63+
if err != nil {
64+
t.Errorf("expected no error, but received %v", err)
65+
}
4766

48-
err := req.Sign()
49-
if err != nil {
50-
t.Errorf("expected no error, but received %v", err)
51-
}
67+
switch tv := req.(type) {
68+
case cognitoidentity.GetIdRequest:
69+
if e, a := aws.AnonymousCredentials, tv.Config.Credentials; e != a {
70+
t.Errorf("expect request to use anonymous credentias, %v", a)
71+
}
72+
if e, a := "", tv.HTTPRequest.Header.Get("Authorization"); e != a {
73+
t.Errorf("expected empty value '%v', but received, %v", e, a)
74+
}
75+
}
5276

53-
if e, a := "", req.HTTPRequest.Header.Get("Authorization"); e != a {
54-
t.Errorf("expected empty value '%v', but received, %v", e, a)
77+
})
5578
}
5679
}

service/sqs/api.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/sts/api.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

service/sts/customizations.go

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)