containers

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

README

Blob Storage Container SDK for API version 2023-11-03

This package allows you to interact with the Containers Blob Storage API

Supported Authorizers

  • Azure Active Directory (for the Resource Endpoint https://storage.azure.com)
  • SharedKeyLite (Blob, File & Queue)

Note: when using the ListBlobs operation, only SharedKeyLite authentication is supported.

Example Usage

package main

import (
	"context"
	"fmt"

	"github.com/hashicorp/go-azure-sdk/sdk/auth"
	"github.com/tombuildsstuff/giovanni/storage/2023-11-03/blob/containers"
)

func Example() error {
	accountName := "storageaccount1"
    storageAccountKey := "ABC123...."
    containerName := "mycontainer"
	domainSuffix := "core.windows.net"

    containersClient, err := containers.NewWithBaseUri(fmt.Sprintf("https://%s.blob.%s", accountName, domainSuffix))
	if err != nil {
		return fmt.Errorf("building client for environment: %+v", err)
	}

	auth, err := auth.NewSharedKeyAuthorizer(accountName, storageAccountKey, auth.SharedKey)
	if err != nil {
		return fmt.Errorf("building SharedKey authorizer: %+v", err)
	}
	containersClient.Client.SetAuthorizer(auth)
    
    ctx := context.TODO()
    createInput := containers.CreateInput{
        AccessLevel: containers.Private,
    }
    if _, err := containersClient.Create(ctx, containerName, createInput); err != nil {
        return fmt.Errorf("Error creating Container: %s", err)
    }
    
    return nil 
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessLevel

type AccessLevel string
var (
	// Blob specifies public read access for blobs.
	// Blob data within this container can be read via anonymous request,
	// but container data is not available.
	// Clients cannot enumerate blobs within the container via anonymous request.
	Blob AccessLevel = "blob"

	// Container specifies full public read access for container and blob data.
	// Clients can enumerate blobs within the container via anonymous request,
	// but cannot enumerate containers within the storage account.
	Container AccessLevel = "container"

	// Private specifies that container data is private to the account owner
	Private AccessLevel = ""
)

type AcquireLeaseInput

type AcquireLeaseInput struct {
	// Specifies the duration of the lease, in seconds, or negative one (-1) for a lease that never expires.
	// A non-infinite lease can be between 15 and 60 seconds
	LeaseDuration int

	ProposedLeaseID string
}

type AcquireLeaseModel

type AcquireLeaseModel struct {
	LeaseID string
}

type AcquireLeaseResponse

type AcquireLeaseResponse struct {
	AcquireLeaseModel
	HttpResponse *http.Response
}

type BlobDetails

type BlobDetails struct {
	Name       string                 `xml:"Name"`
	Deleted    bool                   `xml:"Deleted,omitempty"`
	MetaData   map[string]interface{} `map:"Metadata,omitempty"`
	Properties *BlobProperties        `xml:"Properties,omitempty"`
	Snapshot   *string                `xml:"Snapshot,omitempty"`
}

type BlobPrefix

type BlobPrefix struct {
	Name string `xml:"Name"`
}

type BlobProperties

type BlobProperties struct {
	AccessTier             *string `xml:"AccessTier,omitempty"`
	AccessTierInferred     *bool   `xml:"AccessTierInferred,omitempty"`
	AccessTierChangeTime   *string `xml:"AccessTierChangeTime,omitempty"`
	BlobType               *string `xml:"BlobType,omitempty"`
	BlobSequenceNumber     *string `xml:"x-ms-blob-sequence-number,omitempty"`
	CacheControl           *string `xml:"Cache-Control,omitempty"`
	ContentEncoding        *string `xml:"ContentEncoding,omitempty"`
	ContentLanguage        *string `xml:"Content-Language,omitempty"`
	ContentLength          *int64  `xml:"Content-Length,omitempty"`
	ContentMD5             *string `xml:"Content-MD5,omitempty"`
	ContentType            *string `xml:"Content-Type,omitempty"`
	CopyCompletionTime     *string `xml:"CopyCompletionTime,omitempty"`
	CopyId                 *string `xml:"CopyId,omitempty"`
	CopyStatus             *string `xml:"CopyStatus,omitempty"`
	CopySource             *string `xml:"CopySource,omitempty"`
	CopyProgress           *string `xml:"CopyProgress,omitempty"`
	CopyStatusDescription  *string `xml:"CopyStatusDescription,omitempty"`
	CreationTime           *string `xml:"CreationTime,omitempty"`
	ETag                   *string `xml:"Etag,omitempty"`
	DeletedTime            *string `xml:"DeletedTime,omitempty"`
	IncrementalCopy        *bool   `xml:"IncrementalCopy,omitempty"`
	LastModified           *string `xml:"Last-Modified,omitempty"`
	LeaseDuration          *string `xml:"LeaseDuration,omitempty"`
	LeaseState             *string `xml:"LeaseState,omitempty"`
	LeaseStatus            *string `xml:"LeaseStatus,omitempty"`
	RemainingRetentionDays *string `xml:"RemainingRetentionDays,omitempty"`
	ServerEncrypted        *bool   `xml:"ServerEncrypted,omitempty"`
}

type Blobs

type Blobs struct {
	Blobs      []BlobDetails `xml:"Blob"`
	BlobPrefix *BlobPrefix   `xml:"BlobPrefix"`
}

type BreakLeaseInput

type BreakLeaseInput struct {
	//  For a break operation, proposed duration the lease should continue
	//  before it is broken, in seconds, between 0 and 60.
	//  This break period is only used if it is shorter than the time remaining on the lease.
	//  If longer, the time remaining on the lease is used.
	//  A new lease will not be available before the break period has expired,
	//  but the lease may be held for longer than the break period.
	//  If this header does not appear with a break operation, a fixed-duration lease breaks
	//  after the remaining lease period elapses, and an infinite lease breaks immediately.
	BreakPeriod *int

	LeaseID string
}

type BreakLeaseModel

type BreakLeaseModel struct {
	// Approximate time remaining in the lease period, in seconds.
	// If the break is immediate, 0 is returned.
	LeaseTime int
}

type BreakLeaseResponse

type BreakLeaseResponse struct {
	BreakLeaseModel
	HttpResponse *http.Response
}

type ChangeLeaseInput

type ChangeLeaseInput struct {
	ExistingLeaseID string
	ProposedLeaseID string
}

type ChangeLeaseModel

type ChangeLeaseModel struct {
	LeaseID string
}

type ChangeLeaseResponse

type ChangeLeaseResponse struct {
	ChangeLeaseModel
	HttpResponse *http.Response
}

type Client

type Client struct {
	Client *storage.Client
}

Client is the base client for Blob Storage Containers.

func NewWithBaseUri

func NewWithBaseUri(baseUri string) (*Client, error)

func (Client) AcquireLease

func (c Client) AcquireLease(ctx context.Context, containerName string, input AcquireLeaseInput) (result AcquireLeaseResponse, err error)

AcquireLease establishes and manages a lock on a container for delete operations.

func (Client) BreakLease

func (c Client) BreakLease(ctx context.Context, containerName string, input BreakLeaseInput) (result BreakLeaseResponse, err error)

BreakLease breaks a lock based on it's Lease ID

func (Client) ChangeLease

func (c Client) ChangeLease(ctx context.Context, containerName string, input ChangeLeaseInput) (result ChangeLeaseResponse, err error)

ChangeLease changes the lock from one Lease ID to another Lease ID

func (Client) Create

func (c Client) Create(ctx context.Context, containerName string, input CreateInput) (result CreateResponse, err error)

Create creates a new container under the specified account. If the container with the same name already exists, the operation fails.

func (Client) Delete

func (c Client) Delete(ctx context.Context, containerName string) (result DeleteResponse, err error)

Delete marks the specified container for deletion. The container and any blobs contained within it are later deleted during garbage collection.

func (Client) GetProperties

func (c Client) GetProperties(ctx context.Context, containerName string, input GetPropertiesInput) (result GetPropertiesResponse, err error)

GetProperties returns the properties for this Container without a Lease

func (Client) GetResourceManagerResourceID

func (c Client) GetResourceManagerResourceID(subscriptionID, resourceGroup, accountName, containerName string) string

GetResourceManagerResourceID returns the Resource Manager specific ResourceID for a specific Storage Container

func (Client) ListBlobs

func (c Client) ListBlobs(ctx context.Context, containerName string, input ListBlobsInput) (result ListBlobsResponse, err error)

ListBlobs lists the blobs matching the specified query within the specified Container

func (Client) ReleaseLease

func (c Client) ReleaseLease(ctx context.Context, containerName string, input ReleaseLeaseInput) (result ReleaseLeaseResponse, err error)

ReleaseLease releases the lock based on the Lease ID

func (Client) RenewLease

func (c Client) RenewLease(ctx context.Context, containerName string, input RenewLeaseInput) (result RenewLeaseResponse, err error)

RenewLease renews the lock based on the Lease ID

func (Client) SetAccessControl

func (c Client) SetAccessControl(ctx context.Context, containerName string, input SetAccessControlInput) (result SetAccessControlResponse, err error)

SetAccessControl sets the Access Control for a Container without a Lease ID NOTE: The SetAccessControl operation only supports Shared Key authorization.

func (Client) SetMetaData

func (c Client) SetMetaData(ctx context.Context, containerName string, input SetMetaDataInput) (result SetMetaDataResponse, err error)

SetMetaData sets the specified MetaData on the Container without a Lease ID

type ContainerId added in v0.22.0

type ContainerId struct {
	// AccountId specifies the ID of the Storage Account where this Container exists.
	AccountId accounts.AccountId

	// ContainerName specifies the name of this Container.
	ContainerName string
}

func NewContainerID added in v0.22.0

func NewContainerID(accountId accounts.AccountId, containerName string) ContainerId

func ParseContainerID added in v0.22.0

func ParseContainerID(input, domainSuffix string) (*ContainerId, error)

ParseContainerID parses `input` into a Container ID using a known `domainSuffix`

func (ContainerId) ID added in v0.22.0

func (b ContainerId) ID() string

func (ContainerId) String added in v0.22.0

func (b ContainerId) String() string

type ContainerProperties

type ContainerProperties struct {
	AccessLevel                     AccessLevel
	DefaultEncryptionScope          string
	EncryptionScopeOverrideDisabled bool
	LeaseStatus                     LeaseStatus
	LeaseState                      LeaseState
	LeaseDuration                   *LeaseDuration
	MetaData                        map[string]string
	HasImmutabilityPolicy           bool
	HasLegalHold                    bool
}

type CreateInput

type CreateInput struct {
	// Specifies whether data in the container may be accessed publicly and the level of access
	AccessLevel AccessLevel

	// The encryption scope to set as the default on the container.
	DefaultEncryptionScope string

	// Setting this to ture indicates that every blob that's uploaded to this container uses the default encryption scope.
	EncryptionScopeOverrideDisabled bool

	// A name-value pair to associate with the container as metadata.
	MetaData map[string]string
}

type CreateResponse

type CreateResponse struct {
	HttpResponse *http.Response
}

type Dataset

type Dataset string
var (
	Copy             Dataset = "copy"
	Deleted          Dataset = "deleted"
	MetaData         Dataset = "metadata"
	Snapshots        Dataset = "snapshots"
	UncommittedBlobs Dataset = "uncommittedblobs"
)

type DeleteResponse

type DeleteResponse struct {
	HttpResponse *http.Response
}

type ErrorResponse

type ErrorResponse struct {
	XMLName xml.Name `xml:"Error"`
	Code    *string  `xml:"Code"`
	Message *string  `xml:"Message"`
}

type GetPropertiesInput

type GetPropertiesInput struct {
	LeaseId string
}

type GetPropertiesResponse

type GetPropertiesResponse struct {
	ContainerProperties
	HttpResponse *http.Response
}

type LeaseDuration

type LeaseDuration string
var (
	// If this lease is for a Fixed Duration
	Fixed LeaseDuration = "fixed"

	// If this lease is for an Indefinite Duration
	Infinite LeaseDuration = "infinite"
)

type LeaseState

type LeaseState string
var (
	Available LeaseState = "available"
	Breaking  LeaseState = "breaking"
	Broken    LeaseState = "broken"
	Expired   LeaseState = "expired"
	Leased    LeaseState = "leased"
)

type LeaseStatus

type LeaseStatus string
var (
	Locked   LeaseStatus = "locked"
	Unlocked LeaseStatus = "unlocked"
)

type ListBlobsInput

type ListBlobsInput struct {
	Delimiter  *string
	Include    *[]Dataset
	Marker     *string
	MaxResults *int
	Prefix     *string
}

type ListBlobsResponse

type ListBlobsResponse struct {
	ListBlobsResult

	HttpResponse *http.Response
}

type ListBlobsResult

type ListBlobsResult struct {
	Delimiter  string  `xml:"Delimiter"`
	Marker     string  `xml:"Marker"`
	MaxResults int     `xml:"MaxResults"`
	NextMarker *string `xml:"NextMarker,omitempty"`
	Prefix     string  `xml:"Prefix"`
	Blobs      Blobs   `xml:"Blobs"`
}

type ReleaseLeaseInput

type ReleaseLeaseInput struct {
	LeaseId string
}

type ReleaseLeaseResponse

type ReleaseLeaseResponse struct {
	HttpResponse *http.Response
}

type RenewLeaseInput

type RenewLeaseInput struct {
	LeaseId string
}

type RenewLeaseResponse

type RenewLeaseResponse struct {
	HttpResponse *http.Response
}

type SetAccessControlInput

type SetAccessControlInput struct {
	AccessLevel AccessLevel
	LeaseId     string
}

type SetAccessControlResponse

type SetAccessControlResponse struct {
	HttpResponse *http.Response
}

type SetMetaDataInput

type SetMetaDataInput struct {
	MetaData map[string]string
	LeaseId  string
}

type SetMetaDataResponse

type SetMetaDataResponse struct {
	HttpResponse *http.Response
}

type StorageContainer

type StorageContainer interface {
	Create(ctx context.Context, containerName string, input CreateInput) (CreateResponse, error)
	Delete(ctx context.Context, containerName string) (DeleteResponse, error)
	GetProperties(ctx context.Context, containerName string, input GetPropertiesInput) (GetPropertiesResponse, error)
	AcquireLease(ctx context.Context, containerName string, input AcquireLeaseInput) (AcquireLeaseResponse, error)
	BreakLease(ctx context.Context, containerName string, input BreakLeaseInput) (BreakLeaseResponse, error)
	ChangeLease(ctx context.Context, containerName string, input ChangeLeaseInput) (ChangeLeaseResponse, error)
	ReleaseLease(ctx context.Context, containerName string, input ReleaseLeaseInput) (ReleaseLeaseResponse, error)
	RenewLease(ctx context.Context, containerName string, input RenewLeaseInput) (RenewLeaseResponse, error)
	ListBlobs(ctx context.Context, containerName string, input ListBlobsInput) (ListBlobsResponse, error)
	GetResourceManagerResourceID(subscriptionID, resourceGroup, accountName, containerName string) string
	SetAccessControl(ctx context.Context, containerName string, input SetAccessControlInput) (SetAccessControlResponse, error)
	SetMetaData(ctx context.Context, containerName string, metaData SetMetaDataInput) (SetMetaDataResponse, error)
}

Jump to

Keyboard shortcuts

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