api

package
v0.1.0-beta.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 16, 2020 License: MIT Imports: 35 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrorUpgradeWebsocket describes an error while upgrading http to a websocket endpoint.
	ErrorUpgradeWebsocket = HTTPError{
		Code: 500,
		Errors: []string{
			"could not upgrade to websocket",
		},
	}

	// ErrorDataWrite describes an error in writing to the database
	ErrorDataWrite = HTTPError{
		Code: 500,
		Errors: []string{
			"could not write to database",
		},
	}

	// ErrorWebsocketWrite describes an error in writing to websocket connection
	ErrorWebsocketWrite = HTTPError{
		Code: 500,
		Errors: []string{
			"could not write data via websocket",
		},
	}

	// ErrorDataRead describes an error when reading from the database
	ErrorDataRead = HTTPError{
		Code: 500,
		Errors: []string{
			"could not read from database",
		},
	}

	// ErrorInternal describes a generic internal server error
	ErrorInternal = HTTPError{
		Code: 500,
		Errors: []string{
			"internal server error",
		},
	}
)

Functions

This section is empty.

Types

type App

type App struct {
	TestAgents   *TestAgents
	GithubConfig *oauth2.Config
	// contains filtered or unexported fields
}

App represents an API instance with handler methods attached, a DB connection and a logger instance

func New

func New(
	logger *lr.Logger,
	db *gorm.DB,
	repo *repository.Repository,
	validator *validator.Validate,
	store sessions.Store,
	cookieName string,
	testing bool,
	githubConfig *oauth.Config,
) *App

New returns a new App instance

func (*App) HandleAuthCheck

func (app *App) HandleAuthCheck(w http.ResponseWriter, r *http.Request)

HandleAuthCheck checks whether current session is authenticated and returns user ID if so.

func (*App) HandleCreateProject

func (app *App) HandleCreateProject(w http.ResponseWriter, r *http.Request)

HandleCreateProject validates a project form entry, converts the project to a gorm model, and saves the user to the database

func (*App) HandleCreateProjectSACandidates

func (app *App) HandleCreateProjectSACandidates(w http.ResponseWriter, r *http.Request)

HandleCreateProjectSACandidates handles the creation of ServiceAccountCandidates using a kubeconfig and a project id

func (*App) HandleCreateUser

func (app *App) HandleCreateUser(w http.ResponseWriter, r *http.Request)

HandleCreateUser validates a user form entry, converts the user to a gorm model, and saves the user to the database

func (*App) HandleDeleteProject

func (app *App) HandleDeleteProject(w http.ResponseWriter, r *http.Request)

HandleDeleteProject deletes a project from the db, reading from the project_id in the URL param

func (*App) HandleDeleteUser

func (app *App) HandleDeleteUser(w http.ResponseWriter, r *http.Request)

HandleDeleteUser removes a user after checking that the sent password is correct

func (*App) HandleGetBranchContents

func (app *App) HandleGetBranchContents(w http.ResponseWriter, r *http.Request)

HandleGetBranchContents retrieves the contents of a specific branch and subdirectory

func (*App) HandleGetBranches

func (app *App) HandleGetBranches(w http.ResponseWriter, r *http.Request)

HandleGetBranches retrieves a list of branch names for a specified repo

func (*App) HandleGetPodLogs

func (app *App) HandleGetPodLogs(w http.ResponseWriter, r *http.Request)

HandleGetPodLogs returns real-time logs of the pod via websockets TODO: Refactor repeated calls.

func (*App) HandleGetRelease

func (app *App) HandleGetRelease(w http.ResponseWriter, r *http.Request)

HandleGetRelease retrieves a single release based on a name and revision

func (*App) HandleGetReleaseComponents

func (app *App) HandleGetReleaseComponents(w http.ResponseWriter, r *http.Request)

HandleGetReleaseComponents retrieves a single release based on a name and revision

func (*App) HandleGithubOAuthCallback

func (app *App) HandleGithubOAuthCallback(w http.ResponseWriter, r *http.Request)

HandleGithubOAuthCallback verifies the callback request by checking that the state parameter has not been modified, and validates the token. There is a difference between the oauth flow when logging a user in, and when linking a repository.

When logging a user in, the access token gets stored in the session, and no refresh token is requested. We store the access token in the session because a user can be logged in multiple times with a single access token.

NOTE: this user flow will likely be augmented with Dex, or entirely replaced with Dex.

However, when linking a repository, the access token and refresh token are requested when the flow has started. A project also gets linked to the session. After callback, a new github config gets stored for the project, and the user will then get redirected to a URL that allows them to select their repositories they'd like to link. We require a refresh token because we need permanent access to the linked repository.

func (*App) HandleGithubOAuthStartProject

func (app *App) HandleGithubOAuthStartProject(w http.ResponseWriter, r *http.Request)

HandleGithubOAuthStartProject starts the oauth2 flow for a project repo request. In this handler, the project id gets written to the session (along with the oauth state param), so that the correct project id can be identified in the callback.

func (*App) HandleGithubOAuthStartUser

func (app *App) HandleGithubOAuthStartUser(w http.ResponseWriter, r *http.Request)

HandleGithubOAuthStartUser starts the oauth2 flow for a user login request.

func (*App) HandleListNamespaces

func (app *App) HandleListNamespaces(w http.ResponseWriter, r *http.Request)

HandleListNamespaces retrieves a list of namespaces

func (*App) HandleListPods

func (app *App) HandleListPods(w http.ResponseWriter, r *http.Request)

HandleListPods returns all pods that match the given selectors TODO: Refactor repeated calls.

func (*App) HandleListProjectClusters

func (app *App) HandleListProjectClusters(w http.ResponseWriter, r *http.Request)

HandleListProjectClusters returns a list of clusters that have linked ServiceAccounts. If multiple service accounts exist for a cluster, the service account created later will take precedence. This may be changed in a future release to return multiple service accounts.

func (*App) HandleListProjectSACandidates

func (app *App) HandleListProjectSACandidates(w http.ResponseWriter, r *http.Request)

HandleListProjectSACandidates returns a list of externalized ServiceAccountCandidate ([]models.ServiceAccountCandidateExternal) based on a project ID

func (*App) HandleListReleaseHistory

func (app *App) HandleListReleaseHistory(w http.ResponseWriter, r *http.Request)

HandleListReleaseHistory retrieves a history of releases based on a release name

func (*App) HandleListReleases

func (app *App) HandleListReleases(w http.ResponseWriter, r *http.Request)

HandleListReleases retrieves a list of releases for a cluster with various filter options

func (*App) HandleListRepos

func (app *App) HandleListRepos(w http.ResponseWriter, r *http.Request)

HandleListRepos retrieves a list of repo names

func (*App) HandleListTemplates

func (app *App) HandleListTemplates(w http.ResponseWriter, r *http.Request)

HandleListTemplates retrieves a list of Porter templates TODO: test and reduce fragility (handle untar/parse error for individual charts) TODO: separate markdown retrieval into its own query if necessary

func (*App) HandleListUserProjects

func (app *App) HandleListUserProjects(w http.ResponseWriter, r *http.Request)

HandleListUserProjects lists all projects belonging to a given user

func (*App) HandleLive

func (app *App) HandleLive(w http.ResponseWriter, r *http.Request)

HandleLive responds immediately with an HTTP 200 status.

func (*App) HandleLoginUser

func (app *App) HandleLoginUser(w http.ResponseWriter, r *http.Request)

HandleLoginUser checks the request header for cookie and validates the user.

func (*App) HandleLogoutUser

func (app *App) HandleLogoutUser(w http.ResponseWriter, r *http.Request)

HandleLogoutUser detaches the user from the session

func (*App) HandleReadProject

func (app *App) HandleReadProject(w http.ResponseWriter, r *http.Request)

HandleReadProject returns an externalized Project (models.ProjectExternal) based on an ID

func (*App) HandleReadProjectServiceAccount

func (app *App) HandleReadProjectServiceAccount(w http.ResponseWriter, r *http.Request)

HandleReadProjectServiceAccount reads a service account by id

func (*App) HandleReadUser

func (app *App) HandleReadUser(w http.ResponseWriter, r *http.Request)

HandleReadUser returns an externalized User (models.UserExternal) based on an ID

func (*App) HandleReady

func (app *App) HandleReady(w http.ResponseWriter, r *http.Request)

HandleReady responds with HTTP 200 if healthy, 500 otherwise

func (*App) HandleResolveSACandidateActions

func (app *App) HandleResolveSACandidateActions(w http.ResponseWriter, r *http.Request)

HandleResolveSACandidateActions accepts a list of action configurations for a given ServiceAccountCandidate, which "resolves" that ServiceAccountCandidate and creates a ServiceAccount for a specific project

func (*App) HandleRollbackRelease

func (app *App) HandleRollbackRelease(w http.ResponseWriter, r *http.Request)

HandleRollbackRelease rolls a release back to a specified revision

func (*App) HandleUpgradeRelease

func (app *App) HandleUpgradeRelease(w http.ResponseWriter, r *http.Request)

HandleUpgradeRelease upgrades a release with new values.yaml

func (*App) Logger

func (app *App) Logger() *lr.Logger

Logger returns the logger instance in use by App

type ChartYAML

type ChartYAML []struct {
	APIVersion  string   `yaml:"apiVersion"`
	AppVersion  string   `yaml:"appVersion"`
	Created     string   `yaml:"created"`
	Description string   `yaml:"description"`
	Digest      string   `yaml:"digest"`
	Icon        string   `yaml:"icon"`
	Name        string   `yaml:"name"`
	Type        string   `yaml:"type"`
	Urls        []string `yaml:"urls"`
	Version     string   `yaml:"version"`
}

ChartYAML represents the data for chart in index.yaml

type DirectoryItem

type DirectoryItem struct {
	Path string
	Type string
}

DirectoryItem represents a file or subfolder in a repository

type ErrorCode

type ErrorCode int64

ErrorCode is a custom Porter error code, useful for frontend messages

const (
	ErrK8sDecode ErrorCode = iota + 600
	ErrK8sValidate
)

Enumeration of k8s API error codes, represented as int64

const (
	ErrProjectDecode ErrorCode = iota + 600
	ErrProjectValidateFields
	ErrProjectDataRead
)

Enumeration of user API error codes, represented as int64

const (
	ErrReleaseDecode ErrorCode = iota + 600
	ErrReleaseValidateFields
	ErrReleaseReadData
	ErrReleaseDeploy
)

Enumeration of release API error codes, represented as int64

const (
	ErrUserDecode ErrorCode = iota + 600
	ErrUserValidateFields
	ErrUserDataRead
)

Enumeration of user API error codes, represented as int64

type FormYAML

type FormYAML struct {
	Name        string   `yaml:"name"`
	Icon        string   `yaml:"icon"`
	Description string   `yaml:"description"`
	Tags        []string `yaml:"tags"`
	Sections    []struct {
		Name     string `yaml:"name"`
		ShowIf   string `yaml:"show_if"`
		Contents []struct {
			Type     string `yaml:"type"`
			Label    string `yaml:"label"`
			Name     string `yaml:"name,omitempty"`
			Variable string `yaml:"variable,omitempty"`
			Settings struct {
				Default interface{}
			} `yaml:"settings,omitempty"`
		} `yaml:"contents"`
	} `yaml:"sections"`
}

FormYAML represents a chart's values.yaml form abstraction

type HTTPError

type HTTPError struct {
	Code   ErrorCode `json:"code"`
	Errors []string  `json:"errors"`
}

HTTPError is the object returned when the API encounters an error: this gets marshaled into JSON

type IndexYAML

type IndexYAML struct {
	APIVersion string                    `yaml:"apiVersion"`
	Generated  string                    `yaml:"generated"`
	Entries    map[interface{}]ChartYAML `yaml:"entries"`
}

IndexYAML represents a chart repo's index.yaml

type PorterChart

type PorterChart struct {
	Name        string
	Description string
	Icon        string
	Form        FormYAML
	Markdown    string
}

PorterChart represents a bundled Porter template

type Repo

type Repo struct {
	FullName string
	Kind     string
}

Repo represents a GitHub or Gitab repository

type TestAgents

type TestAgents struct {
	HelmAgent             *helm.Agent
	HelmTestStorageDriver *storage.Storage
	K8sAgent              *kubernetes.Agent
}

TestAgents are the k8s agents used for testing

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL