Documentation
¶
Overview ¶
Package gcp is the CLI's Google Cloud client: REST over net/http with the tokens of gcloud (no Google client library), Google's error JSON as *Error, and the waiting of long-running and Compute Engine operations.
Index ¶
- Constants
- func ExecRunner(ctx context.Context, name string, args ...string) ([]byte, error)
- func IsAlreadyExists(err error) bool
- func IsConflict(err error) bool
- func IsDenied(err error) bool
- func IsExhausted(err error) bool
- func IsNotFound(err error) bool
- func IsPrecondition(err error) bool
- func WaitCompute(ctx context.Context, c *Client, selfLink string, timeout time.Duration) error
- func WaitOperation(ctx context.Context, c *Client, url string, every, timeout time.Duration) error
- type Client
- type Error
- type Runner
- type TokenSource
Constants ¶
const InvokeTimeout = 1860 * time.Second
InvokeTimeout bounds one call of Invoke: the controller's longest request (its timeoutSeconds, 1800 s: a wake of up to 1700 s runs inside it) and a margin to read its answer.
Variables ¶
This section is empty.
Functions ¶
func ExecRunner ¶
ExecRunner is the default Runner, on os/exec; a failure carries stderr.
func IsAlreadyExists ¶
IsAlreadyExists is a 409 whose status is ALREADY_EXISTS (a 409 may also be ABORTED: the call lost a race).
func IsExhausted ¶ added in v0.11.0
IsExhausted tells a quota or rate limit's refusal, a 429 (after Do's own tries).
func IsPrecondition ¶
IsPrecondition is a 412, or a 400 whose status is FAILED_PRECONDITION.
func WaitCompute ¶
WaitCompute polls a Compute Engine operation's selfLink until it is DONE.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
Tokens TokenSource
// Sleep waits between the tries of a read that met a transient error (nil: a timer).
Sleep func(ctx context.Context, d time.Duration) error
}
Client calls Google Cloud REST APIs as the account of Tokens.
func (*Client) Do ¶
Do sends in as JSON (when non-nil) and decodes the answer into out (when non-nil). A non-2xx answer is an *Error. A 401 (the token expired before gcloud's cache knew it) drops the cached token and sends the request once more with a new one from gcloud. A read answered 429, 500, 502, 503 or 504 is tried again up to 3 times, after 1 s, 2 s and 4 s; a request that may change something is sent once.
func (*Client) Head ¶
Head is Do's HEAD, asking for the media types of accept: nil when the resource is there.
func (*Client) Invoke ¶
Invoke is Do with an identity token for audience instead of the access token: a call of a Cloud Run service whose invoker IAM check is on.
A controller call may take long (an offboarding wakes the workload inside its request, up to 1700 s): it is bound by InvokeTimeout, not by the shorter timeout of the client Do uses.
type Error ¶
type Error struct {
Code int
Status string
Reason string
Message string
Permission string
Service string
}
Error is a Google Cloud API error. Reason, Permission and Service are from its google.rpc.ErrorInfo: Service is the API a SERVICE_DISABLED names.
type TokenSource ¶
type TokenSource interface {
AccessToken(ctx context.Context) (string, error)
IdentityToken(ctx context.Context, audience string) (string, error)
Account(ctx context.Context) (string, error)
}
TokenSource gives the credentials of the Google account in use.
func NewGcloud ¶
func NewGcloud(configuration string, run Runner) TokenSource
NewGcloud reads the tokens from gcloud's configuration (empty: the active one). A nil run is ExecRunner.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package access is the manifest of what Dormeto needs in Google Cloud: the APIs, the custom roles, the predefined roles' permissions, the router's grants and, per `dormeto gcp` command, the permissions the operator needs by step.
|
Package access is the manifest of what Dormeto needs in Google Cloud: the APIs, the custom roles, the predefined roles' permissions, the router's grants and, per `dormeto gcp` command, the permissions the operator needs by step. |
|
Package gcptest is a fake Google Cloud for tests: an httptest.Server and an http.Client whose transport sends every request for a *.googleapis.com, *.pkg.dev or *.run.app host to it, so production code keeps its real URLs.
|
Package gcptest is a fake Google Cloud for tests: an httptest.Server and an http.Client whose transport sends every request for a *.googleapis.com, *.pkg.dev or *.run.app host to it, so production code keeps its real URLs. |