backend

package
v0.7.4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ContextKey = &struct{ string }{"backend"}

ContextKey is the key for the backend in the context.

Functions

func GenerateToken

func GenerateToken() string

GenerateToken returns a random unique token.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword hashes the password using bcrypt.

func HashToken

func HashToken(token string) string

HashToken hashes the token using sha256.

func LatestFile

func LatestFile(r proto.Repository, ref *git.Reference, pattern string) (string, string, error)

LatestFile returns the contents of the latest file at the specified path in the repository and its file path.

func Readme

func Readme(r proto.Repository, ref *git.Reference) (readme string, path string, err error)

Readme returns the repository's README.

func StoreRepoMissingLFSObjects

func StoreRepoMissingLFSObjects(ctx context.Context, repo proto.Repository, dbx *db.DB, store store.Store, lfsClient lfs.Client) error

StoreRepoMissingLFSObjects stores missing LFS objects for a repository.

func VerifyPassword

func VerifyPassword(password, hash string) bool

VerifyPassword verifies the password against the hash.

func WithContext

func WithContext(ctx context.Context, b *Backend) context.Context

WithContext returns a new context with the backend attached.

Types

type Backend

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

Backend is the Soft Serve backend that handles users, repositories, and server settings management and operations.

func FromContext

func FromContext(ctx context.Context) *Backend

FromContext returns the backend from a context.

func New

func New(ctx context.Context, cfg *config.Config, db *db.DB) *Backend

New returns a new Soft Serve backend.

func (*Backend) AccessLevel

func (d *Backend) AccessLevel(ctx context.Context, repo string, username string) access.AccessLevel

AccessLevel returns the access level of a user for a repository.

It implements backend.Backend.

func (*Backend) AccessLevelByPublicKey

func (d *Backend) AccessLevelByPublicKey(ctx context.Context, repo string, pk ssh.PublicKey) access.AccessLevel

AccessLevelByPublicKey returns the access level of a user's public key for a repository.

It implements backend.Backend.

func (*Backend) AccessLevelForUser

func (d *Backend) AccessLevelForUser(ctx context.Context, repo string, user proto.User) access.AccessLevel

AccessLevelForUser returns the access level of a user for a repository. TODO: user repository ownership

func (*Backend) AddCollaborator

func (d *Backend) AddCollaborator(ctx context.Context, repo string, username string, level access.AccessLevel) error

AddCollaborator adds a collaborator to a repository.

It implements backend.Backend.

func (*Backend) AddPublicKey

func (d *Backend) AddPublicKey(ctx context.Context, username string, pk ssh.PublicKey) error

AddPublicKey adds a public key to a user.

It implements backend.Backend.

func (*Backend) AllowKeyless

func (b *Backend) AllowKeyless(ctx context.Context) bool

AllowKeyless returns whether or not keyless access is allowed.

It implements backend.Backend.

func (*Backend) AnonAccess

func (b *Backend) AnonAccess(ctx context.Context) access.AccessLevel

AnonAccess returns the level of anonymous access.

It implements backend.Backend.

func (*Backend) Collaborators

func (d *Backend) Collaborators(ctx context.Context, repo string) ([]string, error)

Collaborators returns a list of collaborators for a repository.

It implements backend.Backend.

func (*Backend) CreateAccessToken

func (b *Backend) CreateAccessToken(ctx context.Context, user proto.User, name string, expiresAt time.Time) (string, error)

CreateAccessToken creates an access token for user.

func (*Backend) CreateRepository

func (d *Backend) CreateRepository(ctx context.Context, name string, user proto.User, opts proto.RepositoryOptions) (proto.Repository, error)

CreateRepository creates a new repository.

It implements backend.Backend.

func (*Backend) CreateUser

func (d *Backend) CreateUser(ctx context.Context, username string, opts proto.UserOptions) (proto.User, error)

CreateUser creates a new user.

It implements backend.Backend.

func (*Backend) CreateWebhook

func (b *Backend) CreateWebhook(ctx context.Context, repo proto.Repository, url string, contentType webhook.ContentType, secret string, events []webhook.Event, active bool) error

CreateWebhook creates a webhook for a repository.

func (*Backend) DeleteAccessToken

func (b *Backend) DeleteAccessToken(ctx context.Context, user proto.User, id int64) error

