feat(config):lab4 add S3 settings
This commit is contained in:
@@ -17,6 +17,13 @@ type Config struct {
|
|||||||
SessionTTL time.Duration
|
SessionTTL time.Duration
|
||||||
IdempotencyTTL time.Duration
|
IdempotencyTTL time.Duration
|
||||||
ShutdownDrain time.Duration
|
ShutdownDrain time.Duration
|
||||||
|
|
||||||
|
S3Endpoint string
|
||||||
|
S3Bucket string
|
||||||
|
S3UseSSL bool
|
||||||
|
S3Region string
|
||||||
|
S3AccessKey string
|
||||||
|
S3SecretKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load() (*Config, error) {
|
func Load() (*Config, error) {
|
||||||
@@ -61,6 +68,29 @@ func Load() (*Config, error) {
|
|||||||
return nil, fmt.Errorf("SESSION_STORE=%q не поддерживается", store)
|
return nil, fmt.Errorf("SESSION_STORE=%q не поддерживается", store)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s3Endpoint := getenv("S3_ENDPOINT", "")
|
||||||
|
if s3Endpoint == "" {
|
||||||
|
return nil, fmt.Errorf("S3_ENDPOINT не задан")
|
||||||
|
}
|
||||||
|
s3Bucket := getenv("S3_BUCKET", "")
|
||||||
|
if s3Bucket == "" {
|
||||||
|
return nil, fmt.Errorf("S3_BUCKET не задан")
|
||||||
|
}
|
||||||
|
s3UseSSL, err := readBool("S3_USE_SSL", false)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("S3_USE_SSL: %w", err)
|
||||||
|
}
|
||||||
|
s3Region := getenv("S3_REGION", "us-east-1")
|
||||||
|
|
||||||
|
s3AccessKey, err := readSecret("S3_ACCESS_KEY_FILE", "S3_ACCESS_KEY")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("s3 access key: %w", err)
|
||||||
|
}
|
||||||
|
s3SecretKey, err := readSecret("S3_SECRET_KEY_FILE", "S3_SECRET_KEY")
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("s3 secret key: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
return &Config{
|
return &Config{
|
||||||
Host: getenv("APP_HOST", "0.0.0.0"),
|
Host: getenv("APP_HOST", "0.0.0.0"),
|
||||||
Port: getenv("APP_PORT", "8080"),
|
Port: getenv("APP_PORT", "8080"),
|
||||||
@@ -70,6 +100,13 @@ func Load() (*Config, error) {
|
|||||||
SessionTTL: time.Duration(ttlSeconds) * time.Second,
|
SessionTTL: time.Duration(ttlSeconds) * time.Second,
|
||||||
IdempotencyTTL: time.Duration(idemSeconds) * time.Second,
|
IdempotencyTTL: time.Duration(idemSeconds) * time.Second,
|
||||||
ShutdownDrain: time.Duration(drainSeconds) * time.Second,
|
ShutdownDrain: time.Duration(drainSeconds) * time.Second,
|
||||||
|
|
||||||
|
S3Endpoint: s3Endpoint,
|
||||||
|
S3Bucket: s3Bucket,
|
||||||
|
S3UseSSL: s3UseSSL,
|
||||||
|
S3Region: s3Region,
|
||||||
|
S3AccessKey: s3AccessKey,
|
||||||
|
S3SecretKey: s3SecretKey,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -92,6 +129,18 @@ func readInt(key string, def int) (int, error) {
|
|||||||
return n, nil
|
return n, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func readBool(key string, def bool) (bool, error) {
|
||||||
|
v := os.Getenv(key)
|
||||||
|
if v == "" {
|
||||||
|
return def, nil
|
||||||
|
}
|
||||||
|
b, err := strconv.ParseBool(v)
|
||||||
|
if err != nil {
|
||||||
|
return false, fmt.Errorf("не bool: %q", v)
|
||||||
|
}
|
||||||
|
return b, nil
|
||||||
|
}
|
||||||
|
|
||||||
func readSecret(fileEnv, envKey string) (string, error) {
|
func readSecret(fileEnv, envKey string) (string, error) {
|
||||||
v, err := readSecretOptional(fileEnv, envKey)
|
v, err := readSecretOptional(fileEnv, envKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user