Skip to content

Commit

Permalink
Revert "feat: adds allowed_regexp_prefixes parameter to use with th…
Browse files Browse the repository at this point in the history
…e `--enable-regexp-cmd` flag (#1884)"

This reverts commit 79af924.
  • Loading branch information
chenrui333 authored Nov 18, 2021
1 parent 79af924 commit 4f3feb5
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 207 deletions.
5 changes: 0 additions & 5 deletions runatlantis.io/docs/repo-level-atlantis-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ workflows:
steps:
- run: echo hi
- apply
allowed_regexp_prefixes:
- dev/
- staging/
```
## Use Cases
Expand Down Expand Up @@ -197,7 +194,6 @@ automerge:
delete_source_branch_on_merge:
projects:
workflows:
allowed_regexp_prefixes:
```
| Key | Type | Default | Required | Description |
|-------------------------------|----------------------------------------------------------|---------|----------|-------------------------------------------------------------|
Expand All @@ -206,7 +202,6 @@ allowed_regexp_prefixes:
| delete_source_branch_on_merge | bool | `false` | no | Automatically deletes the source branch on merge |
| projects | array[[Project](repo-level-atlantis-yaml.html#project)] | `[]` | no | Lists the projects in this repo |
| workflows<br />*(restricted)* | map[string: [Workflow](custom-workflows.html#reference)] | `{}` | no | Custom workflows |
| allowed_regexp_prefixes | array[string] | `[]` | no | Lists the allowed regexp prefixes to use when the [`--enable-regexp-cmd`](server-configuration.html#enable-regexp-cmd) flag is used

### Project
```yaml
Expand Down
2 changes: 0 additions & 2 deletions server/events/yaml/raw/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ type RepoCfg struct {
ParallelApply *bool `yaml:"parallel_apply,omitempty"`
ParallelPlan *bool `yaml:"parallel_plan,omitempty"`
DeleteSourceBranchOnMerge *bool `yaml:"delete_source_branch_on_merge,omitempty"`
AllowedRegexpPrefixes []string `yaml:"allowed_regexp_prefixes,omitempty"`
}

func (r RepoCfg) Validate() error {
Expand Down Expand Up @@ -88,6 +87,5 @@ func (r RepoCfg) ToValid() valid.RepoCfg {
ParallelPlan: parallelPlan,
ParallelPolicyCheck: parallelPlan,
DeleteSourceBranchOnMerge: r.DeleteSourceBranchOnMerge,
AllowedRegexpPrefixes: r.AllowedRegexpPrefixes,
}
}
6 changes: 1 addition & 5 deletions server/events/yaml/raw/repo_cfg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,7 @@ workflows:
policy_check:
steps: []
apply:
steps: []
allowed_regexp_prefixes:
- dev/
- staging/`,
steps: []`,
exp: raw.RepoCfg{
Version: Int(3),
Automerge: Bool(true),
Expand Down Expand Up @@ -179,7 +176,6 @@ allowed_regexp_prefixes:
},
},
},
AllowedRegexpPrefixes: []string{"dev/", "staging/"},
},
},
}
Expand Down
25 changes: 5 additions & 20 deletions server/events/yaml/valid/repo_cfg.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ type RepoCfg struct {
ParallelPlan bool
ParallelPolicyCheck bool
DeleteSourceBranchOnMerge *bool
AllowedRegexpPrefixes []string
}

func (r RepoCfg) FindProjectsByDirWorkspace(repoRelDir string, workspace string) []Project {
Expand Down Expand Up @@ -58,31 +57,17 @@ func (r RepoCfg) FindProjectByName(name string) *Project {
// FindProjectsByName returns all projects that match with name.
func (r RepoCfg) FindProjectsByName(name string) []Project {
var ps []Project
if isRegexAllowed(name, r.AllowedRegexpPrefixes) {
sanitizedName := "^" + name + "$"
for _, p := range r.Projects {
if p.Name != nil {
if match, _ := regexp.MatchString(sanitizedName, *p.Name); match {
ps = append(ps, p)
}
sanitizedName := "^" + name + "$"
for _, p := range r.Projects {
if p.Name != nil {
if match, _ := regexp.MatchString(sanitizedName, *p.Name); match {
ps = append(ps, p)
}
}
}
return ps
}

func isRegexAllowed(name string, allowedRegexpPrefixes []string) bool {
if len(allowedRegexpPrefixes) == 0 {
return true
}
for _, allowedRegexPrefix := range allowedRegexpPrefixes {
if strings.HasPrefix(name, allowedRegexPrefix) {
return true
}
}
return false
}

// 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
Expand Down
175 changes: 0 additions & 175 deletions server/events/yaml/valid/repo_cfg_test.go

This file was deleted.

0 comments on commit 4f3feb5

Please sign in to comment.