mirror of https://github.com/kubernetes/kops.git
Correctly detect GovCloud regions
This commit is contained in:
parent
6844934e1a
commit
210d072da9
|
|
@ -36,11 +36,12 @@ import (
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// matches all regional naming conventions of S3:
|
// matches regional naming conventions of S3:
|
||||||
// https://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
|
// https://docs.aws.amazon.com/general/latest/gr/s3.html
|
||||||
|
// TODO: match fips and S3 access point naming conventions
|
||||||
// TODO: perhaps make region regex more specific, i.e. (us|eu|ap|cn|ca|sa), to prevent matching bucket names that match region format?
|
// TODO: perhaps make region regex more specific, i.e. (us|eu|ap|cn|ca|sa), to prevent matching bucket names that match region format?
|
||||||
// but that will mean updating this list when AWS introduces new regions
|
// but that will mean updating this list when AWS introduces new regions
|
||||||
var s3UrlRegexp = regexp.MustCompile(`(s3([-.](?P<region>\w{2}-\w+-\d{1})|[-.](?P<bucket>[\w.\-\_]+)|)?|(?P<bucket>[\w.\-\_]+)[.]s3([.](?P<region>\w{2}-\w+-\d{1}))?)[.]amazonaws[.]com([.]cn)?(?P<path>.*)?`)
|
var s3UrlRegexp = regexp.MustCompile(`(s3([-.](?P<region>\w{2}(-gov)?-\w+-\d{1})|[-.](?P<bucket>[\w.\-\_]+)|)?|(?P<bucket>[\w.\-\_]+)[.]s3([.-](?P<region>\w{2}(-gov)?-\w+-\d{1}))?)[.]amazonaws[.]com([.]cn)?(?P<path>.*)?`)
|
||||||
|
|
||||||
type S3BucketDetails struct {
|
type S3BucketDetails struct {
|
||||||
// context is the S3Context we are associated with
|
// context is the S3Context we are associated with
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,16 @@ func Test_VFSPath(t *testing.T) {
|
||||||
ExpectedResult: "s3://bucket/path",
|
ExpectedResult: "s3://bucket/path",
|
||||||
ExpectError: false,
|
ExpectError: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Input: "https://s3.us-gov-west-1.amazonaws.com/bucket",
|
||||||
|
ExpectedResult: "s3://bucket",
|
||||||
|
ExpectError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "https://s3.us-gov-west-1.amazonaws.com/bucket/path",
|
||||||
|
ExpectedResult: "s3://bucket/path",
|
||||||
|
ExpectError: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Input: "https://s3.amazonaws.com/bucket",
|
Input: "https://s3.amazonaws.com/bucket",
|
||||||
ExpectedResult: "s3://bucket",
|
ExpectedResult: "s3://bucket",
|
||||||
|
|
@ -124,6 +134,16 @@ func Test_VFSPath(t *testing.T) {
|
||||||
ExpectedResult: "s3://bucket-name/path",
|
ExpectedResult: "s3://bucket-name/path",
|
||||||
ExpectError: false,
|
ExpectError: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Input: "https://bucket-name.s3-us-gov-west-1.amazonaws.com",
|
||||||
|
ExpectedResult: "s3://bucket-name",
|
||||||
|
ExpectError: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Input: "https://bucket-name.s3-us-gov-west-1.amazonaws.com/path",
|
||||||
|
ExpectedResult: "s3://bucket-name/path",
|
||||||
|
ExpectError: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Input: "example.com/bucket",
|
Input: "example.com/bucket",
|
||||||
ExpectedResult: "",
|
ExpectedResult: "",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue