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
- func ActionBody(err error) ([]byte, bool)
- func Create(c client.Client, payload map[string]any) ([]byte, error)
- func CreatePayload(r CreateRequest) (map[string]any, error)
- func DefaultAppName(repo, branch string) string
- func IsActionBody(body []byte) bool
- func NameTaken(c client.Client, name string) (bool, error)
- func Plan(c client.Client, repo, branch string) ([]byte, error)
- func PublicValues(appName string, projects ...Project) []string
- func RedactError(err error, items []EnvItem, public ...string) error
- func RedactString(s string, items []EnvItem, public ...string) string
- func RedactValues(body []byte, items []EnvItem, public ...string) []byte
- func SplitRepo(repo string) (owner, name string, err error)
- func Update(c client.Client, id string, payload map[string]any) ([]byte, error)
- func UpdatePayload(r UpdateRequest) (map[string]any, error)
- func ValidAppName(name string) bool
- type ActionResponse
- type CreateRequest
- type EnvItem
- type EnvName
- type NextStep
- type PlanResponse
- type PlanService
- type Project
- type Route
- type RouteCandidate
- type UpdateRequest
Constants ¶
const ( KindRuntime = "runtime" KindBuildArg = "build_arg" )
Env var kinds: runtime vars are sent as secrets, build args as build_args.
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.
const (
// RouteLabel is the compose label that sets a service's route.
RouteLabel = "shipyard.route"
)
Variables ¶
This section is empty.
Functions ¶
func ActionBody ¶
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 CreatePayload ¶
func CreatePayload(r CreateRequest) (map[string]any, error)
CreatePayload builds the POST /application body.
func DefaultAppName ¶
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 ¶
IsActionBody reports whether body carries a needs_action, already_exists or creating status, or a next_step.
func NameTaken ¶
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 ¶
Plan asks core what creating an app for repo ("owner/name") and branch would do. It changes nothing.
func PublicValues ¶
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 ¶
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 ¶
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 ¶
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 UpdatePayload ¶
func UpdatePayload(r UpdateRequest) (map[string]any, error)
UpdatePayload builds the PATCH /application/<id> body.
func ValidAppName ¶
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 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 ¶
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.