config

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 28, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	SchemaVersion int      `koanf:"schema_version"`
	Project       Project  `koanf:"project"`
	Dispatch      Dispatch `koanf:"dispatch"`
	// contains filtered or unexported fields
}

Config is a struct representing the data from a well-defined config file

func MustNew

func MustNew() *Config

MustNew returns a Config object initialized with default values and panics if that is not possible

func New

func New() (*Config, error)

New returns a Config object initialized with default values

func (*Config) GetConfigPath

func (c *Config) GetConfigPath() string

GetConfigPath returns the absolute path of the last loaded HCL config. If LoadConfigFile() has not been called, it will return an empty string.

func (*Config) LoadCommandFlags

func (c *Config) LoadCommandFlags(flagSet *pflag.FlagSet, mapping map[string]string, clobberWithDefaults bool) error

LoadCommandFlags updates the running config with any command-line flags based on a mapping of flag names to config keys

Example mapping (flag name: config key):

mapping := map[string]string{
	`license`: `project.license`,
	`year`:    `project.copyright_year`,
}

Merge Behavior: If a configuration value already exists (e.g., from previously reading a .copywrite.hcl config file), those values will only be overwritten by default flag values if clobberWithDefaults is true. If it is false, only values from flags the user explicitly sets will be transferred to the configuration.

Default flag options will be always be loaded if no value was previously set in the running configuration.

func (*Config) LoadConfMap

func (c *Config) LoadConfMap(mp map[string]interface{}) error

LoadConfMap updates the running config with a key-value map, where keys are delimited configuration key references.

Example mapping:

map[string]interface{}{
	"schema_version":         2,
	"project.copyright_year": 2022,
	"project.license":        "MPL-2.0",
	"dispatch.ignored_repos": []string{"foo", "bar"},
}

func (*Config) LoadConfigFile

func (c *Config) LoadConfigFile(cfgPath string) error

LoadConfigFile takes a path to an HCL config file and merges it with the running config

Example HCL config:

schema_version = 1
project {
	copyright_year = 2022
	license        = "MPL-2.0"
}

func (*Config) Sprint

func (c *Config) Sprint() string

Sprint returns a textual version of the current running config. The string is newline-delimited and contains alphabetical key -> value pairs

type Dispatch

type Dispatch struct {
	// A unique identifier for the current batch of workflow runs
	BatchID string `koanf:"batch_id"`

	// The GitHub Branch to base workflow runs off of
	Branch string `koanf:"branch"`

	// The GitHub Organization who's repositories you want to audit
	GitHubOrgToAudit string `koanf:"github_org_to_audit"`

	// A list of repos that should be exempted from scans.
	// Repo names must be fully-qualified (i.e., include the org name), like so:
	// "hashicorp/copywrite"
	IgnoredRepos []string `koanf:"ignored_repos"`

	// Sleep time in seconds between polling operations
	Sleep int `koanf:"sleep"`

	// maxAttempts is the maximum number of times a worker will check if a
	// workflow is finished (sleeping between each attempt) before timing out
	MaxAttempts int `koanf:"max_attempts"`

	// The number of concurrent workers in the worker pool
	Workers int `koanf:"workers"`

	// The workflow file name to be used when triggering GitHub Actions jobs
	WorkflowFileName string `koanf:"workflow_file_name"`
}

Dispatch represents data needed by the `copywrite dispatch` command, and is used to control ignored repos, concurrency, and other information

type Project

type Project struct {
	CopyrightYear   int      `koanf:"copyright_year"`
	CopyrightHolder string   `koanf:"copyright_holder"`
	HeaderIgnore    []string `koanf:"header_ignore"`
	License         string   `koanf:"license"`

	// Upstream is optional and only used if a given repo pulls from another
	Upstream string `koanf:"upstream"`
}

Project represents data needed for copyright and licensing statements inside a specific project/repo

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL