handler
v1.1.1
Documentation
pkg.go.dev ↗Types
API
type API struct {
Build
// Prefix is the part of the URL under which the API is being served, for
// example "/api".
Prefix string
}
API is the handler for handling API requests made for build creation, submission, and retrieval.
API.Destroy
func (h API) Destroy(w http.ResponseWriter, r *http.Request)
Destroy kills the build in the given request.
API.Index
func (h API) Index(w http.ResponseWriter, r *http.Request)
Index serves the JSON encoded list of builds for the given request. If multiple pages of builds are returned then the database.Paginator is encoded in the Link response header.
API.Show
func (h API) Show(w http.ResponseWriter, r *http.Request)
Show serves up the JSON response for the build in the given request. This serves different responses based on the base path of the request URL.
API.Store
func (h API) Store(w http.ResponseWriter, r *http.Request)
Store stores and submits the build from the given request body. If any validation errors occur then these will be sent back in the JSON response. On success the build is sent in the JSON response.
Artifact
type Artifact struct {
web.Handler
Prefix string
// contains filtered or unexported fields
}
NewArtifact
func NewArtifact(h web.Handler, artifacts fs.Store) Artifact
Artifact.Index
func (h Artifact) Index(w http.ResponseWriter, r *http.Request)
Index serves the JSON encoded list of artifacts for the build in the given request context.
Artifact.Show
func (h Artifact) Show(w http.ResponseWriter, r *http.Request)
Show serves the JSON encoded data of the given build artifact for the build in the given request context.
Build
type Build struct {
web.Handler
// contains filtered or unexported fields
}
Build is the base handler that provides shared logic for the UI and API handlers for build creation, submission, and retrieval.
New
func New(h web.Handler, artifacts fs.Store, redis *redis.Client, hasher *crypto.Hasher, producers map[string]*curlyq.Producer) Build
Build.IndexWithRelations
func (h Build) IndexWithRelations(r *http.Request) ([]*build.Build, database.Paginator, error)
IndexWithRelations retreives a slice of *build.Build models for the user in the given request context. All of the relations for each build will be loaded into each model we have. If any of the builds have a bound namespace, then the namespace's user will be loaded too. A database.Paginator will also be returned if there are multiple pages of builds.
Build.Kill
func (h Build) Kill(r *http.Request) error
Kill will kill the build in the given request context.
Build.ShowWithRelations
func (h Build) ShowWithRelations(r *http.Request) (*build.Build, error)
ShowWithRelations retrieves the *build.Build model from the context of the given request. All of the relations for the build will be loaded into the model we have. If the build has a namespace bound to it, then the namespace's user will be loaded to the namespace.
Build.StoreModel
func (h Build) StoreModel(r *http.Request) (*build.Build, build.Form, error)
StoreModel unmarshals the request's data into a build, validates it and stores it in the database. Upon success this will return the newly created build. This also returns the form for creating a build.
Hook
type Hook struct {
Build
// contains filtered or unexported fields
}
Hook providers the handlers used for consuming webhooks from the various providers we integrate with.
NewHook
func NewHook(b Build, crypto *crypto.AESGCM, providers *provider.Registry) Hook
Hook.GitHub
func (h Hook) GitHub(w http.ResponseWriter, r *http.Request)
GitHub serves the response for webhooks received from GitHub. This will only process webhooks for "ping", "push", and "pull_request" events. The owner of each build submitted will be set to the owner of the GitHub access token. Each request sent from GitHub is verified using the HMAC signature sent with the request. This will respond with 204 No Content on a successful execution of a hook, otherwise it will respond with 500 Internal Server Error. If any invalid manifest is found during hook execution, then the response 202 Accepted is sent, with a message detailing what was wrong with any invalid manifest that was found. If an invalid namespace name is found in any of the manifests then 400 Bad Request is sent.
On a "push" event, the repository being pushed to will be scraped to have all manifests extraced from it. Each of these will be submitted as a new build. The most recent commit is used as the build not, and the commit author is used as the author of the build.
On a "pull_request" event, the repository from which the pull request was sent is scraped for all manifests to be extracted. Each of these will be submitted as a new build. The title and body of the pull request are used as the build note.
Hook.GitLab
func (h Hook) GitLab(w http.ResponseWriter, r *http.Request)
GitLab serves the response for webhooks received from GitLab. This will only process webhooks for "Push Hook", and "Merge Request Hook", events. The owner of each build submitted will be set to the owner of the GitLab access token. Each request sent from GitLab is verified by checking the webhook token that was sent in the request. This will respond with 204 No Content on a successful execution of a hook, otherwise it will respond with 500 Internal Server Error. If any invalid manifest is found during hook execution, then the response 202 Accepted is sent, with a message detailing what was wrong with any invalid manifest that was found. If an invalid namespace name is found in any of the manifests then 400 Bad Request is sent.
On a "Push Hook" event, the repository being pushed to will be scraped to have all manifests extraced from it. Each of these will be submitted as a new build. The most recent commit is used as the build not, and the commit author is used as the author of the build.
On a "Merge Request Hook" event, the repository from which the pull request was sent is scraped for all manifests to be extracted. Each of these will be submitted as a new build. The title and body of the pull request are used as the build note.
Job
type Job struct {
web.Handler
// contains filtered or unexported fields
}
Job is the base handler that provides shared logic for the UI and API handlers for working with build jobs.
NewJob
func NewJob(h web.Handler) Job
Job.IndexWithRelations
func (h Job) IndexWithRelations(s *build.JobStore, vals url.Values) ([]*build.Job, error)
IndexWithRelations returns all of the jobs with their relationships loaded into each return job.
Job.ShowWithRelations
func (h Job) ShowWithRelations(r *http.Request) (*build.Job, error)
ShowWithRelations returns a job with all of the relations loaded for that job.
JobAPI
type JobAPI struct {
Job
// Prefix is the part of the URL under which the API is being served, for
// example "/api".
Prefix string
}
JobAPI is the handler for handling API requests made for working with the jobs within a build.
JobAPI.Index
func (h JobAPI) Index(w http.ResponseWriter, r *http.Request)
Index serves the JSON encoded list of jobs within a build for the given request. This is not paginated.
JobAPI.Show
func (h JobAPI) Show(w http.ResponseWriter, r *http.Request)
Show serves the JSON encoded build job for the given request.
JobUI
type JobUI struct {
Job
}
JobUI is the handler for handling UI requests made for managing build jobs.
JobUI.Show
func (h JobUI) Show(w http.ResponseWriter, r *http.Request)
Show will serve the HTML response for an individual build job. If the base of the URL path is "/raw", then a "text/plain" response is served with the output of the job.
Tag
type Tag struct {
web.Handler
// contains filtered or unexported fields
}
Tag is the base handler that provides shared logic for the UI and API handlers for working with build tags.
NewTag
func NewTag(h web.Handler) Tag
Tag.DeleteModel
func (h Tag) DeleteModel(r *http.Request) error
Tag.StoreModel
func (h Tag) StoreModel(r *http.Request) ([]*build.Tag, error)
StoreModel unmarshals the request's data into build tags, validates it and stores it in the database. Upon success this will return the newly created build tags.
TagAPI
type TagAPI struct {
Tag
// Prefix is the part of the URL under which the API is being served, for
// example "/api".
Prefix string
}
TagAPI is the handler for handling API requests made for working with build tags.
TagAPI.Destroy
func (h TagAPI) Destroy(w http.ResponseWriter, r *http.Request)
Destroy removes the given tag from the build in the given request context. This serves no content as it's response.
TagAPI.Index
func (h TagAPI) Index(w http.ResponseWriter, r *http.Request)
Index serves the JSON encoded list of build tags for the build in the given request context.
TagAPI.Show
func (h TagAPI) Show(w http.ResponseWriter, r *http.Request)
Show serves the JSON encoded response for an individual tag on the build in the given request context.
TagAPI.Store
func (h TagAPI) Store(w http.ResponseWriter, r *http.Request)
Store adds the given tags in the request's body to the build in the given request context. This will serve a response to the JSON encoded list of tags that were added.
TagUI
type TagUI struct {
Tag
}
TagUI is the handler for handling UI requests made for managing build tags.
TagUI.Destroy
func (h TagUI) Destroy(w http.ResponseWriter, r *http.Request)
Destroy will remove the specified tag from the build in the given request. On success this will redirect back, otherwise it will redirect back with an error message.
TagUI.Store
func (h TagUI) Store(w http.ResponseWriter, r *http.Request)
Store adds the tags in the given form submitted in the request. Upon success this will redirect back to the previous page. On a failure this will redirect back with an error message.
UI
type UI struct {
Build
}
UI is the handler for handling UI requests made for build creation, submission, and retrieval.
UI.Create
func (h UI) Create(w http.ResponseWriter, r *http.Request)
Create serves the HTML response for submitting builds via the web frontend.
UI.Destroy
func (h UI) Destroy(w http.ResponseWriter, r *http.Request)
Destroy kills the build. On success this will redirect back, on failure it will redirect back with an error message.
UI.Download
func (h UI) Download(w http.ResponseWriter, r *http.Request)
Download will serve the contents of a build's artifact in the given request. Depending on the MIME type of the artifact will depend on whether the content is served in the browser directly, or downloaded.
UI.Index
func (h UI) Index(w http.ResponseWriter, r *http.Request)
Index serves the HTML response detailing the list of builds.
UI.Show
func (h UI) Show(w http.ResponseWriter, r *http.Request)
Show serves the HTML response for viewing an individual build in the given request. This serves different responses based on the base path of the request URL.
UI.Store
func (h UI) Store(w http.ResponseWriter, r *http.Request)
Store validates the form submitted in the given request for submitting a build. If validation fails then the user is redirected back to the previous request, otherwise they are redirect back to the newly submitted build.