Skip to content

Commit c524699

Browse files
authored
FIPS & DualStack Endpoint Resolver Support (#1274)
* DualStack and FIPS Modelling Support
1 parent 11d7738 commit c524699

File tree

1,654 files changed

+100676
-15194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,654 files changed

+100676
-15194
lines changed

.github/workflows/license-check.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ name: License Scan
33
on: [pull_request]
44

55
jobs:
6-
build:
7-
6+
licensescan:
7+
name: License Scan
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
@@ -14,15 +14,17 @@ jobs:
1414
- name: Checkout target
1515
uses: actions/checkout@v2
1616
with:
17-
path: sdkmain
17+
path: sdkbase
1818
ref: ${{ github.base_ref }}
1919
- name: Checkout this ref
2020
uses: actions/checkout@v2
2121
with:
2222
path: new-ref
2323
fetch-depth: 0
2424
- name: Get Diff
25-
run: git --git-dir ./new-ref/.git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }}| xargs > fileList.txt
25+
run: git --git-dir ./new-ref/.git diff --name-only --diff-filter=ACMRT ${{ github.event.pull_request.base.sha }} ${{ github.sha }} > refDiffFiles.txt
26+
- name: Get Target Files
27+
run: git --git-dir ./sdkbase/.git ls-files | grep -xf refDiffFiles.txt - > targetFiles.txt
2628
- name: Checkout scancode
2729
uses: actions/checkout@v2
2830
with:
@@ -37,10 +39,10 @@ jobs:
3739
- name: Self-configure scancode
3840
working-directory: ./scancode-toolkit
3941
run: ./scancode --help
40-
- name: Run Scan code on pr ref
41-
run: for filename in $(< fileList.txt); do ./scancode-toolkit/scancode -l -n 30 --json-pp - ./sdkmain/$filename | grep short_name | sort | uniq >> old-licenses.txt; done
4242
- name: Run Scan code on target
43-
run: for filename in $(< fileList.txt); do ./scancode-toolkit/scancode -l -n 30 --json-pp - ./new-ref/$filename | grep short_name | sort | uniq >> new-licenses.txt; done
43+
run: cat targetFiles.txt | while read filename; do echo ./sdkbase/$filename; done | xargs ./scancode-toolkit/scancode -l -n 30 --json-pp - | grep short_name | sort | uniq >> old-licenses.txt
44+
- name: Run Scan code on pr ref
45+
run: cat refDiffFiles.txt | while read filename; do echo ./new-ref/$filename; done | xargs ./scancode-toolkit/scancode -l -n 30 --json-pp - | grep short_name | sort | uniq >> new-licenses.txt
4446
# compare
4547
- name: License test
46-
run: if ! cmp old-licenses.txt new-licenses.txt; then echo "Licenses differ! Failing."; exit -1; else echo "Licenses are the same. Success."; exit 0; fi
48+
run: if ! cmp old-licenses.txt new-licenses.txt; then echo "Licenses differ! Failing."; exit -1; else echo "Licenses are the same. Success."; exit 0; fi

