Skip to content

Commit

Permalink
add minio as storage type
Browse files Browse the repository at this point in the history
  • Loading branch information
drgarcia1986 committed Aug 3, 2017
1 parent efd1b75 commit 7c72172
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 4 deletions.
33 changes: 33 additions & 0 deletions pkg/server/storage/minio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package storage

import "strings"

type Minio struct {
Storage
}

func (m *Minio) Type() string {
return string(MinioType)
}

func (m *Minio) PodEnvVars() map[string]string {
s3 := m.Storage.(*S3)
endpoint := strings.Split(trimEndpoint(s3.Endpoint), ":")
return map[string]string{
"S3_HOST": endpoint[0],
"S3_PORT": endpoint[1],
"MINIO_BUCKET": s3.Bucket,
}
}

func trimEndpoint(endpoint string) string {
for _, s := range []string{"http://", "https://"} {
endpoint = strings.TrimPrefix(endpoint, s)
}
return endpoint
}

func newMinio(conf *Config) Storage {
s3 := newS3(conf)
return &Minio{Storage: s3}
}
55 changes: 55 additions & 0 deletions pkg/server/storage/minio_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package storage

import (
"fmt"
"testing"
)

func TestMinioType(t *testing.T) {
minio := newMinio(&Config{})
if tmp := minio.Type(); tmp != "minio" {
t.Errorf("expected minio, got %s", tmp)
}
}

func TestMinioPodEnvVars(t *testing.T) {
expectedHost := "url"
expectedPort := "9000"
expectedBucket := "test"
minio := newMinio(&Config{
AwsEndpoint: fmt.Sprintf("http://%s:%s", expectedHost, expectedPort),
AwsBucket: expectedBucket,
})
ev := minio.PodEnvVars()

var testCases = []struct {
env string
expected string
}{
{"S3_HOST", expectedHost},
{"S3_PORT", expectedPort},
{"MINIO_BUCKET", expectedBucket},
}

for _, tc := range testCases {
if tmp := ev[tc.env]; tmp != tc.expected {
t.Errorf("expected %s, got %s", tc.expected, tc.env)
}
}
}

func TestTrimEndpoint(t *testing.T) {
var testCases = []struct {
input string
expected string
}{
{"http://foo.com", "foo.com"},
{"https://teresa.io", "teresa.io"},
}

for _, tc := range testCases {
if actual := trimEndpoint(tc.input); actual != tc.expected {
t.Errorf("expected %s, got %s", tc.expected, actual)
}
}
}
13 changes: 9 additions & 4 deletions pkg/server/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
type storageType string

const (
S3Type storageType = "s3"
FakeType storageType = "fake"
S3Type storageType = "s3"
MinioType storageType = "minio"
FakeType storageType = "fake"
)

type Config struct {
Expand All @@ -31,8 +32,12 @@ type Storage interface {
}

func New(conf *Config) (Storage, error) {
if conf.Type != S3Type {
switch conf.Type {
case S3Type:
return newS3(conf), nil
case MinioType:
return newMinio(conf), nil
default:
return nil, ErrInvalidStorageType
}
return newS3(conf), nil
}

0 comments on commit 7c72172

Please sign in to comment.