Skip to content

Commit

Permalink
Add support for specifying S3 host to support Ceph and the like
Browse files Browse the repository at this point in the history
  • Loading branch information
zackbloom committed Mar 27, 2018
1 parent 1f022e4 commit cc5c143
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func UpdateRoute(options Options, dist cloudfront.DistributionSummary) error {

func Create(options Options) {
if s3Session == nil {
s3Session = openS3(options.AWSKey, options.AWSSecret, options.AWSRegion)
s3Session = openS3(options.AWSKey, options.AWSSecret, options.AWSRegion, options.S3Host)
}
if iamSession == nil {
iamSession = openIAM(options.AWSKey, options.AWSSecret, options.AWSRegion)
Expand Down
2 changes: 1 addition & 1 deletion src/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ func (f HTMLFile) GetLocalPath() string {

func Deploy(options Options) {
if s3Session == nil {
s3Session = openS3(options.AWSKey, options.AWSSecret, options.AWSRegion)
s3Session = openS3(options.AWSKey, options.AWSSecret, options.AWSRegion, options.S3Host)
}

files := listFiles(options)
Expand Down
2 changes: 1 addition & 1 deletion src/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

func Rollback(options Options, version string) {
if s3Session == nil {
s3Session = openS3(options.AWSKey, options.AWSSecret, options.AWSRegion)
s3Session = openS3(options.AWSKey, options.AWSSecret, options.AWSRegion, options.S3Host)
}

bucket := s3Session.Bucket(options.Bucket)
Expand Down
21 changes: 15 additions & 6 deletions src/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"flag"
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"
"regexp"
"strings"

"github.com/imdario/mergo"
"github.com/mitchellh/go-homedir"
"github.com/zackbloom/go-ini"
homedir "github.com/mitchellh/go-homedir"
ini "github.com/sspencer/go-ini"
"github.com/zackbloom/goamz/aws"
"github.com/zackbloom/goamz/cloudfront"
"github.com/zackbloom/goamz/iam"
Expand All @@ -30,16 +31,22 @@ var iamSession *iam.IAM
var r53Session *route53.Route53
var cfSession *cloudfront.CloudFront

func getRegion(region string) aws.Region {
func getRegion(region string, s3Host string) aws.Region {
regionS, ok := aws.Regions[region]
if !ok {
panic("Region not found")
}

log.Println("HOST", s3Host)
if s3Host != "" {
regionS.S3Endpoint = "https://" + s3Host
regionS.S3BucketEndpoint = "https://${bucket}." + s3Host
}
return regionS
}

func openS3(key, secret, region string) *s3.S3 {
regionS := getRegion(region)
func openS3(key, secret, region, s3Host string) *s3.S3 {
regionS := getRegion(region, s3Host)

auth := aws.Auth{
AccessKey: key,
Expand All @@ -49,7 +56,7 @@ func openS3(key, secret, region string) *s3.S3 {
}

func openIAM(key, secret, region string) *iam.IAM {
regionS := getRegion(region)
regionS := getRegion(region, "")

auth := aws.Auth{
AccessKey: key,
Expand Down Expand Up @@ -107,6 +114,7 @@ type Options struct {
AWSKey string `yaml:"key"`
AWSSecret string `yaml:"secret"`
AWSRegion string `yaml:"region"`
S3Host string `yaml:"s3Host"`
NoUser bool `yaml:"-"`
}

Expand All @@ -123,6 +131,7 @@ func parseOptions() (o Options, set *flag.FlagSet) {
set.StringVar(&o.AWSKey, "key", "", "The AWS key to use")
set.StringVar(&o.AWSSecret, "secret", "", "The AWS secret of the provided key")
set.StringVar(&o.AWSRegion, "region", "us-east-1", "The AWS region the S3 bucket is in")
set.StringVar(&o.S3Host, "s3-host", "s3.amazonaws.com", "The hostname of an S3 implementation, overrides region")
set.BoolVar(&o.NoUser, "no-user", false, "When creating, should we make a user account?")

set.Parse(os.Args[2:])
Expand Down

0 comments on commit cc5c143

Please sign in to comment.