Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AddAliasCmd = &cobra.Command{ Use: "add-alias NAME VERSION [ORG]", Short: "Add Alias", Long: `Add an alias to a project`, Args: cobra.MinimumNArgs(2), Run: func(cmd *cobra.Command, args []string) { options := ionic.AddAliasOptions{ Name: args[0], ProjectID: projectID, TeamID: teamID, Version: args[1], } if len(args) == 3 { options.Org = args[2] } p, e := ion.AddAlias(options, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(p) }, }
AddAliasCmd - Container for holder add alias cmd
var AnalysisCmd = &cobra.Command{
Use: "analysis",
Short: "Analysis resource",
Long: `Analysis resource - access data relating to analyses and their associations`,
}
AnalysisCmd - Container for holding project root and secondary commands
var AnalyzeProjectCmd = &cobra.Command{ Use: "analyze-project [flags]", Short: "Requests an analysis on a project", Long: `Requests an analysis on a project with the analysis/status id in the response`, Run: func(cmd *cobra.Command, args []string) { a, e := ion.AnalyzeProject(projectID, teamID, branch, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(a) }, }
AnalyzeProjectCmd - requests an analysis on a project
var CommunityCmd = &cobra.Command{
Use: "community",
Short: "Community resource",
Long: `Community resource - access data relating to communities, repositories and their associations`,
}
CommunityCmd - Container for holding com root and secondary commands
var CreateDestinationCmd = &cobra.Command{ Use: "create-destination [flags] PATHTOJSON", Short: "Create Destination", Long: `Create destination from a Ion Channel JSON input file`, Args: func(cmd *cobra.Command, args []string) error { if skel { return nil } if len(args) != 1 { return fmt.Errorf("accepts 1 arg(s), received 0") } return nil }, Run: func(cmd *cobra.Command, args []string) { if skel { fmt.Println("{") fmt.Println(" \"team_id\":\"\",") fmt.Println(" \"location\":\"\",") fmt.Println(" \"region\":\"\",") fmt.Println(" \"name\":\"\",") fmt.Println(" \"type\":\"\",") fmt.Println(" \"access_key\":\"\",") fmt.Println(" \"secret_key\":\"\"") fmt.Println("}") return } filename := args[0] f, err := ioutil.ReadFile(filename) if err != nil { fmt.Println(err.Error()) return } var data deliveries.CreateDestination err = json.Unmarshal(f, &data) if err != nil { fmt.Println(err.Error()) return } r, err := ion.CreateDeliveryDestinations(&data, viper.GetString(secretKey)) if err != nil { fmt.Println(err.Error()) return } PPrint(r) }, }
CreateDestinationCmd - Container for holding create destination root and secondary commands
var CreateProjectCmd = &cobra.Command{ Use: "create-project [flags] PATHTOJSON", Short: "Create Project", Long: `Create project from a Ion Channel JSON input file`, Args: func(cmd *cobra.Command, args []string) error { if skel { return nil } if len(args) != 1 { return fmt.Errorf("accepts 1 arg(s), received 0") } return nil }, Run: func(cmd *cobra.Command, args []string) { if skel { fmt.Println("{") fmt.Println(" \"team_id\":\"\",") fmt.Println(" \"ruleset_id\":\"\",") fmt.Println(" \"name\":\"\",") fmt.Println(" \"type\":\"\",") fmt.Println(" \"source\":\"\",") fmt.Println(" \"description\":\"\",") fmt.Println(" \"username\":\"\",") fmt.Println(" \"password\":\"\"") fmt.Println("}") return } filename := args[0] f, err := ioutil.ReadFile(filename) if err != nil { fmt.Println(err.Error()) return } var data projects.Project err = json.Unmarshal(f, &data) if err != nil { fmt.Println(err.Error()) return } errs, err := data.Validate(cc) if err != nil { for name, e := range errs { fmt.Printf("%v : %v\n", name, e) } fmt.Println(err.Error()) return } data.Active = true r, err := ion.CreateProject(&data, teamID, viper.GetString(secretKey)) if err != nil { fmt.Println(err.Error()) return } PPrint(r) }, }
CreateProjectCmd - Container for holding create project root and secondary commands
var CreateProjectsCSVCmd = &cobra.Command{ Use: "create-projects-csv [flags] PATHTOCSV", Short: "Create Projects", Long: `Create projects from a Ion Channel CSV input file`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { csv := args[0] ps, e := ion.CreateProjectsFromCSV(csv, teamID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(ps) }, }
CreateProjectsCSVCmd - Container for holding project root and secondary commands
var CreateProjectsSPDXCmd = &cobra.Command{ Use: "create-projects-spdx [flags] PATHTOSPDX", Short: "Create Projects SPDX", Long: `Create projects from an spdx file`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { var err error spdxFilePath := args[0] spdxFile, err := os.Open(spdxFilePath) if err != nil { fmt.Printf("Error while opening %v for reading: %v\n", spdxFilePath, err) return } defer spdxFile.Close() if len(args) > 1 { spdxVersion = args[1] } var spdxDoc interface{} // store doc as version-agnostic interface switch spdxVersion { case "2.1": spdxDoc, err = tvloader.Load2_1(spdxFile) if err != nil { fmt.Printf("Could not load %s. Error from SPDX library: %s\n", spdxFilePath, err.Error()) printSPDXErrorHelp(err) return } case "2.2": spdxDoc, err = tvloader.Load2_2(spdxFile) if err != nil { fmt.Printf("Could not load %s. Error from SPDX library: %s\n", spdxFilePath, err.Error()) printSPDXErrorHelp(err) return } default: fmt.Printf("Invalid SPDX specification version: %s\n", spdxVersion) return } newProjects, err := spdx.ProjectsFromSPDX(spdxDoc, includeDependencies) if err != nil { fmt.Printf("Failed to convert SPDX packages to projects: %s\n", err.Error()) } numProjects := len(newProjects) if numProjects == 0 { printSPDXErrorHelp(fmt.Errorf("no packages found in SPDX file")) return } fmt.Printf("Found %d projects in SBOM.\n", numProjects) // compare new projects to existing projects to exclude duplicates var projectsToCreate []projects.Project existingProjects, err := ion.GetProjects(projects.Filter{TeamID: &teamID}, viper.GetString(secretKey), pagination.AllItems) if err != nil { fmt.Printf("Failed to retrieve team's existing projects to check for duplicates: %s\n", err.Error()) projectsToCreate = newProjects } else { existingProjectNames := make(map[string]bool) for _, existingProject := range existingProjects { if existingProject.Name != nil { existingProjectNames[*existingProject.Name] = true } } numDuplicates := 0 for _, newProject := range newProjects { projectAlreadyExists := existingProjectNames[*newProject.Name] if !projectAlreadyExists { projectsToCreate = append(projectsToCreate, newProject) } else { numDuplicates++ } } if numDuplicates > 0 { numProjects = numProjects - numDuplicates fmt.Printf("Ignoring %d projects that already exist.\n", numDuplicates) } } fmt.Printf("Importing %d projects...\n", numProjects) successes := 0 projectsErrored := make(map[string]string) for ii := range projectsToCreate { projectsToCreate[ii].RulesetID = &rulesetID projectsToCreate[ii].TeamID = &teamID if pocName != "" { projectsToCreate[ii].POCName = pocName } if pocEmail != "" { projectsToCreate[ii].POCEmail = pocEmail } errs, err := projectsToCreate[ii].Validate(cc) if err != nil { fmt.Printf("[%d/%d]\tProject %s doesn't meet Ion requirements: %s. Details: \n", ii+1, numProjects, *(projectsToCreate[ii].Name), err.Error()) errorStored := "" for name, e := range errs { fmt.Printf("%s : %s\n", name, e) errorStored += fmt.Sprintf("%s : %s\n", name, e) } projectsErrored[*(projectsToCreate[ii].Name)] = errorStored continue } fmt.Printf("[%d/%d]\tCreating project: %s\n", ii+1, numProjects, *projectsToCreate[ii].Name) _, err = ion.CreateProject(&projectsToCreate[ii], teamID, viper.GetString(secretKey)) if err != nil { fmt.Printf("\tError: %s\n", err.Error()) projectsErrored[*(projectsToCreate[ii].Name)] = err.Error() continue } successes++ } fmt.Printf("Successfully created %d/%d projects.\n", successes, numProjects) numErrors := len(projectsErrored) if numErrors > 0 { fmt.Printf("%d errors:\n", numErrors) for k, v := range projectsErrored { fmt.Printf("%v: %v\n", k, v) } } }, }
CreateProjectsSPDXCmd - Attempts to create a project from an SPDX V2.1 or V2.2 file
var DeleteDestinationCmd = &cobra.Command{ Use: "delete-destination", Short: "Delete Delivery Destination", Long: `Delete a single delivery destination`, Run: func(cmd *cobra.Command, args []string) { e := ion.DeleteDeliveryDestination(deliveryID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) return } PPrint("delivery marked as deleted") }, }
DeleteDestinationCmd - Container for holding delete destination root and secondary commands
var DeliveryCmd = &cobra.Command{
Use: "delivery",
Short: "Delivery resource",
Long: `Delivery resource - access data relating to deliveries and their associations`,
}
DeliveryCmd - Container for holding delivery root and secondary commands
var DependencyCmd = &cobra.Command{
Use: "dependency",
Short: "Dependency resource",
Long: `Dependency resource - access data relating to dependencies and their associations`,
}
DependencyCmd - Container for holding dep root and secondary commands
var GetAnalysisCmd = &cobra.Command{ Use: "get-analysis [flags] ANALYSISID", Short: "Get Analysis", Long: `Get the data for an analysis`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { id := args[0] a, e := ion.GetAnalysis(id, teamID, projectID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(a) }, }
GetAnalysisCmd - Container for holding project root and secondary commands
var GetAnalysisReportCmd = &cobra.Command{ Use: "get-analysis [flags] ANALYSISID", Short: "Get Analysis", Long: `Get the data for an analysis`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { id := args[0] a, e := ion.GetAnalysisReport(id, teamID, projectID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(a) }, }
GetAnalysisReportCmd - Container for holding project root and secondary commands
var GetAnalysisStatusCmd = &cobra.Command{ Use: "get-analysis-status [flags] ANALYSISID", Short: "Get Scanner", Long: `Get the data for a project`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { id := args[0] a, e := ion.GetAnalysisStatus(id, teamID, projectID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(a) }, }
GetAnalysisStatusCmd - Container for holding project root and secondary commands
var GetDestinationsCmd = &cobra.Command{ Use: "get-destinations", Short: "Get Delivery Destinations", Long: `Get the data for destintations in a team`, Run: func(cmd *cobra.Command, args []string) { ps, e := ion.GetDeliveryDestinations(teamID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(ps) }, }
GetDestinationsCmd - Container for holding destinations root and secondary commands
var GetExportData = &cobra.Command{ Use: "export-data [flags] PATHTOJSON", Short: "Export Data", Long: `Export Data - requires team id and project id(s) from a json file`, Args: func(cmd *cobra.Command, args []string) error { if skel { return nil } if len(args) != 1 { return fmt.Errorf("accepts 1 arg(s), received 0") } return nil }, Run: func(cmd *cobra.Command, args []string) { if skel { fmt.Println("{") fmt.Println(" \"team_id\":\"\",") fmt.Println(" \"ids\": [") fmt.Println(" \"project_id\",") fmt.Println(" \"2nd project_id\",") fmt.Println(" \"...\",") fmt.Println(" \"last project_id\"") fmt.Println(" ]") fmt.Println("}") return } filename := args[0] f, err := ioutil.ReadFile(filename) if err != nil { fmt.Println(err.Error()) return } var data requests.ByIDsAndTeamID err = json.Unmarshal(f, &data) if err != nil { fmt.Println(err.Error()) return } if data.TeamID == "" { fmt.Println("team_id is required") return } if len(data.IDs) == 0 { fmt.Println("one or more project ids are required in ids json filed") return } r, err := ion.GetExportedProjectsData(data.IDs, data.TeamID, viper.GetString(secretKey)) if err != nil { fmt.Println(err.Error()) return } PPrint(r) }, }
GetExportData - Container for holding get exported data root and secondary commands
var GetLatestAnalysisCmd = &cobra.Command{ Use: "get-latest-analysis [flags]", Short: "Get Latest Analysis", Long: `Get the data for a latest analysis`, Run: func(cmd *cobra.Command, args []string) { a, e := ion.GetLatestAnalysis(teamID, projectID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(a) }, }
GetLatestAnalysisCmd - Container for holding project root and secondary commands
var GetProjectCmd = &cobra.Command{ Use: "get-project", Short: "Get Project", Long: `Get the data for a project`, Run: func(cmd *cobra.Command, args []string) { p, e := ion.GetProject(projectID, teamID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(p) }, }
GetProjectCmd - Container for holding project root and secondary commands
var GetProjectsCmd = &cobra.Command{ Use: "get-projects", Short: "Get Projects", Long: `Get the data for a projects in a team`, Run: func(cmd *cobra.Command, args []string) { page := pagination.New(offset, limit) ps, e := ion.GetProjects(projects.Filter{TeamID: &teamID}, viper.GetString(secretKey), page) if e != nil { fmt.Println(e.Error()) } PPrint(ps) }, }
GetProjectsCmd - Container for holding project root and secondary commands
var GetRepoCmd = &cobra.Command{ Use: "get-repo NAME", Short: "Get a repository", Long: `Get the data for repository in a community`, Args: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { return errors.New("name is a required argument") } name = args[0] return nil }, Run: func(cmd *cobra.Command, args []string) { r, e := ion.GetRepo(name, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(r) }, }
GetRepoCmd - Container for holding get repo command
var GetReposForActorCmd = &cobra.Command{ Use: "get-repos-for-actor NAME", Short: "Get repos for a community actor", Long: `Get the data for repositories connected to an actor in a community`, Args: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { return errors.New("name is a required argument") } name = args[0] return nil }, Run: func(cmd *cobra.Command, args []string) { ps, e := ion.GetReposForActor(name, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(ps) }, }
GetReposForActorCmd - Container for holding get repos for actor command
var GetReposInCommonCmd = &cobra.Command{ Use: "get-repos-in-common SUBJECT", Short: "Get repos in common data", Long: `Get the data for repositories connected to another repository through actors in a community`, Args: func(cmd *cobra.Command, args []string) error { if len(args) != 1 { return errors.New("subject is a required argument") } name = args[0] return nil }, Run: func(cmd *cobra.Command, args []string) { options := ionic.GetReposInCommonOptions{ Subject: name, Comparand: comparand, ByActor: byactor, } ps, e := ion.GetReposInCommon(options, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(ps) }, }
GetReposInCommonCmd - Container for holding get repos in common command
var GetVersionsCmd = &cobra.Command{ Use: "get-versions [flags] NAME", Short: "Resolves versions for a dependency", Long: `Get a list of versions for a dependency`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { dep := args[0] vs, e := ion.GetVersionsForDependency(dep, tipe, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(vs) }, }
GetVersionsCmd - Resolves versions for a dependency
var GetVulnerabilitiesCmd = &cobra.Command{ Use: "get-vulnerabilities [flags] NAME [VERSION]", Short: "Resolves vulnerabilities for a product", Long: `Get a list of vulnerabilities for a product`, Args: func(cmd *cobra.Command, args []string) error { if len(args) < 1 { return fmt.Errorf("name is required") } name = args[0] if len(args) > 1 { version = args[1] } return nil }, Run: func(cmd *cobra.Command, args []string) { vs, e := ion.GetVulnerabilities(name, version, viper.GetString(secretKey), pagination.AllItems) if e != nil { fmt.Println(e.Error()) } PPrint(vs) }, }
GetVulnerabilitiesCmd - Resolves vulnerabilities for a name version pair
var ProjectCmd = &cobra.Command{
Use: "project",
Short: "Project resource",
Long: `Project resource - access data relating to projects and their associations`,
}
ProjectCmd - Container for holding project root and secondary commands
var ReportCmd = &cobra.Command{
Use: "report",
Short: "Report resource",
Long: `Report resource - access data relating to analyses, evaluations and their associations`,
}
ReportCmd - Container for holding project root and secondary commands
var ResolveDependecyFileCmd = &cobra.Command{ Use: "resolve-dependencies-in-file [flags] PATHTODEPFILE", Short: "Resolve Dependencies in a file", Long: `Get the data for a dependency file`, Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { dep := args[0] o := dependencies.DependencyResolutionRequest{ File: dep, Flatten: flatten, Ecosystem: tipe, } deps, e := ion.ResolveDependenciesInFile(o, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(deps) }, }
ResolveDependecyFileCmd - Resolves dependencies in a file
var RootCmd = &cobra.Command{ Use: "ion-connect", Short: "Provides a micro level interface for performing supply chain analysis of a project", Long: `ion-connect is a CLI tool that allows for rich interaction with the Ion Channel API to perform supply chain analysis for a project. `, PersistentPreRun: func(cmd *cobra.Command, args []string) { viper.SetConfigType("yaml") viper.SetConfigName("credentials") dirname, err := os.UserHomeDir() if err != nil { fmt.Printf("Failed to locate home directory: %v", err.Error()) return } if cfgFile != "" { viper.AddConfigPath(cfgFile) } viper.AddConfigPath(strings.Replace(configPath, "$HOME", dirname, -1)) if !strings.Contains(cmd.CommandPath(), "configure") { initConfig() } }, }
RootCmd represents the base command when called without any subcommands
var ScannerCmd = &cobra.Command{
Use: "scanner",
Short: "Scanner resource",
Long: `Scanner resource - access data relating to the status of analyses and their associations`,
}
ScannerCmd - Container for holding project root and secondary commands
var SearchCmd = &cobra.Command{ Use: "search", Short: "For a query string provide a result set", Long: `For a queary string provide a resutl set comprised of known data about a software artifact`, Args: func(cmd *cobra.Command, args []string) error { if (*Resource)(&resource).Valid() { return nil } return fmt.Errorf("invalid resource type specified: %s", resource) }, Run: func(cmd *cobra.Command, args []string) { r, _, e := ion.GetSearch(query, resource, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(r) }, }
SearchCmd For a queary string provide a resutl set comprised of known data about a software artifact
var SetSourceCmd = &cobra.Command{ Use: "set-source LOCATION", Short: "Set source", Long: "Set the source for the project", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { Src := args[0] p, e := ion.GetProject(projectID, teamID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) return } p.Source = &Src p, e = ion.UpdateProject(p, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(p) }, }
SetSourceCmd - Set the source location of a project
var SetTypeCmd = &cobra.Command{ Use: "set-type TYPE [SOURCE] [BRANCH]", Short: "Set type", Long: "Set the type for the project", Args: cobra.MinimumNArgs(1), Run: func(cmd *cobra.Command, args []string) { Type := args[0] if Type != "source_unavailable" && len(source) == 0 { fmt.Println("Source location required") return } p, e := ion.GetProject(projectID, teamID, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) return } p.Type = &Type if *p.Type == "source_unavailable" { empty := "" p.Source = &empty } else if len(source) != 0 { p.Source = &source } if len(branch) != 0 { p.Branch = &branch } p, e = ion.UpdateProject(p, viper.GetString(secretKey)) if e != nil { fmt.Println(e.Error()) } PPrint(p) }, }
SetTypeCmd - set project source type (git, http, etc...)
var ( // Version of ion-connect. Version string )
var VulnerabilityCmd = &cobra.Command{
Use: "vulnerability",
Short: "Vulnerability resource",
Long: `Vulnerability resource - access data relating to vulnerabilities and their associations`,
}
VulnerabilityCmd - Container for holding v root and secondary commands
Functions ¶
Types ¶
type Resource ¶
type Resource string
Resource enum for defining resource types
const ( // Repo repository resource type Repo Resource = "repos" // Product product (cpe, software) resource type Product Resource = "products" // Package package (dependencies, libraries) resource type Package Resource = "packages" // Report (repo, products, packages) resource type Report Resource = "reports" )