resource

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MPL-2.0 Imports: 11 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 ErrInfinitePaginationDetected = errors.New("infinite pagination detected")
View Source
var ReStringID = regexp.MustCompile(`^[a-zA-Z0-9\-\._]+$`)

ReStringID is a regular expression used to validate common string ID patterns.

View Source
var SiteID site

SiteID identifies the "site", a top-level abstraction identifying the OTF system as a whole.

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 Deleter added in v0.4.9

type Deleter[R deleteableResource] struct {
	logr.Logger

	OverrideCheckInterval time.Duration
	AgeThreshold          time.Duration
	Client                deleterClient[R]
}

Deleter deletes resources that are older than a user-specified age.

func (*Deleter[R]) Start added in v0.4.9

func (e *Deleter[R]) Start(ctx context.Context) error

Start the deleter daemon.

type ID added in v0.3.6

type ID interface {
	fmt.Stringer
	Kind() Kind
}

ID uniquely identifies an OTF resource.

type Kind added in v0.3.6

type Kind string
const (
	SiteKind                      Kind = "site"
	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"
	VCSProviderKind               Kind = "vcs"

	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,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.

type TfeID added in v0.3.17

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

TfeID is an ID using the same format used for Terraform Enterprise resources, with a prefix designating the type of resource, appended with a unique base58 encoded id.

func ConvertTfeID added in v0.3.17

func ConvertTfeID(id TfeID, to Kind) TfeID

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

func MustHardcodeTfeID added in v0.3.17

func MustHardcodeTfeID(kind Kind, suffix string) TfeID

func NewTfeID added in v0.3.17

func NewTfeID(kind Kind) TfeID

NewTfeID constructs a resource ID

func ParseTfeID added in v0.3.17

func ParseTfeID(s string) (TfeID, error)

ParseTfeID parses the ID from a string representation.

func (TfeID) IsZero added in v0.4.2

func (id TfeID) IsZero() bool

func (TfeID) Kind added in v0.3.17

func (id TfeID) Kind() Kind

func (TfeID) MarshalText added in v0.3.17

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

func (*TfeID) Scan added in v0.3.17

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

func (*TfeID) Set added in v0.4.0

func (id *TfeID) Set(text string) error

Set implements pflag.Value

func (TfeID) String added in v0.3.17

func (id TfeID) String() string

func (*TfeID) Type added in v0.4.0

func (*TfeID) Type() string

Type implements pflag.Value

func (*TfeID) UnmarshalText added in v0.3.17

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

func (*TfeID) Value added in v0.3.17

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

Jump to

Keyboard shortcuts

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