Documentation ¶
Overview ¶
Package server handles the web server and executing commands that come in via webhooks.
Index ¶
- Constants
- type Config
- type DefaultGithubRequestValidator
- type DefaultGitlabRequestParser
- type EventsController
- func (e *EventsController) HandleGithubCommentEvent(w http.ResponseWriter, event *github.IssueCommentEvent, githubReqID string)
- func (e *EventsController) HandleGithubPullRequestEvent(w http.ResponseWriter, pullEvent *github.PullRequestEvent, githubReqID string)
- func (e *EventsController) HandleGitlabCommentEvent(w http.ResponseWriter, event gitlab.MergeCommentEvent)
- func (e *EventsController) HandleGitlabMergeRequestEvent(w http.ResponseWriter, event gitlab.MergeEvent)
- func (e *EventsController) Post(w http.ResponseWriter, r *http.Request)
- type GithubRequestValidator
- type GitlabRequestParser
- type LockDetailData
- type LockIndexData
- type RequestLogger
- type Server
- func (s *Server) DeleteLock(w http.ResponseWriter, _ *http.Request, id string)
- func (s *Server) DeleteLockRoute(w http.ResponseWriter, r *http.Request)
- func (s *Server) GetLock(w http.ResponseWriter, _ *http.Request, id string)
- func (s *Server) GetLockRoute(w http.ResponseWriter, r *http.Request)
- func (s *Server) Index(w http.ResponseWriter, _ *http.Request)
- func (s *Server) Start() error
- type TemplateWriter
- type WebhookConfig
Constants ¶
const LockRouteName = "lock-detail"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶ added in v0.1.3
type Config struct { AtlantisURL string `mapstructure:"atlantis-url"` DataDir string `mapstructure:"data-dir"` GithubHostname string `mapstructure:"gh-hostname"` GithubToken string `mapstructure:"gh-token"` GithubUser string `mapstructure:"gh-user"` GithubWebHookSecret string `mapstructure:"gh-webhook-secret"` GitlabHostname string `mapstructure:"gitlab-hostname"` GitlabToken string `mapstructure:"gitlab-token"` GitlabUser string `mapstructure:"gitlab-user"` GitlabWebHookSecret string `mapstructure:"gitlab-webhook-secret"` LogLevel string `mapstructure:"log-level"` Port int `mapstructure:"port"` // RequireApproval is whether to require pull request approval before // allowing terraform apply's to be run. RequireApproval bool `mapstructure:"require-approval"` SlackToken string `mapstructure:"slack-token"` Webhooks []WebhookConfig `mapstructure:"webhooks"` }
Config configures Server. The mapstructure tags correspond to flags in cmd/server.go and are used when the config is parsed from a YAML file.
type DefaultGithubRequestValidator ¶ added in v0.2.0
type DefaultGithubRequestValidator struct{}
DefaultGithubRequestValidator handles checking if GitHub requests are signed properly by the secret.
type DefaultGitlabRequestParser ¶ added in v0.2.0
type DefaultGitlabRequestParser struct{}
DefaultGitlabRequestParser parses and validates GitLab requests.
type EventsController ¶ added in v0.1.3
type EventsController struct { CommandRunner events.CommandRunner PullCleaner events.PullCleaner Logger *logging.SimpleLogger Parser events.EventParsing // GithubWebHookSecret is the secret added to this webhook via the GitHub // UI that identifies this call as coming from GitHub. If empty, no // request validation is done. GithubWebHookSecret []byte GithubRequestValidator GithubRequestValidator GitlabRequestParser GitlabRequestParser // 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 // SupportedVCSHosts is which VCS hosts Atlantis was configured upon // startup to support. SupportedVCSHosts []vcs.Host }
EventsController handles all webhook requests which signify 'events' in the VCS host, ex. GitHub. It's split out from Server to make testing easier.
func (*EventsController) HandleGithubCommentEvent ¶ added in v0.2.0
func (e *EventsController) HandleGithubCommentEvent(w http.ResponseWriter, event *github.IssueCommentEvent, githubReqID string)
HandleGithubCommentEvent handles comment events from GitHub where Atlantis commands can come from. It's exported to make testing easier.
func (*EventsController) HandleGithubPullRequestEvent ¶ added in v0.2.0
func (e *EventsController) HandleGithubPullRequestEvent(w http.ResponseWriter, pullEvent *github.PullRequestEvent, githubReqID string)
HandleGithubPullRequestEvent will delete any locks associated with the pull request if the event is a pull request closed event. It's exported to make testing easier.
func (*EventsController) HandleGitlabCommentEvent ¶ added in v0.2.0
func (e *EventsController) HandleGitlabCommentEvent(w http.ResponseWriter, event gitlab.MergeCommentEvent)
HandleGitlabCommentEvent handles comment events from GitLab where Atlantis commands can come from. It's exported to make testing easier.
func (*EventsController) HandleGitlabMergeRequestEvent ¶ added in v0.2.0
func (e *EventsController) HandleGitlabMergeRequestEvent(w http.ResponseWriter, event gitlab.MergeEvent)
HandleGitlabMergeRequestEvent will delete any locks associated with the pull request if the event is a merge request closed event. It's exported to make testing easier.
func (*EventsController) Post ¶ added in v0.1.3
func (e *EventsController) Post(w http.ResponseWriter, r *http.Request)
Post handles POST webhook requests.
type GithubRequestValidator ¶ added in v0.2.0
type GithubRequestValidator interface { // Validate returns the JSON payload of the request. // If secret is not empty, it checks that the request was signed // by secret and returns an error if it was not. // If secret is empty, it does not check if the request was signed. Validate(r *http.Request, secret []byte) ([]byte, error) }
GithubRequestValidator handles checking if GitHub requests are signed properly by the secret.
type GitlabRequestParser ¶ added in v0.2.0
type GitlabRequestParser interface { // Validate validates that the request has a token header matching secret. // If the secret does not match it returns an error. // If secret is empty it does not check the token header. // It then parses the request as a GitLab object depending on the header // provided by GitLab identifying the webhook type. If the webhook type // is not recognized it will return nil but will not return an error. // Usage: // event, err := GitlabRequestParser.Validate(r, secret) // if err != nil { // return // } // switch event := event.(type) { // case gitlab.MergeCommentEvent: // // handle // case gitlab.MergeEvent: // // handle // default: // // unsupported event // } Validate(r *http.Request, secret []byte) (interface{}, error) }
GitlabRequestParser parses and validates GitLab requests.
type LockDetailData ¶ added in v0.1.3
type LockDetailData struct { UnlockURL string LockKeyEncoded string LockKey string RepoOwner string RepoName string PullRequestLink string LockedBy string Environment string Time time.Time }
LockDetailData holds the fields needed to display the lock detail view.
type LockIndexData ¶ added in v0.1.3
LockIndexData holds the fields needed to display the index view for locks.
type RequestLogger ¶
type RequestLogger struct {
// contains filtered or unexported fields
}
RequestLogger logs requests and their response codes.
func NewRequestLogger ¶
func NewRequestLogger(logger *logging.SimpleLogger) *RequestLogger
NewRequestLogger creates a RequestLogger.
func (*RequestLogger) ServeHTTP ¶
func (l *RequestLogger) ServeHTTP(rw http.ResponseWriter, r *http.Request, next http.HandlerFunc)
ServeHTTP implements the middleware function. It logs a request at INFO level unless it's a request to /static/*.
type Server ¶
type Server struct { Router *mux.Router Port int CommandHandler *events.CommandHandler Logger *logging.SimpleLogger Locker locking.Locker AtlantisURL string EventsController *EventsController IndexTemplate TemplateWriter LockDetailTemplate TemplateWriter }
Server runs the Atlantis web server.
func NewServer ¶
NewServer returns a new server. If there are issues starting the server or its dependencies an error will be returned. This is like the main() function for the server CLI command because it injects all the dependencies.
func (*Server) DeleteLock ¶ added in v0.1.3
DeleteLock deletes the lock. DeleteLockRoute should be called first. This method is split out to make this route testable.
func (*Server) DeleteLockRoute ¶ added in v0.1.3
func (s *Server) DeleteLockRoute(w http.ResponseWriter, r *http.Request)
DeleteLockRoute handles deleting the lock at id.
func (*Server) GetLock ¶ added in v0.1.3
GetLock handles a lock detail page view. getLockRoute is expected to be called before. This function was extracted to make it testable.
func (*Server) GetLockRoute ¶ added in v0.1.3
func (s *Server) GetLockRoute(w http.ResponseWriter, r *http.Request)
GetLockRoute is the GET /locks/{id} route. It renders the lock detail view.
type TemplateWriter ¶ added in v0.1.3
type TemplateWriter interface { // Execute applies a parsed template to the specified data object, // writing the output to wr. Execute(wr io.Writer, data interface{}) error }
TemplateWriter is an interface over html/template that's used to enable mocking.
type WebhookConfig ¶ added in v0.2.0
type WebhookConfig struct { // Event is the type of event we should send this webhook for, ex. apply. Event string `mapstructure:"event"` // WorkspaceRegex is a regex that is used to match against the workspace // that is being modified for this event. If the regex matches, we'll // send the webhook, ex. "production.*". WorkspaceRegex string `mapstructure:"workspace-regex"` // Kind is the type of webhook we should send, ex. slack. Kind string `mapstructure:"kind"` // Channel is the channel to send this webhook to. It only applies to // slack webhooks. Should be without '#'. Channel string `mapstructure:"channel"` }
WebhookConfig is nested within Config. It's used to configure webhooks.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
locking
Package locking handles locking projects when they have in-progress runs.
|
Package locking handles locking projects when they have in-progress runs. |
locking/boltdb
Package boltdb provides a locking implementation using Bolt.
|
Package boltdb provides a locking implementation using Bolt. |
models
Package models holds all models that are needed across packages.
|
Package models holds all models that are needed across packages. |
run
Package run handles running commands prior and following the regular Atlantis commands.
|
Package run handles running commands prior and following the regular Atlantis commands. |
terraform
Package terraform handles the actual running of terraform commands
|
Package terraform handles the actual running of terraform commands |
Package logging handles logging throughout Atlantis.
|
Package logging handles logging throughout Atlantis. |
Package recovery is taken from https://github.com/gin-gonic/gin/blob/master/recovery.go License of source below: Copyright 2014 Manu Martinez-Almeida.
|
Package recovery is taken from https://github.com/gin-gonic/gin/blob/master/recovery.go License of source below: Copyright 2014 Manu Martinez-Almeida. |