database

package
v0.16.2 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ER_ACCESS_DENIED_ERROR = 1045
	ER_DUP_ENTRY           = 1062
)
View Source
const (
	DefaultBranch          = "mainline"
	DefaultCompressionALGO = "zstd"
	DefaultHashALGO        = "BLAKE3"
	DeletedSuffix          = ".deleted"
	Dot                    = "."
	DotDot                 = ".."
	DotZeta                = ".zeta"
)
View Source
const (
	PrivateNamespace = 1
	GroupNamespace   = 2
)
View Source
const (
	PrivateRepository   = 0
	InternalRepository  = 10
	PublicRepository    = 20
	AnonymousRepository = 30
)

Variables

View Source
var (
	ErrReferenceNotAllowed = errors.New("reference types not allowed")
	ErrUserNotGiven        = errors.New("user not given")
)

Functions

func IsDupEntry

func IsDupEntry(err error) bool

func IsErrAlreadyLocked

func IsErrAlreadyLocked(err error) bool

func IsErrExist

func IsErrExist(err error) bool

func IsErrNamingRule

func IsErrNamingRule(err error) bool

func IsErrRevisionNotFound

func IsErrRevisionNotFound(err error) bool

func IsErrorCode

func IsErrorCode(err error, code uint16) bool

func IsNotFound

func IsNotFound(err error) bool

Types

type AccessLevel

type AccessLevel int
const (
	NoneAccess     AccessLevel = 0
	ReporterAccess AccessLevel = 20
	DevAccess      AccessLevel = 30
	MasterAccess   AccessLevel = 40
	OwnerAccess    AccessLevel = 50
)

func (AccessLevel) Readable

func (accessLevel AccessLevel) Readable() bool

func (AccessLevel) Sudo

func (accessLevel AccessLevel) Sudo() bool

func (AccessLevel) Writeable

func (accessLevel AccessLevel) Writeable() bool

type Branch

