key
v1.1.1
Documentation
pkg.go.dev ↗Package key providers the database.Model implementation for the Key entity.
Functions
InitEvent
func InitEvent(dis event.Dispatcher) queue.InitFunc
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.
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
Event
type Event struct {
Key *Key
Action string
// contains filtered or unexported fields
}
Event.Name
func (ev *Event) Name() string
Event.Perform
func (ev *Event) Perform() error
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.
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.
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.
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.
FromContext
func FromContext(ctx context.Context) (*Key, bool)
FromContext returns the Key model from the given context, if any.
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.
Key.Endpoint
func (k *Key) Endpoint(uri ...string) string
Key.IsZero
func (k *Key) IsZero() bool
IsZero implements the database.Model interface.
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.
Key.Primary
func (k *Key) Primary() (string, int64)
Primary implements the database.Model interface.
Key.SetPrimary
func (k *Key) SetPrimary(id int64)
SetPrimary implements the database.Model interface.
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.
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.
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.
NewStoreWithCrypto
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.
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.
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.
Store.Chown
func (s *Store) Chown(from, to int64) error
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.
Store.Delete
func (s *Store) Delete(ids ...int64) error
Delete removes all of the keys from the database with the given list of ids.
Store.Get
func (s *Store) Get(opts ...query.Option) (*Key, error)
Get returns a single Key model, applying each query.Option that is given.
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
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.
Store.New
func (s *Store) New() *Key
New returns a new Key binding any non-nil models to it from the current Store.
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.
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.