DeleteAccessToken deletes an access token for a user.

func (*Backend) DeleteRepository

func (d *Backend) DeleteRepository(ctx context.Context, name string) error

DeleteRepository deletes a repository.

It implements backend.Backend.

func (*Backend) DeleteUser

func (d *Backend) DeleteUser(ctx context.Context, username string) error

DeleteUser deletes a user.

It implements backend.Backend.

func (*Backend) DeleteUserRepositories

func (d *Backend) DeleteUserRepositories(ctx context.Context, username string) error

DeleteUserRepositories deletes all user repositories.

func (*Backend) DeleteWebhook

func (b *Backend) DeleteWebhook(ctx context.Context, repo proto.Repository, id int64) error

DeleteWebhook deletes a webhook for a repository.

func (*Backend) Description

func (d *Backend) Description(ctx context.Context, name string) (string, error)

Description returns the description of a repository.

It implements backend.Backend.

func (*Backend) ImportRepository

func (d *Backend) ImportRepository(_ context.Context, name string, user proto.User, remote string, opts proto.RepositoryOptions) (proto.Repository, error)

ImportRepository imports a repository from remote. XXX: This a expensive operation and should be run in a goroutine.

func (*Backend) IsCollaborator

func (d *Backend) IsCollaborator(ctx context.Context, repo string, username string) (access.AccessLevel, bool, error)

IsCollaborator returns the access level and true if the user is a collaborator of the repository.

It implements backend.Backend.

func (*Backend) IsHidden

func (d *Backend) IsHidden(ctx context.Context, name string) (bool, error)

IsHidden returns true if the repository is hidden.

It implements backend.Backend.

func (*Backend) IsMirror

func (d *Backend) IsMirror(ctx context.Context, name string) (bool, error)

IsMirror returns true if the repository is a mirror.

It implements backend.Backend.

func (*Backend) IsPrivate

func (d *Backend) IsPrivate(ctx context.Context, name string) (bool, error)

IsPrivate returns true if the repository is private.

It implements backend.Backend.

func (*Backend) ListAccessTokens

func (b *Backend) ListAccessTokens(ctx context.Context, user proto.User) ([]proto.AccessToken, error)

ListAccessTokens lists access tokens for a user.

func (*Backend) ListPublicKeys

func (d *Backend) ListPublicKeys(ctx context.Context, username string) ([]ssh.PublicKey, error)

ListPublicKeys lists the public keys of a user.

func (*Backend) ListWebhookDeliveries

func (b *Backend) ListWebhookDeliveries(ctx context.Context, id int64) ([]webhook.Delivery, error)

ListWebhookDeliveries lists webhook deliveries for a webhook.

func (*Backend) ListWebhooks

func (b *Backend) ListWebhooks(ctx context.Context, repo proto.Repository) ([]webhook.Hook, error)

ListWebhooks lists webhooks for a repository.

func (*Backend) PostReceive

func (d *Backend) PostReceive(_ context.Context, _ io.Writer, _ io.Writer, repo string, args []hooks.HookArg)

PostReceive is called by the git post-receive hook.

It implements Hooks.

func (*Backend) PostUpdate

func (d *Backend) PostUpdate(ctx context.Context, _ io.Writer, _ io.Writer, repo string, args ...string)

PostUpdate is called by the git post-update hook.

It implements Hooks.

func (*Backend) PreReceive

func (d *Backend) PreReceive(_ context.Context, _ io.Writer, _ io.Writer, repo string, args []hooks.HookArg)

PreReceive is called by the git pre-receive hook.

It implements Hooks.

func (*Backend) ProjectName

func (d *Backend) ProjectName(ctx context.Context, name string) (string, error)

ProjectName returns the project name of a repository.

It implements backend.Backend.

func (*Backend) RedeliverWebhookDelivery

func (b *Backend) RedeliverWebhookDelivery(ctx context.Context, repo proto.Repository, id int64, delID uuid.UUID) error

RedeliverWebhookDelivery redelivers a webhook delivery.

func (*Backend) RemoveCollaborator

func (d *Backend) RemoveCollaborator(ctx context.Context, repo string, username string) error

RemoveCollaborator removes a collaborator from a repository.

It implements backend.Backend.

func (*Backend) RemovePublicKey

