resource

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: Unlicense Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Global is the global locality.
	Global = GlobalLocality("global")
)

Variables

View Source
var ErrResourceNotFound = errors.New("store: resource not found")

ErrResourceNotFound is returned when a resource is not found.

Functions

This section is empty.

Types

type Action added in v0.2.0

type Action struct {
	// Name is the name of the action.
	Name string

	// Do performs the action on the resource.
	// It should return an error if the action failed.
	// The index is provided to add or delete resources.
	Do func(ctx context.Context, index Indexer, client *scw.Client) error
}

type Actionable added in v0.2.0

type Actionable interface {
	Resource

	// Actions returns the list of actions that can be performed on the resource.
	Actions() []Action
}

type CockpitMetadata

type CockpitMetadata struct {
	// CanViewLogs is true if the logs associated with the resource can be viewed Scaleway Cockpit.
	CanViewLogs bool

	// ResourceName is the name of the resource in Scaleway Cockpit.
	ResourceName string

	// ResourceID is the ID of the resource in Scaleway Cockpit.
	ResourceID string

	// ResourceType is the type of the resource in Scaleway Cockpit.
	ResourceType string
}

type GlobalLocality

type GlobalLocality string

func (GlobalLocality) IsRegion

func (g GlobalLocality) IsRegion() bool

func (GlobalLocality) IsZone

func (g GlobalLocality) IsZone() bool

func (GlobalLocality) String

func (g GlobalLocality) String() string

type Index added in v0.2.1

type Index struct {
	Store  Storer
	Search Searcher
}

func NewIndex added in v0.2.1

func NewIndex(store Storer, search Searcher) *Index

func (*Index) Deindex added in v0.2.1

func (i *Index) Deindex(ctx context.Context, r Resource) error

func (*Index) Index added in v0.2.1

func (i *Index) Index(ctx context.Context, r Resource) error

type Indexer added in v0.2.1

type Indexer interface {
	// Index indexes the given resource.
	Index(ctx context.Context, r Resource) error

	// Deindex deindexes the given resource.
	Deindex(ctx context.Context, r Resource) error
}

Indexer is a very simple wrapper around a Storer and a Searcher. It makes it harder to forget to update one of the two when adding a new resource.

type Locality

type Locality interface {
	IsRegion() bool
	IsZone() bool
	fmt.Stringer
}

type Log

type Log struct {
	Timestamp time.Time
	Line      string
}

type Metadata

type Metadata struct {
	// Name is the name of the resource.
	Name string `json:"name"`

	// ID is the unique identifier of the resource.
	ID string `json:"id"`

	// ProjectID is the unique identifier of the project the resource belongs to.
	ProjectID string `json:"project_id"`

	// Status is the status of the resource.
	// Maybe nil if not available.
	Status *Status `json:"status"`

	// Description is the description of the resource.
	// May be empty.
	Description *string `json:"description"`

	// CreatedAt is the date the resource was created.
	// Maybe nil if not available.
	CreatedAt *time.Time `json:"created_at,omitempty"`

	// Tags is the list of tags associated with the resource.
	Tags []string `json:"tags"`

	// Type is the type of the resource.
	Type Type `json:"type"`

	// Locality is the locality of the resource.
	Locality Locality `json:"locality,omitempty"`
}

type Monitorer

type Monitorer interface {
	// Logs returns the logs of a resource.
	Logs(ctx context.Context, r Resource) ([]Log, error)
}

type Predicate

type Predicate func(r Resource) bool

type Region

type Region scw.Region

func (Region) IsRegion

func (r Region) IsRegion() bool

func (Region) IsZone

func (r Region) IsZone() bool

func (Region) String

func (r Region) String() string

type Resource

type Resource interface {
	// Metadata returns the metadatas of the resource.
	Metadata() Metadata

	// CockpitMetadata returns the metadatas of the resource for Scaleway Cockpit.
	CockpitMetadata() CockpitMetadata

	// Delete deletes the resource.
	// It will also remove the resource from the index.
	Delete(ctx context.Context, index Indexer, client *scw.Client) error
}

type Searcher

type Searcher interface {
	// Search searches for resources. Returns a list of resource IDs that match the query.
	Search(ctx context.Context, query string) (SetOfIDs, error)

	// Index indexes a resource.
	Index(r Resource) error

	// Deindex deindexes a resource.
	Deindex(r Resource) error
}

type SetOfIDs added in v0.2.1

type SetOfIDs = map[string]struct{}

type Status

type Status string
const (
	StatusUnknown Status = "unknown"
	StatusActive  Status = "active"
	StatusError   Status = "error"
	StatusDeleted Status = "deleted"
	StatusReady   Status = "ready"
	StatusPending Status = "pending"
	StatusRunning Status = "running"

	StatusQueued   Status = "queued"
	StatusSucceded Status = "succeeded"
	StatusFailed   Status = "failed"
	StatusCanceled Status = "canceled"
)

func (*Status) Emoji

func (s *Status) Emoji(resourceType Type) rune

type Storer

type Storer interface {
	// Store stores a resource.
	Store(ctx context.Context, r Resource) error

	// ListAllResources returns all resources.
	ListAllResources(ctx context.Context) ([]Resource, error)

	// DeleteResource deletes a resource.
	DeleteResource(ctx context.Context, r Resource) error
}

type Type

type Type int
const (
	TypeProject        Type = iota
	TypeIAMApplication      // IAM Application
	TypeCockpit
	TypeFunctionNamespace // Function Namespace
	TypeFunction
	TypeContainerNamespace // Container Namespace
	TypeContainer
	TypeRegistryNamespace // Registry Namespace
	TypeRdbInstance       // RDB Instance
	TypeKapsuleCluster    // Kapsule Cluster
	TypeInstance
	TypeJobDefinition // Job Definition
	TypeJobRun        // Job Run
	NumberOfResourceTypes
)

func (Type) String

func (i Type) String() string

type Zone

type Zone scw.Zone

func (Zone) IsRegion

func (z Zone) IsRegion() bool

func (Zone) IsZone

func (z Zone) IsZone() bool

func (Zone) String

func (z Zone) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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