Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[State] Feat: Added Remote backend option for S3, GCS and Azblob #10

Merged
merged 3 commits into from
Jan 17, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ refreshInterval: 4
StateBackend:
type: local
path: /path/to/local/store/state
#StateBackend:
# type: s3
# bucket: bucket_name
# path: path/to/local/store

aws:
# # Env: AWS_SECRET_ACCESS_KEY
Expand Down Expand Up @@ -82,4 +86,17 @@ rules:


timezone: Africa/Lagos
# timezone: UTC+1
# timezone: UTC+1

# # Example remote state backends
#StateBackend:
# type: s3
# bucket: random
# path: tracks/reka-store.json
# region: us-east-2

#StateBackend:
# type: azblob
# bucket: random
# path: tracks/reka-store.json

33 changes: 31 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ type Config struct {
// State files contain details used for infrastructure resumption and history of
// infrastructural management
StateBackend struct {
Type string
Path string
Type string
Path string
Bucket string
Region string
}

// Rules block define how reka should behave given certain resources. These rules
Expand All @@ -81,6 +83,9 @@ type Config struct {
Gcp Gcp
}

// Allowed StateBackend Types
var StateBackendTypes = []string{"local", "s3", "azblob", "gs"}

// LoadConfig load all passed configs and defaults
func LoadConfig() *Config {
workingDir, err = os.Getwd()
Expand Down Expand Up @@ -130,6 +135,20 @@ func LoadConfig() *Config {
log.Fatal("No providers specified. Reka needs atleast one provider to monitor")
}

if !Contains(StateBackendTypes, config.StateBackend.Type) {
log.Fatalf("State Backend Type is not permitted, Please use one of %s", StateBackendTypes)

} else {
if config.StateBackend.Type != StateBackendTypes[0] {
if config.StateBackend.Bucket == "" || config.StateBackend.Path == "" {
log.Fatalf("State Backend (type: %s) - bucket and path must be set in config", config.StateBackend.Type)
}
if config.StateBackend.Type == "s3" && config.StateBackend.Region == "" {
log.Fatal("State Backend (type: s3) - Must configure Region")
}
}
}

if !path.IsAbs(viper.GetString("StaticPath")) {
config.staticPath = path.Join(workingDir, viper.GetString("StaticPath"))
}
Expand All @@ -151,6 +170,16 @@ func LoadConfig() *Config {
return config
}

// Contains check if array contains value
func Contains(arr []string, str string) bool {
for _, a := range arr {
if a == str {
return true
}
}
return false
}

// GetConfig return the config object
func GetConfig() *Config {
return config
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/mensaah/reka
go 1.14

require (
cloud.google.com/go/storage v1.0.0
cloud.google.com/go/storage v1.12.0
github.com/aws/aws-sdk-go-v2 v0.31.0
github.com/aws/aws-sdk-go-v2/config v0.4.0
github.com/aws/aws-sdk-go-v2/credentials v0.2.0
Expand All @@ -19,7 +19,8 @@ require (
github.com/sirupsen/logrus v1.7.0
github.com/spf13/cobra v1.1.1
github.com/spf13/viper v1.7.1
google.golang.org/api v0.13.0
gocloud.dev v0.21.0
google.golang.org/api v0.36.0
gorm.io/driver/postgres v1.0.6
gorm.io/driver/sqlite v1.1.4
gorm.io/gorm v1.20.9
Expand Down
Loading