Skip to content
This repository has been archived by the owner on Aug 5, 2020. It is now read-only.

Commit

Permalink
Merge pull request #187 from phylake/validation
Browse files Browse the repository at this point in the history
region and instance type validation
  • Loading branch information
phylake authored Apr 9, 2018
2 parents 69cd19e + 55fef3e commit 127c470
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 57 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
`porter` is [semantically versioned](http://semver.org/spec/v2.0.0.html)

### v5.1.0

- build porter with Go 1.10.1
- regex matching on region names and instance types instead of whitelist

### v5.0.0

- build porter with Go 1.9.2
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.godep
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
FROM golang:1.9.2
FROM golang:1.10.1

RUN go get github.com/tools/godep
2 changes: 1 addition & 1 deletion Dockerfile.linux
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.9.2
FROM golang:1.10.1

ADD . /go/src/github.com/adobe-platform/porter
WORKDIR /go/src/github.com/adobe-platform/porter
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.9.2
FROM golang:1.10.1

RUN go get github.com/onsi/ginkgo/ginkgo
RUN go get github.com/onsi/gomega
Expand Down
5 changes: 5 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ See the [CHANGELOG](CHANGELOG.md) for a complete list of changes.

`porter` is [semantically versioned](http://semver.org/spec/v2.0.0.html)

v5.1
====

Removed whitelisting on AWS Regions and EC2 Instance types.

v5.0
====

Expand Down
2 changes: 2 additions & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ var (
vpcIdRegex = regexp.MustCompile(`^vpc-(\d|\w){8}$`)
subnetIdRegex = regexp.MustCompile(`^subnet-(\d|\w){8}$`)
commonNameRegex = regexp.MustCompile(`^(\w+\.)?[a-z]+$`)
regionRegex = regexp.MustCompile(`^[a-z]{2}-[a-z]+-\d$`)
instanceTypeRegex = regexp.MustCompile(`^[a-z0-9]{2}\.[a-z0-9]+$`)

// https://github.com/docker/docker/blob/v1.11.2/utils/names.go#L6
// minus '-' which is reserved
Expand Down
4 changes: 2 additions & 2 deletions conf/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func (recv *Config) ValidateEnvironments() error {
}
}

if _, exists := constants.AwsInstanceTypes[environment.InstanceType]; !exists {
if !instanceTypeRegex.MatchString(environment.InstanceType) {
return errors.New("Invalid instance_type for environment [" + environment.Name + "]")
}

Expand Down Expand Up @@ -247,7 +247,7 @@ func ValidateRegion(region *Region, validateRoleArn bool) error {
return err
}

if _, exists := constants.AwsRegions[region.Name]; !exists {
if !regionRegex.MatchString(region.Name) {
return errors.New("Invalid region name " + region.Name)
}

Expand Down
53 changes: 1 addition & 52 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@ const (
)

var (
AwsRegions map[string]interface{}
AwsInstanceTypes map[string]interface{}
AwsRegions map[string]interface{}
)

func StackCreationTimeout() time.Duration {
Expand Down Expand Up @@ -197,54 +196,4 @@ func init() {
"us-west-1": nil,
"us-west-2": nil,
}

AwsInstanceTypes = map[string]interface{}{
"t2.nano": nil,
"t2.micro": nil,
"t2.small": nil,
"t2.medium": nil,
"t2.large": nil,
"t2.xlarge": nil,
"t2.2xlarge": nil,

"m4.large": nil,
"m4.xlarge": nil,
"m4.2xlarge": nil,
"m4.4xlarge": nil,
"m4.10xlarge": nil,
"m4.16xlarge": nil,

"m3.medium": nil,
"m3.large": nil,
"m3.xlarge": nil,
"m3.2xlarge": nil,

"c4.large": nil,
"c4.xlarge": nil,
"c4.2xlarge": nil,
"c4.4xlarge": nil,
"c4.8xlarge": nil,

"c3.large": nil,
"c3.xlarge": nil,
"c3.2xlarge": nil,
"c3.4xlarge": nil,
"c3.8xlarge": nil,

"x1.32xlarge": nil,
"x1.16xlarge": nil,

"r4.large": nil,
"r4.xlarge": nil,
"r4.2xlarge": nil,
"r4.4xlarge": nil,
"r4.8xlarge": nil,
"r4.16xlarge": nil,

"r3.large": nil,
"r3.xlarge": nil,
"r3.2xlarge": nil,
"r3.4xlarge": nil,
"r3.8xlarge": nil,
}
}

0 comments on commit 127c470

Please sign in to comment.