Skip to content

Commit 0ff44a1

Browse files
author
Aaron Schlesinger
committed
ref(storage.go,storage_creds.go): move basic storage logic into convenience package
1 parent 630333d commit 0ff44a1

2 files changed

Lines changed: 13 additions & 40 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
package gitreceive
1+
package storage
22

33
import (
44
"fmt"
55
"io/ioutil"
66
"os"
77
"strings"
8+
9+
"github.com/aws/aws-sdk-go/aws/credentials"
810
)
911

1012
const (
@@ -17,19 +19,14 @@ var (
1719
errMissingSecret = fmt.Errorf("missing %s", accessSecretKeyFile)
1820
)
1921

20-
type storageCreds struct {
21-
key string
22-
secret string
23-
}
24-
25-
// getStorageCreds gets storage credentials from accessKeyIDFile and accessSecretKeyFile.
26-
// returns os.ErrNotExist if both files are missing and otherwise, if a file was missing,
27-
// returns errMissingKey or errMissingSecret according to the file
28-
func getStorageCreds() (*storageCreds, error) {
22+
// getCreds gets storage credentials from accessKeyIDFile and accessSecretKeyFile.
23+
// if either a key exists but not a secret or vice-versa, returns an error.
24+
// if neither exists, returns credentials.AnonymousCredentials
25+
func getCreds() (*credentials.Credentials, error) {
2926
accessKeyIDBytes, accessKeyErr := ioutil.ReadFile(accessKeyIDFile)
3027
accessSecretKeyBytes, accessSecretKeyErr := ioutil.ReadFile(accessSecretKeyFile)
3128
if accessKeyErr == os.ErrNotExist && accessSecretKeyErr == os.ErrNotExist {
32-
return nil, os.ErrNotExist
29+
return credentials.AnonymousCredentials, nil
3330
}
3431
if accessKeyErr != nil && accessSecretKeyErr == nil {
3532
return nil, errMissingKey
@@ -39,5 +36,5 @@ func getStorageCreds() (*storageCreds, error) {
3936
}
4037
accessKeyID := strings.TrimSpace(string(accessKeyIDBytes))
4138
accessSecretKey := strings.TrimSpace(string(accessSecretKeyBytes))
42-
return &storageCreds{key: accessKeyID, secret: accessSecretKey}, nil
39+
return credentials.NewStaticCredentials(accessKeyID, accessSecretKey, ""), nil
4340
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package gitreceive
1+
package storage
22

33
import (
44
"fmt"
@@ -22,40 +22,16 @@ var (
2222
)
2323
)
2424

25-
type storageConfig interface {
26-
schema() string
27-
host() string
28-
port() string
29-
}
30-
31-
func getStorageConfig() (storageConfig, error) {
25+
func getEndpoint() (string, error) {
3226
mHost := os.Getenv(minioHostEnvVar)
3327
mPort := os.Getenv(minioPortEnvVar)
3428
oHost := os.Getenv(outsideStorageHostEnvVar)
3529
oPort := os.Getenv(outsideStoragePortEnvVar)
3630
if mHost != "" && mPort != "" {
37-
return minioConfig{hst: mHost, prt: mPort}, nil
31+
return fmt.Sprintf("http://%s:%s", mHost, mPort), nil
3832
} else if oHost != "" && oPort != "" {
39-
return outsideConfig{hst: oHost, prt: oPort}, nil
33+
return fmt.Sprintf("https://%s:%s", oHost, oPort), nil
4034
} else {
4135
return nil, errNoStorageConfig
4236
}
4337
}
44-
45-
type minioConfig struct {
46-
hst string
47-
prt string
48-
}
49-
50-
func (m minioConfig) schema() string { return "http" }
51-
func (m minioConfig) host() string { return m.hst }
52-
func (m minioConfig) port() string { return m.prt }
53-
54-
type outsideConfig struct {
55-
hst string
56-
prt string
57-
}
58-
59-
func (o outsideConfig) schema() string { return "https" }
60-
func (o outsideConfig) host() string { return o.hst }
61-
func (o outsideConfig) port() string { return o.prt }

0 commit comments

Comments
 (0)