Skip to content

Commit

Permalink
feat: load config
Browse files Browse the repository at this point in the history
  • Loading branch information
adikari committed Sep 13, 2022
1 parent a68fb75 commit b057b93
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 6 deletions.
5 changes: 2 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package cmd

import (
"log"

c "github.com/adikari/safebox/v2/config"
"github.com/spf13/cobra"
)

Expand All @@ -19,6 +18,6 @@ func init() {
}

func execute(cmd *cobra.Command, args []string) error {
log.Print(stage)
c.LoadConfig()
return nil
}
50 changes: 50 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package config

import (
"errors"
"io/ioutil"

"gopkg.in/yaml.v2"
)

type ConfigParam struct {
Name string
Description string
Value string
Override map[string]string
Secret bool
Required bool
}

type Config struct {
Provider string

Defaults struct {
Path string
}

Params []ConfigParam
}

func loadConfig() (*Config, error) {
path := "example/safebox.yml"
yamlFile, err := ioutil.ReadFile(path)

config := Config{}

if err != nil {
return nil, errors.New("Could not find config file: " + path)
}

err = yaml.Unmarshal(yamlFile, &config)

if err != nil {
return nil, errors.New("Could not parse config file")
}

return &config, nil
}

func GetConfig() []ConfigParam {
return nil
}
23 changes: 23 additions & 0 deletions example/safebox.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
provider: ssm

defaults:
path: /${STAGE}/gateway/

params:
- name: DB_NAME
description: 'database name'
value: database-name
override:
production: production-database-name
staging: staging-database-name

- name: DB_PASSWORD
description: 'database password'
secret: true

- name: DB_PORT
required: false

- name: DATADOG_API_KEY
path: /shared/
secret: true
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/adikari/safebox/v2
go 1.19

require (
github.com/pkg/errors v0.9.1
github.com/spf13/cobra v1.5.0
gopkg.in/yaml.v2 v2.4.0
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
github.com/inconshreveable/mousetrap v1.0.1 h1:U3uMjPSQEBMNp1lFxmllqCPM6P5u/Xq7Pgzkat/bFNc=
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=

0 comments on commit b057b93

Please sign in to comment.