Skip to content

Commit

Permalink
Merge pull request #474 from twhiston/remove_default_config
Browse files Browse the repository at this point in the history
remove the need for config init function
  • Loading branch information
twhiston committed Mar 6, 2018
2 parents d1946fd + 59a0b74 commit 7bb044f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
4 changes: 2 additions & 2 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ machine:
dependencies:
pre:
- sudo rm -rf /usr/local/go
- sudo curl -L https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz > /tmp/go.tar.gz
- sudo curl -L https://storage.googleapis.com/golang/go1.10.linux-amd64.tar.gz > /tmp/go.tar.gz
- sudo tar -C /usr/local -xzf /tmp/go.tar.gz
- git submodule update --init --recursive
- npm i -g less pug-cli
Expand All @@ -21,7 +21,7 @@ dependencies:

test:
pre:
- cd $CPATH && go run cli/main.go --migrate
- cd $CPATH && go run cli/main.go --migrate -config config.json

override:
- cd $CPATH && go vet ./...
Expand Down
1 change: 1 addition & 0 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
)

func main() {
util.ConfigInit()
if util.InteractiveSetup {
os.Exit(doSetup())
}
Expand Down
2 changes: 1 addition & 1 deletion make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ HEREDOC
github-release release --draft -u ansible-semaphore -r semaphore -t "v$VERSION" -d "## Special thanks to\n\n## Installation\n\nFollow [wiki/Installation](https://github.com/ansible-semaphore/semaphore/wiki/Installation)\n\n## Changelog"
fi

go-bindata $BINDATA_ARGS config.json db/migrations/ $(find public/* -type d -print)
go-bindata $BINDATA_ARGS db/migrations/ $(find public/* -type d -print)

if [ "$1" == "ci_test" ]; then
exit 0
Expand Down
22 changes: 9 additions & 13 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,20 +81,24 @@ func NewConfig() *configType {
return &configType{}
}

func init() {
func ConfigInit() {
flag.BoolVar(&InteractiveSetup, "setup", false, "perform interactive setup")
flag.BoolVar(&Migration, "migrate", false, "execute migrations")
flag.BoolVar(&Upgrade, "upgrade", false, "upgrade semaphore")
path := flag.String("config", "", "config path")

var pwd string
flag.StringVar(&pwd, "hash", "", "generate hash of given password")
var unhashedPwd string
flag.StringVar(&unhashedPwd, "hash", "", "generate hash of given password")

var printConfig bool
flag.BoolVar(&printConfig, "printConfig", false, "print example configuration")

flag.Parse()

if InteractiveSetup {
return
}

if printConfig {
cfg := &configType{
MySQL: mySQLConfig{
Expand All @@ -113,8 +117,8 @@ func init() {
os.Exit(0)
}

if len(pwd) > 0 {
password, _ := bcrypt.GenerateFromPassword([]byte(pwd), 11)
if len(unhashedPwd) > 0 {
password, _ := bcrypt.GenerateFromPassword([]byte(unhashedPwd), 11)
fmt.Println("Generated password: ", string(password))

os.Exit(0)
Expand All @@ -132,16 +136,8 @@ func init() {
panic(err)
}
} else {
configFile, err := Asset("config.json")
if err != nil {
fmt.Println("Cannot Find configuration! Use -c parameter to point to a JSON file generated by -setup.\n\n Hint: have you run `-setup` ?")
os.Exit(1)
}

if err := json.Unmarshal(configFile, &Config); err != nil {
fmt.Println("Could not decode configuration!")
panic(err)
}
}

if len(os.Getenv("PORT")) > 0 {
Expand Down

0 comments on commit 7bb044f

Please sign in to comment.