func (d *Backend) RemovePublicKey(ctx context.Context, username string, pk ssh.PublicKey) error

RemovePublicKey removes a public key from a user.

It implements backend.Backend.

func (*Backend) RenameRepository

func (d *Backend) RenameRepository(ctx context.Context, oldName string, newName string) error

RenameRepository renames a repository.

It implements backend.Backend.

func (*Backend) Repositories

func (d *Backend) Repositories(ctx context.Context) ([]proto.Repository, error)

Repositories returns a list of repositories per page.

It implements backend.Backend.

func (*Backend) Repository

func (d *Backend) Repository(ctx context.Context, name string) (proto.Repository, error)

Repository returns a repository by name.

It implements backend.Backend.

func (*Backend) SetAdmin

func (d *Backend) SetAdmin(ctx context.Context, username string, admin bool) error

SetAdmin sets the admin flag of a user.

It implements backend.Backend.

func (*Backend) SetAllowKeyless

func (b *Backend) SetAllowKeyless(ctx context.Context, allow bool) error

SetAllowKeyless sets whether or not keyless access is allowed.

It implements backend.Backend.

func (*Backend) SetAnonAccess

func (b *Backend) SetAnonAccess(ctx context.Context, level access.AccessLevel) error

SetAnonAccess sets the level of anonymous access.

It implements backend.Backend.

func (*Backend) SetDescription

func (d *Backend) SetDescription(ctx context.Context, name string, desc string) error

SetDescription sets the description of a repository.

It implements backend.Backend.

func (*Backend) SetHidden

func (d *Backend) SetHidden(ctx context.Context, name string, hidden bool) error

SetHidden sets the hidden flag of a repository.

It implements backend.Backend.

func (*Backend) SetPassword

func (d *Backend) SetPassword(ctx context.Context, username string, rawPassword string) error

SetPassword sets the password of a user.

func (*Backend) SetPrivate

func (d *Backend) SetPrivate(ctx context.Context, name string, private bool) error

SetPrivate sets the private flag of a repository.

It implements backend.Backend.

func (*Backend) SetProjectName

func (d *Backend) SetProjectName(ctx context.Context, repo string, name string) error

SetProjectName sets the project name of a repository.

It implements backend.Backend.

func (*Backend) SetUsername

func (d *Backend) SetUsername(ctx context.Context, username string, newUsername string) error

SetUsername sets the username of a user.

It implements backend.Backend.

func (*Backend) Update

func (d *Backend) Update(ctx context.Context, _ io.Writer, _ io.Writer, repo string, arg hooks.HookArg)

Update is called by the git update hook.

It implements Hooks.

func (*Backend) UpdateWebhook

func (b *Backend) UpdateWebhook(ctx context.Context, repo proto.Repository, id int64, url string, contentType webhook.ContentType, secret string, updatedEvents []webhook.Event, active bool) error

UpdateWebhook updates a webhook.

func (*Backend) User

func (d *Backend) User(ctx context.Context, username string) (proto.User, error)

User finds a user by username.

It implements backend.Backend.

func (*Backend) UserByAccessToken

func (d *Backend) UserByAccessToken(ctx context.Context, token string) (proto.User, error)

UserByAccessToken finds a user by access token. This also validates the token for expiration and returns proto.ErrTokenExpired.

func (*Backend) UserByID

func (d *Backend) UserByID(ctx context.Context, id int64) (proto.User, error)

UserByID finds a user by ID.

func (*Backend) UserByPublicKey

func (d *Backend) UserByPublicKey(ctx context.Context, pk ssh.PublicKey) (proto.User, error)

UserByPublicKey finds a user by public key.

It implements backend.Backend.

func (*Backend) Users

func (d *Backend) Users(ctx context.Context) ([]string, error)

Users returns all users.

It implements backend.Backend.

func (*Backend) Webhook

func (b *Backend) Webhook(ctx context.Context, repo proto.Repository, id int64) (webhook.Hook, error)

Webhook returns a webhook for a repository.

func (*Backend) WebhookDelivery

func (b *Backend) WebhookDelivery(ctx context.Context, webhookID int64, id uuid.UUID) (webhook.Delivery, error)

WebhookDelivery returns a webhook delivery.

Jump to

Keyboard shortcuts

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