registry

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2021 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultRoleView  = "view"
	DefaultRoleEdit  = "edit"
	DefaultRoleAdmin = "admin"

	DefaultInfraSourceKind = "infra"
)

Functions

func ApplyPermissions

func ApplyPermissions(db *gorm.DB, permissions []Permission) ([]string, error)

func ExportConfig

func ExportConfig(db *gorm.DB) ([]byte, error)

GetConfig serializes a config from the database

func ImportConfig

func ImportConfig(db *gorm.DB, bs []byte) error

func ImportPermissions

func ImportPermissions(db *gorm.DB, permissions []Permission) error

func ImportSources

func ImportSources(db *gorm.DB, sources []Source) error

func NewDB

func NewDB(dbpath string) (*gorm.DB, error)

func NewToken

func NewToken(db *gorm.DB, userID string, token *Token) (secret string, err error)

func Run

func Run(options Options) error

Types

type APIKey

type APIKey struct {
	ID      string `gorm:"primaryKey"`
	Created int64  `json:"created" gorm:"autoCreateTime"`
	Updated int64  `json:"updated" gorm:"autoUpdateTime"`
	Name    string `json:"name" gorm:"unique"`
	Key     string `json:"key"`
}

func (*APIKey) BeforeCreate

func (a *APIKey) BeforeCreate(tx *gorm.DB) (err error)

type Config

type Config struct {
	Sources     []Source     `yaml:"sources"`
	Permissions []Permission `yaml:"permissions"`
}

type DeleteResponse

type DeleteResponse struct {
	Deleted bool `json:"deleted"`
}

type Destination

type Destination struct {
	ID                 string `gorm:"primaryKey"`
	Created            int64  `json:"created" gorm:"autoCreateTime"`
	Updated            int64  `json:"updated" gorm:"autoUpdateTime"`
	Kind               string `json:"kind"`
	Name               string `json:"name"`
	KubernetesCA       string `json:"kubernetesCA"`
	KubernetesEndpoint string `json:"kubernetesEndpoint"`
}

func (*Destination) AfterCreate

func (d *Destination) AfterCreate(tx *gorm.DB) (err error)

func (*Destination) BeforeCreate

func (r *Destination) BeforeCreate(tx *gorm.DB) (err error)

func (*Destination) BeforeDelete

func (d *Destination) BeforeDelete(tx *gorm.DB) (err error)

type ErrorResponse

type ErrorResponse struct {
	Error string `json:"error"`
}

type Handlers

type Handlers struct {
	// contains filtered or unexported fields
}

func (*Handlers) APIKeyMiddleware

func (h *Handlers) APIKeyMiddleware() gin.HandlerFunc

func (*Handlers) AdminMiddleware

func (h *Handlers) AdminMiddleware() gin.HandlerFunc

func (*Handlers) ApiKeyOrTokenMiddleware

func (h *Handlers) ApiKeyOrTokenMiddleware() gin.HandlerFunc

func (*Handlers) CreateCreds

func (h *Handlers) CreateCreds(c *gin.Context)

func (*Handlers) CreateDestination

func (h *Handlers) CreateDestination(c *gin.Context)

func (*Handlers) CreateSource

func (h *Handlers) CreateSource(c *gin.Context)

func (*Handlers) CreateUser

func (h *Handlers) CreateUser(c *gin.Context)

func (*Handlers) DeleteSource

func (h *Handlers) DeleteSource(c *gin.Context)

func (*Handlers) DeleteUser

func (h *Handlers) DeleteUser(c *gin.Context)

func (*Handlers) Healthz

func (h *Handlers) Healthz(c *gin.Context)

func (*Handlers) ListAPIKeys

func (h *Handlers) ListAPIKeys(c *gin.Context)

func (*Handlers) ListDestinations

func (h *Handlers) ListDestinations(c *gin.Context)

func (*Handlers) ListPermissions

func (h *Handlers) ListPermissions(c *gin.Context)

func (*Handlers) ListSources

func (h *Handlers) ListSources(c *gin.Context)

func (*Handlers) ListUsers

func (h *Handlers) ListUsers(c *gin.Context)

func (*Handlers) Login

func (h *Handlers) Login(c *gin.Context)

func (*Handlers) Logout

func (h *Handlers) Logout(c *gin.Context)

func (*Handlers) Signup

func (h *Handlers) Signup(c *gin.Context)

func (*Handlers) TokenMiddleware

func (h *Handlers) TokenMiddleware() gin.HandlerFunc

func (*Handlers) WellKnownJWKs

func (h *Handlers) WellKnownJWKs(c *gin.Context)

type Options

