object_storage_keys.go raw

   1  package linodego
   2  
   3  import (
   4  	"context"
   5  )
   6  
   7  type ObjectStorageKeyRegion struct {
   8  	ID           string                    `json:"id"`
   9  	S3Endpoint   string                    `json:"s3_endpoint"`
  10  	EndpointType ObjectStorageEndpointType `json:"endpoint_type"`
  11  }
  12  
  13  // ObjectStorageKey represents a linode object storage key object
  14  type ObjectStorageKey struct {
  15  	ID           int                             `json:"id"`
  16  	Label        string                          `json:"label"`
  17  	AccessKey    string                          `json:"access_key"`
  18  	SecretKey    string                          `json:"secret_key"`
  19  	Limited      bool                            `json:"limited"`
  20  	BucketAccess *[]ObjectStorageKeyBucketAccess `json:"bucket_access"`
  21  	Regions      []ObjectStorageKeyRegion        `json:"regions"`
  22  }
  23  
  24  // ObjectStorageKeyBucketAccess represents a linode limited object storage key's bucket access
  25  type ObjectStorageKeyBucketAccess struct {
  26  	// Deprecated: Cluster field has been deprecated.
  27  	// Please consider switching to use the 'Region' field.
  28  	// If your Cluster is `us-mia-1`, then the region would be `us-mia`.
  29  	Cluster string `json:"cluster,omitempty"`
  30  	Region  string `json:"region,omitempty"`
  31  
  32  	BucketName  string `json:"bucket_name"`
  33  	Permissions string `json:"permissions"`
  34  }
  35  
  36  // ObjectStorageKeyCreateOptions fields are those accepted by CreateObjectStorageKey
  37  type ObjectStorageKeyCreateOptions struct {
  38  	Label        string                          `json:"label"`
  39  	BucketAccess *[]ObjectStorageKeyBucketAccess `json:"bucket_access,omitempty"`
  40  	Regions      []string                        `json:"regions,omitempty"`
  41  }
  42  
  43  // ObjectStorageKeyUpdateOptions fields are those accepted by UpdateObjectStorageKey
  44  type ObjectStorageKeyUpdateOptions struct {
  45  	Label   string   `json:"label,omitempty"`
  46  	Regions []string `json:"regions,omitempty"`
  47  }
  48  
  49  // ListObjectStorageKeys lists ObjectStorageKeys
  50  func (c *Client) ListObjectStorageKeys(ctx context.Context, opts *ListOptions) ([]ObjectStorageKey, error) {
  51  	return getPaginatedResults[ObjectStorageKey](ctx, c, "object-storage/keys", opts)
  52  }
  53  
  54  // CreateObjectStorageKey creates a ObjectStorageKey
  55  func (c *Client) CreateObjectStorageKey(ctx context.Context, opts ObjectStorageKeyCreateOptions) (*ObjectStorageKey, error) {
  56  	return doPOSTRequest[ObjectStorageKey](ctx, c, "object-storage/keys", opts)
  57  }
  58  
  59  // GetObjectStorageKey gets the object storage key with the provided ID
  60  func (c *Client) GetObjectStorageKey(ctx context.Context, keyID int) (*ObjectStorageKey, error) {
  61  	e := formatAPIPath("object-storage/keys/%d", keyID)
  62  	return doGETRequest[ObjectStorageKey](ctx, c, e)
  63  }
  64  
  65  // UpdateObjectStorageKey updates the object storage key with the specified id
  66  func (c *Client) UpdateObjectStorageKey(ctx context.Context, keyID int, opts ObjectStorageKeyUpdateOptions) (*ObjectStorageKey, error) {
  67  	e := formatAPIPath("object-storage/keys/%d", keyID)
  68  	return doPUTRequest[ObjectStorageKey](ctx, c, e, opts)
  69  }
  70  
  71  // DeleteObjectStorageKey deletes the ObjectStorageKey with the specified id
  72  func (c *Client) DeleteObjectStorageKey(ctx context.Context, keyID int) error {
  73  	e := formatAPIPath("object-storage/keys/%d", keyID)
  74  	return doDELETERequest(ctx, c, e)
  75  }
  76