hub

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidInput indicates that the input provided is not valid.
	ErrInvalidInput = errors.New("invalid input")

	// ErrInsufficientPrivilege indicates that the user does not have the
	// required privilege to perform the operation.
	ErrInsufficientPrivilege = errors.New("insufficient_privilege")

	// ErrNotFound indicates that the requested item was not found.
	ErrNotFound = errors.New("not found")
)
View Source
var IndexMetaDescriptionKey = indexMetaDescriptionKey{}

IndexMetaDescriptionKey represents the key used for the description in the index metadata.

View Source
var IndexMetaTitleKey = indexMetaTitleKey{}

IndexMetaTitleKey represents the key used for the title in the index metadata.

View Source
var UserIDKey = userIDKey{}

UserIDKey represents the key used for the userID value inside a context.

Functions

func GetKindName added in v0.3.0

func GetKindName(kind RepositoryKind) string

GetKindName returns the name of the provided repository kind.

Types

type APIKey added in v0.2.0

type APIKey struct {
	APIKeyID  string `json:"api_key_id"`
	Name      string `json:"name"`
	CreatedAt int64  `json:"created_at"`
	UserID    string `json:"user_id"`
}

APIKey represents a key used to interact with the HTTP API.

type APIKeyManager added in v0.2.0

type APIKeyManager interface {
	Add(ctx context.Context, ak *APIKey) ([]byte, error)
	Delete(ctx context.Context, apiKeyID string) error
	GetJSON(ctx context.Context, apiKeyID string) ([]byte, error)
	GetOwnedByUserJSON(ctx context.Context) ([]byte, error)
	Update(ctx context.Context, ak *APIKey) error
}

APIKeyManager describes the methods an APIKeyManager implementation must provide.

type Channel added in v0.3.0

type Channel struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

Channel represents a package's channel.

type CheckAPIKeyOutput added in v0.2.0

type CheckAPIKeyOutput struct {
	Valid  bool   `json:"valid"`
	UserID string `json:"user_id"`
}

CheckAPIKeyOutput represents the output returned by the CheckApiKey method.

type CheckCredentialsOutput

type CheckCredentialsOutput struct {
	Valid  bool   `json:"valid"`
	UserID string `json:"user_id"`
}

CheckCredentialsOutput represents the output returned by the CheckCredentials method.

type CheckSessionOutput

type CheckSessionOutput struct {
	Valid  bool   `json:"valid"`
	UserID string `json:"user_id"`
}

CheckSessionOutput represents the output returned by the CheckSession method.

type DB

type DB interface {
	Begin(ctx context.Context) (pgx.Tx, error)
	Exec(ctx context.Context, sql string, arguments ...interface{}) (pgconn.CommandTag, error)
	QueryRow(ctx context.Context, sql string, args ...interface{}) pgx.Row
}

DB defines the methods the database handler must provide.

type EmailSender

type EmailSender interface {
	SendEmail(data *email.Data) error
}

EmailSender defines the methods the email sender must provide.

type Event

type Event struct {
	EventID        string    `json:"event_id"`
	EventKind      EventKind `json:"event_kind"`
	PackageID      string    `json:"package_id"`
	PackageVersion string    `json:"package_version"`
}

Event represents the details of an event related to a package.

type EventKind

type EventKind int64

EventKind represents the kind of an event.

const (
	// NewRelease represents an event for a new package release.
	NewRelease EventKind = 0

	// SecurityAlert represents an event for a security alert.
	SecurityAlert EventKind = 1
)

type EventManager

type EventManager interface {
	GetPending(ctx context.Context, tx pgx.Tx) (*Event, error)
}

EventManager describes the methods an EventManager implementation must provide.

type GetPackageInput

type GetPackageInput struct {
	PackageID      string `json:"package_id"`
	RepositoryName string `json:"repository_name"`
	PackageName    string `json:"package_name"`
	Version        string `json:"version"`
}

GetPackageInput represents the input used to get a specific package.

type GitCloner added in v0.3.0

type GitCloner interface {
	// CloneRepository clones the operators repository provided in a temporary
	// dir, returning the temporary directory path and the path where the
	// operators are located. It's the caller's responsibility to delete them
	// temporary dir when done.
	CloneRepository(r *Repository) (string, string, error)
}

GitCloner describes the methods a GitCloner implementation must provide.

type HelmIndexLoader added in v0.3.0

type HelmIndexLoader interface {
	LoadIndex(r *Repository) (*helmrepo.IndexFile, error)
}

HelmIndexLoader interface defines the methods a Helm index loader implementation should provide.

type Link struct {
	Name string `json:"name" yaml:"name"`
	URL  string `json:"url" yaml:"url"`
}

Link represents a url associated with a package.

type Maintainer

type Maintainer struct {
	MaintainerID string `json:"maintainer_id"`
	Name         string `json:"name" yaml:"name"`
	Email        string `json:"email" yaml:"email"`
}

Maintainer represents a package's maintainer.

type Notification

type Notification struct {
	NotificationID string   `json:"notification_id"`
	Event          *Event   `json:"event"`
	User           *User    `json:"user"`
	Webhook        *Webhook `json:"webhook"`
}

Notification represents the details of a notification pending to be delivered.

type NotificationManager

type NotificationManager interface {
	Add(ctx context.Context, tx pgx.Tx, n *Notification) error
	GetPending(ctx context.Context, tx pgx.Tx) (*Notification, error)
	UpdateStatus(
		ctx context.Context,
		tx pgx.Tx,
		notificationID string,
		delivered bool,
		deliveryErr error,
	) error
}

NotificationManager describes the methods an NotificationManager implementation must provide.

type NotificationTemplateData

type NotificationTemplateData struct {
	BaseURL string                 `json:"base_url"`
	Event   map[string]interface{} `json:"event"`
	Package map[string]interface{} `json:"package"`
}

NotificationTemplateData represents some details of a notification that will be exposed to notification templates.

type Organization

type Organization struct {
	OrganizationID string `json:"organization_id"`
	Name           string `json:"name"`
	DisplayName    string `json:"display_name"`
	Description    string `json:"description"`
	HomeURL        string `json:"home_url"`
	LogoImageID    string `json:"logo_image_id"`
}

Organization represents an entity with one or more users associated that can own repositories and other entities like webhooks.

type OrganizationManager

type OrganizationManager interface {
	Add(ctx context.Context, org *Organization) error
	AddMember(ctx context.Context, orgName, userAlias, baseURL string) error
	CheckAvailability(ctx context.Context, resourceKind, value string) (bool, error)
	ConfirmMembership(ctx context.Context, orgName string) error
	DeleteMember(ctx context.Context, orgName, userAlias string) error
	GetJSON(ctx context.Context, orgName string) ([]byte, error)
	GetByUserJSON(ctx context.Context) ([]byte, error)
	GetMembersJSON(ctx context.Context, orgName string) ([]byte, error)
	Update(ctx context.Context, org *Organization) error
}

OrganizationManager describes the methods an OrganizationManager implementation must provide.

type Package

type Package struct {
	PackageID         string                 `json:"package_id"`
	Name              string                 `json:"name"`
	NormalizedName    string                 `json:"normalized_name"`
	LogoURL           string                 `json:"logo_url"`
	LogoImageID       string                 `json:"logo_image_id"`
	IsOperator        bool                   `json:"is_operator"`
	Channels          []*Channel             `json:"channels"`
	DefaultChannel    string                 `json:"default_channel"`
	DisplayName       string                 `json:"display_name"`
	Description       string                 `json:"description"`
	Keywords          []string               `json:"keywords"`
	HomeURL           string                 `json:"home_url"`
	Readme            string                 `json:"readme"`
	Install           string                 `json:"install"`
	Links             []*Link                `json:"links"`
	Data              map[string]interface{} `json:"data"`
	Version           string                 `json:"version"`
	AvailableVersions []*Version             `json:"available_versions"`
	AppVersion        string                 `json:"app_version"`
	Digest            string                 `json:"digest"`
	Deprecated        bool                   `json:"deprecated"`
	License           string                 `json:"license"`
	Signed            bool                   `json:"signed"`
	ContentURL        string                 `json:"content_url"`
	ContainerImage    string                 `json:"container_image"`
	Provider          string                 `json:"provider"`
	Maintainers       []*Maintainer          `json:"maintainers"`
	Repository        *Repository            `json:"repository"`
	CreatedAt         int64                  `json:"created_at,omitempty"`
}

Package represents a Kubernetes package.

type PackageManager