type Options struct {
	DBPath     string
	ConfigPath string
	TLSCache   string
}

type Permission

type Permission struct {
	ID              string      `gorm:"primaryKey"`
	Created         int64       `json:"created" yaml:"-" gorm:"autoCreateTime"`
	Updated         int64       `json:"updated" yaml:"-" gorm:"autoUpdateTime"`
	UserEmail       string      `json:"-" yaml:"user"`
	User            User        `json:"user,omitempty" yaml:"-" gorm:"foreignKey:UserEmail;references:Email"`
	DestinationName string      `json:"-" yaml:"destination"`
	Destination     Destination `json:"destination,omitempty" yaml:"-" gorm:"foreignKey:DestinationName;references:Name"`
	Role            string      `json:"role" yaml:"role"`
	FromConfig      bool        `json:"-" yaml:"-"`
}

func (*Permission) BeforeCreate

func (g *Permission) BeforeCreate(tx *gorm.DB) (err error)

type Settings

type Settings struct {
	ID            string `gorm:"primaryKey"`
	Created       int64  `json:"-" yaml:"-" gorm:"autoCreateTime"`
	Updated       int64  `json:"-" yaml:"-" gorm:"autoUpdateTime"`
	DisableSignup bool   `json:"disableSignup" yaml:"disableSignup,omitempty"`
	PrivateJWK    []byte
	PublicJWK     []byte
}

func (*Settings) BeforeCreate

func (s *Settings) BeforeCreate(tx *gorm.DB) (err error)

func (*Settings) BeforeSave

func (s *Settings) BeforeSave(tx *gorm.DB) error

type Source

type Source struct {
	ID           string `gorm:"primaryKey"`
	Created      int64  `json:"created" yaml:"-" gorm:"autoCreateTime"`
	Updated      int64  `json:"updated" yaml:"-" gorm:"autoUpdateTime"`
	Kind         string `json:"kind" yaml:"kind"`
	Domain       string `json:"domain" yaml:"domain,omitempty" gorm:"unique"`
	ClientID     string `json:"clientID" yaml:"clientID,omitempty"`
	ClientSecret string `json:"-" yaml:"clientSecret,omitempty"`
	ApiToken     string `json:"-" yaml:"apiToken,omitempty"`
	Users        []User `json:"-" yaml:"-" gorm:"many2many:users_sources"`
}

func (*Source) BeforeCreate

func (s *Source) BeforeCreate(tx *gorm.DB) (err error)

func (*Source) BeforeDelete

func (s *Source) BeforeDelete(tx *gorm.DB) error

func (*Source) CreateUser

func (s *Source) CreateUser(db *gorm.DB, user *User, email string, password string) error

CreateUser will create a user and associate them with the source If the user already exists, they will not be created, instead an association will be added instead

func (*Source) DeleteUser

func (s *Source) DeleteUser(db *gorm.DB, u *User) error

Delete will delete a user's association with a source If this is their only source, then the user will be deleted entirely TODO (jmorganca): wrap this in a transaction or at least find out why there seems to cause a bug when used in a nested transaction

func (*Source) SyncUsers

func (s *Source) SyncUsers(db *gorm.DB) error

type Token

type Token struct {
	ID      string `gorm:"primaryKey"`
	Created int64  `json:"created" gorm:"autoCreateTime"`
	Updated int64  `json:"updated" gorm:"autoUpdateTime"`
	Expires int64  `json:"expires"`
	Secret  []byte `json:"-" gorm:"autoCreateTime"`

	UserID string
	User   User `json:"-"`
}

func (*Token) BeforeCreate

func (t *Token) BeforeCreate(tx *gorm.DB) (err error)

func (*Token) CheckSecret

func (t *Token) CheckSecret(secret string) (err error)

type User

type User struct {
	ID       string `gorm:"primaryKey"`
	Created  int64  `json:"created" gorm:"autoCreateTime"`
	Updated  int64  `json:"updated" gorm:"autoUpdateTime"`
	Email    string `json:"email" gorm:"unique"`
	Password []byte `json:"-"`
	Admin    bool   `json:"admin"`

	Sources     []Source     `json:"sources,omitempty" gorm:"many2many:users_sources"`
	Permissions []Permission `json:"permissions,omitempty" gorm:"foreignKey:UserEmail;references:Email"`
}

func (*User) AfterCreate

func (u *User) AfterCreate(tx *gorm.DB) (err error)

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) (err error)

func (*User) BeforeDelete

func (u *User) BeforeDelete(tx *gorm.DB) error

TODO (jmorganca): use foreign constraints instead?

Jump to

Keyboard shortcuts

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