-
Notifications
You must be signed in to change notification settings - Fork 4
/
s3_config.go
49 lines (39 loc) · 1.09 KB
/
s3_config.go
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
44
45
46
47
48
49
package remoteconfig
import (
"errors"
"net/url"
)
const (
S3_CONFIG_DEFAULT_EXPIRY uint = 60
)
type S3Config struct {
Endpoint *string `json:"endpoint,omitempty" yaml:"endpoint,omitempty" remoteconfig:"optional"`
Bucket *string `json:"bucket,omitempty" yaml:"bucket,omitempty"` // i.e. bucket
Region *AWSRegion `json:"region,omitempty" yaml:"region,omitempty"` // i.e. us-west-2
Expiry *uint `json:"expiry,omitempty" yaml:"expiry,omitempty" remoteconfig:"optional"` // i.e. 60
}
func (c S3Config) GetEndpoint() string {
if c.Endpoint != nil {
return *c.Endpoint
}
return ""
}
func (c S3Config) GetExpiry() uint {
if c.Expiry != nil {
return *c.Expiry
}
return S3_CONFIG_DEFAULT_EXPIRY
}
func S3URLToConfig(s3URL string) (*S3Config, string, error) {
// i.e. s3://bucket/test/path.json
c := &S3Config{}
pURL, err := url.Parse(s3URL)
if err != nil {
return nil, "", err
}
if pURL.Scheme != "s3" {
return nil, "", errors.New("URL does not have the s3:// scheme")
}
c.Bucket = &pURL.Host
return c, pURL.Path[1:], nil
}