resource

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package resource contains code common to all resources (orgs, workspaces, runs, etc)

Index

Constants

View Source
const (
	DefaultPageNumber = 1
	DefaultPageSize   = 20
	MaxPageSize       = 100
)

Variables

View Source
var (
	// EmptyID for use in comparisons to check whether ID has been
	// uninitialized.
	EmptyID = ID{}
	// ReStringID is a regular expression used to validate common string ID patterns.
	ReStringID = regexp.MustCompile(`^[a-zA-Z0-9\-\._]+$`)
)
View Source
var ErrInfinitePaginationDetected = errors.New("infinite pagination detected")

Functions

func GenerateRandomStringFromAlphabet added in v0.3.6

func GenerateRandomStringFromAlphabet(size int, alphabet string) string

GenerateRandomStringFromAlphabet generates a random string of a given size using characters from the given alphabet.

func ListAll

func ListAll[T any](fn func(PageOptions) (*Page[T], error)) ([]T, error)

ListAll is a helper for retrieving all pages. The provided fn should perform an operation that retrieves a page at a time.

func ValidateName added in v0.1.8

func ValidateName(name *string) error

Types

type ID added in v0.3.6

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

ID uniquely identifies an OTF resource.

func ConvertID added in v0.3.6

func ConvertID(id ID, to Kind) ID

ConvertID converts an ID for use with a different resource kind, e.g. convert run-123 to plan-123.

func MustHardcodeID added in v0.3.6

func MustHardcodeID(kind Kind, suffix string) ID

func NewID added in v0.3.6

func NewID(kind Kind) ID

NewID constructs a resource ID

func ParseID added in v0.3.6

func ParseID(s string) (ID, error)

ParseID parses the ID from a string representation.

func (ID) Kind added in v0.3.6

func (id ID) Kind() Kind

func (ID) MarshalText added in v0.3.6

func (id ID) MarshalText() ([]byte, error)

func (*ID) Scan added in v0.3.6

func (id *ID) Scan(text any) error

func (ID) String added in v0.3.6

func (id ID) String() string

func (*ID) UnmarshalText added in v0.3.6

func (id *ID) UnmarshalText(text []byte) error

func (*ID) Value added in v0.3.6

func (id *ID) Value() (driver.Value, error)

type Kind added in v0.3.6

type Kind string
const (
	OrganizationKind              Kind = "org"
	WorkspaceKind                 Kind = "ws"
	RunKind                       Kind = "run"
	ConfigVersionKind             Kind = "cv"
	IngressAttributesKind         Kind = "ia"
	JobKind                       Kind = "job"
	ChunkKind                     Kind = "chunk"
	UserKind                      Kind = "user"
	TeamKind                      Kind = "team"
	ModuleKind                    Kind = "mod"
	ModuleVersionKind             Kind = "modver"
	NotificationConfigurationKind Kind = "nc"
	AgentPoolKind                 Kind = "apool"
	RunnerKind                    Kind = "runner"
	StateVersionKind              Kind = "sv"
	StateVersionOutputKind        Kind = "wsout"
	VariableSetKind               Kind = "varset"
	VariableKind                  Kind = "var"

	OrganizationTokenKind Kind = "ot"
	UserTokenKind         Kind = "ut"
	TeamTokenKind         Kind = "tt"
	AgentTokenKind        Kind = "at"
)

func (Kind) String added in v0.3.6

func (k Kind) String() string

type Page

type Page[T any] struct {
	Items []T
	*Pagination
}

Page is a segment of a result set.

func NewPage

func NewPage[T any](resources []T, opts PageOptions, count *int64) *Page[T]

NewPage constructs a page from a list of resources. If the list argument represents the full result set then count should be nil; if count is non-nil then the list is deemed to be a segment of a result set and count is the size of the full result set. This latter case is useful, say, if a database has already produced a segment of a full result set, e.g. using LIMIT and OFFSET.

type PageOptions

type PageOptions struct {
	// The page number to request. The results vary based on the PageSize.
	PageNumber int `schema:"page[number],omitempty"`
	// The number of elements returned in a single page.
	PageSize int `schema:"page[size],omitempty"`
}

PageOptions are used to request a specific page.

func (PageOptions) Normalize added in v0.3.6

func (o PageOptions) Normalize() PageOptions

Normalize page number and size

type Pagination

type Pagination struct {
	CurrentPage  int  `json:"current-page"`
	PreviousPage *int `json:"prev-page"`
	NextPage     *int `json:"next-page"`
	TotalPages   int  `json:"total-pages"`
	TotalCount   int  `json:"total-count"`
}

Pagination provides metadata about a page.

Jump to

Keyboard shortcuts

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