providers

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// UserPersonalTokenLength is the length of the generated user personal access tokens.
	UserPersonalTokenLength = 60
)

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeysAuthenticator

type APIKeysAuthenticator interface {
	// Match matches a given user's api keys with the stored ones.
	Match(ctx context.Context, key *models.APIKey) error
	// Encrypt takes an api key secret and encrypts it for storage.
	Encrypt(ctx context.Context, secret []byte) ([]byte, error)
	// Generate a secret and a key ID pair. Returns the secret unencrypted for showing,
	// but does save it encrypted.
	Generate(ctx context.Context, name string, userID int) (*models.APIKey, error)
}

APIKeysAuthenticator deals with authenticating api keys.

type APIKeysHandler

type APIKeysHandler interface {
	Create() echo.HandlerFunc
	Delete() echo.HandlerFunc
	Get() echo.HandlerFunc
	List() echo.HandlerFunc
}

APIKeysHandler provides functions which define operations on api key pairs.

type APIKeysStorer

type APIKeysStorer interface {
	// Create an apikey.
	Create(ctx context.Context, key *models.APIKey) (*models.APIKey, error)
	// Delete an apikey.
	Delete(ctx context.Context, id int, userID int) error
	// List will list all apikeys for a user.
	List(ctx context.Context, userID int) ([]*models.APIKey, error)
	// Get an apikey.
	Get(ctx context.Context, id int, userID int) (*models.APIKey, error)
	// GetByAPIKeyID an apikey by apikeyid.
	GetByAPIKeyID(ctx context.Context, id string) (*models.APIKey, error)
}

APIKeysStorer defines operations that an api key provider must have

type AuthHandler

type AuthHandler interface {
	OAuthLogin() echo.HandlerFunc
	OAuthCallback() echo.HandlerFunc
	Refresh() echo.HandlerFunc
}

AuthHandler provides the handler functions for the authentication flow.

type Clock

type Clock interface {
	Now() time.Time
}

Clock wraps time based functions for mocking.

type CommandHandler

type CommandHandler interface {
	Create() echo.HandlerFunc
	Upload() echo.HandlerFunc
	Delete() echo.HandlerFunc
	Get() echo.HandlerFunc
	List() echo.HandlerFunc
	Update() echo.HandlerFunc

	// AddCommandRelForRepository adds an entry for this command id to the given repositoryID.
	AddCommandRelForRepository() echo.HandlerFunc
	// RemoveCommandRelForRepository remove a relation to a repository for a command.
	RemoveCommandRelForRepository() echo.HandlerFunc

	// AddCommandRelForPlatform adds an entry for this command id to the given platform id.
	AddCommandRelForPlatform() echo.HandlerFunc
	// RemoveCommandRelForPlatform remove a relation to a platform for a command.
	RemoveCommandRelForPlatform() echo.HandlerFunc
}

CommandHandler defines the actions of commands.

type CommandRunHandler

type CommandRunHandler interface {
	GetCommandRun() echo.HandlerFunc
}

CommandRunHandler deals with command run details.

type CommandRunStorer

type CommandRunStorer interface {
	CreateRun(ctx context.Context, run *models.CommandRun) (*models.CommandRun, error)
	UpdateRunStatus(ctx context.Context, id int, status string, outcome string) error
	Get(ctx context.Context, id int) (*models.CommandRun, error)
}

CommandRunStorer will store and update individual command run details and progress.

type CommandSettingsHandler

type CommandSettingsHandler interface {
	Create() echo.HandlerFunc
	Delete() echo.HandlerFunc
	Get() echo.HandlerFunc
	List() echo.HandlerFunc
	Update() echo.HandlerFunc
}

CommandSettingsHandler defines the actions of command settings.

type CommandStorer

