mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-30 11:18:58 +00:00
* feat: --allow-command configuration restricts available atlantis commands * add version and approve_policies into allow commands defaults * allow-commands accept all keyword which allows all commands * remove redundant nest * more detail abount allow-commands all keyword * Update server/events/comment_parser.go
101 lines
2.2 KiB
Go
101 lines
2.2 KiB
Go
package command
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"golang.org/x/text/cases"
|
|
"golang.org/x/text/language"
|
|
)
|
|
|
|
// Name is which command to run.
|
|
type Name int
|
|
|
|
const (
|
|
// Apply is a command to run terraform apply.
|
|
Apply Name = iota
|
|
// Plan is a command to run terraform plan.
|
|
Plan
|
|
// Unlock is a command to discard previous plans as well as the atlantis locks.
|
|
Unlock
|
|
// PolicyCheck is a command to run conftest test.
|
|
PolicyCheck
|
|
// ApprovePolicies is a command to approve policies with owner check
|
|
ApprovePolicies
|
|
// Autoplan is a command to run terraform plan on PR open/update if autoplan is enabled
|
|
Autoplan
|
|
// Version is a command to run terraform version.
|
|
Version
|
|
// Import is a command to run terraform import
|
|
Import
|
|
// Adding more? Don't forget to update String() below
|
|
)
|
|
|
|
// AllCommentCommands are list of commands that can be run from a comment.
|
|
var AllCommentCommands = []Name{
|
|
Version,
|
|
Plan,
|
|
Apply,
|
|
Unlock,
|
|
ApprovePolicies,
|
|
Import,
|
|
}
|
|
|
|
// TitleString returns the string representation in title form.
|
|
// ie. policy_check becomes Policy Check
|
|
func (c Name) TitleString() string {
|
|
return cases.Title(language.English).String(strings.ReplaceAll(strings.ToLower(c.String()), "_", " "))
|
|
}
|
|
|
|
// String returns the string representation of c.
|
|
func (c Name) String() string {
|
|
switch c {
|
|
case Apply:
|
|
return "apply"
|
|
case Plan, Autoplan:
|
|
return "plan"
|
|
case Unlock:
|
|
return "unlock"
|
|
case PolicyCheck:
|
|
return "policy_check"
|
|
case ApprovePolicies:
|
|
return "approve_policies"
|
|
case Version:
|
|
return "version"
|
|
case Import:
|
|
return "import"
|
|
}
|
|
return ""
|
|
}
|
|
|
|
// DefaultUsage returns the command default usage
|
|
func (c Name) DefaultUsage() string {
|
|
switch c {
|
|
case Import:
|
|
return "import ADDRESS ID"
|
|
default:
|
|
return c.String()
|
|
}
|
|
}
|
|
|
|
// ParseCommandName parses raw name into a command name.
|
|
func ParseCommandName(name string) (Name, error) {
|
|
switch name {
|
|
case "apply":
|
|
return Apply, nil
|
|
case "plan":
|
|
return Plan, nil
|
|
case "unlock":
|
|
return Unlock, nil
|
|
case "policy_check":
|
|
return PolicyCheck, nil
|
|
case "approve_policies":
|
|
return ApprovePolicies, nil
|
|
case "version":
|
|
return Version, nil
|
|
case "import":
|
|
return Import, nil
|
|
}
|
|
return -1, fmt.Errorf("unknown command name: %s", name)
|
|
}
|