github.com/billybanfield/evergreen@v0.0.0-20170525200750-eeee692790f7/plugin/builtin/s3copy/s3_copy_validation.go (about)

     1  package s3copy
     2  
     3  import (
     4  	"regexp"
     5  	"strings"
     6  
     7  	"github.com/evergreen-ci/evergreen/plugin"
     8  	"github.com/pkg/errors"
     9  )
    10  
    11  var (
    12  	BucketNameRegex = regexp.MustCompile(`^[a-z0-9\-.]+$`)
    13  )
    14  
    15  func validateS3BucketName(bucket string) error {
    16  	// if it's an expandable string, we can't expand yet since we don't have
    17  	// access to the task config expansions. So, we defer till during runtime
    18  	// to do the validation
    19  	if plugin.IsExpandable(bucket) {
    20  		return nil
    21  	}
    22  	if len(bucket) < 3 {
    23  		return errors.New("must be at least 3 characters")
    24  	}
    25  	if len(bucket) > 63 {
    26  		return errors.New("must be no more than 63 characters")
    27  	}
    28  	if strings.HasPrefix(bucket, ".") || strings.HasPrefix(bucket, "-") {
    29  		return errors.New("must not begin with a period or hyphen")
    30  	}
    31  	if strings.HasSuffix(bucket, ".") || strings.HasSuffix(bucket, "-") {
    32  		return errors.New("must not end with a period or hyphen")
    33  	}
    34  	if strings.Contains(bucket, "..") {
    35  		return errors.New("must not have two consecutive periods")
    36  	}
    37  	/*
    38  		if !BucketNameRegex.MatchString(bucket) {
    39  			return errors.New("must contain only lowercase letters, numbers," +
    40  				" hyphens, and periods")
    41  		}
    42  	*/
    43  	return nil
    44  }