Documentation
¶
Index ¶
- Constants
- func AgentAuthCheckCmd() string
- func AgentAuthLoginCmd() string
- func AgentBranchListCmd(org, database string) string
- func AgentDatabaseListCmd(org string) string
- func AgentGuideCmd() string
- func AgentOrgListCmd() string
- func AgentSQLCmd(org, database, branch string, force bool) string
- func BranchClusterSizesCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective)
- func CheckAuthentication(cfg *config.Config) func(cmd *cobra.Command, args []string) error
- func ClusterSizesCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective)
- func DatabaseCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
- func DeployRequestBranchToNumber(ctx context.Context, client *ps.Client, organization string, database string, ...) (uint64, error)
- func ErrCode(err error) planetscale.ErrorCode
- func HandleError(err error) error
- func HandleNotFoundWithServiceTokenCheck(ctx context.Context, cmd *cobra.Command, cfg *config.Config, ...) error
- func HasHomebrew() bool
- func IsUnderHomebrew(binpath string) bool
- func MySQLClientPath() (string, mysql.AuthMethodDescription, error)
- func NewZapLogger(debug bool) *zap.Logger
- func ParseDuration(s string) (time.Duration, error)
- func ParseSSLMode(sslMode string) ps.ExternalDataSourceSSLVerificationMode
- func PostgreSQLClientPath() (string, error)
- func PostgresBranchClusterSizesCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective)
- func PostgresInheritedRoles(role PasswordRole) (inherited []string, successor string)
- func RegionsCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective)
- func ReportGlobalJSONError(w, errW io.Writer, err error) int
- func RequiredArgs(reqArgs ...string) cobra.PositionalArgs
- func SnakeToSentenceCase(s string) string
- func TimeToMilliseconds(t time.Time) int64
- func ToClusterSizeSlug(c string) string
- func TryOpenBrowser(goos, url string) error
- func ValidateServiceTokenOnNotFound(ctx context.Context, cmd *cobra.Command, cfg *config.Config, ...) error
- func WriteJSONError(w io.Writer, resp JSONErrorResponse) error
- type ByteFormat
- type Error
- type Helper
- type JSONErrorIssue
- type JSONErrorResponse
- type PasswordRole
- type TTLFlag
Constants ¶
const ( ActionRequestedExitCode = 1 FatalErrExitCode = 2 )
const ApplicationURL = "https://app.planetscale.com"
const WarnAuthMessage = "not authenticated yet. Please run 'pscale auth login'"
Variables ¶
This section is empty.
Functions ¶
func AgentAuthCheckCmd ¶ added in v0.292.0
func AgentAuthCheckCmd() string
func AgentAuthLoginCmd ¶ added in v0.292.0
func AgentAuthLoginCmd() string
func AgentBranchListCmd ¶ added in v0.292.0
func AgentDatabaseListCmd ¶ added in v0.292.0
func AgentGuideCmd ¶ added in v0.292.0
func AgentGuideCmd() string
func AgentOrgListCmd ¶ added in v0.292.0
func AgentOrgListCmd() string
func AgentSQLCmd ¶ added in v0.292.0
func BranchClusterSizesCompletionFunc ¶ added in v0.224.0
func BranchClusterSizesCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective)
func CheckAuthentication ¶ added in v0.15.0
CheckAuthentication checks whether the user is authenticated and returns a actionable error message.
func ClusterSizesCompletionFunc ¶ added in v0.224.0
func ClusterSizesCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective)
func DatabaseCompletionFunc ¶ added in v0.224.0
func DeployRequestBranchToNumber ¶ added in v0.149.0
func ErrCode ¶ added in v0.12.0
func ErrCode(err error) planetscale.ErrorCode
ErrCode returns the code from a *planetscale.Error, if available. If the error is not of type *planetscale.Error or is nil, it returns an empty, undefined error code.
func HandleError ¶ added in v0.21.1
HandleError checks whether the given err is an *planetscale.Error and returns a descriptive, human readable error if the error code matches a certain planetscale Error types. If the error doesn't match these requirements, err is returned unmodified.
func HandleNotFoundWithServiceTokenCheck ¶ added in v0.244.0
func HandleNotFoundWithServiceTokenCheck(ctx context.Context, cmd *cobra.Command, cfg *config.Config, clientFunc func() (*planetscale.Client, error), originalErr error, requiredPermission string, notFoundMsgFormat string, args ...interface{}) error
HandleNotFoundWithServiceTokenCheck is a convenience function that combines the common pattern of handling 404 errors with service token validation. It should be used in the ErrNotFound case of error handling switch statements.
The requiredPermission parameter is optional (can be empty string). When provided, it will be included in the error message to help users understand what permission their service token needs.
Usage example:
switch cmdutil.ErrCode(err) {
case planetscale.ErrNotFound:
return cmdutil.HandleNotFoundWithServiceTokenCheck(
ctx, cmd, ch.Config, ch.Client, err, "read_branch",
"branch %s does not exist in database %s (organization: %s)",
printer.BoldBlue(branch), printer.BoldBlue(database), printer.BoldBlue(ch.Config.Organization))
default:
return cmdutil.HandleError(err)
}
func HasHomebrew ¶ added in v0.31.0
func HasHomebrew() bool
HasHomebrew check whether the user has installed brew
func IsUnderHomebrew ¶ added in v0.31.0
IsUnderHomebrew checks whether the given binary is under the homebrew path. copied from: https://github.com/cli/cli/blob/trunk/cmd/gh/main.go#L298
func MySQLClientPath ¶ added in v0.31.0
func MySQLClientPath() (string, mysql.AuthMethodDescription, error)
MySQLClientPath checks whether the 'mysql' client exists and returns the path to the binary. The returned error contains instructions to install the client.
func NewZapLogger ¶ added in v0.17.1
NewZapLogger returns a logger to be used with the sql-proxy. By default it only outputs error leveled messages, unless debug is true.
func ParseDuration ¶ added in v0.251.0
ParseDuration extends time.ParseDuration with a "d" unit that is not permitted by the Go standard library. For more information, see: https://github.com/golang/go/issues/11473.
func ParseSSLMode ¶ added in v0.100.0
func ParseSSLMode(sslMode string) ps.ExternalDataSourceSSLVerificationMode
func PostgreSQLClientPath ¶ added in v0.251.0
func PostgresBranchClusterSizesCompletionFunc ¶ added in v0.292.0
func PostgresBranchClusterSizesCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective)
PostgresBranchClusterSizesCompletionFunc completes cluster sizes for a specific Postgres branch. It returns the fully-qualified SKU names (e.g. PS_10_GCP_X86) that the branch's resize endpoint accepts, scoped to the branch's engine, provider, and architecture.
func PostgresInheritedRoles ¶ added in v0.292.0
func PostgresInheritedRoles(role PasswordRole) (inherited []string, successor string)
PostgresInheritedRoles maps --role to Postgres inherited roles (used by shell and sql). MySQL/Vitess uses branch passwords via passwordutil instead — same --role flag, different API.
func RegionsCompletionFunc ¶ added in v0.224.0
func RegionsCompletionFunc(ch *Helper, cmd *cobra.Command, args []string, toComplete string) ([]cobra.Completion, cobra.ShellCompDirective)
func ReportGlobalJSONError ¶ added in v0.296.0
ReportGlobalJSONError writes the classified envelope for err to w and returns the process exit code. On encoding failure it falls back to a plain error line on errW.
func RequiredArgs ¶ added in v0.3.1
func RequiredArgs(reqArgs ...string) cobra.PositionalArgs
required arguments are not available.
func SnakeToSentenceCase ¶ added in v0.221.0
func TimeToMilliseconds ¶ added in v0.131.0
func ToClusterSizeSlug ¶ added in v0.199.0
func TryOpenBrowser ¶ added in v0.292.0
TryOpenBrowser opens the default web browser at url. It does not require a TTY. Callers should print the URL when this returns an error (headless CI, SSH, etc.). Only http and https URLs are opened; other schemes and values starting with '-' are rejected.
func ValidateServiceTokenOnNotFound ¶ added in v0.244.0
func ValidateServiceTokenOnNotFound(ctx context.Context, cmd *cobra.Command, cfg *config.Config, clientFunc func() (*planetscale.Client, error), originalErr error) error
ValidateServiceTokenOnNotFound checks if a 404 error might be due to invalid service token authentication. It performs an additional authentication check when using service tokens to distinguish between a genuine "not found" error and an authentication failure.
This function should be called when: 1. The API returns a 404 error 2. The user is authenticated with a service token
Returns: - nil if the service token is valid (indicating a genuine 404) - An authentication error if the service token is invalid - The original error if not using service tokens or if the validation check fails
func WriteJSONError ¶ added in v0.296.0
func WriteJSONError(w io.Writer, resp JSONErrorResponse) error
WriteJSONError writes a JSON error envelope to w.
Types ¶
type ByteFormat ¶ added in v0.224.0
type ByteFormat struct {
// contains filtered or unexported fields
}
func FormatParts ¶ added in v0.225.0
func FormatParts(bytes int64) ByteFormat
func FormatPartsGB ¶ added in v0.226.0
func FormatPartsGB(bytes int64) ByteFormat
func (ByteFormat) IntString ¶ added in v0.224.0
func (b ByteFormat) IntString() string
func (ByteFormat) String ¶ added in v0.224.0
func (b ByteFormat) String() string
type Error ¶ added in v0.42.0
type Error struct {
Msg string
// ExitCode is returned to the shell when the command fails.
ExitCode int
// Handled suppresses Execute's stderr message when JSON was already printed to stdout.
Handled bool
}
Error can be used by a command to change the exit status of the CLI.
func JSONReportedError ¶ added in v0.292.0
JSONReportedError returns an exit error after structured JSON was written to stdout.
type Helper ¶ added in v0.14.0
type Helper struct {
// Config contains globally sourced configuration
Config *config.Config
ConfigFS *config.ConfigFS
// Client returns the PlanetScale API client
Client func() (*ps.Client, error)
// Printer is used to print output of a command to stdout.
Printer *printer.Printer
// contains filtered or unexported fields
}
Helper is passed to every single command and is used by individual subcommands.
type JSONErrorIssue ¶ added in v0.296.0
JSONErrorIssue mirrors the issue shape used by auth check, sql, and import d1 responses: a stable machine-readable code plus the human message.
type JSONErrorResponse ¶ added in v0.296.0
type JSONErrorResponse struct {
Status string `json:"status"`
Error string `json:"error"`
Issues []JSONErrorIssue `json:"issues"`
NextSteps []string `json:"next_steps"`
}
JSONErrorResponse is the fallback JSON envelope for unhandled command errors. It follows the same schema as command-specific error responses: status, error, issues (code + message), next_steps.
func GlobalJSONError ¶ added in v0.296.0
func GlobalJSONError(err error) JSONErrorResponse
GlobalJSONError classifies an error for the global JSON envelope.
Classification is by message text because this is the top-level fallback: command-specific handlers with typed errors have already had their chance. next_steps must earn their place: each case lists only the commands that actually address the failure, not generic bootstrap commands.
func (JSONErrorResponse) Code ¶ added in v0.296.0
func (r JSONErrorResponse) Code() string
Code returns the classification code of the first issue.
type PasswordRole ¶ added in v0.90.0
type PasswordRole int
const ( ReaderRole PasswordRole = iota WriterRole ReadWriterRole AdministratorRole )
func ResolveAccessRole ¶ added in v0.292.0
func ResolveAccessRole(roleFlag string, replica bool, defaultRole PasswordRole) (PasswordRole, error)
ResolveAccessRole picks the credential access level from --role and --replica, using defaultRole when neither is set (shell uses AdministratorRole; sql uses ReaderRole).
func RoleFromString ¶ added in v0.90.0
func RoleFromString(r string) (PasswordRole, error)
func (PasswordRole) ToString ¶ added in v0.90.0
func (r PasswordRole) ToString() string