type CommandStorer interface {
	Create(ctx context.Context, c *models.Command) (*models.Command, error)
	Get(ctx context.Context, id int) (*models.Command, error)
	GetByName(ctx context.Context, name string) (*models.Command, error)
	Delete(ctx context.Context, id int) error
	Update(ctx context.Context, c *models.Command) (*models.Command, error)
	List(ctx context.Context, opts *models.ListOptions) ([]*models.Command, error)

	// AddCommandRelForRepository adds an entry for this command id to the given repositoryID.
	AddCommandRelForRepository(ctx context.Context, commandID int, repositoryID int) error
	// RemoveCommandRelForRepository remove a relation to a repository for a command.
	RemoveCommandRelForRepository(ctx context.Context, commandID int, repositoryID int) error

	// AcquireLock creates a lock entry for a name
	AcquireLock(ctx context.Context, name string) (io.Closer, error)

	CreateSetting(ctx context.Context, settings *models.CommandSetting) error
	DeleteSetting(ctx context.Context, id int) error
	ListSettings(ctx context.Context, commandID int) ([]*models.CommandSetting, error)
	GetSetting(ctx context.Context, id int) (*models.CommandSetting, error)
	UpdateSetting(ctx context.Context, setting *models.CommandSetting) error

	// AddCommandRelForPlatform adds a relationship for a platform on a command. This means
	// that this command will support this platform. If the relationship doesn't exist
	// this command will not run on that platform.
	AddCommandRelForPlatform(ctx context.Context, commandID int, platformID int) error
	// RemoveCommandRelForPlatform removes the above relationship, disabling this command
	// for that platform. Meaning this command will not be executed if that platform is
	// detected.
	RemoveCommandRelForPlatform(ctx context.Context, commandID int, platformID int) error
	// IsPlatformSupported returns if a command supports a platform or not.
	IsPlatformSupported(ctx context.Context, commandID, platformID int) (bool, error)
}

CommandStorer handles CRUD operations for commands.

type Email

type Email interface {
	Notify(email string, event Event, payload Payload) error
}

Email defines an email sending provider's capabilities.

type EnvironmentConverter

type EnvironmentConverter interface {
	// LoadValueFromFile provides the ability to load a secret from a docker
	// mounted secret file if the value contains `/run/secret`.
	LoadValueFromFile(f string) (string, error)
}

EnvironmentConverter provides an option to parse the environment. This is needed in case we are running in a docker swarm where secrets come from a mounted file instead of an environment variable.

type Event

type Event string

Event is an event type when a notification is sent out.

type EventHandler

type EventHandler interface {
	List() echo.HandlerFunc
	Get() echo.HandlerFunc
}

EventHandler defines a handler for repository events.

type EventsStorer

type EventsStorer interface {
	Create(ctx context.Context, event *models.Event) (*models.Event, error)
	ListEventsForRepository(ctx context.Context, repoID int, options *models.ListOptions) ([]*models.Event, error)
	GetEvent(ctx context.Context, eventID int) (*models.Event, error)
}

EventsStorer will store events.

type Executor

type Executor interface {
	// CreateRun creates a run for an event.
	// The created run will have to be saved somehow. This is up to the implementation.
	// It MUST use the Event's ID as identification because that's what defines/holds
	// the currently running commands. The loose coupling between a run and the commands
	// is the event. So to cancel a Run, the user will provide the Event's ID.
	CreateRun(ctx context.Context, event *models.Event, commands []*models.Command) error
	// CancelRun will cancel a run and mark all commands as cancelled.
	// The ID here is the ID of the event corresponding to this run.
	CancelRun(ctx context.Context, id int) error
}

Executor manages runs regarding events for repositories.

type Generator

type Generator struct{}

Generator defines a wrapper for uuid generator for testing purposes.

func NewUUIDGenerator

func NewUUIDGenerator() *Generator

NewUUIDGenerator creates a new Generator.

func (*Generator) Generate

func (u *Generator) Generate() (string, error)

Generate will generate a unique ID for a resource.

type HookHandler

type HookHandler interface {
	// HandleHooks handles all hooks incoming to Krok.
	HandleHooks() echo.HandlerFunc
}

HookHandler represents what the Krok server is capable off.

type Hooks

type Hooks interface {
	// Execute will be called for the command which can be executed.
	// opts is a variable number of arguments which can be given to a hook.
	// exp.: Environment properties, auth information, tokens, etc.
	Execute(ctx context.Context, raw string, opts ...interface{}) (string, bool, error)
}

Hooks defines what the hooks can do, which is mostly just Execute. Gets the raw payload return outcome, success, error

type KrokClock

type KrokClock struct{}

KrokClock defines a clock for Krok for testing purposes.

func NewClock

func NewClock() *KrokClock

NewClock creates a new KrokClock.

func (*KrokClock) Now

func (*KrokClock) Now() time.Time

Now gets the current time.

type OAuthAuthenticator

type OAuthAuthenticator interface {
	GetAuthCodeURL(state string) string
	Exchange(ctx context.Context, code string) (*oauth2.Token, error)
	GenerateState(redirectURL string) (string, error)
	VerifyState(rawToken string) (string, error)
}

OAuthAuthenticator handles user authentication via OAuth2.

type Payload

type Payload string

Payload is a payload that is sent by an email.

type Platform

type Platform interface {
	// CreateHook creates a hook for the respective platform.
	// Events define the events this hook subscribes to. Since we don't want all hooks
	// to subscribe to all events all the time, we provide the option to the user
	// to select the events.
	CreateHook(ctx context.Context, repo *models.Repository) error
	// ValidateRequest will take a hook and verify it being a valid hook request according to
	// platform rules.
	ValidateRequest(ctx context.Context, r *http.Request, repoID int) error
	// GetEventID Based on the platform, retrieve the ID of the event.
	GetEventID(ctx context.Context, r *http.Request) (string, error)
}

Platform defines what a platform should be able to do in order for it to work with hooks. Once a provider is selected when creating a repository given the right authorization the platform provider will create the hook on this repository.

type PlatformTokenProvider

type PlatformTokenProvider interface {
	GetTokenForPlatform(vcs int) (string, error)
	SaveTokenForPlatform(token string, vcs int) error
}

PlatformTokenProvider defines the operations a token provider must perform. A single platform will manage a single token for now. Later maybe we'll provider the ability to handle multiple tokens.

type Plugins

type Plugins interface {
	Create(ctx context.Context, src string) (string, string, error)
	Delete(ctx context.Context, name string) error
}

Plugins handles create and delete events on the file system for concrete plugins / commands.

type Ready added in v0.0.4

type Ready interface {
	Ready(ctx context.Context) bool
}

Ready provides a ready check for Krok.

type ReadyHandler added in v0.0.4

type ReadyHandler interface {
	Ready() echo.HandlerFunc
}

ReadyHandler provides a ready handler for the ready provider.

type RepositoryAuth

type RepositoryAuth interface {
	// GetRepositoryAuth returns auth data for a repository.
	GetRepositoryAuth(ctx context.Context, id int) (*models.Auth, error)
	// CreateRepositoryAuth creates auth data for a repository in vault.
	CreateRepositoryAuth(ctx context.Context, repositoryID int, info *models.Auth) error
}

RepositoryAuth defines the capabilities of a repository authentication storage framework.

type RepositoryHandler

type RepositoryHandler interface {
	Create() echo.HandlerFunc
	Delete() echo.HandlerFunc
	Get() echo.HandlerFunc
	List() echo.HandlerFunc
	Update() echo.HandlerFunc
}

RepositoryHandler defines the handler's capabilities. The handler is a front wrapper for database operations, but also provides additional abilities, i.e.: generate a unique url

type RepositoryStorer

type RepositoryStorer interface {
	Create(ctx context.Context, c *models.Repository) (*models.Repository, error)
	Get(ctx context.Context, id int) (*models.Repository, error)
	GetByName(ctx context.Context, name string) (*models.Repository, error)
	Delete(ctx context.Context, id int) error
	Update(ctx context.Context, c *models.Repository) (*models.Repository, error)
	List(ctx context.Context, opt *models.ListOptions) ([]*models.Repository, error)
}

