Skip to content

app

go
import "github.com/tempestdx/sdk-go/app"

Index

Constants

go
const ResourceTypePattern = `^[A-Za-z_][A-Za-z0-9_]*$`

Variables

go
var GenericEmptySchema []byte

type ActionDefinition

go
type ActionDefinition struct {
    // Name is the unique identifier for the action.
    Name string
    // DisplayName is the name of the action as it should be displayed in the UI.
    DisplayName string
    // Description is a short description of the action.
    Description string
    // InputSchema is the parsed JSON schema for the input schema.
    InputSchema *JSONSchema
    // OutputSchema is the parsed JSON schema for the output schema.
    OutputSchema *JSONSchema
    // Handler is the function that will be called when the action is invoked.
    Handler func(context.Context, *ActionRequest) (*ActionResponse, error)
}

type ActionRequest

ActionRequest contains the input data for an operation on a resource.

go
type ActionRequest struct {
    // Metadata contains information about the Project and User making the request.
    // This metadata does not contain information about the Resource being operated on.
    Metadata *Metadata
    // Resource is the resource being actioned, and contains the ExternalID of the resource,
    // as well as the properties at the time of the request.
    Resource *Resource
    // Action is the name of the action being performed.
    Action string
    // Input contains the input data for the request, after it has been validated against the schema.
    // Default values have already been applied to missing input properties.
    Input map[string]any
    // Environment contains the environment variables that are available to the operation.
    Environment map[string]EnvironmentVariable
}

type ActionResponse

go
type ActionResponse struct {
    // Output contains the output data for the request. This data must validate against the output schema.
    Output map[string]any
}

type App

go
type App struct {
    appv1connect.UnimplementedAppServiceHandler
    // contains filtered or unexported fields
}

func New

go
func New(opts ...AppOption) *App

func (*App) Describe

go
func (a *App) Describe(_ context.Context, _ *connect.Request[appv1.DescribeRequest]) (*connect.Response[appv1.DescribeResponse], error)

func (*App) ExecuteResourceAction

go
func (a *App) ExecuteResourceAction(ctx context.Context, req *connect.Request[appv1.ExecuteResourceActionRequest]) (*connect.Response[appv1.ExecuteResourceActionResponse], error)

func (*App) ExecuteResourceOperation

go
func (a *App) ExecuteResourceOperation(ctx context.Context, req *connect.Request[appv1.ExecuteResourceOperationRequest]) (*connect.Response[appv1.ExecuteResourceOperationResponse], error)

func (*App) HealthCheck

go
func (a *App) HealthCheck(ctx context.Context, req *connect.Request[appv1.HealthCheckRequest]) (*connect.Response[appv1.HealthCheckResponse], error)

func (*App) ListResources

go
func (a *App) ListResources(ctx context.Context, req *connect.Request[appv1.ListResourcesRequest]) (*connect.Response[appv1.ListResourcesResponse], error)

type AppOption

go
type AppOption func(*appOptions)

func WithResourceDefinition

go
func WithResourceDefinition(rd ResourceDefinition) AppOption

func WithResourceDefinitions

go
func WithResourceDefinitions(rds ...ResourceDefinition) AppOption

type EnvironmentVariable

go
type EnvironmentVariable struct {
    Key   string
    Value string
    Type  EnvironmentVariableType
}

type EnvironmentVariableType

go
type EnvironmentVariableType string

go
const (
    ENVIRONMENT_VARIABLE_TYPE_VAR         EnvironmentVariableType = "variable"
    ENVIRONMENT_VARIABLE_TYPE_SECRET      EnvironmentVariableType = "secret"
    ENVIRONMENT_VARIABLE_TYPE_CERTIFICATE EnvironmentVariableType = "certificate"
    ENVIRONMENT_VARIABLE_TYPE_PRIVATE_KEY EnvironmentVariableType = "private_key"
    ENVIRONMENT_VARIABLE_TYPE_PUBLIC_KEY  EnvironmentVariableType = "public_key"
)

type HealthCheckFunc

go
type HealthCheckFunc func(context.Context) (*HealthCheckResponse, error)

type HealthCheckResponse

go
type HealthCheckResponse struct {
    Status  HealthCheckStatus
    Message string
}

type HealthCheckStatus

go
type HealthCheckStatus int

go
const (
    HealthCheckStatusUnknown   HealthCheckStatus = iota // unknown
    HealthCheckStatusHealthy                            // healthy
    HealthCheckStatusDegraded                           // degraded
    HealthCheckStatusDisrupted                          // disrupted
)

func (HealthCheckStatus) String

go
func (i HealthCheckStatus) String() string

type JSONSchema

go
type JSONSchema struct {
    *jsonschema.Schema
    // contains filtered or unexported fields
}

func MustParseJSONSchema

go
func MustParseJSONSchema(schema []byte) *JSONSchema

MustParseJSONSchema parses a JSON schema and returns a JSONSchema object. It will panic if the schema cannot be parsed.

func ParseJSONSchema

go
func ParseJSONSchema(schema []byte) (*JSONSchema, error)

ParseJSONSchema parses a JSON schema and returns a JSONSchema object. The schema is compiled with annotations extraction enabled.

type LifecycleStage

Represents a stage in the Developer Journey lifecycle.

go
type LifecycleStage int

go
const (
    LifecycleStageCode    LifecycleStage = iota + 1 // code
    LifecycleStageBuild                             // build
    LifecycleStageTest                              // test
    LifecycleStageRelease                           // release
    LifecycleStageDeploy                            // deploy
    LifecycleStageOperate                           // operate
    LifecycleStageMonitor                           // monitor
    LifecycleStageOther                             // other
)

func (LifecycleStage) String

go
func (i LifecycleStage) String() string

go
type Link struct {
    URL   string
    Title string
    Type  LinkType
}

type LinkType

go
type LinkType int

go
const (
    LinkTypeUnspecified    LinkType = iota // unspecified
    LinkTypeDocumentation                  // documentation
    LinkTypeAdministration                 // administration
    LinkTypeSupport                        // support
    LinkTypeEndpoint                       // endpoint
    LinkTypeExternal                       // external
)

func (LinkType) String

go
func (i LinkType) String() string

type ListFunc

go
type ListFunc func(context.Context, *ListRequest) (*ListResponse, error)

type ListRequest

ListRequest contains the input data for listing resources.

go
type ListRequest struct {
    // Metadata contains information about the Project and User making the request.
    // This metadata does not contain information about the Resource being operated on.
    Metadata *Metadata
    // Resource is the resource being listed, and contains at least the Resource Type.
    Resource *Resource
    // Next is a token that can be used to fetch the next page of results.
    Next string
}

type ListResponse

ListResponse contains the output data for listing resources.

go
type ListResponse struct {
    Resources []*Resource
    // Next is a token that can be used to fetch the next page of results.
    Next string
}

type Metadata

go
type Metadata struct {
    // ProjectID is the ID of the Tempest Project. This guaranteed to be unique.
    ProjectID string
    // ProjectName is the user defined name of the Tempest Project.
    ProjectName string
    // Owners are the user(s) who created or own the Project.
    Owners []Owner
    // Author is the user or team who created the Project.
    Author Owner
}

type OperationFunc

go
type OperationFunc func(context.Context, *OperationRequest) (*OperationResponse, error)

type OperationRequest

OperationRequest contains the input data for an operation on a resource.

go
type OperationRequest struct {
    // Metadata contains information about the Project and User making the request.
    // This metadata does not contain information about the Resource being operated on.
    Metadata *Metadata
    // Resource is the resource being operated on, and contains the ExternalID of the resource,
    // as well as the properties at the time of the request.
    Resource *Resource
    // Input contains the input data for the request, after it has been validated against the schema.
    // Default values have already been applied to missing input properties.
    Input map[string]any
    // Environment contains the environment variables that are available to the operation.
    Environment map[string]EnvironmentVariable
}

type OperationResponse

OperationResponse contains the output data for an operation on a resource.

go
type OperationResponse struct {
    // Resource contains the properties of the resource after the operation has been performed.
    Resource *Resource
}

type Owner

go
type Owner struct {
    Email string
    Name  string
    Type  OwnerType
}

type OwnerType

go
type OwnerType string

go
const (
    OwnerTypeUser OwnerType = "user"
    OwnerTypeTeam OwnerType = "team"
)

type Resource

go
type Resource struct {
    // ExternalID is the unique identifier for the resource in the external system.
    ExternalID string
    // DisplayName represents the human-readable name of the resource, to be displayed in the Tempest UI.
    DisplayName string
    // Type is the name of the ResourceDefinition that this resource is an instance of.
    Type string
    // Links are resource-specific links that can help users understand how to use this Resource.
    // A good example of a link is a LinkTypeExternal with a URL to the external system's UI for this resource.
    Links []*Link
    // Properties contains the properties of the resource. These properties are validated against the resource Properties schema.
    Properties map[string]any
}

type ResourceDefinition

ResourceDefinition represents a type of resource that can be managed by Tempest.

go
type ResourceDefinition struct {
    // The type by which this resource is identified. Must match `ResourceTypePattern`.
    Type string
    // The display name of the type for Tempest to show in the UI.
    DisplayName string
    // A description of the Resource type.
    Description string
    // PropertiesSchema is the parsed JSON schema for the Properties.
    PropertiesSchema *JSONSchema
    // LifecycleStage represents how the Resource fits in the Developer Journey.
    LifecycleStage LifecycleStage
    // Links are links to documentation or other resources that can help users
    // understand how to use this Resource.
    Links []Link
    // Markdown formatted instructions for setting up or using the resource.
    // This field supports resource property variables in the format of {{ resource.<property name> }}.
    InstructionsMarkdown string
    // contains filtered or unexported fields
}

func (*ResourceDefinition) AddActionDefinition

go
func (rd *ResourceDefinition) AddActionDefinition(ad ActionDefinition)

func (*ResourceDefinition) CreateFn

go
func (rd *ResourceDefinition) CreateFn(fn OperationFunc, inputSchema *JSONSchema)

CreateFn adds a Create operation Handler to the ResourceDefinition.

Tempest will use the inputSchema to validate the input data before calling the Handler. The Handler should create the resource in the external system and return the resource's ExternalID and properties. See the Create operation in the Printer example for an example implementation.

func (*ResourceDefinition) DeleteFn

go
func (rd *ResourceDefinition) DeleteFn(fn OperationFunc)

DeleteFn adds a Delete operation Handler to the ResourceDefinition.

The Handler should delete the resource in the external system. See the Delete operation in the Printer example for an example implementation.

func (*ResourceDefinition) HealthCheckFn

go
func (rd *ResourceDefinition) HealthCheckFn(fn HealthCheckFunc)

HealthCheckFn adds a HealthCheck Handler to the ResourceDefinition.

The Handler should return the provisioning health of the resource.

func (*ResourceDefinition) ListFn

go
func (rd *ResourceDefinition) ListFn(fn ListFunc)

ListFn adds a List Handler to the ResourceDefinition. The output will be validated against the ResourceDefinition's Properties schema.

The Handler should query the external system for all resources of this type and return them. See the List operation in the Printer example for an example implementation.

func (*ResourceDefinition) ReadFn

go
func (rd *ResourceDefinition) ReadFn(fn OperationFunc)

ReadFn adds a Read Operation to the ResourceDefinition.

The Handler should query the external system for the resource's current state and return it. See the Read operation in the Printer example for an example implementation.

func (*ResourceDefinition) UpdateFn

go
func (rd *ResourceDefinition) UpdateFn(fn OperationFunc, inputSchema *JSONSchema)

UpdateFn adds an Update operation Handler to the ResourceDefinition.

Tempest will use the inputSchema to validate the input data before calling the Handler. The Handler should update the resource in the external system and return the updated resource's properties. See the Update operation in the Printer example for an example implementation.