diff --git a/server/events/repo_whitelist.go b/server/events/repo_whitelist_checker.go similarity index 86% rename from server/events/repo_whitelist.go rename to server/events/repo_whitelist_checker.go index 06c500f48..0e4540133 100644 --- a/server/events/repo_whitelist.go +++ b/server/events/repo_whitelist_checker.go @@ -21,16 +21,16 @@ import ( // Wildcard matches 0-n of all characters except commas. const Wildcard = "*" -// RepoWhitelist implements checking if repos are whitelisted to be used with +// RepoWhitelistChecker implements checking if repos are whitelisted to be used with // this Atlantis. -type RepoWhitelist struct { +type RepoWhitelistChecker struct { // Whitelist is a comma separated list of rules with wildcards '*' allowed. Whitelist string } // IsWhitelisted returns true if this repo is in our whitelist and false // otherwise. -func (r *RepoWhitelist) IsWhitelisted(repoFullName string, vcsHostname string) bool { +func (r *RepoWhitelistChecker) IsWhitelisted(repoFullName string, vcsHostname string) bool { candidate := fmt.Sprintf("%s/%s", vcsHostname, repoFullName) rules := strings.Split(r.Whitelist, ",") for _, rule := range rules { @@ -41,7 +41,7 @@ func (r *RepoWhitelist) IsWhitelisted(repoFullName string, vcsHostname string) b return false } -func (r *RepoWhitelist) matchesRule(rule string, candidate string) bool { +func (r *RepoWhitelistChecker) matchesRule(rule string, candidate string) bool { // Case insensitive compare. rule = strings.ToLower(rule) candidate = strings.ToLower(candidate) diff --git a/server/events/repo_whitelist_test.go b/server/events/repo_whitelist_checker_test.go similarity index 96% rename from server/events/repo_whitelist_test.go rename to server/events/repo_whitelist_checker_test.go index 21e358572..d6f3f07e1 100644 --- a/server/events/repo_whitelist_test.go +++ b/server/events/repo_whitelist_checker_test.go @@ -20,7 +20,7 @@ import ( . "github.com/runatlantis/atlantis/testing" ) -func TestIsWhitelisted(t *testing.T) { +func TestRepoWhitelistChecker_IsWhitelisted(t *testing.T) { cases := []struct { Description string Whitelist string @@ -151,7 +151,7 @@ func TestIsWhitelisted(t *testing.T) { for _, c := range cases { t.Run(c.Description, func(t *testing.T) { - w := events.RepoWhitelist{Whitelist: c.Whitelist} + w := events.RepoWhitelistChecker{Whitelist: c.Whitelist} Equals(t, c.Exp, w.IsWhitelisted(c.RepoFullName, c.Hostname)) }) } diff --git a/server/events_controller.go b/server/events_controller.go index 95faa7029..3db62bd96 100644 --- a/server/events_controller.go +++ b/server/events_controller.go @@ -45,8 +45,8 @@ type EventsController struct { // GitlabWebHookSecret is the secret added to this webhook via the GitLab // UI that identifies this call as coming from GitLab. If empty, no // request validation is done. - GitlabWebHookSecret []byte - RepoWhitelist *events.RepoWhitelist + GitlabWebHookSecret []byte + RepoWhitelistChecker *events.RepoWhitelistChecker // SupportedVCSHosts is which VCS hosts Atlantis was configured upon // startup to support. SupportedVCSHosts []models.VCSHostType @@ -159,7 +159,7 @@ const ClosedPullEvent = "closed" const OtherPullEvent = "other" func (e *EventsController) handlePullRequestEvent(w http.ResponseWriter, baseRepo models.Repo, headRepo models.Repo, pull models.PullRequest, user models.User, eventType string) { - if !e.RepoWhitelist.IsWhitelisted(baseRepo.FullName, baseRepo.VCSHost.Hostname) { + if !e.RepoWhitelistChecker.IsWhitelisted(baseRepo.FullName, baseRepo.VCSHost.Hostname) { // If the repo isn't whitelisted and we receive an opened pull request // event we comment back on the pull request that the repo isn't // whitelisted. This is because the user might be expecting Atlantis to @@ -254,7 +254,7 @@ func (e *EventsController) handleCommentEvent(w http.ResponseWriter, baseRepo mo // At this point we know it's a command we're not supposed to ignore, so now // we check if this repo is allowed to run commands in the first place. - if !e.RepoWhitelist.IsWhitelisted(baseRepo.FullName, baseRepo.VCSHost.Hostname) { + if !e.RepoWhitelistChecker.IsWhitelisted(baseRepo.FullName, baseRepo.VCSHost.Hostname) { e.commentNotWhitelisted(baseRepo, pullNum) e.respond(w, logging.Warn, http.StatusForbidden, "Repo not whitelisted") return diff --git a/server/events_controller_e2e_test.go b/server/events_controller_e2e_test.go index f1dc0958f..7d9f300a7 100644 --- a/server/events_controller_e2e_test.go +++ b/server/events_controller_e2e_test.go @@ -293,7 +293,7 @@ func setupE2E(t *testing.T) (server.EventsController, *vcsmocks.MockClientProxy, GithubRequestValidator: &server.DefaultGithubRequestValidator{}, GitlabRequestParserValidator: &server.DefaultGitlabRequestParserValidator{}, GitlabWebHookSecret: nil, - RepoWhitelist: &events.RepoWhitelist{ + RepoWhitelistChecker: &events.RepoWhitelistChecker{ Whitelist: "*", }, SupportedVCSHosts: []models.VCSHostType{models.Gitlab, models.Github}, diff --git a/server/events_controller_test.go b/server/events_controller_test.go index 9d35a2265..a7f5c81a6 100644 --- a/server/events_controller_test.go +++ b/server/events_controller_test.go @@ -177,10 +177,10 @@ func TestPost_GitlabCommentNotWhitelisted(t *testing.T) { Logger: logging.NewNoopLogger(), CommentParser: &events.CommentParser{}, GitlabRequestParserValidator: &server.DefaultGitlabRequestParserValidator{}, - Parser: &events.EventParser{}, - SupportedVCSHosts: []models.VCSHostType{models.Gitlab}, - RepoWhitelist: &events.RepoWhitelist{}, - VCSClient: vcsClient, + Parser: &events.EventParser{}, + SupportedVCSHosts: []models.VCSHostType{models.Gitlab}, + RepoWhitelistChecker: &events.RepoWhitelistChecker{}, + VCSClient: vcsClient, } requestJSON, err := ioutil.ReadFile(filepath.Join("testfixtures", "gitlabMergeCommentEvent_notWhitelisted.json")) Ok(t, err) @@ -207,7 +207,7 @@ func TestPost_GithubCommentNotWhitelisted(t *testing.T) { CommentParser: &events.CommentParser{}, Parser: &events.EventParser{}, SupportedVCSHosts: []models.VCSHostType{models.Github}, - RepoWhitelist: &events.RepoWhitelist{}, + RepoWhitelistChecker: &events.RepoWhitelistChecker{}, VCSClient: vcsClient, } requestJSON, err := ioutil.ReadFile(filepath.Join("testfixtures", "githubIssueCommentEvent_notWhitelisted.json")) @@ -325,7 +325,7 @@ func TestPost_GithubPullRequestInvalidRepo(t *testing.T) { func TestPost_GithubPullRequestNotWhitelisted(t *testing.T) { t.Log("when the event is a github pull request to a non-whitelisted repo we return a 400") e, v, _, p, _, _, _, _ := setup(t) - e.RepoWhitelist = &events.RepoWhitelist{Whitelist: "github.com/nevermatch"} + e.RepoWhitelistChecker = &events.RepoWhitelistChecker{Whitelist: "github.com/nevermatch"} req, _ := http.NewRequest("GET", "", bytes.NewBuffer(nil)) req.Header.Set(githubHeader, "pull_request") @@ -424,7 +424,7 @@ func setup(t *testing.T) (server.EventsController, *mocks.MockGithubRequestValid SupportedVCSHosts: []models.VCSHostType{models.Github, models.Gitlab}, GitlabWebHookSecret: secret, GitlabRequestParserValidator: gl, - RepoWhitelist: &events.RepoWhitelist{ + RepoWhitelistChecker: &events.RepoWhitelistChecker{ Whitelist: "*", }, VCSClient: vcsmock, diff --git a/server/router.go b/server/router.go index af9319b98..4f4e2840d 100644 --- a/server/router.go +++ b/server/router.go @@ -9,7 +9,7 @@ import ( // Router can be used to retrieve Atlantis URLs. It acts as an intermediary // between the underlying router and the rest of Atlantis that might need to -// know URLs to different resources. +// construct URLs to different resources. type Router struct { // Underlying is the router that the routes have been constructed on. Underlying *mux.Router diff --git a/server/server.go b/server/server.go index 63bd77a83..fe97620d5 100644 --- a/server/server.go +++ b/server/server.go @@ -262,7 +262,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { }, }, } - repoWhitelist := &events.RepoWhitelist{ + repoWhitelist := &events.RepoWhitelistChecker{ Whitelist: userConfig.RepoWhitelist, } locksController := &LocksController{ @@ -282,7 +282,7 @@ func NewServer(userConfig UserConfig, config Config) (*Server, error) { GithubRequestValidator: &DefaultGithubRequestValidator{}, GitlabRequestParserValidator: &DefaultGitlabRequestParserValidator{}, GitlabWebHookSecret: []byte(userConfig.GitlabWebHookSecret), - RepoWhitelist: repoWhitelist, + RepoWhitelistChecker: repoWhitelist, SupportedVCSHosts: supportedVCSHosts, VCSClient: vcsClient, AtlantisGithubUser: models.User{Username: userConfig.GithubUser},