type PackageManager interface {
	Get(ctx context.Context, input *GetPackageInput) (*Package, error)
	GetJSON(ctx context.Context, input *GetPackageInput) ([]byte, error)
	GetRandomJSON(ctx context.Context) ([]byte, error)
	GetStarredByUserJSON(ctx context.Context) ([]byte, error)
	GetStarsJSON(ctx context.Context, packageID string) ([]byte, error)
	GetStatsJSON(ctx context.Context) ([]byte, error)
	Register(ctx context.Context, pkg *Package) error
	SearchJSON(ctx context.Context, input *SearchPackageInput) ([]byte, error)
	ToggleStar(ctx context.Context, packageID string) error
	Unregister(ctx context.Context, pkg *Package) error
}

PackageManager describes the methods a PackageManager implementation must provide.

type PackageMetadata added in v0.4.0

type PackageMetadata struct {
	Version        string        `yaml:"version"`
	Name           string        `yaml:"name"`
	DisplayName    string        `yaml:"displayName"`
	CreatedAt      string        `yaml:"createdAt"`
	Description    string        `yaml:"description"`
	LogoPath       string        `yaml:"logoPath"`
	Digest         string        `yaml:"digest"`
	License        string        `yaml:"license"`
	HomeURL        string        `yaml:"homeURL"`
	AppVersion     string        `yaml:"appVersion"`
	PublisherID    string        `yaml:"publisherID"`
	ContainerImage string        `yaml:"containerImage"`
	Operator       bool          `yaml:"operator"`
	Deprecated     bool          `yaml:"deprecated"`
	Keywords       []string      `yaml:"keywords"`
	Links          []*Link       `yaml:"links"`
	Readme         string        `yaml:"readme"`
	Install        string        `yaml:"install"`
	Maintainers    []*Maintainer `yaml:"maintainers"`
	Provider       *Provider     `yaml:"provider"`
	Ignore         []string      `yaml:"ignore"`
}

PackageMetadata represents some metadata about a given package. It's usually provided by repositories publishers, to provide the required information about the content they'd like to be indexed.

type Provider added in v0.4.0

type Provider struct {
	Name string `yaml:"name"`
}

Provider represents a package's provider.

type Repository added in v0.3.0

type Repository struct {
	RepositoryID            string         `json:"repository_id"`
	Name                    string         `json:"name"`
	DisplayName             string         `json:"display_name"`
	URL                     string         `json:"url"`
	Kind                    RepositoryKind `json:"kind"`
	UserID                  string         `json:"user_id"`
	UserAlias               string         `json:"user_alias"`
	OrganizationID          string         `json:"organization_id"`
	OrganizationName        string         `json:"organization_name"`
	OrganizationDisplayName string         `json:"organization_display_name"`
}

Repository represents a packages repository.

type RepositoryCloner added in v0.3.0

type RepositoryCloner interface {
	// CloneRepository clones the packages repository provided in a temporary
	// dir, returning the temporary directory path and the path where the
	// packages are located. It's the caller's responsibility to delete them
	// temporary dir when done.
	CloneRepository(ctx context.Context, r *Repository) (tmpDir string, packagesPath string, err error)
}

RepositoryCloner describes the methods a Cloner implementation must provide.

type RepositoryKind added in v0.3.0

type RepositoryKind int64

RepositoryKind represents the kind of a given repository.

const (
	// Helm represents a repository with Helm charts.
	Helm RepositoryKind = 0

	// Falco represents a repository with Falco rules.
	Falco RepositoryKind = 1

	// OPA represents a repository with OPA policies.
	OPA RepositoryKind = 2

	// OLM represents a repository with OLM operators.
	OLM RepositoryKind = 3
)

type RepositoryManager added in v0.3.0

type RepositoryManager interface {
	Add(ctx context.Context, orgName string, r *Repository) error
	CheckAvailability(ctx context.Context, resourceKind, value string) (bool, error)
	Delete(ctx context.Context, name string) error
	GetAll(ctx context.Context) ([]*Repository, error)
	GetByName(ctx context.Context, name string) (*Repository, error)
	GetPackagesDigest(ctx context.Context, repositoryID string) (map[string]string, error)
	GetOwnedByOrgJSON(ctx context.Context, orgName string) ([]byte, error)
	GetOwnedByUserJSON(ctx context.Context) ([]byte, error)
	SetLastTrackingResults(ctx context.Context, repositoryID, errs string) error
	Transfer(ctx context.Context, name, orgName string) error
	Update(ctx context.Context, r *Repository) error
}

RepositoryManager describes the methods an RepositoryManager implementation must provide.

type SearchPackageInput

type SearchPackageInput struct {
	Limit           int              `json:"limit,omitempty"`
	Offset          int              `json:"offset,omitempty"`
	Facets          bool             `json:"facets"`
	TsQueryWeb      string           `json:"ts_query_web,omitempty"`
	TsQuery         string           `json:"ts_query,omitempty"`
	Users           []string         `json:"users,omitempty"`
	Orgs            []string         `json:"orgs,omitempty"`
	Repositories    []string         `json:"repositories,omitempty"`
	RepositoryKinds []RepositoryKind `json:"repository_kinds,omitempty"`
	Operators       bool             `json:"operators"`
	Deprecated      bool             `json:"deprecated"`
}

SearchPackageInput represents the query input when searching for packages.

type Session

type Session struct {
	SessionID string `json:"session_id"`
	UserID    string `json:"user_id"`
	IP        string `json:"ip"`
	UserAgent string `json:"user_agent"`
}

Session represents some information about a user session.

type Subscription

type Subscription struct {
	UserID    string    `json:"user_id"`
	PackageID string    `json:"package_id"`
	EventKind EventKind `json:"event_kind"`
}

Subscription represents a user's subscription to receive notifications about a given package and event kind.

type SubscriptionManager

type SubscriptionManager interface {
	Add(ctx context.Context, s *Subscription) error
	Delete(ctx context.Context, s *Subscription) error
	GetByPackageJSON(ctx context.Context, packageID string) ([]byte, error)
	GetByUserJSON(ctx context.Context) ([]byte, error)
	GetSubscriptors(ctx context.Context, packageID string, eventKind EventKind) ([]*User, error)
}

SubscriptionManager describes the methods a SubscriptionManager implementation must provide.

type User

type User struct {
	UserID         string `json:"user_id"`
	Alias          string `json:"alias"`
	FirstName      string `json:"first_name"`
	LastName       string `json:"last_name"`
	Email          string `json:"email"`
	EmailVerified  bool   `json:"email_verified"`
	Password       string `json:"password"`
	ProfileImageID string `json:"profile_image_id"`
}

User represents a Hub user.

type UserManager

type UserManager interface {
	CheckAPIKey(ctx context.Context, key []byte) (*CheckAPIKeyOutput, error)
	CheckAvailability(ctx context.Context, resourceKind, value string) (bool, error)
	CheckCredentials(ctx context.Context, email, password string) (*CheckCredentialsOutput, error)
	CheckSession(ctx context.Context, sessionID []byte, duration time.Duration) (*CheckSessionOutput, error)
	DeleteSession(ctx context.Context, sessionID []byte) error
	GetProfileJSON(ctx context.Context) ([]byte, error)
	GetUserID(ctx context.Context, email string) (string, error)
	RegisterSession(ctx context.Context, session *Session) ([]byte, error)
	RegisterUser(ctx context.Context, user *User, baseURL string) error
	UpdatePassword(ctx context.Context, old, new string) error
	UpdateProfile(ctx context.Context, user *User) error
	VerifyEmail(ctx context.Context, code string) (bool, error)
}

UserManager describes the methods a UserManager implementation must provide.

type Version added in v0.3.0

type Version struct {
	Version   string `json:"version"`
	CreatedAt int64  `json:"created_at"`
}

Version represents a package's version

type Webhook

type Webhook struct {
	WebhookID   string      `json:"webhook_id"`
	Name        string      `json:"name"`
	Description string      `json:"description"`
	URL         string      `json:"url"`
	Secret      string      `json:"secret"`
	ContentType string      `json:"content_type"`
	Template    string      `json:"template"`
	Active      bool        `json:"active"`
	EventKinds  []EventKind `json:"event_kinds"`
	Packages    []*Package  `json:"packages"`
}

Webhook represents the configuration of a webhook where notifications will be posted to.

type WebhookManager

type WebhookManager interface {
	Add(ctx context.Context, orgName string, wh *Webhook) error
	Delete(ctx context.Context, webhookID string) error
	GetJSON(ctx context.Context, webhookID string) ([]byte, error)
	GetOwnedByOrgJSON(ctx context.Context, orgName string) ([]byte, error)
	GetOwnedByUserJSON(ctx context.Context) ([]byte, error)
	GetSubscribedTo(ctx context.Context, eventKind EventKind, packageID string) ([]*Webhook, error)
	Update(ctx context.Context, wh *Webhook) error
}

WebhookManager describes the methods a WebhookManager implementation must provide.

Jump to

Keyboard shortcuts

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