-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(config): Read config file values
- Loading branch information
Showing
4 changed files
with
95 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters