valid

package
v0.27.3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package valid contains the structs representing the atlantis.yaml config after it's been parsed and validated.

Package valid contains definitions of valid yaml configuration after its been parsed and validated.

Index

Constants

View Source
const (
	LocalPolicySet  string = "local"
	GithubPolicySet string = "github"
)
View Source
const (
	PostProcessRunOutputShow            = "show"
	PostProcessRunOutputHide            = "hide"
	PostProcessRunOutputStripRefreshing = "strip_refreshing"
)
View Source
const AllowCustomWorkflowsKey = "allow_custom_workflows"
View Source
const AllowedOverridesKey = "allowed_overrides"
View Source
const ApplyRequirementsKey = "apply_requirements"
View Source
const ApprovedCommandReq = "approved"
View Source
const AutoDiscoverKey = "autodiscover"
View Source
const CustomPolicyCheckKey = "custom_policy_check"
View Source
const DefaultAtlantisFile = "atlantis.yaml"

DefaultAtlantisFile is the default name of the config file for each repo.

View Source
const DefaultAutoPlanEnabled = true
View Source
const DefaultWorkflowName = "default"
View Source
const DeleteSourceBranchOnMergeKey = "delete_source_branch_on_merge"
View Source
const ImportRequirementsKey = "import_requirements"
View Source
const MergeableCommandReq = "mergeable"
View Source
const PlanRequirementsKey = "plan_requirements"
View Source
const PoliciesPassedCommandReq = "policies_passed"
View Source
const PolicyCheckKey = "policy_check"
View Source
const RepoLockingKey = "repo_locking"
View Source
const UnDivergedCommandReq = "undiverged"
View Source
const WorkflowKey = "workflow"

Variables

View Source
var DefaultApplyStage = Stage{
	Steps: []Step{
		{
			StepName: "apply",
		},
	},
}

DefaultApplyStage is the Atlantis default apply stage.

View Source
var DefaultImportStage = Stage{
	Steps: []Step{
		{
			StepName: "init",
		},
		{
			StepName: "import",
		},
	},
}

DefaultImportStage is the Atlantis default import stage.

View Source
var DefaultPlanStage = Stage{
	Steps: []Step{
		{
			StepName: "init",
		},
		{
			StepName: "plan",
		},
	},
}

DefaultPlanStage is the Atlantis default plan stage.

View Source
var DefaultPolicyCheckStage = Stage{
	Steps: []Step{
		{
			StepName: "show",
		},
		{
			StepName: "policy_check",
		},
	},
}

DefaultPolicyCheckStage is the Atlantis default policy check stage.

View Source
var DefaultStateRmStage = Stage{
	Steps: []Step{
		{
			StepName: "init",
		},
		{
			StepName: "state_rm",
		},
	},
}

DefaultStateRmStage is the Atlantis default state_rm stage.

View Source
var NonOverrideableApplyReqs = []string{PoliciesPassedCommandReq}

NonOverrideableApplyReqs will get applied across all "repos" in the server side config. If repo config is allowed overrides, they can override this. TODO: Make this more customizable, not everyone wants this rigid workflow maybe something along the lines of defining overridable/non-overrideable apply requirements in the config and removing the flag to enable policy checking.

Functions

This section is empty.

Types

type AutoDiscover added in v0.27.0

type AutoDiscover struct {
	Mode AutoDiscoverMode
}

type AutoDiscoverMode added in v0.27.0

type AutoDiscoverMode string

AutoDiscoverMode enum

const (
	AutoDiscoverEnabledMode  AutoDiscoverMode = "enabled"
	AutoDiscoverDisabledMode AutoDiscoverMode = "disabled"
	AutoDiscoverAutoMode     AutoDiscoverMode = "auto"
)

type Autoplan

type Autoplan struct {
	WhenModified []string
	Enabled      bool
}

type GlobalCfg

type GlobalCfg struct {
	Repos      []Repo
	Workflows  map[string]Workflow
	PolicySets PolicySets
	Metrics    Metrics
}

GlobalCfg is the final parsed version of server-side repo config.

func NewGlobalCfgFromArgs

func NewGlobalCfgFromArgs(args GlobalCfgArgs) GlobalCfg

func (GlobalCfg) DefaultProjCfg

func (g GlobalCfg) DefaultProjCfg(log logging.SimpleLogging, repoID string, repoRelDir string, workspace string) MergedProjectCfg

DefaultProjCfg returns the default project config for all projects under the repo with id repoID. It is used when there is no repo config.

func (GlobalCfg) MatchingRepo

func (g GlobalCfg) MatchingRepo(repoID string) *Repo

MatchingRepo returns an instance of Repo which matches a given repoID. If multiple repos match, return the last one for consistency with getMatchingCfg.

func (GlobalCfg) MergeProjectCfg

func (g GlobalCfg) MergeProjectCfg(log logging.SimpleLogging, repoID string, proj Project, rCfg RepoCfg) MergedProjectCfg

MergeProjectCfg merges proj and rCfg with the global config to return a final config. It assumes that all configs have been validated.

func (GlobalCfg) RepoAutoDiscoverCfg added in v0.27.0

func (g GlobalCfg) RepoAutoDiscoverCfg(repoID string) *AutoDiscover

RepoAutoDiscoverCfg returns the AutoDiscover config from the global config for the repo with id repoID. If no matching repo is found or there is no AutoDiscover config then this function returns nil.

func (GlobalCfg) RepoConfigFile added in v0.22.0

func (g GlobalCfg) RepoConfigFile(repoID string) string

RepoConfigFile returns a repository specific file path If not defined, return atlantis.yaml as default

func (GlobalCfg) ValidateRepoCfg

func (g GlobalCfg) ValidateRepoCfg(rCfg RepoCfg, repoID string) error

ValidateRepoCfg validates that rCfg for repo with id repoID is valid based on our global config.

type GlobalCfgArgs

type GlobalCfgArgs struct {
	RepoConfigFile string
	// No longer a user option as of https://github.com/runatlantis/atlantis/pull/3911,
	// but useful for tests to set to true to not require enumeration of allowed settings
	// on the repo side
	AllowAllRepoSettings bool
	MergeableReq         bool
	ApprovedReq          bool
	UnDivergedReq        bool
	PolicyCheckEnabled   bool
	PreWorkflowHooks     []*WorkflowHook
	PostWorkflowHooks    []*WorkflowHook
}

type MergedProjectCfg

type MergedProjectCfg struct {
	PlanRequirements          []string
	ApplyRequirements         []string
	ImportRequirements        []string
	Workflow                  Workflow
	AllowedWorkflows          []string
	DependsOn                 []string
	RepoRelDir                string
	Workspace                 string
	Name                      string
	AutoplanEnabled           bool
	AutoMergeDisabled         bool
	TerraformVersion          *version.Version
	RepoCfgVersion            int
	PolicySets                PolicySets
	DeleteSourceBranchOnMerge bool
	ExecutionOrderGroup       int
	RepoLocking               bool
	PolicyCheck               bool
	CustomPolicyCheck         bool
}

type Metrics added in v0.19.3

type Metrics struct {
	Statsd     *Statsd
	Prometheus *Prometheus
}

type PolicyOwners

type PolicyOwners struct {
	Users []string
	Teams []string
}

func (*PolicyOwners) IsOwner added in v0.24.0

func (o *PolicyOwners) IsOwner(username string, userTeams []string) bool

type PolicySet

type PolicySet struct {
	Source       string
	Path         string
	Name         string
	ApproveCount int
	Owners       PolicyOwners
}

type PolicySets

type PolicySets struct {
	Version      *version.Version
	Owners       PolicyOwners
	ApproveCount int
	PolicySets   []PolicySet
}

PolicySets defines version of policy checker binary(conftest) and a list of PolicySet objects. PolicySets struct is used by PolicyCheck workflow to build context to enforce policies.

func (*PolicySets) HasPolicies

func (p *PolicySets) HasPolicies() bool

func (*PolicySets) HasTeamOwners added in v0.22.3

func (p *PolicySets) HasTeamOwners() bool

Check if any level of policy owners includes teams

type PostProcessRunOutputOption added in v0.24.4

type PostProcessRunOutputOption string

PostProcessRunOutputOption is an enum of options for post-processing RunCommand output

type Project

type Project struct {
	Dir                       string
	BranchRegex               *regexp.Regexp
	Workspace                 string
	Name                      *string
	WorkflowName              *string
	TerraformVersion          *version.Version
	Autoplan                  Autoplan
	PlanRequirements          []string
	ApplyRequirements         []string
	ImportRequirements        []string
	DependsOn                 []string
	DeleteSourceBranchOnMerge *bool
	RepoLocking               *bool
	ExecutionOrderGroup       int
	PolicyCheck               *bool
	CustomPolicyCheck         *bool
}

func (Project) GetName

func (p Project) GetName() string

GetName returns the name of the project or an empty string if there is no project name.

type Prometheus added in v0.19.5

type Prometheus struct {
	Endpoint string
}

type Repo

type Repo struct {
	// ID is the exact match id of this config.
	// If IDRegex is set then this will be empty.
	ID string
	// IDRegex is the regex match for this config.
	// If ID is set then this will be nil.
	IDRegex                   *regexp.Regexp
	BranchRegex               *regexp.Regexp
	RepoConfigFile            string
	PlanRequirements          []string
	ApplyRequirements         []string
	ImportRequirements        []string
	PreWorkflowHooks          []*WorkflowHook
	Workflow                  *Workflow
	PostWorkflowHooks         []*WorkflowHook
	AllowedWorkflows          []string
	AllowedOverrides          []string
	AllowCustomWorkflows      *bool
	DeleteSourceBranchOnMerge *bool
	RepoLocking               *bool
	PolicyCheck               *bool
	CustomPolicyCheck         *bool
	AutoDiscover              *AutoDiscover
}

Repo is the final parsed version of server-side repo config.

func (Repo) BranchMatches

func (r Repo) BranchMatches(other string) bool

BranchMatches returns true if the branch other matches a branch regex (if preset).

func (Repo) IDMatches

func (r Repo) IDMatches(otherID string) bool

IDMatches returns true if the repo ID otherID matches this config.

func (Repo) IDString

func (r Repo) IDString() string

IDString returns a string representation of this config.

type RepoCfg

type RepoCfg struct {
	// Version is the version of the atlantis YAML file.
	Version                    int
	Projects                   []Project
	Workflows                  map[string]Workflow
	PolicySets                 PolicySets
	Automerge                  *bool
	AutoDiscover               *AutoDiscover
	ParallelApply              *bool
	ParallelPlan               *bool
	ParallelPolicyCheck        *bool
	DeleteSourceBranchOnMerge  *bool
	RepoLocking                *bool
	CustomPolicyCheck          *bool
	EmojiReaction              string
	AllowedRegexpPrefixes      []string
	AbortOnExcecutionOrderFail bool
}

RepoCfg is the atlantis.yaml config after it's been parsed and validated.

func (RepoCfg) AutoDiscoverEnabled added in v0.27.0

func (r RepoCfg) AutoDiscoverEnabled(defaultAutoDiscoverMode AutoDiscoverMode) bool

This function returns a final true/false decision for whether AutoDiscover is enabled for a repo. It takes into account the defaultAutoDiscoverMode when there is no explicit repo config. The defaultAutoDiscoverMode param should be understood as the default AutoDiscover mode as may be set via CLI params or server side repo config.

func (RepoCfg) FindProjectByName

func (r RepoCfg) FindProjectByName(name string) *Project

func (RepoCfg) FindProjectsByDir

func (r RepoCfg) FindProjectsByDir(dir string) []Project

FindProjectsByDir returns all projects that are in dir.

func (RepoCfg) FindProjectsByDirWorkspace

func (r RepoCfg) FindProjectsByDirWorkspace(repoRelDir string, workspace string) []Project

func (RepoCfg) FindProjectsByName

func (r RepoCfg) FindProjectsByName(name string) []Project

FindProjectsByName returns all projects that match with name.

func (RepoCfg) ValidateWorkspaceAllowed

func (r RepoCfg) ValidateWorkspaceAllowed(repoRelDir string, workspace string) error

validateWorkspaceAllowed returns an error if repoCfg defines projects in repoRelDir but none of them use workspace. We want this to be an error because if users have gone to the trouble of defining projects in repoRelDir then it's likely that if we're running a command for a workspace that isn't defined then they probably just typed the workspace name wrong.

type Stage

type Stage struct {
	Steps []Step
}

type Statsd added in v0.19.3

type Statsd struct {
	Port string
	Host string
}

type Step

type Step struct {
	StepName  string
	ExtraArgs []string
	// RunCommand is either a custom run step or the command to run
	// during an env step to populate the environment variable dynamically.
	RunCommand string
	// Output is option for post-processing a RunCommand output
	Output PostProcessRunOutputOption
	// EnvVarName is the name of the
	// environment variable that should be set by this step.
	EnvVarName string
	// EnvVarValue is the value to set EnvVarName to.
	EnvVarValue string
}

type Workflow

type Workflow struct {
	Name        string
	Apply       Stage
	Plan        Stage
	PolicyCheck Stage
	Import      Stage
	StateRm     Stage
}

type WorkflowHook

type WorkflowHook struct {
	StepName        string
	RunCommand      string
	StepDescription string
	Shell           string
	ShellArgs       string
	Commands        string
}

WorkflowHook is a map of custom run commands to run before or after workflows.

Jump to

Keyboard shortcuts

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