Skip to content

Commit

Permalink
feat(config): Read config file values
Browse files Browse the repository at this point in the history
  • Loading branch information
elldritch committed Jan 24, 2018
1 parent df2d7d8 commit 6010976
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
25 changes: 25 additions & 0 deletions .fossa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
cli:
api_key: some-key-here
# server: https://fossa.on-prem

analyze:
- name: fossa-cli
path: github.com/fossas/fossa-cli/cmd/fossa
type: gopackage
# - name: vendored-jquery
# path: vendor/jquery-stuff/bower.json
# type: bowerpackage

# These take a lot of inspiration from CircleCI
# build:
# working_directory: /fossa
# docker:
# - image: some-image-host/image-name
# auth:
# username: foo
# password: $BAR
# environment:
# key: value
# steps: |
# echo "test"
# ls
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ endif
.PHONY: default

default:
GOBIN=${GOBIN} go install ./cmd/fossa.go
GOBIN=${GOBIN} go install github.com/fossas/fossa-cli/cmd/fossa
62 changes: 62 additions & 0 deletions cmd/fossa/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"io/ioutil"
"os"

yaml "gopkg.in/yaml.v2"
)

type Config struct {
Cli struct {
APIKey string `yaml:"api_key"`
Server string
}
Analyze []struct {
Name string
Path string
Type string
}
Build struct {
WorkingDirectory string `yaml:"working_directory"`
Docker []struct {
Image string
Auth struct {
Username string
Password string
}
}
Environment map[string]string
Steps string
}
}

func ReadConfig() (*Config, error) {
_, err := os.Stat(".fossa.yml")
if err == nil {
return unmarshalConfig(".fossa.yml")
}

_, err = os.Stat(".fossa.yaml")
if err == nil {
return unmarshalConfig(".fossa.yaml")
}

return nil, nil
}

func unmarshalConfig(filename string) (*Config, error) {
var config Config

bytes, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}

err = yaml.Unmarshal(bytes, &config)
if err != nil {
return nil, err
}

return &config, nil
}
8 changes: 7 additions & 1 deletion cmd/fossa.go → cmd/fossa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func main() {
},
}

app.Before = BootstrapCmd
// app.Before = BootstrapCmd

app.Run(os.Args)
}
Expand Down Expand Up @@ -73,6 +73,12 @@ func MakeCmd(c *cli.Context) error {
// A successful build will set Module.Resolved to true
// An unsuccessful build will set Module.Error to a value
func BuildCmd(c *cli.Context) error {
config, err := ReadConfig()
if err != nil {
return err
}
log.Logger.Errorf("read config: %+v\n", config)

mod := build.Module{
Type: c.String("type"),
}
Expand Down

0 comments on commit 6010976

Please sign in to comment.