models

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const MaxFiles = 10000

Variables

View Source
var ErrAccessDenied = errors.New("access denied")
View Source
var ErrAppNotFound = errors.New("app not found")
View Source
var ErrAppUsedID = errors.New("used app ID")
View Source
var ErrCertificateDataLocked = errors.New("cert locked")
View Source
var ErrCertificateDataNotFound = errors.New("cert data not found")
View Source
var ErrDeploymentAlreadyUploaded = errors.New("deployment is already uploaded")
View Source
var ErrDeploymentExpired = errors.New("deployment expired")
View Source
var ErrDeploymentNotFound = errors.New("deployment not found")
View Source
var ErrDeploymentNotUploaded = errors.New("deployment is not uploaded")
View Source
var ErrDeploymentUsedName = errors.New("used deployment name")
View Source
var ErrDomainNotFound = errors.New("domain not found")
View Source
var ErrDomainUsedName = errors.New("used domain name")
View Source
var ErrInvalidCredentials = errors.New("invalid credentials")
View Source
var ErrSiteNotFound = errors.New("site not found")
View Source
var ErrUndefinedDomain = errors.New("undefined domain")
View Source
var ErrUndefinedSite = errors.New("undefined site")
View Source
var ErrUserNotFound = errors.New("user not found")

Functions

func DetectContentType

func DetectContentType(fileName string, initialBytes []byte) string

func RandomID

func RandomID(n int) string

Types

type App

type App struct {
	ID          string            `json:"id" db:"id"`
	CreatedAt   time.Time         `json:"createdAt" db:"created_at"`
	UpdatedAt   time.Time         `json:"updatedAt" db:"updated_at"`
	DeletedAt   *time.Time        `json:"deletedAt" db:"deleted_at"`
	OwnerUserID string            `json:"ownerUserID" db:"owner_user_id"`
	Config      *config.AppConfig `json:"config" db:"config"`
}

func NewApp

func NewApp(now time.Time, id string, ownerUserID string) *App

func (*App) CheckAuthz

func (a *App) CheckAuthz(level config.AccessLevel, userID string, credentials []CredentialID) (*AppAuthzResult, error)

func (*App) CredentialIndexKeys

func (a *App) CredentialIndexKeys() []CredentialIndexKey

type AppAuthzResult

type AppAuthzResult struct {
	CredentialID CredentialID
	Rule         *config.ACLSubjectRule // nil => is owner
}

func CheckACLAuthz

func CheckACLAuthz(access config.ACL, credentials []CredentialID) (*AppAuthzResult, error)

func (*AppAuthzResult) MatchedRule

func (i *AppAuthzResult) MatchedRule() string

type CertDataEntry

type CertDataEntry struct {
	Key       string    `db:"key"`
	UpdatedAt time.Time `db:"updated_at"`
	Value     string    `db:"value"`
}

func NewCertDataEntry

func NewCertDataEntry(key string, value string, now time.Time) *CertDataEntry

type CredentialID

type CredentialID string

func CredentialGitHubRepositoryActions

func CredentialGitHubRepositoryActions(repo string) CredentialID

func CredentialGitHubUser

func CredentialGitHubUser(username string) CredentialID

func CredentialIP

func CredentialIP(ip string) CredentialID

func CredentialUserID

func CredentialUserID(id string) CredentialID

func (CredentialID) Matches

func (c CredentialID) Matches(r *config.ACLSubjectRule) bool

type CredentialIDKind

type CredentialIDKind string
const (
	CredentialIDKindUserID              CredentialIDKind = ""
	CredentialIDKindGitHubUser          CredentialIDKind = "github"
	CredentialIDGitHubRepositoryActions CredentialIDKind = "github-repo-actions"
	CredentialIDIP                      CredentialIDKind = "ip"
)

type CredentialIndexKey

type CredentialIndexKey string

func CollectCredentialIDIndexKeys

func CollectCredentialIDIndexKeys(ids []CredentialID) []CredentialIndexKey

func MakeCredentialIDIndexKeys

func MakeCredentialIDIndexKeys(id CredentialID) []CredentialIndexKey

func MakeCredentialRuleIndexKeys

func MakeCredentialRuleIndexKeys(r *config.ACLSubjectRule) []CredentialIndexKey

type Deployment

