// Package console is Alta's CARLOS console client. It holds one `team` // service credential per app (carlos/platform // implementation/team-scoped-credentials.md) and reaches only the doors // that role admits: config, instances, domains and restart/scope, under // /api/cli/apps/{account}/{app}. // // The credential's scope is the fence (CARLOS refuses anything outside // the environments scope `alta` owns). The guards here are defence in // depth (team-provisioning-app.md §8): every request passes Guard first, // and a request Guard refuses never leaves the process. package console import ( "bytes" "context" "encoding/json" "errors" "fmt" "io" "net/http" "net/url" "regexp" "strings" ) // ErrNotFound is the console's 404, which for a team credential means // "absent, or not this scope's": the two are deliberately the same bytes. var ErrNotFound = errors.New("console: not found") // ErrGuard is a request Alta's own guard refused before sending it. var ErrGuard = errors.New("console: refused by Alta's guard") // StatusError is any other non-2xx answer. Message is the console's own // sentence; it names keys and hosts, never values. type StatusError struct { Code int Message string } func (e *StatusError) Error() string { return fmt.Sprintf("console: %d %s", e.Code, e.Message) } // IsConflict reports a 409. func IsConflict(err error) bool { var s *StatusError return errors.As(err, &s) && s.Code == http.StatusConflict } // Guard is the §8 check every request passes. The provisioning store // implements it from its own records. type Guard interface { // Environment admits env for app: non-empty and owned per Alta's // records. write is false for a read, which a preflight may make for // a label not yet recorded. Environment(ctx context.Context, app, env string, write bool) error // Host admits host for app: