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 1bed556 commit 96ad584
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 4 deletions.
26 changes: 26 additions & 0 deletions pkg/server/storage/minio.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
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(strings.TrimPrefix(s3.Endpoint, "http://"), ":")
return map[string]string{
"S3_HOST": endpoint[0],
"S3_PORT": endpoint[1],
"MINIO_BUCKET": s3.Bucket,
}
}

func newMinio(conf *Config) Storage {
s3 := newS3(conf)
return &Minio{Storage: s3}
}
39 changes: 39 additions & 0 deletions pkg/server/storage/minio_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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)
}
}
}
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 96ad584

Please sign in to comment.