aws/config.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ type Config struct {
4040

4141
// An endpoint resolver that can be used to provide or override an endpoint for the given
4242
// service and region Please see the `aws.EndpointResolver` documentation on usage.
43+
//
44+
// Deprecated: See Config.EndpointResolverWithOptions
4345
EndpointResolver EndpointResolver
4446

47+
// An endpoint resolver that can be used to provide or override an endpoint for the given
48+
// service and region Please see the `aws.EndpointResolverWithOptions` documentation on usage.
49+
EndpointResolverWithOptions EndpointResolverWithOptions
50+
4551
// Retryer is a function that provides a Retryer implementation. A Retryer guides how HTTP requests should be
4652
// retried in case of recoverable failures. When nil the API client will use a default
4753
// retryer.

aws/endpoints.go

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,66 @@ import (
44
"fmt"
55
)
66

7+
// DualStackEndpointState is a constant to describe the dual-stack endpoint resolution behavior.
8+
type DualStackEndpointState uint
9+
10+
const (
11+
// DualStackEndpointStateUnset is the default value behavior for dual-stack endpoint resolution.
12+
DualStackEndpointStateUnset DualStackEndpointState = iota
13+
14+
// DualStackEndpointStateEnabled enables dual-stack endpoint resolution for service endpoints.
15+
DualStackEndpointStateEnabled
16+
17+
// DualStackEndpointStateDisabled disables dual-stack endpoint resolution for endpoints.
18+
DualStackEndpointStateDisabled
19+
)
20+
21+
// GetUseDualStackEndpoint takes a service's EndpointResolverOptions and returns the UseDualStackEndpoint value.
22+
// Returns boolean false if the provided options does not have a method to retrieve the DualStackEndpointState.
23+
func GetUseDualStackEndpoint(options ...interface{}) (value DualStackEndpointState, found bool) {
24+
type iface interface {
25+
GetUseDualStackEndpoint() DualStackEndpointState
26+
}
27+
for _, option := range options {
28+
if i, ok := option.(iface); ok {
29+
value = i.GetUseDualStackEndpoint()
30+
found = true
31+
break
32+
}
33+
}
34+
return value, found
35+
}
36+
37+
// FIPSEndpointState is a constant to describe the FIPS endpoint resolution behavior.
38+
type FIPSEndpointState uint
39+
40+
const (
41+
// FIPSEndpointStateUnset is the default value behavior for FIPS endpoint resolution.
42+
FIPSEndpointStateUnset FIPSEndpointState = iota
43+
44+
// FIPSEndpointStateEnabled enables FIPS endpoint resolution for service endpoints.
45+
FIPSEndpointStateEnabled
46+
47+
// FIPSEndpointStateDisabled disables FIPS endpoint resolution for endpoints.
48+
FIPSEndpointStateDisabled
49+
)
50+
51+
// GetUseFIPSEndpoint takes a service's EndpointResolverOptions and returns the UseDualStackEndpoint value.
52+
// Returns boolean false if the provided options does not have a method to retrieve the DualStackEndpointState.
53+
func GetUseFIPSEndpoint(options ...interface{}) (value FIPSEndpointState, found bool) {
54+
type iface interface {
55+
GetUseFIPSEndpoint() FIPSEndpointState
56+
}
57+
for _, option := range options {
58+
if i, ok := option.(iface); ok {
59+
value = i.GetUseFIPSEndpoint()
60+
found = true
61+
break
62+
}
63+
}
64+
return value, found
65+
}
66+
767
// Endpoint represents the endpoint a service client should make API operation
868
// calls to.
969
//
@@ -111,3 +171,53 @@ type EndpointResolverFunc func(service, region string) (Endpoint, error)
111171
func (e EndpointResolverFunc) ResolveEndpoint(service, region string) (Endpoint, error) {
112172
return e(service, region)
113173
}
174+
175+
// EndpointResolverWithOptions is an endpoint resolver that can be used to provide or
176+
// override an endpoint for the given service, region, and the service clients EndpointOptions. API clients will
177+
// attempt to use the EndpointResolver first to resolve an endpoint if
178+
// available. If the EndpointResolver returns an EndpointNotFoundError error,
179+
// API clients will fallback to attempting to resolve the endpoint using its
180+
// internal default endpoint resolver.
181+
type EndpointResolverWithOptions interface {
182+
ResolveEndpoint(service, region string, options ...interface{}) (Endpoint, error)
183+
}
184+
185+
// EndpointResolverWithOptionsFunc wraps a function to satisfy the EndpointResolverWithOptions interface.
186+
type EndpointResolverWithOptionsFunc func(service, region string, options interface{}) (Endpoint, error)
187+
188+
// ResolveEndpoint calls the wrapped function and returns the results.
189+
func (e EndpointResolverWithOptionsFunc) ResolveEndpoint(service, region string, options interface{}) (Endpoint, error) {
190+
return e(service, region, options)
191+
}
192+
193+
// GetDisableHTTPS takes a service's EndpointResolverOptions and returns the DisableHTTPS value.
194+
// Returns boolean false if the provided options does not have a method to retrieve the DisableHTTPS.
195+
func GetDisableHTTPS(options ...interface{}) (value bool, found bool) {
196+
type iface interface {
197+
GetDisableHTTPS() bool
198+
}
199+
for _, option := range options {
200+
if i, ok := option.(iface); ok {
201+
value = i.GetDisableHTTPS()
202+
found = true
203+
break
204+
}
205+
}
206+
return value, found
207+
}
208+
209+
// GetResolvedRegion takes a service's EndpointResolverOptions and returns the ResolvedRegion value.
210+
// Returns boolean false if the provided options does not have a method to retrieve the ResolvedRegion.
211+
func GetResolvedRegion(options ...interface{}) (value string, found bool) {
212+
type iface interface {
213+
GetResolvedRegion() string
214+
}
215+
for _, option := range options {
216+
if i, ok := option.(iface); ok {
217+
value = i.GetResolvedRegion()
218+
found = true
219+
break
220+
}
221+
}
222+
return value, found
223+
}

aws/endpoints_test.go

Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
package aws
2+
3+
import (
4+
"strconv"
5+
"testing"
6+
)
7+
8+
type mockOptions struct {
9+
Bool bool
10+
Str string
11+
DualStackEndpointState DualStackEndpointState
12+
FIPSEndpointState FIPSEndpointState
13+
}
14+
15+
func (m mockOptions) GetDisableHTTPS() bool {
16+
return m.Bool
17+
}
18+
19+
func (m mockOptions) GetUseDualStackEndpoint() DualStackEndpointState {
20+
return m.DualStackEndpointState
21+
}
22+
23+
func (m mockOptions) GetUseFIPSEndpoint() FIPSEndpointState {
24+
return m.FIPSEndpointState
25+
}
26+
27+
func (m mockOptions) GetResolvedRegion() string {
28+
return m.Str
29+
}
30+
31+
func TestGetDisableHTTPS(t *testing.T) {
32+
cases := []struct {
33+
Options []interface{}
34+
ExpectFound bool
35+
ExpectValue bool
36+
}{
37+
{
38+
Options: []interface{}{struct{}{}},
39+
},
40+
{
41+
Options: []interface{}{mockOptions{
42+
Bool: false,
43+
}},
44+
ExpectFound: true,
45+
ExpectValue: false,
46+
},
47+
{
48+
Options: []interface{}{mockOptions{
49+
Bool: true,
50+
}},
51+
ExpectFound: true,
52+
ExpectValue: true,
53+
},
54+
{
55+
Options: []interface{}{struct{}{}, mockOptions{Bool: true}, mockOptions{Bool: false}},
56+
ExpectFound: true,
57+
ExpectValue: true,
58+
},
59+
}
60+
61+
for i, tt := range cases {
62+
t.Run(strconv.Itoa(i), func(t *testing.T) {
63+
value, found := GetDisableHTTPS(tt.Options...)
64+
if found != tt.ExpectFound {
65+
t.Fatalf("expect value to not be found")
66+
}
67+
if value != tt.ExpectValue {
68+
t.Errorf("expect %v, got %v", tt.ExpectValue, value)
69+
}
70+
})
71+
}
72+
}
73+
74+
func TestGetResolvedRegion(t *testing.T) {
75+
cases := []struct {
76+
Options []interface{}
77+
ExpectFound bool
78+
ExpectValue string
79+
}{
80+
{
81+
Options: []interface{}{struct{}{}},
82+
},
83+
{
84+
Options: []interface{}{mockOptions{Str: ""}},
85+
ExpectFound: true,
86+
ExpectValue: "",
87+
},
88+
{
89+
Options: []interface{}{mockOptions{Str: "foo"}},
90+
ExpectFound: true,
91+
ExpectValue: "foo",
92+
},
93+
{
94+
Options: []interface{}{struct{}{}, mockOptions{Str: "bar"}, mockOptions{Str: "baz"}},
95+
ExpectFound: true,
96+
ExpectValue: "bar",
97+
},
98+
}
99+
100+
for i, tt := range cases {
101+
t.Run(strconv.Itoa(i), func(t *testing.T) {
102+
value, found := GetResolvedRegion(tt.Options...)
103+
if found != tt.ExpectFound {
104+
t.Fatalf("expect value to not be found")
105+
}
106+
if value != tt.ExpectValue {
107+
t.Errorf("expect %v, got %v", tt.ExpectValue, value)
108+
}
109+
})
110+
}
111+
}
112+
113+
func TestGetUseDualStackEndpoint(t *testing.T) {
114+
cases := []struct {
115+
Options []interface{}
116+
ExpectFound bool
117+
ExpectValue DualStackEndpointState
118+
}{
119+
{
120+
Options: []interface{}{struct{}{}},
121+
},
122+
{
123+
Options: []interface{}{mockOptions{DualStackEndpointState: DualStackEndpointStateUnset}},
124+
ExpectFound: true,
125+
ExpectValue: DualStackEndpointStateUnset,
126+
},
127+
{
128+
Options: []interface{}{mockOptions{DualStackEndpointState: DualStackEndpointStateEnabled}},
129+
ExpectFound: true,
130+
ExpectValue: DualStackEndpointStateEnabled,
131+
},
132+
{
133+
Options: []interface{}{struct{}{}, mockOptions{DualStackEndpointState: DualStackEndpointStateEnabled}, mockOptions{DualStackEndpointState: DualStackEndpointStateDisabled}},
134+
ExpectFound: true,
135+
ExpectValue: DualStackEndpointStateEnabled,
136+
},
137+
}
138+
139+
for i, tt := range cases {
140+
t.Run(strconv.Itoa(i), func(t *testing.T) {
141+
value, found := GetUseDualStackEndpoint(tt.Options...)
142+
if found != tt.ExpectFound {
143+
t.Fatalf("expect value to not be found")
144+
}
145+
if value != tt.ExpectValue {
146+
t.Errorf("expect %v, got %v", tt.ExpectValue, value)
147+
}
148+
})
149+
}
150+
}
151+
152+
func TestGetUseFIPSEndpoint(t *testing.T) {
153+
cases := []struct {
154+
Options []interface{}
155+
ExpectFound bool
156+
ExpectValue FIPSEndpointState
157+
}{
158+
{
159+
Options: []interface{}{struct{}{}},
160+
},
161+
{
162+
Options: []interface{}{mockOptions{FIPSEndpointState: FIPSEndpointStateUnset}},
163+
ExpectFound: true,
164+
ExpectValue: FIPSEndpointStateUnset,
165+
},
166+
{
167+
Options: []interface{}{mockOptions{FIPSEndpointState: FIPSEndpointStateEnabled}},
168+
ExpectFound: true,
169+
ExpectValue: FIPSEndpointStateEnabled,
170+
},
171+
{
172+
Options: []interface{}{struct{}{}, mockOptions{FIPSEndpointState: FIPSEndpointStateEnabled}, mockOptions{FIPSEndpointState: FIPSEndpointStateDisabled}},
173+
ExpectFound: true,
174+
ExpectValue: FIPSEndpointStateEnabled,
175+
},
176+
}
177+
178+
for i, tt := range cases {
179+
t.Run(strconv.Itoa(i), func(t *testing.T) {
180+
value, found := GetUseFIPSEndpoint(tt.Options...)
181+
if found != tt.ExpectFound {
182+
t.Fatalf("expect value to not be found")
183+
}
184+
if value != tt.ExpectValue {
185+
t.Errorf("expect %v, got %v", tt.ExpectValue, value)
186+
}
187+
})
188+
}
189+
}

0 commit comments

Comments
 (0)