api

package
v0.0.0-...-d9c5257 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2024 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const ErrorType = "Error"

ErrorType is the name of the type used to report errors.

Variables

This section is empty.

Functions

func CloudEventToJSONMap

func CloudEventToJSONMap(evt *cloudevents.Event) (datatypes.JSONMap, error)

CloudEventToJSONMap converts a CloudEvent to a JSONMap (resource manifest or status)

func DecodeBundleStatus

func DecodeBundleStatus(status datatypes.JSONMap) (map[string]interface{}, error)

DecodeBundleStatus converts a CloudEvent JSONMap representation of a resource bundle status into resource bundle status (map[string]interface{}) in openapi output.

func DecodeManifest

func DecodeManifest(manifest datatypes.JSONMap) (map[string]interface{}, map[string]interface{}, map[string]interface{}, error)

DecodeManifest converts a CloudEvent JSONMap representation of a resource manifest into resource manifest, deleteOption and updateStrategy (map[string]interface{}).

func DecodeManifestBundle

func DecodeManifestBundle(manifest datatypes.JSONMap) (map[string]any, *workpayload.ManifestBundle, error)

DecodeManifestBundle converts a CloudEvent JSONMap representation of a list of resource manifest into manifest bundle payload.

func DecodeManifestBundleToObjects

func DecodeManifestBundleToObjects(manifest datatypes.JSONMap) ([]map[string]interface{}, error)

DecodeManifestBundleToObjects converts a CloudEvent JSONMap representation of a list of resource manifest into a list of resource object (map[string]interface{}).

func DecodeStatus

func DecodeStatus(status datatypes.JSONMap) (map[string]interface{}, error)

DecodeStatus converts a CloudEvent JSONMap representation of a resource status into resource status (map[string]interface{}).

func EncodeManifest

func EncodeManifest(manifest, deleteOption, updateStrategy map[string]interface{}) (datatypes.JSONMap, error)

EncodeManifest converts resource manifest, deleteOption and updateStrategy (map[string]interface{}) into a CloudEvent JSONMap representation.

func JSONMAPToCloudEvent

func JSONMAPToCloudEvent(res datatypes.JSONMap) (*cloudevents.Event, error)

JSONMAPToCloudEvent converts a JSONMap (resource manifest or status) to a CloudEvent

func NewID

func NewID() string

func SendAPI

func SendAPI(w http.ResponseWriter, r *http.Request)

SendAPI sends API documentation response.

func SendAPIV1

func SendAPIV1(w http.ResponseWriter, r *http.Request)

SendAPIV1 sends API version v1 documentation response.

func SendNotFound

func SendNotFound(w http.ResponseWriter, r *http.Request)

SendNotFound sends a 404 response with some details about the non existing resource.

func SendPanic

func SendPanic(w http.ResponseWriter, r *http.Request)

SendPanic sends a panic error response to the client, but it doesn't end the process.

func SendUnauthorized

func SendUnauthorized(w http.ResponseWriter, r *http.Request, message string)

Types

type CollectionMetadata

type CollectionMetadata struct {
	ID   string `json:"id"`
	HREF string `json:"href"`
	Kind string `json:"kind"`
}

CollectionMetadata represents a collection.

type Consumer

type Consumer struct {
	Meta

	// Name must be unique and not null, it can be treated as the consumer external ID.
	// The format of the name should be follow the RFC 1123 (same as the k8s namespace).
	// When creating a consumer, if its name is not specified, the consumer id will be used as its name.
	//
	// Cannot be updated.
	Name   string
	Labels *db.StringMap
}

func (*Consumer) BeforeCreate

func (d *Consumer) BeforeCreate(tx *gorm.DB) error

type ConsumerIndex

type ConsumerIndex map[string]*Consumer

type ConsumerList

type ConsumerList []*Consumer

func (ConsumerList) Index

func (l ConsumerList) Index() ConsumerIndex

type ConsumerPatchRequest

type ConsumerPatchRequest struct {
}

type Error

type Error struct {
	Type   string `json:"type,omitempty"`
	ID     string `json:"id,omitempty"`
	HREF   string `json:"href,omitempty"`
	Code   string `json:"code,omitempty"`
	Reason string `json:"reason,omitempty"`
}

Error represents an error reported by the API.

type Event

type Event struct {
	Meta
	Source         string     // MyTable
	SourceID       string     // primary key of MyTable
	EventType      EventType  // Add|Update|Delete
	ReconciledDate *time.Time `json:"gorm:null"`
}

func (*Event) BeforeCreate

func (d *Event) BeforeCreate(tx *gorm.DB) error

type EventIndex

type EventIndex map[string]*Event

type EventInstance

type EventInstance struct {
	EventID    string
	InstanceID string
}

type EventInstanceList

type EventInstanceList []*EventInstance

type EventList

type EventList []*Event

func (EventList) Index

func (l EventList) Index() EventIndex

type EventType

type EventType string
const (
	CreateEventType EventType = "Create"
	UpdateEventType EventType = "Update"
	DeleteEventType EventType = "Delete"
)

type Meta

type Meta struct {
	ID        string
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

Meta is base model definition, embedded in all kinds

type Metadata

type Metadata struct {
	ID       string            `json:"id"`
	HREF     string            `json:"href"`
	Kind     string            `json:"kind"`
	Versions []VersionMetadata `json:"versions"`
}

Metadata api metadata.

type PagingMeta

type PagingMeta struct {
	Page  int
	Size  int64
	Total int64
}

List Paging metadata

type ReconcileStatus

type ReconcileStatus struct {
	ObservedVersion int32
	SequenceID      string
	Conditions      []metav1.Condition
}

type Resource

type Resource struct {
	Meta
	Version      int32
	Source       string
	ConsumerName string
	Type         ResourceType
	Payload      datatypes.JSONMap
	Status       datatypes.JSONMap
	// Name must be unique and not null, it can be treated as the resource external ID.
	// The format of the name should be follow the RFC 1123 (same as the k8s namespace).
	// When creating a resource, if its name is not specified, the resource id will be used as its name.
	// Cannot be updated.
	Name string
}

func (*Resource) BeforeCreate

func (d *Resource) BeforeCreate(tx *gorm.DB) error

func (*Resource) GetDeletionTimestamp

func (d *Resource) GetDeletionTimestamp() *metav1.Time

func (*Resource) GetResourceVersion

func (d *Resource) GetResourceVersion() string

func (*Resource) GetUID

func (d *Resource) GetUID() ktypes.UID

type ResourceBundleStatus

type ResourceBundleStatus struct {
	ObservedVersion int32
	SequenceID      string
	*workpayload.ManifestBundleStatus
}

type ResourceIndex

type ResourceIndex map[string]*Resource

type ResourceList

type ResourceList []*Resource

func (ResourceList) Index

func (l ResourceList) Index() ResourceIndex

type ResourcePatchRequest

type ResourcePatchRequest struct{}

type ResourceStatus

type ResourceStatus struct {
	ContentStatus   datatypes.JSONMap
	ReconcileStatus *ReconcileStatus
}

type ResourceType

type ResourceType string
const (
	ResourceTypeSingle ResourceType = "Single"
	ResourceTypeBundle ResourceType = "Bundle"
)

type ServerInstance

type ServerInstance struct {
	Meta
	LastHeartbeat time.Time // LastHeartbeat indicates the last time the instance sent a heartbeat.
	Ready         bool      // Ready indicates whether the instance is ready to serve requests.
}

ServerInstance is employed by Maestro to discover active server instances. The updatedAt field determines the liveness of the instance; if the instance remains unchanged for three consecutive check intervals (30 seconds by default), it is marked as dead. However, it is not meant for direct exposure to end users through the API.

func (*ServerInstance) String

func (i *ServerInstance) String() string

String returns the identifier of the maestro instance.

type ServerInstanceList

type ServerInstanceList []*ServerInstance

type StatusEvent

type StatusEvent struct {
	Meta
	ResourceID      string
	ResourceSource  string
	ResourceType    ResourceType
	Payload         datatypes.JSONMap
	Status          datatypes.JSONMap
	StatusEventType StatusEventType // Update|Delete
	ReconciledDate  *time.Time      `json:"gorm:null"`
}

func (*StatusEvent) BeforeCreate

func (e *StatusEvent) BeforeCreate(tx *gorm.DB) error

type StatusEventIndex

type StatusEventIndex map[string]*StatusEvent

type StatusEventList

type StatusEventList []*StatusEvent

func (StatusEventList) Index

type StatusEventType

type StatusEventType string
const (
	StatusUpdateEventType StatusEventType = "StatusUpdate"
	StatusDeleteEventType StatusEventType = "StatusDelete"
)

type VersionMetadata

type VersionMetadata struct {
	ID          string               `json:"id"`
	HREF        string               `json:"href"`
	Kind        string               `json:"kind"`
	Collections []CollectionMetadata `json:"collections"`
}

VersionMetadata represents a version.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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