type Deployment struct {
	ID        string     `json:"id" db:"id"`
	CreatedAt time.Time  `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time  `json:"updatedAt" db:"updated_at"`
	DeletedAt *time.Time `json:"deletedAt" db:"deleted_at"`

	Name  string `json:"name" db:"name"`
	AppID string `json:"appID" db:"app_id"`

	StorageKeyPrefix string              `json:"-" db:"storage_key_prefix"`
	Metadata         *DeploymentMetadata `json:"metadata" db:"metadata"`
	UploadedAt       *time.Time          `json:"uploadedAt" db:"uploaded_at"`
	ExpireAt         *time.Time          `json:"expireAt" db:"expire_at"`
}

func NewDeployment

func NewDeployment(
	now time.Time,
	name string,
	appID string,
	storageKeyPrefix string,
	metadata *DeploymentMetadata,
) *Deployment

func (*Deployment) CheckAlive

func (d *Deployment) CheckAlive(now time.Time) error

func (*Deployment) IsExpired

func (d *Deployment) IsExpired(now time.Time) bool

type DeploymentMetadata

type DeploymentMetadata struct {
	Files  []FileEntry       `json:"files,omitempty"`
	Config config.SiteConfig `json:"config"`
}

func (*DeploymentMetadata) Scan

func (m *DeploymentMetadata) Scan(val any) error

func (*DeploymentMetadata) Value

func (m *DeploymentMetadata) Value() (driver.Value, error)

type Domain added in v0.5.0

type Domain struct {
	ID        string     `json:"id" db:"id"`
	CreatedAt time.Time  `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time  `json:"updatedAt" db:"updated_at"`
	DeletedAt *time.Time `json:"deletedAt" db:"deleted_at"`
	Domain    string     `json:"domain" db:"domain"`
	AppID     string     `json:"appID" db:"app_id"`
	SiteName  string     `json:"siteName" db:"site_name"`
}

func NewDomain added in v0.5.0

func NewDomain(now time.Time, domain string, appID string, siteName string) *Domain

type FileEntry

type FileEntry struct {
	Path        string `json:"path" validate:"required,max=256"` // Directory has trailing slash in path
	Size        int64  `json:"size" validate:"required,gte=0"`
	Hash        string `json:"hash" validate:"required,max=100"`
	ContentType string `json:"contentType" validate:"required,max=100"`
}

type Site

type Site struct {
	ID           string     `json:"id" db:"id"`
	AppID        string     `json:"appID" db:"app_id"`
	Name         string     `json:"name" db:"name"`
	CreatedAt    time.Time  `json:"createdAt" db:"created_at"`
	UpdatedAt    time.Time  `json:"updatedAt" db:"updated_at"`
	DeletedAt    *time.Time `json:"deletedAt" db:"deleted_at"`
	DeploymentID *string    `json:"deploymentID" db:"deployment_id"`
}

func NewSite

func NewSite(now time.Time, appID string, name string) *Site

type TokenClaims

type TokenClaims struct {
	Name        string         `json:"name,omitempty"`
	Credentials []CredentialID `json:"credentials,omitempty"`
	jwt.RegisteredClaims
}

func NewTokenClaims

func NewTokenClaims(sub TokenSubject, name string) *TokenClaims

type TokenSubject

type TokenSubject string

func TokenSubjectGitHubActions

func TokenSubjectGitHubActions(jti string) TokenSubject

func TokenSubjectUser

func TokenSubjectUser(id string) TokenSubject

func (TokenSubject) Parse

func (s TokenSubject) Parse() (TokenSubjectKind, string, bool)

type TokenSubjectKind

type TokenSubjectKind string
const (
	TokenSubjectKindUser          TokenSubjectKind = ""
	TokenSubjectKindGitHubActions TokenSubjectKind = "github-actions"
)

func (TokenSubjectKind) IsValid

func (k TokenSubjectKind) IsValid() bool

type User

type User struct {
	ID        string     `json:"id" db:"id"`
	CreatedAt time.Time  `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time  `json:"updatedAt" db:"updated_at"`
	DeletedAt *time.Time `json:"deletedAt" db:"deleted_at"`
	Name      string     `json:"name" db:"name"`
}

func NewUser

func NewUser(now time.Time, name string) *User

type UserCredential

type UserCredential struct {
	ID        CredentialID        `json:"id" db:"id"`
	CreatedAt time.Time           `json:"createdAt" db:"created_at"`
	UpdatedAt time.Time           `json:"updatedAt" db:"updated_at"`
	DeletedAt *time.Time          `json:"deletedAt" db:"deleted_at"`
	UserID    string              `json:"userID" db:"user_id"`
	Data      *UserCredentialData `json:"data" db:"data"`
}

func NewUserCredential

func NewUserCredential(now time.Time, userID string, id CredentialID, data *UserCredentialData) *UserCredential

type UserCredentialData

type UserCredentialData struct {
	KeyFingerprint string `json:"keyFingerprint,omitempty"`
}

func (*UserCredentialData) Scan

func (d *UserCredentialData) Scan(val any) error

func (*UserCredentialData) Value

func (d *UserCredentialData) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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