key

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package key providers the database.Model implementation for the Key entity.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitEvent added in v1.1.0

func InitEvent(dis event.Dispatcher) queue.InitFunc

func LoadRelations

func LoadRelations(loaders *database.Loaders, kk ...*Key) error

LoadRelations loads all of the available relations for the given Key models using the given loaders available.

func Model

func Model(kk []*Key) func(int) database.Model

Model is called along with database.ModelSlice to convert the given slice of Key models to a slice of database.Model interfaces.

Types

type Event added in v1.1.0

type Event struct {
	Key    *Key
	Action string
	// contains filtered or unexported fields
}

func (*Event) Name added in v1.1.0

func (ev *Event) Name() string

func (*Event) Perform added in v1.1.0

func (ev *Event) Perform() error

type Form

type Form struct {
	namespace.Resource

	Key        *Key   `schema:"-"`
	Keys       *Store `schema:"-"`
	Name       string `schema:"name"   json:"name"`
	PrivateKey string `schema:"key"    json:"key"`
	Config     string `schema:"config" json:"config"`
}

Form is the type that represents input data for adding a new SSH key.

func (Form) Fields

func (f Form) Fields() map[string]string

Fields returns a map containing the namespace, name, key, and config fields from the original Form.

func (Form) Validate

func (f Form) Validate() error

Validate checks to see if there is a name for the key, and if that name is unique to the namespace it is being added to or, to the user adding the key. It then checks to see if the key itself is a valid SSH private key.

type Key

type Key struct {
	ID          int64         `db:"id"`
	UserID      int64         `db:"user_id"`
	AuthorID    int64         `db:"author_id"`
	NamespaceID sql.NullInt64 `db:"namespace_id"`
	Name        string        `db:"name"`
	Key         []byte        `db:"key"`
	Config      string        `db:"config"`
	CreatedAt   time.Time     `db:"created_at"`
	UpdatedAt   time.Time     `db:"updated_at"`

	Author    *user.User           `db:"-"`
	User      *user.User           `db:"-"`
	Namespace *namespace.Namespace `db:"-"`
}

Key is the type that represents an SSH key that can be placed in the build environment.

func FromContext

func FromContext(ctx context.Context) (*Key, bool)

FromContext returns the Key model from the given context, if any.

func (*Key) Bind

func (k *Key) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User or namespace.Namespace.

func (*Key) Endpoint

func (k *Key) Endpoint(uri ...string) string

func (*Key) IsZero

func (k *Key) IsZero() bool

IsZero implements the database.Model interface.

func (*Key) JSON

func (k *Key) JSON(addr string) map[string]interface{}

JSON implements the database.Model interface. This will return a map with the current Image values under each key. If any of the User, or Namespace bound models exist on the Artifact, then the JSON representation of these models will be in the returned map, under the user, and namespace keys respectively.

func (*Key) Primary

func (k *Key) Primary() (string, int64)

Primary implements the database.Model interface.

func (*Key) SetPrimary

func (k *Key) SetPrimary(id int64)

SetPrimary implements the database.Model interface.

func (*Key) Values

func (k *Key) Values() map[string]interface{}

Values implements the database.Model interface. This will return a map with the following values, user_id, namespace_id, name, key, and config.

type Store

type Store struct {
	database.Store

	// User is the bound user.User model. If not nil this will bind the
	// user.User model to any Image models that are created. If not nil this
	// will append a WHERE clause on the user_id column for all SELECT queries
	// performed.
	User *user.User

	// Namespace is the bound namespace.Namespace model. If not nil this will
	// bind the namespace.Namespace model to any Image models that are created.
	// If not nil this will append a WHERE clause on the namespace_id column for
	// all SELECT queries performed.
	Namespace *namespace.Namespace
	// contains filtered or unexported fields
}

Store is the type for creating and modifying Key models in the database. The Store type can have an underlying crypto.AESGCM for encrypting the SSH keys that are stored.

func NewStore

func NewStore(db *sqlx.DB, mm ...database.Model) *Store

NewStore returns a new Store for querying the keys table. Each model passed to this function will be bound to the returned Store.

func NewStoreWithCrypto added in v1.1.0

func NewStoreWithCrypto(db *sqlx.DB, crypto *crypto.AESGCM, mm ...database.Model) *Store

NewStoreWithCrypto is functionally the same as NewStore, however it sets the crypto.AESGCM to use on the returned Store. This will allow for encryption of keys during creation.

func (*Store) All

func (s *Store) All(opts ...query.Option) ([]*Key, error)

All returns a slice of Key models, applying each query.Option that is given.

func (*Store) Bind

func (s *Store) Bind(mm ...database.Model)

Bind implements the database.Binder interface. This will only bind the model if they are pointers to either user.User or namespace.Namespace.

func (*Store) Chown

func (s *Store) Chown(from, to int64) error

func (*Store) Create

func (s *Store) Create(authorId int64, name, key, config string) (*Key, error)

Create creates a new key with the given name and config. The given key string should be the contents of the key itself, this will be encrypted with the underlying crypto.AESGCM that is set on the Store. If no crypto.AESGCM is set on the Store then this will error.

func (*Store) Delete

func (s *Store) Delete(ids ...int64) error

Delete removes all of the keys from the database with the given list of ids.

func (*Store) Get

func (s *Store) Get(opts ...query.Option) (*Key, error)

Get returns a single Key model, applying each query.Option that is given.

func (*Store) Index

func (s *Store) Index(vals url.Values, opts ...query.Option) ([]*Key, database.Paginator, error)

Index returns the paginated results from the keys table depending on the values that are present in url.Values. Detailed below are the values that are used from the given url.Values,

search - This applies the database.Search query.Option using the value of name

func (*Store) Load

func (s *Store) Load(key string, vals []interface{}, load database.LoaderFunc) error

Load loads in a slice of Key models where the given key is in the list of given vals. Each database is loaded individually via a call to the given load callback. This method calls Store.All under the hood, so any bound models will impact the models being loaded.

func (*Store) New

func (s *Store) New() *Key

New returns a new Key binding any non-nil models to it from the current Store.

func (*Store) Paginate

func (s *Store) Paginate(page int64, opts ...query.Option) (database.Paginator, error)

Paginate returns the database.Paginator for the keys table for the given page.

func (*Store) Update

func (s *Store) Update(id int64, config string) error

Update updates the key with the given id, and set's the new namespace for the key, and the new config to use.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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