RepositoryStorer handles operations for repositories and relationship to commands.

type SupportedPlatformListHandler

type SupportedPlatformListHandler interface {
	ListSupportedPlatforms() echo.HandlerFunc
}

SupportedPlatformListHandler lists all supported platforms.

type Tar

type Tar interface {
	// Untar will untar the contents of a reader.
	Untar(dst string, reader io.Reader) error
}

Tar provides functionality to untar an uploaded tar.gz.

type TokenHandler

type TokenHandler interface {
	TokenHandler() echo.HandlerFunc
}

TokenHandler provides operations to get and validation JWT tokens.

type TokenIssuer

type TokenIssuer interface {
	Create(token *models.User) (*oauth2.Token, error)
	Refresh(ctx context.Context, refreshToken string) (*oauth2.Token, error)
}

TokenIssuer handles creation of user authentication tokens.

type UUIDGenerator

type UUIDGenerator interface {
	Generate() (string, error)
}

UUIDGenerator generates UUIDs.

type UserHandler

type UserHandler interface {
	GetUser() echo.HandlerFunc
	ListUsers() echo.HandlerFunc
	DeleteUser() echo.HandlerFunc
	UpdateUser() echo.HandlerFunc
	CreateUser() echo.HandlerFunc
}

UserHandler defines operations for the users.

type UserMiddleware

type UserMiddleware interface {
	JWT() echo.MiddlewareFunc
}

UserMiddleware provides UserMiddleware authentication capabilities.

type UserStorer

type UserStorer interface {
	Create(ctx context.Context, c *models.User) (*models.User, error)
	Delete(ctx context.Context, id int) error
	List(ctx context.Context) ([]*models.User, error)
	Get(ctx context.Context, id int) (*models.User, error)
	GetByEmail(ctx context.Context, email string) (*models.User, error)
	Update(ctx context.Context, user *models.User) (*models.User, error)
}

UserStorer handles CRUD operations for users.

type VCSTokenHandler

type VCSTokenHandler interface {
	Create() echo.HandlerFunc
}

VCSTokenHandler provides operations to manage tokens for the various platforms..

type Vault

type Vault interface {
	// LoadSecrets unlocks the vault and loads in all secrets.
	LoadSecrets() error
	// ListSecrets lists all secret names. Not the values.
	ListSecrets() []string
	// SaveSecrets saves all the secrets to the vault. Persisting new values.
	SaveSecrets() error
	// AddSecret adds a value to the vault.
	AddSecret(key string, value []byte)
	// DeleteSecret deletes a secret from the vault.
	DeleteSecret(key string)
	// GetSecret returns a single secret's value from the vault.
	GetSecret(key string) ([]byte, error)
}

Vault defines the capabilities of the vault storage.

type VaultHandler

type VaultHandler interface {
	GetSecret() echo.HandlerFunc
	ListSecrets() echo.HandlerFunc
	DeleteSecret() echo.HandlerFunc
	UpdateSecret() echo.HandlerFunc
	CreateSecret() echo.HandlerFunc
}

VaultHandler defines operations for the secure vault.

type VaultStorer

type VaultStorer interface {
	// Init initializes the medium by creating the file, or bootstrapping the
	// db or simply setting up an in-memory mock storage device. The Init
	// function of a storage medium should be idempotent. Meaning it should
	// be callable multiple times without changing the underlying medium.
	Init() error
	// Read will read bytes from the storage medium and return it to the caller.
	Read() (data []byte, err error)
	// Write will store the passed in data. How, is up to the implementor. Syncing
	// is up the caller. Otherwise data will be overwritten.
	Write(data []byte) error
}

VaultStorer defines the interface for storing things in the vault. This can be any kind of store which supports these operations.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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