type Branch struct {
	Name            string    `json:"name"`
	ID              int64     `json:"id"`
	RID             int64     `json:"rid"`
	Hash            string    `json:"hash"`
	ProtectionLevel int       `json:"protection_level"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

type Command

type Command struct {
	ReferenceName plumbing.ReferenceName `json:"reference_name"`
	OldRev        string                 `json:"old_rev"`
	NewRev        string                 `json:"new_rev"`
	Subject       string                 `json:"subject,"`
	Description   string                 `json:"description"`
	RID           int64                  `json:"rid"`
	UID           int64                  `json:"uid"`
}

type DB

type DB interface {
	Database() *sql.DB
	FindUser(ctx context.Context, uid int64) (*User, error)
	SearchUser(ctx context.Context, emailOrName string) (*User, error)
	SearchKey(ctx context.Context, fingerprint string) (*Key, error)
	NewUser(ctx context.Context, u *User) (*User, error)
	AddMember(ctx context.Context, m *Member) error
	FindKey(ctx context.Context, id int64) (*Key, error)
	AddKey(ctx context.Context, k *Key) (*Key, error)
	IsDeployKeyEnabled(ctx context.Context, rid int64, kid int64) (bool, error)
	FindNamespaceByID(ctx context.Context, namespaceID int64) (*Namespace, error)
	FindNamespaceByPath(ctx context.Context, namespacePath string) (*Namespace, error)
	FindRepositoryByID(ctx context.Context, rid int) (*Namespace, *Repository, error)
	FindRepositoryByPath(ctx context.Context, namespacePath, repoPath string) (*Namespace, *Repository, error)
	NewRepository(ctx context.Context, r *Repository) (*Repository, error)
	RepoAccessLevel(ctx context.Context, r *Repository, u *User) (AccessLevel, AccessLevel, error)
	FindBranchForPrefix(ctx context.Context, rid int64, prefix string) (*Branch, error)
	FindTagForPrefix(ctx context.Context, rid int64, prefix string) (*Tag, error)
	FindBranch(ctx context.Context, rid int64, branchName string) (*Branch, error)
	FindTag(ctx context.Context, rid int64, tagName string) (*Tag, error)
	DoBranchUpdate(ctx context.Context, cmd *Command) (*Branch, error)
	DoReferenceUpdate(ctx context.Context, cmd *Command) (*Reference, error)
	Close() error
}

func NewDB

func NewDB(cfg *mysql.Config) (DB, error)

type ErrAlreadyLocked

type ErrAlreadyLocked struct {
	Reference string
}

func (*ErrAlreadyLocked) Error

func (e *ErrAlreadyLocked) Error() string

type ErrExist

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

func (*ErrExist) Error

func (e *ErrExist) Error() string

type ErrNamingRule

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

func (*ErrNamingRule) Error

func (e *ErrNamingRule) Error() string

type ErrRevisionNotFound

type ErrRevisionNotFound struct {
	Revision string
}

func (*ErrRevisionNotFound) Error

func (err *ErrRevisionNotFound) Error() string

type Key

type Key struct {
	ID          int64     `json:"id"`
	UID         int64     `json:"uid"`
	Content     string    `json:"content"`
	Title       string    `json:"title"`
	Type        KeyType   `json:"type"`
	Fingerprint string    `json:"fingerprint"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type KeyType

type KeyType int
const (
	BasicKey KeyType = iota
	DeployKey
)

func (KeyType) String

func (t KeyType) String() string

type Member

type Member struct {
	ID          int64       `json:"id"`
	UID         int64       `json:"uid"`
	AccessLevel AccessLevel `json:"access_level"`
	SourceID    int64       `json:"source_id"`
	SourceType  MemberType  `json:"source_type"`
	ExpiresAt   time.Time   `json:"expires_at"`
	CreatedAt   time.Time   `json:"created_at"`
	UpdatedAt   time.Time   `json:"updated_at"`
}

type MemberType

type MemberType int
const (
	ProjectMember MemberType = 2
	GroupMember   MemberType = 3
)

type Namespace

type Namespace struct {
	ID          int64
	Path        string
	Name        string
	Owner       int64
	Type        int // 1-personal , 2-normal
	Description string
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type Reference

type Reference struct {
	ID              int64                  `json:"id"`
	Name            plumbing.ReferenceName `json:"name"`
	RID             int64                  `json:"rid"`
	Hash            string                 `json:"hash"`
	ProtectionLevel int                    `json:"protection_level"`
	CreatedAt       time.Time              `json:"created_at"`
	UpdatedAt       time.Time              `json:"updated_at"`
}

type Repository

type Repository struct {
	ID              int64     `json:"id"`
	NamespaceID     int64     `json:"namespace_id"`
	Name            string    `json:"name"`
	Path            string    `json:"path"`
	Description     string    `json:"description"`
	VisibleLevel    int       `json:"visible_level"` //	0-private, 20-public, 30-anonymous
	DefaultBranch   string    `json:"default_branch"`
	HashAlgo        string    `json:"hash_algo"`
	CompressionAlgo string    `json:"compression_algo"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

func (*Repository) IsInternal

func (r *Repository) IsInternal() bool

func (*Repository) IsPublic

func (r *Repository) IsPublic() bool

func (*Repository) Validate

func (r *Repository) Validate() error

type Tag

type Tag struct {
	Name        string    `json:"name"`
	RID         int64     `json:"rid"`
	UID         int64     `json:"uid"`
	Hash        string    `json:"hash"`
	Subject     string    `json:"subject"`
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type User

type User struct {
	ID             int64     `json:"id"`
	UserName       string    `json:"username"`
	Name           string    `json:"name"`
	Administrator  bool      `json:"administrator"`
	Email          string    `json:"email"`
	Type           UserType  `json:"type"`
	LockedAt       time.Time `json:"locked_at"`
	CreatedAt      time.Time `json:"created_at"`
	UpdatedAt      time.Time `json:"updated_at"`
	Password       string    `json:"-"`
	SignatureToken string    `json:"-"`
}

func (*User) Guard

func (u *User) Guard()

type UserType

type UserType int //revive:disable-line:exported

UserType defines the user type

const (
	// UserTypeIndividual defines an individual user
	UserTypeIndividual UserType = iota

	// UserTypeBot defines a bot user
	UserTypeBot

	// UserTypeRemoteUser defines a remote user for federated users
	UserTypeRemoteUser
)

Jump to

Keyboard shortcuts

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