apps

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package apps calls core's application create, reconfigure and plan APIs. The MCP tools and `shipyard add` share it, so both send the same bodies.

Index

Constants

View Source
const (
	KindRuntime  = "runtime"
	KindBuildArg = "build_arg"
)

Env var kinds: runtime vars are sent as secrets, build args as build_args.

View Source
const (
	StatusNeedsAction   = "needs_action"
	StatusAlreadyExists = "already_exists"
	// StatusCreating: another request is still creating this app; nothing was
	// queued. Asking again shortly returns already_exists.
	StatusCreating = "creating"
)

Response statuses core sets when the agent or user must act before a create can go ahead.

View Source
const (

	// RouteLabel is the compose label that sets a service's route.
	RouteLabel = "shipyard.route"
)

Variables

This section is empty.

Functions

func ActionBody

func ActionBody(err error) ([]byte, bool)

ActionBody returns the body of a failed request when core answered with a needs_action, already_exists or creating status or a next_step, which the caller should show as an answer rather than a bare error.

func Create

func Create(c client.Client, payload map[string]any) ([]byte, error)

Create posts a CreatePayload body.

func CreatePayload

func CreatePayload(r CreateRequest) (map[string]any, error)

CreatePayload builds the POST /application body.

func DefaultAppName

func DefaultAppName(repo, branch string) string

DefaultAppName is "<repo name>-<branch>", since app names are unique per org and another branch of the repo may already have an app. Characters core rejects become dashes, and then a short hash of the original keeps feature/x and feature-x apart; the name is cut to core's length limit.

func IsActionBody

func IsActionBody(body []byte) bool

IsActionBody reports whether body carries a needs_action, already_exists or creating status, or a next_step.

func NameTaken

func NameTaken(c client.Client, name string) (bool, error)

NameTaken reports whether a live environment in the org already uses name, which core refuses on create. The listing is cached and covers only the environment types it shows, so core's own check stays authoritative.

func Plan

func Plan(c client.Client, repo, branch string) ([]byte, error)

Plan asks core what creating an app for repo ("owner/name") and branch would do. It changes nothing.

func PublicValues

func PublicValues(appName string, projects ...Project) []string

PublicValues lists what a request sends in the clear: repo, branch, app name, services and routes. A sent env value equal to one is no secret, and masking it would garble service names and links in core's answer.

func RedactError

func RedactError(err error, items []EnvItem, public ...string) error

RedactError returns err with every env value masked. An API error is rebuilt from its redacted body, so values are masked before the message is shaped: the title's first letter is lower-cased and JSON escapes are decoded only after redaction, and neither can hide a value from it.

func RedactString

func RedactString(s string, items []EnvItem, public ...string) string

RedactString masks every sent env value found in s, including its JSON-escaped form, which is how a value with a newline or quote appears in a raw error body. Values shorter than minSubstringLen are left alone inside text: masking them would garble the message without hiding anything secret.

func RedactValues

func RedactValues(body []byte, items []EnvItem, public ...string) []byte

RedactValues returns body with every env value replaced, so a response or error that echoes one does not reach the agent or the terminal. Objects with both name and value fields lose their value, a string or number equal to a sent value is masked, and a sent value inside a longer string is masked as RedactString does.

public lists values the request sent in the clear (see PublicValues). An env value equal to one of them is left alone everywhere.

func SplitRepo

func SplitRepo(repo string) (owner, name string, err error)

SplitRepo splits "owner/name". A bare name returns an empty owner.

func Update

func Update(c client.Client, id string, payload map[string]any) ([]byte, error)

Update patches the app with an UpdatePayload body.

func UpdatePayload

func UpdatePayload(r UpdateRequest) (map[string]any, error)

UpdatePayload builds the PATCH /application/<id> body.

func ValidAppName

func ValidAppName(name string) bool

ValidAppName reports whether core accepts name as an app name.

Types

type ActionResponse

type ActionResponse struct {
	Status   string    `json:"status"`
	NextStep *NextStep `json:"next_step,omitempty"`
}

ActionResponse is the part of a create or update answer that says whether the user must act first.

type CreateRequest

type CreateRequest struct {
	AppName string
	Project Project
	Env     []EnvItem
	// HeadSHA is the commit the plan saw, so core can refuse a stale plan.
	HeadSHA string
	// Visitors are GitHub logins who may open the environment. An org API
	// token has no user to add, so core requires them with one.
	Visitors []string
}

CreateRequest is the input of Create.

type EnvItem

type EnvItem struct {
	Name     string   `json:"name"`
	Value    string   `json:"value"`
	Kind     string   `json:"kind,omitempty"`
	Hidden   *bool    `json:"hidden,omitempty"`
	Services []string `json:"services,omitempty"`
}

EnvItem is a variable to set on the app. Value is a secret: never log it or put it in a result.

type EnvName

type EnvName struct {
	Name string `json:"name"`
	Kind string `json:"kind"`
	// Services are the services the compose file gives the variable to; a
	// value set without them reaches every service. None means the file
	// interpolates it (${VAR}), so it is set for the whole app.
	Services []string `json:"services,omitempty"`
	// Optional is true when the compose file has a default for the variable.
	Optional bool `json:"optional,omitempty"`
}

EnvName is one variable the plan found, without a value.

type NextStep

type NextStep struct {
	Kind    string `json:"kind"`
	URL     string `json:"url,omitempty"`
	Message string `json:"message"`
}

NextStep is what core says to do about a needs_action, already_exists or creating answer.

type PlanResponse

type PlanResponse struct {
	Status          string           `json:"status"`
	Org             string           `json:"org"`
	Repo            string           `json:"repo"`
	Branch          string           `json:"branch"`
	HeadSHA         string           `json:"head_sha"`
	ComposeFile     string           `json:"compose_file"`
	Services        []PlanService    `json:"services"`
	Routes          []Route          `json:"routes"`
	RouteCandidates []RouteCandidate `json:"route_candidates"`
	Env             []EnvName        `json:"env"`
	ExistingApp     json.RawMessage  `json:"existing_app,omitempty"`
	// AppName is a name core says create can take: free in the org, with a free
	// URL. Older cores don't send it.
	AppName string `json:"app_name,omitempty"`
	// VisitorsRequired is true for an org token, which has no user to let in.
	VisitorsRequired bool      `json:"visitors_required,omitempty"`
	NextStep         *NextStep `json:"next_step,omitempty"`
}

PlanResponse is the body of POST /application/plan.

type PlanService

type PlanService struct {
	Name             string   `json:"name"`
	EnabledByDefault bool     `json:"enabled_by_default"`
	Profiles         []string `json:"profiles"`
}

PlanService is a compose service in a plan. A service that runs only under a compose profile is off by default.

func (*PlanService) UnmarshalJSON

func (s *PlanService) UnmarshalJSON(b []byte) error

UnmarshalJSON accepts core's {"name": "web", "enabled_by_default": true, ...} or a bare "web", which is on by default.

type Project

type Project struct {
	// Repo is owner/name, or a bare name for a repo already linked to the app.
	Repo            string
	Branch          string
	Services        []string
	ComposeFilename string
	// Routes maps a service to its shipyard.route label value. A nil value
	// removes the label.
	Routes map[string]*string
	// SelectedProfiles are the compose profiles to turn on. Core rejects an
	// enabled service whose profiles are all unselected.
	SelectedProfiles []string
}

Project is one repo of an app.

type Route

type Route struct {
	Service string `json:"service"`
	Route   string `json:"route"`
}

Route is a service's route in a plan.

type RouteCandidate

type RouteCandidate string

RouteCandidate is a service that could take the app's main route. Core may send a bare service name or an object with a service field.

func (*RouteCandidate) UnmarshalJSON

func (c *RouteCandidate) UnmarshalJSON(b []byte) error

UnmarshalJSON accepts "web" or {"service": "web", ...}.

type UpdateRequest

type UpdateRequest struct {
	Projects    []Project
	RemoveRepos []string
}

UpdateRequest is the input of Update. Only the fields set are changed. Env vars are not among them: core's PATCH ignores secrets and build_args.

Jump to

Keyboard shortcuts

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