api

package
v0.1.0-beta.3.5 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2021 License: MIT Imports: 46 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 {
	// Server configuration
	ServerConf config.ServerConf

	// Logger for logging
	Logger *lr.Logger

	// Repo implements a query repository
	Repo *repository.Repository

	// session store for cookie-based sessions
	Store sessions.Store

	// agents exposed for testing
	TestAgents *TestAgents

	// redis client for redis connection
	RedisConf *config.RedisConf

	// config for db
	DBConf config.DBConf

	// oauth-specific clients
	GithubUserConf    *oauth2.Config
	GithubProjectConf *oauth2.Config
	DOConf            *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(conf *AppConfig) (*App, error)

New returns a new App instance

func (*App) HandleAcceptInvite

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

HandleAcceptInvite accepts an invite to a new project: if successful, a new role is created for that user in the project

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) HandleCLILoginExchangeToken

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

HandleCLILoginExchangeToken exchanges an authorization code for a token

func (*App) HandleCLILoginUser

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

HandleCLILoginUser verifies that a user is logged in, and generates an access token for usage from the CLI

func (*App) HandleCreateAWSIntegration

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

HandleCreateAWSIntegration creates a new AWS integration in the DB

func (*App) HandleCreateBasicAuthIntegration

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

HandleCreateBasicAuthIntegration creates a new basic auth integration in the DB

func (*App) HandleCreateGCPIntegration

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

HandleCreateGCPIntegration creates a new GCP integration in the DB

func (*App) HandleCreateGitAction

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

HandleCreateGitAction creates a new Github action in a repository for a given release

func (*App) HandleCreateHelmRepo

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

HandleCreateHelmRepo creates a new helm repo for a project

func (*App) HandleCreateInvite

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

HandleCreateInvite creates a new invite for a project

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) HandleCreateProjectCluster

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

HandleCreateProjectCluster creates a new cluster

func (*App) HandleCreateProjectClusterCandidates

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

HandleCreateProjectClusterCandidates handles the creation of ClusterCandidates using a kubeconfig and a project id

func (*App) HandleCreateRegistry

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

HandleCreateRegistry creates a new registry

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) HandleDOOAuthCallback

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

HandleDOOAuthCallback verifies the callback request by checking that the state parameter has not been modified, and validates the token.

func (*App) HandleDOOAuthStartProject

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

HandleDOOAuthStartProject starts the oauth2 flow for a project digitalocean 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) 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) HandleDeleteProjectCluster

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

HandleDeleteProjectCluster handles the deletion of a Cluster via the cluster ID

func (*App) HandleDeleteProjectGitRepo

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

HandleDeleteProjectGitRepo handles the deletion of a Github Repo via the git repo ID

func (*App) HandleDeleteProjectInvite

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

HandleDeleteProjectInvite handles the deletion of an Invite via the invite ID

func (*App) HandleDeleteProjectRegistry

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

HandleDeleteProjectRegistry handles the deletion of a Registry via the registry ID

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) HandleDeployTemplate

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

HandleDeployTemplate triggers a chart deployment from a template

func (*App) HandleDestroyAWSECRInfra

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

HandleDestroyAWSECRInfra destroys ecr infra

func (*App) HandleDestroyAWSEKSInfra

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

HandleDestroyAWSEKSInfra destroys eks infra

func (*App) HandleDestroyDODOCRInfra

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

HandleDestroyAWSDOCRInfra destroys docr infra

func (*App) HandleDestroyDODOKSInfra

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

HandleDestroyDODOKSInfra destroys DOKS infra

func (*App) HandleDestroyGCPGKEInfra

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

HandleDestroyGCPGKEInfra destroys gke infra

func (*App) HandleDestroyTestInfra

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

HandleDestroyTestInfra destroys test infra

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) HandleGetIngress

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

HandleGetIngress returns the ingress object given the name and namespace.

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) HandleGetProjectRegistryDOCRToken

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

HandleGetProjectRegistryDOCRToken gets a DOCR token for a registry

func (*App) HandleGetProjectRegistryDockerhubToken

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

HandleGetProjectRegistryDockerhubToken gets a Dockerhub token for a registry

func (*App) HandleGetProjectRegistryECRToken

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

HandleGetProjectRegistryECRToken gets an ECR token for a registry

func (*App) HandleGetProjectRegistryGCRToken

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

HandleGetProjectRegistryGCRToken gets a GCR token for a registry

func (*App) HandleGetProvisioningLogs

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

HandleGetProvisioningLogs returns real-time logs of the provisioning process via websockets

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 kubernetes objects listed in a release identified by name and revision

func (*App) HandleGetReleaseControllers

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

HandleGetReleaseControllers retrieves controllers that belong to a release. Used to display status of charts.

func (*App) HandleGetReleaseToken

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

HandleGetReleaseToken retrieves the webhook token of a specific release.

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) HandleListClusterIntegrations

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

HandleListClusterIntegrations lists the cluster integrations available to the instance

func (*App) HandleListHelmRepoCharts

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

HandleListHelmRepoCharts lists the charts for a given linked helm repo

func (*App) HandleListHelmRepoIntegrations

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

HandleListHelmRepoIntegrations lists the Helm repo integrations available to the instance

func (*App) HandleListImages

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

HandleListImages retrieves a list of repo names

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) HandleListProjectClusterCandidates

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

HandleListProjectClusterCandidates returns a list of externalized ClusterCandidates ([]models.ClusterCandidateExternal) based on a project ID

func (*App) HandleListProjectClusters

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

HandleListProjectClusters returns a list of clusters that have linked Integrations.

func (*App) HandleListProjectGitRepos

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

HandleListProjectGitRepos returns a list of git repos for a project

func (*App) HandleListProjectHelmRepos

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

HandleListProjectHelmRepos returns a list of helm repos for a project

func (*App) HandleListProjectInfra

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

HandleListProjectInfra returns a list of infrasa for a project

func (*App) HandleListProjectInvites

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

HandleListProjectInvites returns a list of invites for a project

func (*App) HandleListProjectOAuthIntegrations

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

HandleListProjectOAuthIntegrations lists the oauth integrations for the project

func (*App) HandleListProjectRegistries

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

HandleListProjectRegistries returns a list of registries for a project

func (*App) HandleListRegistryIntegrations

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

HandleListRegistryIntegrations lists the image registry integrations available to the instance

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) HandleListRepoIntegrations

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

HandleListRepoIntegrations lists the repo integrations available to the instance

func (*App) HandleListRepos

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

HandleListRepos retrieves a list of repo names

func (*App) HandleListRepositories

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

HandleListRepositories returns a list of repositories for a given registry

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) HandleProvisionAWSECRInfra

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

HandleProvisionAWSECRInfra provisions a new aws ECR instance for a project

func (*App) HandleProvisionAWSEKSInfra

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

HandleProvisionAWSEKSInfra provisions a new aws EKS instance for a project

func (*App) HandleProvisionDODOCRInfra

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

HandleProvisionDODOCRInfra provisions a new digitalocean DOCR instance for a project

func (*App) HandleProvisionDODOKSInfra

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

HandleProvisionDODOKSInfra provisions a new DO DOKS instance for a project

func (*App) HandleProvisionGCPGCRInfra

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

HandleProvisionGCPGCRInfra enables GCR for a project

func (*App) HandleProvisionGCPGKEInfra

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

HandleProvisionGCPGKEInfra provisions a new GKE instance for a project

func (*App) HandleProvisionTestInfra

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

HandleProvisionTestInfra will create a test resource by deploying a provisioner container pod

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) HandleReadProjectCluster

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

HandleReadProjectCluster reads a cluster by id

func (*App) HandleReadTemplate

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

HandleReadTemplate reads a given template with name and version field

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) HandleReleaseDeployWebhook

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

HandleReleaseDeployWebhook upgrades a release when a chart specific webhook is called.

func (*App) HandleResolveClusterCandidate

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

HandleResolveClusterCandidate accepts a list of resolving objects (ClusterResolver) for a given ClusterCandidate, which "resolves" that ClusterCandidate and creates a Cluster 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) HandleStreamControllerStatus

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

HandleStreamControllerStatus test calls TODO: Refactor repeated calls.

func (*App) HandleUninstallTemplate

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

HandleUninstallTemplate triggers a chart deployment from a template

func (*App) HandleUpdateProjectCluster

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

HandleUpdateProjectCluster updates a project's cluster

func (*App) HandleUpdateProjectRegistry

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

HandleUpdateProjectRegistry updates a registry

func (*App) HandleUpgradeRelease

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

HandleUpgradeRelease upgrades a release with new values.yaml

type AppConfig

type AppConfig struct {
	DB         *gorm.DB
	Logger     *lr.Logger
	Repository *repository.Repository
	ServerConf config.ServerConf
	RedisConf  *config.RedisConf
	DBConf     config.DBConf

	// TestAgents if API is in testing mode
	TestAgents *TestAgents
}

AppConfig is the configuration required for creating a new App

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 ExchangeRequest

type ExchangeRequest struct {
	AuthorizationCode string `json:"authorization_code"`
}

type ExchangeResponse

type ExchangeResponse struct {
	Token string `json:"token"`
}

type GCRTokenRequestBody

type GCRTokenRequestBody struct {
	ServerURL string `json:"server_url"`
}

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 PorterRelease

type PorterRelease struct {
	*release.Release
	Form *models.FormYAML `json:"form"`
}

PorterRelease is a helm release with a form attached

type RegTokenResponse

type RegTokenResponse struct {
	Token     string     `json:"token"`
	ExpiresAt *time.Time `json:"expires_at"`
}

temp -- token response

type Repo

type Repo struct {
	FullName string
	Kind     string
}

Repo represents a GitHub or Gitab repository

type SendUserExt

type SendUserExt struct {
	ID       uint   `json:"id"`
	Email    string `json:"email"`
	Redirect string `json:"redirect,omitempty"`
}

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