cubapi

package
v0.0.0-...-0675f50 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EntityTypeSpace        = "Space"
	EntityTypeFilter       = "Filter"
	EntityTypeView         = "View"
	EntityTypeInvocation   = "Invocation"
	EntityTypeTrigger      = "Trigger"
	EntityTypeTag          = "Tag"
	EntityTypeChangeSet    = "ChangeSet"
	EntityTypeTarget       = "Target"
	EntityTypeBridgeWorker = "BridgeWorker"
	EntityTypeUnit         = "Unit"
	EntityTypeLink         = "Link"
	EntityTypeSet          = "Set"
	// Pseudo-EntityType
	EntityTypeInventory = "Inventory"
)

Entity types

View Source
const (
	AuthTypeBasic = "Basic"
	AuthTypeJWT   = "JWT"
)

Variables

View Source
var ErrEntityNotFound = errors.New("entity not found")

ErrEntityNotFound is used to mark entities that are not found during refresh

Functions

func Apply

func Apply(
	ctx context.Context,
	client *goclientnew.ClientWithResponses,
	data, lastAppliedData []byte,
	oldInventory *Inventory,
	defaultSpaceSlug string,
) ([]ApplyResult, *Inventory, error)

Apply processes the configuration data and returns the results and updated inventory.

func BuildWhereFilterFromImportFilters

func BuildWhereFilterFromImportFilters(filters []goclientnew.ImportFilter) (string, error)

BuildWhereFilterFromImportFilters constructs a where filter string from ImportFilters

func GetEntityBySlug

func GetEntityBySlug(ctx context.Context, client *goclientnew.ClientWithResponses, entityType, slug, spaceID string) (interface{}, error)

GetEntityBySlug fetches an entity by its slug, similar to the old apiGet* functions but using direct client library calls without global variable dependencies

func GetRevisionByNum

func GetRevisionByNum(ctx context.Context, client *goclientnew.ClientWithResponses, spaceID, unitID string, revisionNum int64) (*goclientnew.ExtendedRevision, error)

GetRevisionByNum fetches a revision by its RevisionNum for a specific unit

func GetSpaceDetailURL

func GetSpaceDetailURL(serverURL, spaceID string) string

GetSpaceDetailURL returns the web UI URL for a specific space detail page

func GetSpaceListURL

func GetSpaceListURL(serverURL string) string

GetSpaceListURL returns the web UI URL for the spaces list page

func GetTargetListURL

func GetTargetListURL(serverURL string) string

GetTargetListURL returns the web UI URL for the targets list page

func GetUnitDetailURL

func GetUnitDetailURL(serverURL, spaceID, unitID string) string

GetUnitDetailURL returns the web UI URL for a specific unit detail page

func GetUnitEditURL

func GetUnitEditURL(serverURL, spaceID, unitID string) string

GetUnitEditURL returns the web UI URL for unit edit view Tab 1 is the edit tab in the unit detail page

func GetUnitListURL

func GetUnitListURL(serverURL string) string

GetUnitListURL returns the web UI URL for the units list page Note: Space context is handled by the UI session

func GetUnitRevisionsURL

func GetUnitRevisionsURL(serverURL, spaceID, unitID string) string

GetUnitRevisionsURL returns the web UI URL for unit revisions view Tab 2 is the revisions tab in the unit detail page

func GetWorkerListURL

func GetWorkerListURL(serverURL string) string

GetWorkerListURL returns the web UI URL for the bridge workers list page

func InterpretErrorGeneric

func InterpretErrorGeneric(err error, resp interface{}) error

InterpretErrorGeneric checks the response for any errors and returns an error if found. If we found no non-nil JSON4xx or JSON5xx, presumably it is a 2xx success or client initiated termination.

func IsAPIError

func IsAPIError(err error, resp APIResponse) bool

func ListEntitiesForImport

func ListEntitiesForImport(ctx context.Context, client *goclientnew.ClientWithResponses, spaceID string, entityType string, whereFilter string) ([]interface{}, error)

ListEntitiesForImport fetches entities of a specific type using the provided where filter. It returns the entities as a slice of interfaces that can be processed further.

func MarshalYAMLWithoutReadonlyFields

func MarshalYAMLWithoutReadonlyFields(entityType string, entity interface{}, spaceSlug string) ([]byte, error)

MarshalYAMLWithoutReadonlyFields marshals an entity to YAML while excluding readonly fields. It uses the Patch types which contain only the mutable fields that should be included in LiveState. It also removes null fields, the Version field, and adds SpaceSlug for space-resident entities.

func ParseBoolOption

func ParseBoolOption(options *goclientnew.ImportOptions, key string, defaultValue bool) bool

ParseBoolOption extracts a boolean option from the options map

func ParseStringOption

func ParseStringOption(options *goclientnew.ImportOptions, key string, defaultValue string) string

ParseStringOption extracts a string option from the options map

func Refresh

func Refresh(
	ctx context.Context,
	client *goclientnew.ClientWithResponses,
	currentData []byte,
	oldInventory *Inventory,
	defaultSpaceSlug string,
	liveRevisionNum int64,
	spaceID, unitID string,
) ([]ApplyResult, *Inventory, []byte, error)

Refresh gets the current state of entities in the inventory and updates the config data, inventory, and live state. It returns the same ApplyResult structure as Apply, along with updated inventory and refreshed config data.

Types

type APIResponse

type APIResponse interface {
	StatusCode() int
}

type ApplyResult

type ApplyResult struct {
	EntityType string
	EntityName string
	EntityID   string
	SpaceSlug  string
	Action     string // "created", "updated", "deleted", "failed"
	Error      error
	Entity     interface{} // Store the created/updated entity for display
}

func Destroy

func Destroy(ctx context.Context, client *goclientnew.ClientWithResponses, inventory *Inventory, defaultSpaceSlug string) []ApplyResult

type AuthSession

type AuthSession struct {
	User           User   `json:"user"`
	AccessToken    string `json:"access_token"`
	RefreshToken   string `json:"refresh_token,omitempty"`
	OrganizationID string `json:"organization_id"`
	AuthType       string `json:"auth_type"`

	// Note: This field is not part of the API. We just use it to pass the password to setAuthHeaderToken.
	BasicAuthPassword string `json:"basic_auth_password,omitempty"`
}

func PerformWorkerAuth

func PerformWorkerAuth(serverURL, workerID, workerSecret string) (*AuthSession, error)

type Inventory

type Inventory struct {
	EntityType string              `yaml:"EntityType"`
	Resources  []InventoryResource `yaml:"Resources"`
}

type InventoryResource

type InventoryResource struct {
	ResourceType string `yaml:"ResourceType"`
	ResourceName string `yaml:"ResourceName"`
}

type User

type User struct {
	ID                string            `json:"id"`
	Email             string            `json:"email"`
	FirstName         string            `json:"first_name"`
	LastName          string            `json:"last_name"`
	ProfilePictureURL string            `json:"profile_picture_url"`
	CreatedAt         string            `json:"created_at"`
	UpdatedAt         string            `json:"updated_at"`
	ExternalID        string            `json:"external_id,omitempty"`
	Metadata          map[string]string `json:"metadata,omitempty"`
}

Jump to

Keyboard shortcuts

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