buckets

package
v0.0.0-...-7c6f6d5 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DeletingBucketErr = errors.New("cannot update bucket that is currently being deleted")

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(client *rest.Client, option ...Option) *Client

NewClient creates a new instance of a Client, which provides methods for interacting with the Grail bucket management API. This function initializes and returns a new Client instance that can be used to perform various operations on the remote server.

Parameters:

  • client: A pointer to a rest.Client instance used for making HTTP requests to the remote server.
  • option: A variadic slice of apiClient Option. Each Option will be applied to the new Client and define options such as retry settings.

Returns:

  • *Client: A pointer to a new Client instance initialized with the provided rest.Client and logger.

func (Client) Create

func (c Client) Create(ctx context.Context, bucketName string, data []byte) (Response, error)

Create sends a request to the server to create a new bucket with the provided bucketName and data. The function prepares the data by setting the bucket name, then performs a POST request using the underlying apiClient. It returns a Response and an error indicating the success or failure of its execution.

If setting the bucket name in the data encounters an error, or if the HTTP request to the server fails, the function returns an empty Response and an error explaining the issue.

If you wish to receive logs from this method supply a logger inside the context using logr.NewContext.

Parameters:

  • ctx: Context for controlling the HTTP operation's lifecycle. Possibly containing a logger created with logr.NewContext.
  • bucketName: The name of the bucket to be created.
  • data: The data containing information about the new bucket.

Returns:

  • Response: A Response containing the result of the HTTP call, including status code and data.
  • error: An error if the HTTP call fails or another error happened.

func (Client) Delete

func (c Client) Delete(ctx context.Context, bucketName string) (Response, error)

Delete sends a request to the server to delete a bucket definition identified by the provided bucketName. It returns a Response and an error indicating the success or failure of the deletion operation.

If the provided bucketName is empty, the function returns an error indicating that the bucketName must be non-empty. If the HTTP request to the server fails, the method returns an empty Response and an error explaining the issue.

If you wish to receive logs from this method supply a logger inside the context using logr.NewContext.

Parameters:

  • ctx: Context for controlling the deletion operation's lifecycle. Possibly containing a logger created with logr.NewContext.
  • bucketName: The name of the bucket to be deleted.

Returns:

  • Response: A Response containing the result of the HTTP call, including status code and data.
  • error: An error if the HTTP call fails or another error happened.

func (Client) Get

func (c Client) Get(ctx context.Context, bucketName string) (Response, error)

Get retrieves a bucket definition based on the provided bucketName. The function sends a GET request to the server using the given context and bucketName. It returns a Response and an error indicating the success or failure its execution.

If the HTTP request to the server fails, the method returns an empty Response and an error explaining the issue.

If you wish to receive logs from this method supply a logger inside the context using logr.NewContext.

Parameters:

  • ctx: Context for controlling the HTTP operation's lifecycle.
  • bucketName: The name of the bucket to be retrieved.

Returns:

  • Response: A Response containing the result of the HTTP call, including status code and data.
  • error: An error if the HTTP call fails or another error happened.

func (Client) List

func (c Client) List(ctx context.Context) (ListResponse, error)

List retrieves all bucket definitions. The function sends a GET request to the server using the given context. It returns a slice of bucket Responses and an error indicating the success or failure its execution.

If the HTTP request to the server fails, the method returns an empty slice and an error explaining the issue.

If you wish to receive logs from this method supply a logger inside the context using logr.NewContext.

Parameters:

  • ctx: Context for controlling the HTTP operation's lifecycle. Possibly containing a logger created with logr.NewContext.

Returns:

  • []Response: A slice of bucket Response containing the individual buckets resulting from the HTTP call, including status code and data.
  • error: An error if the HTTP call fails or another error happened.

func (Client) Update

func (c Client) Update(ctx context.Context, bucketName string, data []byte) (Response, error)

Update attempts to update a bucket's data using the provided apiClient. It employs a retry mechanism in case of transient errors. The function returns a Response along with an error indicating the success or failure of its execution.

The update process is retried up to a fixed maximum number of times. If the update fails with certain HTTP status codes (401 Unauthorized, 403 Forbidden, 400 Bad Request), the function returns an appropriate Response immediately. If the update is successful, the function returns a Response indicating success, or if all retries fail, it returns a Response and the last encountered error, if any.

If the data to update the bucket fully matches what is already configured on the target environment, Update will not make an HTTP call, as this would needlessly increase the buckets version. This is transparent to callers and a normal StatusCode 200 Response is returned.

If you wish to receive logs from this method supply a logger inside the context using logr.NewContext.

Parameters:

  • ctx: Context for controlling the HTTP operation's lifecycle. Possibly containing a logger created with logr.NewContext.
  • bucketName: The name of the bucket to be updated.
  • data: The new data to be assigned to the bucket.

Returns:

  • Response: A Response containing the result of the HTTP operation, including status code and data.
  • error: An error if the HTTP call fails or another error happened.

func (Client) Upsert

func (c Client) Upsert(ctx context.Context, bucketName string, data []byte) (Response, error)

Upsert creates or updates a bucket definition using the provided apiClient. The function first attempts to create the bucket. If the creation is successful, it returns the created bucket. If the creation fails with a 409 conflict, the function fetches the existing bucket and performs an Update.

If the creation fails with any other HTTP status (e.g. missing authorization or invalid payload) the HTTP Response is returned immediately, as attempting an Update would likely just fail as well.

If any HTTP request to the server fails, the method returns an empty Response and an error explaining the issue.

If you wish to receive logs from this method supply a logger inside the context using logr.NewContext.

Parameters:

  • ctx: Context for controlling the upsert operation's lifecycle. Possibly containing a logger created with logr.NewContext.
  • bucketName: The name of the bucket to be upserted.
  • data: The data for creating or updating the bucket.

Returns:

  • Response: A Response containing the result of the HTTP call, including status code and data.
  • error: An error if the HTTP call fails or another error happened.

type ListResponse

type ListResponse = api.PagedListResponse

ListResponse is a Bucket API response containing multiple bucket objects. For convenience, it contains a slice of Buckets in addition to the base api.Response data.

type Option

type Option func(*Client)

Option represents a functional Option for the Client.

func WithRetrySettings

func WithRetrySettings(maxRetries int, durationBetweenTries time.Duration, maxWaitDuration time.Duration) Option

WithRetrySettings sets the maximum number of retries as well as duration between retries. These settings are honored wherever retries are used in the Client - most notably in Client.Update and Client.Upsert, as well as Client.Create when waiting for a bucket to become available after creation.

Parameters:

  • maxRetries: maximum amount actions may be retries. (Some actions may ignore this and only honor maxWaitDuration)
  • durationBetweenTries: time.Duration to wait between tries.
  • maxWaitDuration: maximum time.Duration to wait before retrying is canceled. If you supply a context.Context with a timeout, the shorter of the two will be honored.

type Response

type Response = api.Response

Jump to

Keyboard shortcuts

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