-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathstorage_creds.go
More file actions
43 lines (38 loc) · 1.22 KB
/
storage_creds.go
File metadata and controls
43 lines (38 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package gitreceive
import (
"fmt"
"io/ioutil"
"os"
)
const (
accessKeyIDFile = "/var/run/secrets/object/store/access-key-id"
accessSecretKeyFile = "/var/run/secrets/object/store/access-secret-key"
)
var (
errMissingKey = fmt.Errorf("missing %s", accessKeyIDFile)
errMissingSecret = fmt.Errorf("missing %s", accessSecretKeyFile)
)
type storageCreds struct {
key string
secret string
}
// getStorageCreds gets storage credentials from accessKeyIDFile and accessSecretKeyFile.
// returns os.ErrNotExist if both files are missing and otherwise, if a file was missing,
// returns errMissingKey or errMissingSecret according to the file
func getStorageCreds() (*storageCreds, error) {
accessKeyIDBytes, accessKeyErr := ioutil.ReadFile(accessKeyIDFile)
accessSecretKeyBytes, accessSecretKeyErr := ioutil.ReadFile(accessSecretKeyFile)
if accessKeyErr == os.ErrNotExist && accessSecretKeyErr == os.ErrNotExist {
return nil, os.ErrNotExist
}
if accessKeyErr != nil && accessSecretKeyErr == nil {
return nil, errMissingKey
}
if accessKeyErr == nil && accessSecretKeyErr != nil {
return nil, errMissingSecret
}
return &storageCreds{
key: string(accessKeyIDBytes),
secret: string(accessSecretKeyBytes),
}, nil
}