diff --git a/README.md b/README.md index 4e16312..e0734e3 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,16 @@ # S3 Manager -Manage S3 buckets from any provider. +A Web UI to written in Go to manage S3 buckets from any provider. ## Environment Variables -* `S3_ACCESS_KEY_ID` -* `S3_SECRET_ACCESS_KEY` +* `S3_ACCESS_KEY_ID`: Required. Your S3 access key ID +* `S3_SECRET_ACCESS_KEY`: Required. Your S3 secret access key * `S3_ENDPOINT`: Optional. In case you are using a different S3 provider than AWS. Defaults to `s3.amazonaws.com` * `V2_SIGNING`: Optional. In case your S3 provider still uses V2 Signing, set this to `true` + +## Run locally + +1. Set all environment variables +1. Run `go build .` +1. Run the binary and visit diff --git a/main.go b/main.go index 9223566..91b51f9 100644 --- a/main.go +++ b/main.go @@ -4,42 +4,13 @@ import ( "log" "net/http" "os" - - "github.com/minio/minio-go" ) -var minioClient *minio.Client - func main() { - var err error - port := os.Getenv("PORT") if len(port) == 0 { port = "8080" } - s3AccessKeyID := os.Getenv("S3_ACCESS_KEY_ID") - if len(s3AccessKeyID) == 0 { - log.Fatalln("Please set S3_ACCESS_KEY_ID") - } - - s3SecretAccessKey := os.Getenv("S3_SECRET_ACCESS_KEY") - if len(s3SecretAccessKey) == 0 { - log.Fatalln("Please set S3_SECRET_ACCESS_KEY") - } - - s3Endpoint := os.Getenv("S3_ENDPOINT") - if len(s3Endpoint) == 0 { - s3Endpoint = "s3.amazonaws.com" - } - - if os.Getenv("V2_SIGNING") == "true" { - minioClient, err = minio.NewV2(s3Endpoint, s3AccessKeyID, s3SecretAccessKey, true) - } else { - minioClient, err = minio.New(s3Endpoint, s3AccessKeyID, s3SecretAccessKey, true) - } - if err != nil { - panic(err) - } router := NewRouter() diff --git a/manifest.yml b/manifest.yml index 16668ff..bbb07be 100644 --- a/manifest.yml +++ b/manifest.yml @@ -5,7 +5,6 @@ applications: buildpack: https://github.com/cloudfoundry/go-buildpack.git env: - GOVERSION: go1.7 S3_ACCESS_KEY_ID: "XXX" S3_SECRET_ACCESS_KEY: "xxx" S3_ENDPOINT: "ds31s3.swisscom.com" diff --git a/minio.go b/minio.go new file mode 100644 index 0000000..5074acf --- /dev/null +++ b/minio.go @@ -0,0 +1,38 @@ +package main + +import ( + "log" + "os" + + minio "github.com/minio/minio-go" +) + +var minioClient *minio.Client + +func init() { + var err error + + s3Endpoint := os.Getenv("S3_ENDPOINT") + if len(s3Endpoint) == 0 { + s3Endpoint = "s3.amazonaws.com" + } + + s3AccessKeyID := os.Getenv("S3_ACCESS_KEY_ID") + if len(s3AccessKeyID) == 0 { + log.Fatalln("Please set S3_ACCESS_KEY_ID") + } + + s3SecretAccessKey := os.Getenv("S3_SECRET_ACCESS_KEY") + if len(s3SecretAccessKey) == 0 { + log.Fatalln("Please set S3_SECRET_ACCESS_KEY") + } + + if os.Getenv("V2_SIGNING") == "true" { + minioClient, err = minio.NewV2(s3Endpoint, s3AccessKeyID, s3SecretAccessKey, true) + } else { + minioClient, err = minio.New(s3Endpoint, s3AccessKeyID, s3SecretAccessKey, true) + } + if err != nil { + log.Fatalln(err) + } +}