Skip to content

Commit

Permalink
switch back to using fetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
anuccio1 committed Mar 2, 2018
1 parent 4d9806c commit c3ccc74
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
2 changes: 2 additions & 0 deletions .fossa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ cli:
# # Defaults to https://app.fossa.io
# server: https://fossa.on-prem
# api_key: some-key-here
# # If you're uploading to an existing git project, or a custom project in FOSSA
# fetcher: custom
# # If `project` is unset infer from VCS.
# project: fossa-proj

Expand Down
8 changes: 5 additions & 3 deletions cmd/fossa/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ var mainLogger = logging.MustGetLogger("main")

const (
configUsage = "path to config file (default: .fossa.{yml,yaml})"
fetcherUsage = "type of fetcher to use for fossa. Default's to custom"
projectUsage = "the FOSSA project name (default: VCS remote 'origin')"
revisionUsage = "the FOSSA project's revision hash (default: VCS hash HEAD)"
endpointUsage = "the FOSSA server endpoint (default: https://app.fossa.io)"
buildForceUsage = "ignore cached build artifacts"
analyzeOutputUsage = "print results to stdout instead of uploading to FOSSA"
analyzeAllowResolvedUsage = "allow unresolved dependencies"
debugUsage = "print debug information to stderr"
managedBuildUsage = "upload results as a custom project to FOSSA"
)

