diff --git a/.gitignore b/.gitignore index 9ef0a01..37148fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -policies.y*ml +policy.y*ml repositories.y*ml coverage.txt diff --git a/README.md b/README.md index d07a160..9d6bc5a 100644 --- a/README.md +++ b/README.md @@ -97,10 +97,10 @@ Simply download the zip for architecture and extract the exe. ## Configuring **credentials** - the credentials file is `~/.config/warden/creds.yaml`. -The key `githubtoken` should be set to a token that has enough permissions to do what you need. +The key `githubToken` should be set to a token that has enough permissions to do what you need. -**policies** - the policy file, `warden.yml`, should be in the current directory. -You can get started by copying over the example one: `cp example.warden.yml warden.yml` +**policies** - the policy file, `policy.yml`, should be in the current directory. +You can get started by copying over the example one: `cp example.policy.yml policy.yml` ## Features diff --git a/warden/cmd/audit.go b/warden/cmd/audit.go index eb0e142..82fb939 100644 --- a/warden/cmd/audit.go +++ b/warden/cmd/audit.go @@ -39,7 +39,7 @@ type UserPermission struct { Permission string `yaml:"permission"` } -type PoliciesFile struct { +type PolicyFile struct { DefaultBranch string `yaml:"defaultBranch"` Archived bool `yaml:"archived"` // include archived repos in lookup? License *LicenseRule `yaml:"license"` @@ -66,7 +66,7 @@ func (re *RuleError) Error() string { var ( auditCmd = &cobra.Command{ Use: "audit", - Short: "Validates that 1 or more repos meet a set of policies", + Short: "Validates that 1 or more repos meet a set of policy", RunE: func(cmd *cobra.Command, args []string) error { var res []RuleError @@ -76,7 +76,7 @@ var ( log.Fatal(err) } - policies, _, err := loadPoliciesFile(policiesFileFl) + policy, _, err := loadPolicyFile(policyFileFl) if err != nil { log.Fatal(err) } @@ -96,22 +96,22 @@ var ( repoResp, _, _ := client.Repositories.Get(context.Background(), repo.Owner, repo.Name) - if repoResp.GetArchived() != policies.Archived { + if repoResp.GetArchived() != policy.Archived { continue } - if repoResp.GetDefaultBranch() != policies.DefaultBranch { + if repoResp.GetDefaultBranch() != policy.DefaultBranch { res = append(res, RuleError{ Repo{org: repo.Owner, repo: repo.Name}, ERR_DEFAULT_BRANCH, }) - fmt.Printf("Error: The default branch should be %s, not %s.\n", policies.DefaultBranch, repoResp.GetDefaultBranch()) + fmt.Printf("Error: The default branch should be %s, not %s.\n", policy.DefaultBranch, repoResp.GetDefaultBranch()) } // if license is to be checked... - if policies.License != nil && policies.License.Scope == repoResp.GetVisibility() || policies.License.Scope == "all" { - if !slices.Contains(policies.License.Names, repoResp.GetLicense().GetKey()) { + if policy.License != nil && policy.License.Scope == repoResp.GetVisibility() || policy.License.Scope == "all" { + if !slices.Contains(policy.License.Names, repoResp.GetLicense().GetKey()) { res = append(res, RuleError{ Repo{org: repo.Owner, repo: repo.Name}, ERR_LICENSE, @@ -120,17 +120,17 @@ var ( } // if label checks are to happen - if len(policies.Labels) > 0 { + if len(policy.Labels) > 0 { labels, _, err := client.Issues.ListLabels(context.Background(), repo.Owner, repo.Name, nil) if err != nil { return err } - if policies.LabelStrategy == "available" || policies.LabelStrategy == "" { + if policy.LabelStrategy == "available" || policy.LabelStrategy == "" { // for each labal we're checking for - for _, label := range policies.Labels { + for _, label := range policy.Labels { found := false @@ -148,14 +148,14 @@ var ( }) } } - } else if policies.LabelStrategy == "only" { + } else if policy.LabelStrategy == "only" { // for each labal we're checking for for _, iLabel := range labels { found := false - for _, label := range policies.Labels { + for _, label := range policy.Labels { if label == iLabel.GetName() { found = true @@ -170,23 +170,23 @@ var ( } } } else { - return errors.New("The labelStrategy of " + policies.LabelStrategy + " isn't valid.") + return errors.New("The labelStrategy of " + policy.LabelStrategy + " isn't valid.") } } // if access permissions are to be checked... - if len(policies.Access) > 0 { + if len(policy.Access) > 0 { teams, _, err := client.Repositories.ListTeams(context.Background(), repo.Owner, repo.Name, nil) if err != nil { return err } - if policies.AccessStrategy == "available" || policies.AccessStrategy == "" { + if policy.AccessStrategy == "available" || policy.AccessStrategy == "" { // for each team we're checking for - for _, user := range policies.Access { + for _, user := range policy.Access { found := false matched := false @@ -216,7 +216,7 @@ var ( } } } else { - return errors.New("The accessStrategy of " + policies.AccessStrategy + " isn't valid.") + return errors.New("The accessStrategy of " + policy.AccessStrategy + " isn't valid.") } } } @@ -241,7 +241,7 @@ var ( func init() { - AddPoliciesFileFlag(auditCmd) + AddPolicyFileFlag(auditCmd) AddRepositoriesFileFlag(auditCmd) rootCmd.AddCommand(auditCmd) diff --git a/warden/cmd/flags.go b/warden/cmd/flags.go index 7410771..da17939 100644 --- a/warden/cmd/flags.go +++ b/warden/cmd/flags.go @@ -2,12 +2,12 @@ package cmd import "github.com/spf13/cobra" -var policiesFileFl string +var policyFileFl string var repositoriesFileFl string -func AddPoliciesFileFlag(cmd *cobra.Command) { +func AddPolicyFileFlag(cmd *cobra.Command) { - cmd.PersistentFlags().StringVar(&policiesFileFl, "policiesFile", "", "file containing rules (default is ./policies.y[a]ml)") + cmd.PersistentFlags().StringVar(&policyFileFl, "policyFile", "", "file containing rules (default is ./policy.y[a]ml)") } func AddRepositoriesFileFlag(cmd *cobra.Command) { diff --git a/warden/cmd/util.go b/warden/cmd/util.go index cda88b3..e212cc8 100644 --- a/warden/cmd/util.go +++ b/warden/cmd/util.go @@ -9,17 +9,17 @@ import ( "gopkg.in/yaml.v3" ) -// loadPoliciesFile tries to intelligently choose a filepath for the -// policiesfile and then return the unmarshalled struct. If customPath is not +// loadPolicyFile tries to intelligently choose a filepath for the +// policy file and then return the unmarshalled struct. If customPath is not // empty, it will try to use that before the default filenames. -func loadPoliciesFile(customPath string) (*PoliciesFile, []byte, error) { +func loadPolicyFile(customPath string) (*PolicyFile, []byte, error) { - var file PoliciesFile + var file PolicyFile var foundFile bool var yamlContent []byte var err error - possibleFilepaths := []string{"policies."} + possibleFilepaths := []string{"policy."} if customPath != "" { possibleFilepaths = append([]string{customPath}, possibleFilepaths...) @@ -40,7 +40,7 @@ func loadPoliciesFile(customPath string) (*PoliciesFile, []byte, error) { } if !foundFile { - return nil, nil, fmt.Errorf("A policies file was not found. Either './policies.yml' needs to be used or the '--policiesFile' flag set.") + return nil, nil, fmt.Errorf("A policy file was not found. Either './policy.yml' needs to be used or the '--policyFile' flag set.") } return &file, yamlContent, nil diff --git a/warden/cmd/validate.go b/warden/cmd/validate.go index 1214b65..3df81c9 100644 --- a/warden/cmd/validate.go +++ b/warden/cmd/validate.go @@ -20,7 +20,7 @@ var ( Short: "Validates a Warden file to match the schema", RunE: func(cmd *cobra.Command, args []string) error { - _, policiesFile, err := loadPoliciesFile(policiesFileFl) + _, policyFile, err := loadPolicyFile(policyFileFl) if err != nil { log.Fatal(err) } @@ -32,7 +32,7 @@ var ( var m interface{} - err = yaml.Unmarshal(policiesFile, &m) + err = yaml.Unmarshal(policyFile, &m) if err != nil { log.Fatal(err) } @@ -60,7 +60,7 @@ var ( func init() { - AddPoliciesFileFlag(validateCmd) + AddPolicyFileFlag(validateCmd) rootCmd.AddCommand(validateCmd) }