livestore

package
v0.0.5 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeysDependencies

type APIKeysDependencies struct {
	Dependencies
	Connector *Connector
}

APIKeysDependencies APIKeysStore specific dependencies.

type APIKeysStore

type APIKeysStore struct {
	APIKeysDependencies
}

APIKeysStore is a postgres based store for APIKeysStore.

func NewAPIKeysStore

func NewAPIKeysStore(deps APIKeysDependencies) *APIKeysStore

NewAPIKeysStore creates a new APIKeysStore

func (*APIKeysStore) Create

func (a *APIKeysStore) Create(ctx context.Context, key *models.APIKey) (*models.APIKey, error)

Create an apikey.

func (*APIKeysStore) Delete

func (a *APIKeysStore) Delete(ctx context.Context, id int, userID int) error

Delete an apikey.

func (*APIKeysStore) Get

func (a *APIKeysStore) Get(ctx context.Context, id int, userID int) (*models.APIKey, error)

Get an apikey.

func (*APIKeysStore) GetByAPIKeyID

func (a *APIKeysStore) GetByAPIKeyID(ctx context.Context, id string) (*models.APIKey, error)

GetByAPIKeyID an apikey by it's generated id.

func (*APIKeysStore) List

func (a *APIKeysStore) List(ctx context.Context, userID int) ([]*models.APIKey, error)

List will list all apikeys for a user.

type CommandDependencies

type CommandDependencies struct {
	Dependencies
	Connector *Connector
	Vault     providers.Vault
}

CommandDependencies command specific dependencies such as, the repository store. In order to not repeat some SQL, the command store will require the repository store and the repository store will require the command store.

type CommandRunDependencies

type CommandRunDependencies struct {
	Dependencies
	Connector *Connector
}

CommandRunDependencies CommandRunStore specific dependencies.

type CommandRunStore

type CommandRunStore struct {
	CommandRunDependencies
}

CommandRunStore is a postgres based store for CommandRunStore.

func NewCommandRunStore

func NewCommandRunStore(deps CommandRunDependencies) *CommandRunStore

NewCommandRunStore creates a new CommandRunStore

func (*CommandRunStore) CreateRun

func (a *CommandRunStore) CreateRun(ctx context.Context, cmdRun *models.CommandRun) (*models.CommandRun, error)

CreateRun creates a new Command run entry.

func (*CommandRunStore) Get

Get returns a single command run.

func (*CommandRunStore) UpdateRunStatus

func (a *CommandRunStore) UpdateRunStatus(ctx context.Context, id int, status string, outcome string) error

UpdateRunStatus takes an id a status and an outcome and updates a run with it. This is a convenient method around update which breaks the normal update flow so it's easy to call by the providers.

type CommandStore

type CommandStore struct {
	CommandDependencies
}

CommandStore is a postgres based store for commands.

func NewCommandStore

func NewCommandStore(deps CommandDependencies) (*CommandStore, error)

NewCommandStore creates a new CommandStore

func (*CommandStore) AcquireLock

func (s *CommandStore) AcquireLock(ctx context.Context, name string) (io.Closer, error)

AcquireLock acquires a lock on a file so no other process deals with the same file.

func (*CommandStore) AddCommandRelForPlatform

func (s *CommandStore) AddCommandRelForPlatform(ctx context.Context, commandID int, platformID int) 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.

func (*CommandStore) AddCommandRelForRepository

func (s *CommandStore) AddCommandRelForRepository(ctx context.Context, commandID int, repositoryID int) error

AddCommandRelForRepository add an assignment for a command to a repository.

func (*CommandStore) Create

func (s *CommandStore) Create(ctx context.Context, c *models.Command) (*models.Command, error)

Create creates a command record.

func (*CommandStore) CreateSetting

func (s *CommandStore) CreateSetting(ctx context.Context, setting *models.CommandSetting) error

CreateSetting will create a setting for a command.

func (*CommandStore) Delete

func (s *CommandStore) Delete(ctx context.Context, id int) error

Delete will remove a command.

func (*CommandStore) DeleteSetting

func (s *CommandStore) DeleteSetting(ctx context.Context, id int) error

DeleteSetting takes a

func (*CommandStore) Get

func (s *CommandStore) Get(ctx context.Context, id int) (*models.Command, error)

Get returns a command model.

func (*CommandStore) GetByName

func (s *CommandStore) GetByName(ctx context.Context, name string) (*models.Command, error)

GetByName returns a command model by name.

func (*CommandStore) GetSetting

func (s *CommandStore) GetSetting(ctx context.Context, id int) (*models.CommandSetting, error)

GetSetting returns a single setting for an ID.

func (*CommandStore) IsPlatformSupported

func (s *CommandStore) IsPlatformSupported(ctx context.Context, commandID, platformID int) (bool, error)

IsPlatformSupported returns if a command supports a platform or not.

func (*CommandStore) List

func (s *CommandStore) List(ctx context.Context, opts *models.ListOptions) ([]*models.Command, error)

List gets all the command records.

func (*CommandStore) ListSettings

func (s *CommandStore) ListSettings(ctx context.Context, commandID int) ([]*models.CommandSetting, error)

ListSettings lists all settings for a command.

func (*CommandStore) RemoveCommandRelForPlatform

func (s *CommandStore) RemoveCommandRelForPlatform(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.

func (*CommandStore) RemoveCommandRelForRepository

func (s *CommandStore) RemoveCommandRelForRepository(ctx context.Context, commandID int, repositoryID int) error

RemoveCommandRelForRepository remove a relation to a repository for a command.

func (*CommandStore) Update

func (s *CommandStore) Update(ctx context.Context, c *models.Command) (*models.Command, error)

Update modifies a command record.

func (*CommandStore) UpdateSetting

func (s *CommandStore) UpdateSetting(ctx context.Context, setting *models.CommandSetting) error

UpdateSetting updates the value of a setting. Transferring values is not supported. Aka.: If a value was in Vault it must remain in vault. If it was in db it must remain in db. Updating the key is also not supported. Update: Only the value can be modified.

type Config

type Config struct {
	Hostname string
	Database string
	Username string
	Password string
}

Config has the configuration options for the store

type Connector

type Connector struct {
	Config
	Dependencies
}

Connector defines the connector's structure.

func NewDatabaseConnector

func NewDatabaseConnector(cfg Config, deps Dependencies) *Connector

NewDatabaseConnector defines some common functionality between the database dependent providers.

func (*Connector) ExecuteWithTransaction

func (s *Connector) ExecuteWithTransaction(ctx context.Context, log zerolog.Logger, f func(tx pgx.Tx) error) error

ExecuteWithTransaction takes a query and executes it inside a transaction.

func (*Connector) GetDB

func (s *Connector) GetDB() (*sql.DB, error)

GetDB returns the db for the locking mechanism.

type Dependencies

type Dependencies struct {
	Logger    zerolog.Logger
	Converter providers.EnvironmentConverter
}

Dependencies defines the dependencies of this command store

type EventsStore

type EventsStore struct {
	EventsStoreDependencies
}

EventsStore is a postgres based store for eventStorer.

func NewEventsStorer

func NewEventsStorer(deps EventsStoreDependencies) *EventsStore

NewEventsStorer creates a new eventsStore

func (*EventsStore) Create

func (e *EventsStore) Create(ctx context.Context, event *models.Event) (*models.Event, error)

Create an event.

func (*EventsStore) GetEvent

func (e *EventsStore) GetEvent(ctx context.Context, id int) (*models.Event, error)

GetEvent retrieves details about an event.

func (*EventsStore) ListEventsForRepository

func (e *EventsStore) ListEventsForRepository(ctx context.Context, repoID int, options *models.ListOptions) ([]*models.Event, error)

ListEventsForRepository gets paginated list of events for a repository. It does not return the command runs and the payloads to prevent potentially big chunks of transfer data. To get those, one must do a Get.

type EventsStoreDependencies

type EventsStoreDependencies struct {
	Dependencies
	Connector *Connector
}

EventsStoreDependencies eventsStoreStore specific dependencies.

type RepositoryDependencies

type RepositoryDependencies struct {
	Dependencies
	Connector *Connector
	Vault     providers.Vault
}

RepositoryDependencies repository specific dependencies such as, the command store.

type RepositoryStore

type RepositoryStore struct {
	RepositoryDependencies
}

RepositoryStore is a postgres based store for repositories.

func NewRepositoryStore

func NewRepositoryStore(deps RepositoryDependencies) *RepositoryStore

NewRepositoryStore creates a new RepositoryStore

func (*RepositoryStore) Create

Create creates a repository. Upon creating we don't assign any commands yet. So we don't save those here. We do save auth information into the vault.

func (*RepositoryStore) Delete

func (r *RepositoryStore) Delete(ctx context.Context, id int) error

Delete removes a repository and all.

func (*RepositoryStore) Get

Get retrieves a single repository using its ID.

func (*RepositoryStore) GetByName

func (r *RepositoryStore) GetByName(ctx context.Context, name string) (*models.Repository, error)

GetByName retrieves a single repository using its name.

func (*RepositoryStore) List

List all repositories or the ones specified by the filter opts. We are ignoring auth information here.

func (*RepositoryStore) Update

Update can only update the name of the repository. If auth information is updated for the repository, it has to be re-created. Since auth is stored elsewhere.

type UserDependencies

type UserDependencies struct {
	Dependencies
	Connector *Connector
	APIKeys   providers.APIKeysStorer
	Time      providers.Clock
}

UserDependencies user specific dependencies.

type UserStore

type UserStore struct {
	UserDependencies
}

UserStore is a postgres based store for users.

func NewUserStore

func NewUserStore(deps UserDependencies) *UserStore

NewUserStore creates a new UserStore

func (*UserStore) Create

func (s *UserStore) Create(ctx context.Context, user *models.User) (*models.User, error)

Create saves a user in the db.

func (*UserStore) Delete

func (s *UserStore) Delete(ctx context.Context, id int) error

Delete deletes a user from the db.

func (*UserStore) Get

func (s *UserStore) Get(ctx context.Context, id int) (*models.User, error)

Get retrieves a user.

func (*UserStore) GetByEmail

func (s *UserStore) GetByEmail(ctx context.Context, email string) (*models.User, error)

GetByEmail retrieves a user by its email address.

func (*UserStore) List

func (s *UserStore) List(ctx context.Context) ([]*models.User, error)

List all users. This will not return api keys. For those we need an explicit get.

func (*UserStore) Update

func (s *UserStore) Update(ctx context.Context, user *models.User) (*models.User, error)

Update updates a user with a given email address.

Jump to

Keyboard shortcuts

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