func main() {
Expand All @@ -47,12 +47,12 @@ func main() {
cli.StringFlag{Name: "r, revision", Usage: revisionUsage},
cli.StringFlag{Name: "e, endpoint", Usage: endpointUsage},
cli.StringFlag{Name: "m, modules", Usage: "the modules to build and analyze"},
cli.StringFlag{Name: "fetcher", Usage: fetcherUsage},
cli.BoolFlag{Name: "o, output", Usage: analyzeOutputUsage},
cli.BoolFlag{Name: "allow-unresolved", Usage: analyzeAllowResolvedUsage},
cli.BoolFlag{Name: "b, build", Usage: "run a default build in module directories if they have not been pre-built"},
cli.BoolFlag{Name: "f, force", Usage: buildForceUsage},
cli.BoolFlag{Name: "debug", Usage: debugUsage},
cli.BoolFlag{Name: "custom-project", Usage: managedBuildUsage},
}

app.Commands = []cli.Command{
Expand Down Expand Up @@ -84,14 +84,14 @@ func main() {
Action: analyzeCmd,
Flags: []cli.Flag{
cli.StringFlag{Name: "c, config", Usage: configUsage},
cli.StringFlag{Name: "fetcher", Usage: fetcherUsage},
cli.StringFlag{Name: "p, project", Usage: projectUsage},
cli.StringFlag{Name: "r, revision", Usage: revisionUsage},
cli.StringFlag{Name: "e, endpoint", Usage: endpointUsage},
cli.StringFlag{Name: "m, modules", Usage: "the modules to analyze"},
cli.BoolFlag{Name: "o, output", Usage: analyzeOutputUsage},
cli.BoolFlag{Name: "allow-unresolved", Usage: analyzeAllowResolvedUsage},
cli.BoolFlag{Name: "debug", Usage: debugUsage},
cli.BoolFlag{Name: "custom-project", Usage: managedBuildUsage},
},
},
{
Expand All @@ -100,6 +100,7 @@ func main() {
Action: testCmd,
Flags: []cli.Flag{
cli.StringFlag{Name: "c, config", Usage: configUsage},
cli.StringFlag{Name: "fetcher", Usage: fetcherUsage},
cli.StringFlag{Name: "p, project", Usage: projectUsage},
cli.StringFlag{Name: "r, revision", Usage: revisionUsage},
cli.StringFlag{Name: "e, endpoint", Usage: endpointUsage},
Expand All @@ -113,6 +114,7 @@ func main() {
Action: uploadCmd,
Flags: []cli.Flag{
cli.StringFlag{Name: "c, config", Usage: configUsage},
cli.StringFlag{Name: "fetcher", Usage: fetcherUsage},
cli.StringFlag{Name: "p, project", Usage: projectUsage},
cli.StringFlag{Name: "r, revision", Usage: revisionUsage},
cli.StringFlag{Name: "e, endpoint", Usage: endpointUsage},
Expand Down
8 changes: 4 additions & 4 deletions cmd/fossa/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ func doUpload(conf config.CLIConfig, results []normalizedModule) (string, error)
analysisLogger.Fatal("Could not infer project name from either `.fossa.yml` or `git` remote named `origin`")
}

if conf.ExistingProject && conf.Revision == "" {
analysisLogger.Fatal("Could not infer revision name from `git` remote named `origin`. To submit a custom project, set existing_project to false in `.fossa.yml`")
if conf.Fetcher != "custom" && conf.Revision == "" {
analysisLogger.Fatal("Could not infer revision name from `git` remote named `origin`. To submit a custom project, set Fetcher to `custom` in `.fossa.yml`")
}

// Re-marshal into build data
Expand All @@ -135,7 +135,7 @@ func doUpload(conf config.CLIConfig, results []normalizedModule) (string, error)
analysisLogger.Debugf("Uploading build data from (%#v) modules: %#v", len(results), string(buildData))

fossaEndpoint := "/api/builds/custom?locator=" + url.QueryEscape(config.MakeLocator(conf.Fetcher, conf.Project, conf.Revision)) + "&v=" + version
if !conf.ExistingProject {
if conf.Fetcher == "custom" {
fossaEndpoint += "&managedBuild=true"
}

Expand All @@ -161,7 +161,7 @@ func doUpload(conf config.CLIConfig, results []normalizedModule) (string, error)
return "", fmt.Errorf("invalid API key (check the $FOSSA_API_KEY environment variable)")
} else if resp.StatusCode == http.StatusPreconditionRequired {
// TODO: handle "Managed Project" workflow
return "", fmt.Errorf("invalid project or revision; make sure this version is published and FOSSA has access to your repo. To submit a custom project, add the --custom-project flag")
return "", fmt.Errorf("invalid project or revision; make sure this version is published and FOSSA has access to your repo. To submit a custom project, set Fetcher to `custom` in `.fossa.yml`")
} else if resp.StatusCode != http.StatusOK {
return "", fmt.Errorf("bad server response (%#v)", responseStr)
}
Expand Down
36 changes: 17 additions & 19 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ type UploadConfig struct {

// CLIConfig specifies the config available to the cli
type CLIConfig struct {
APIKey string
Fetcher string
Project string
Revision string
Endpoint string
Modules []ModuleConfig
Debug bool
ExistingProject bool
APIKey string
Fetcher string
Project string
Revision string
Endpoint string
Modules []ModuleConfig
Debug bool

DefaultCmd DefaultConfig
AnalyzeCmd AnalyzeConfig
Expand Down Expand Up @@ -107,14 +106,14 @@ func New(c *cli.Context) (CLIConfig, error) {
}

var config = CLIConfig{
APIKey: c.String("api_key"),
Project: c.String("project"),
Revision: c.String("revision"),
Endpoint: c.String("endpoint"),
Modules: modules,
Debug: c.Bool("debug"),
ConfigFilePath: c.String("config"),
ExistingProject: c.Bool("existing_project"),
APIKey: c.String("api_key"),
Fetcher: c.String("fetcher"),
Project: c.String("project"),
Revision: c.String("revision"),
Endpoint: c.String("endpoint"),
Modules: modules,
Debug: c.Bool("debug"),
ConfigFilePath: c.String("config"),

DefaultCmd: DefaultConfig{
Build: c.Bool("build"),
Expand Down Expand Up @@ -152,9 +151,8 @@ func New(c *cli.Context) (CLIConfig, error) {
config.Revision = configFile.CLI.Revision
}

config.Fetcher = "custom"
if config.ExistingProject {
config.Fetcher = "git"
if config.Fetcher == "" {
config.Fetcher = configFile.CLI.Fetcher
}

if config.APIKey == "" {
Expand Down
23 changes: 14 additions & 9 deletions config/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ type configFileV1 struct {

type configFileCLIV1 struct {
// Upload configuration.
APIKey string `yaml:"api_key,omitempty"`
Server string `yaml:"server,omitempty"`
Project string `yaml:"project,omitempty"`
Revision string `yaml:"revision,omitempty"`
ExistingProject bool `yaml:"existing_project"` // project exists in FOSSA (defaults to false as managed build is default)
APIKey string `yaml:"api_key,omitempty"`
Server string `yaml:"server,omitempty"`
Project string `yaml:"project,omitempty"`
Revision string `yaml:"revision,omitempty"`
Fetcher string `yaml:"fetcher,omitempty"` // fetcher defaults to custom
}

type configFileAnalyzeV1 struct {
Expand Down Expand Up @@ -87,6 +87,11 @@ func setDefaultValues(c configFileV1) (configFileV1, error) {
c.CLI.APIKey = apiKey
}

// Default to custom.
if c.CLI.Fetcher == "" {
c.CLI.Fetcher = "custom"
}

// Infer default locator and project from `git`.
if c.CLI.Project == "" || c.CLI.Revision == "" {
// TODO: this needs to happen in the module directory, not the working
Expand Down Expand Up @@ -128,10 +133,10 @@ func WriteConfigFile(conf *CLIConfig) error {
writeConfig := configFileV1{
Version: 1,
CLI: configFileCLIV1{
APIKey: keyToWrite,
Server: conf.Endpoint,
Project: conf.Project,
ExistingProject: conf.ExistingProject,
APIKey: keyToWrite,
Server: conf.Endpoint,
Project: conf.Project,
Fetcher: conf.Fetcher,
},
Analyze: configFileAnalyzeV1{
Modules: conf.Modules,
Expand Down

0 comments on commit c3ccc74

Please sign in to comment.