gcsops

package
v1.86.0 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package gcsops provides an API client implementing a fraction of Cloud Storage's API originally needed by gcslock and packages using it.

Index

Constants

View Source
const Endpoint = "https://storage.googleapis.com"

Endpoint is the top-level part of request endpoints to access Cloud Storage.

Variables

View Source
var (
	// Error is the error class for this package.
	Error = errs.Class("gcsops")

	// ErrNotFound is returned when the requested resource is not available.
	ErrNotFound = Error.New("not found")
	// ErrPreconditionFailed is returned when one or more conditions given in
	// the request header fields evaluated to false when tested on the server.
	ErrPreconditionFailed = Error.New("precondition failed")
)

Functions

This section is empty.

Types

type APIError

type APIError struct {
	// Status is the HTTP status (e.g. 502 Gateway Timeout) from the response.
	Status string

	// Message contains details of the error.
	Message string `json:"message" xml:"Message"`
}

APIError is an API response error from Google Cloud Storage.

See the following docs for more details:

func (APIError) Error

func (e APIError) Error() string

Error implements the error interface.

type Client

type Client struct {
	HTTPClient *http.Client
}

Client implements a fraction of Cloud Storage's API originally needed by gcslock and packages using it.

func NewClient

func NewClient(ctx context.Context, jsonKey []byte) (_ *Client, err error)

NewClient properly initializes new Client. It awkwardly takes context.Context because it uses oauth2 that stores it.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, headers http.Header, bucket, name string) (err error)

Delete deletes from the bucket. It uses XML API.

func (*Client) Download

func (c *Client) Download(ctx context.Context, bucket, name string) (_ io.ReadCloser, err error)

Download downloads from the bucket. It uses XML API.

func (*Client) List

func (c *Client) List(ctx context.Context, bucket, prefix string, recursive bool) (_ []string, err error)

List lists the bucket. It uses JSON API.

func (*Client) Stat

func (c *Client) Stat(ctx context.Context, bucket, name string) (_ http.Header, err error)

Stat stats in the bucket. It uses XML API.

func (*Client) TestPermissions

func (c *Client) TestPermissions(ctx context.Context, bucket string) (err error)

TestPermissions does a self-check of the current user's permissions in GCS. It returns nil if all permissions are correct, otherwise an error about the missing permission or error contacting the API.

func (*Client) Upload

func (c *Client) Upload(ctx context.Context, headers http.Header, bucket, name string, body io.Reader) (err error)

Upload uploads to the bucket. It uses XML API.

Jump to

Keyboard shortcuts

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