storage

package
v0.0.0-...-6a40f8d Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2017 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

View Source
const (

	// EnvUser is environmental variable for selectel api username
	EnvUser = "SELECTEL_USER"
	// EnvKey is environmental variable for selectel api key
	EnvKey = "SELECTEL_KEY"
)

Variables

View Source
var (
	// ErrorAuth occurs when client is unable to authenticate
	ErrorAuth = errors.New("Authentication error")
	// ErrorBadCredentials occurs when incorrect user/key provided
	ErrorBadCredentials = errors.New("Bad auth credentials provided")
)
View Source
var (
	// ErrorObjectNotFound occurs when server returns 404
	ErrorObjectNotFound = errors.New("Object not found")
	// ErrorBadResponce occurs when server returns unexpected code
	ErrorBadResponce = errors.New("Unable to process api responce")
	// ErrorBadName
	ErrorBadName = errors.New("Bad container/object name provided")
	// ErrorBadJSON occurs on unmarhalling error
	ErrorBadJSON = errors.New("Unable to parse api responce")
)
View Source
var (
	// ErrorConianerNotEmpty occurs when requested container is not empty
	ErrorConianerNotEmpty = errors.New("Unable to remove container with objects")
)

Functions

This section is empty.

Types

type API

type API interface {
	DoClient
	Info() StorageInformation
	Upload(reader io.Reader, container, filename, t string) error
	UploadBody(reader io.Reader, container, filename, t string) error
	UploadFile(filename, container string) error
	Auth(user, key string) error
	Debug(debug bool)
	Token() string
	C(string) ContainerAPI
	Container(string) ContainerAPI
	СopyFile(srcContainer, srcPath, dstContainer, dstPath string) error
	RemoveObject(container, filename string) error
	URL(container, filename string) string
	CreateContainer(name string, private bool) (ContainerAPI, error)
	RemoveContainer(name string) error
	// ObjectInfo returns information about object in container
	ObjectInfo(container, filename string) (f ObjectInfo, err error)
	ObjectsInfo(container string) ([]ObjectInfo, error)
	ContainerInfo(name string) (info ContainerInfo, err error)
	ContainersInfo() ([]ContainerInfo, error)
	Containers() ([]ContainerAPI, error)
	Credentials() (cache ClientCredentials)
	Dump() ([]byte, error)
}

API for selectel storage

func New

func New(user, key string) (API, error)

New returns new selectel storage api client

func NewAsync

func NewAsync(user, key string) API

NewAsync returns new api client and lazily performs auth

func NewEnv

func NewEnv() (API, error)

NewEnv acts as New, but reads credentials from environment

func NewFromCache

func NewFromCache(data []byte) (API, error)

type Client

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

Client is selectel storage api client

func (*Client) Auth

func (c *Client) Auth(user, key string) error

Auth performs authentication to selectel and stores token and storage url

func (*Client) C

func (c *Client) C(name string) ContainerAPI

C is shortcut to Client.Container

func (*Client) Container

func (c *Client) Container(name string) ContainerAPI

Container returns new ContainerAPI client binted to container name Does no checks for container existance

func (*Client) ContainerInfo

func (c *Client) ContainerInfo(name string) (info ContainerInfo, err error)

func (*Client) Containers

func (c *Client) Containers() ([]ContainerAPI, error)

Containers return all containers from storage

func (*Client) ContainersInfo

func (c *Client) ContainersInfo() ([]ContainerInfo, error)

ContainersInfo return all container-specific information from storage

func (*Client) CreateContainer

func (c *Client) CreateContainer(name string, private bool) (ContainerAPI, error)

CreateContainer creates new container and retuns it. If container already exists, function will return existing container

func (*Client) Credentials

func (c *Client) Credentials() (cache ClientCredentials)

func (*Client) Debug

func (c *Client) Debug(debug bool)

func (*Client) Do

func (c *Client) Do(request *http.Request) (res *http.Response, err error)

Do performs request with auth token

func (*Client) Dump

func (c *Client) Dump() ([]byte, error)

func (*Client) Expired

func (c *Client) Expired() bool

Expired returns true if token is expired or does not exist

func (*Client) Info

func (c *Client) Info() (info StorageInformation)

Info returns StorageInformation for current user

func (*Client) NewRequest

func (c *Client) NewRequest(method string, body io.Reader, parms ...string) (*http.Request, error)

func (*Client) ObjectInfo

func (c *Client) ObjectInfo(container, filename string) (f ObjectInfo, err error)

func (*Client) ObjectsInfo

func (c *Client) ObjectsInfo(container string) ([]ObjectInfo, error)

ObjectsInfo returns information about all objects in container

func (*Client) RemoveContainer

func (c *Client) RemoveContainer(name string) error

RemoveContainer removes container with provided name Container should be empty before removing and must exist

func (*Client) RemoveObject

func (c *Client) RemoveObject(container, filename string) error

DeleteObject removes object from specified container

func (*Client) Token

func (c *Client) Token() string

Token returns current auth token

func (*Client) URL

func (c *Client) URL(container, filename string) string

URL returns url for file in container

func (*Client) Upload

func (c *Client) Upload(reader io.Reader, container, filename, contentType string) error

Upload reads all data from reader and uploads to contaier with filename and content type

func (*Client) UploadBody

func (c *Client) UploadBody(reader io.Reader, container, filename, contentType string) error

func (*Client) UploadFile

func (c *Client) UploadFile(filename, container string) error

UploadFile to container

func (*Client) СopyFile

func (c *Client) СopyFile(srcContainer, srcPath, dstContainer, dstPath string) error

DeleteObject removes object from specified container

type ClientCredentials

type ClientCredentials struct {
	Token      string
	Debug      bool
	Expire     int
	ExpireFrom *time.Time
	URL        string
}

type Container

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

Container is realization of ContainerAPI

func (*Container) Create

func (c *Container) Create(private bool) error

Create creates current container

func (*Container) Info

func (c *Container) Info() (info ContainerInfo, err error)

func (*Container) Name

func (c *Container) Name() string

Name returns container name

func (*Container) Object

func (c *Container) Object(name string) ObjectAPI

func (*Container) ObjectInfo

func (c *Container) ObjectInfo(name string) (ObjectInfo, error)

func (*Container) Objects

func (c *Container) Objects() ([]ObjectAPI, error)

Objects returns all object from container

func (*Container) ObjectsInfo

func (c *Container) ObjectsInfo() ([]ObjectInfo, error)

ObjectsInfo returns information about all objects in container

func (*Container) Remove

func (c *Container) Remove() error

Remove removes current container

func (*Container) RemoveObject

func (c *Container) RemoveObject(filename string) error

DeleteObject is shortcut to API.DeleteObject

func (*Container) URL

func (c *Container) URL(filename string) string

URL returns url for object

func (*Container) Upload

func (c *Container) Upload(reader io.Reader, filename, contentType string) error

Upload reads all data from reader and uploads to contaier with filename and content type shortcut to API.Upload

func (*Container) UploadFile

func (c *Container) UploadFile(filename string) error

UploadFile to current container. Shortcut to API.UploadFile

type ContainerAPI

type ContainerAPI interface {
	Name() string
	Upload(reader io.Reader, name, contentType string) error
	UploadFile(filename string) error
	URL(filename string) string
	RemoveObject(name string) error
	// Remove removes current container
	Remove() error
	// Create creates current container
	Create(bool) error
	// ObjectInfo returns info about object in container
	ObjectInfo(name string) (ObjectInfo, error)
	// Object returns object from container
	Object(name string) ObjectAPI
	ObjectsInfo() ([]ObjectInfo, error)
	Objects() ([]ObjectAPI, error)
	Info() (info ContainerInfo, err error)
}

ContainerAPI is interface for selectel storage container

type ContainerInfo

type ContainerInfo struct {
	BytesUsed       uint64 `json:"bytes"`
	ObjectCount     uint64 `json:"count"`
	Name            string `json:"name"`
	RecievedBytes   uint64 `json:"rx_bytes"`
	TransferedBytes uint64 `json:"tx_bytes"`
	Type            string `json:"type"`
}

ContainerInfo is information about container

type DoClient

type DoClient interface {
	Do(request *http.Request) (*http.Response, error)
}

DoClient is mock of http.Client

type Object

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

func (*Object) Download

func (o *Object) Download() ([]byte, error)

func (*Object) GetReader

func (o *Object) GetReader() (io.ReadCloser, error)

func (*Object) Info

func (o *Object) Info() (info ObjectInfo, err error)

func (*Object) Remove

func (o *Object) Remove() error

func (*Object) Upload

func (o *Object) Upload(reader io.Reader, contentType string) error

func (*Object) UploadFile

func (o *Object) UploadFile(filename string) error

type ObjectAPI

type ObjectAPI interface {
	Info() (ObjectInfo, error)
	Remove() error
	Download() ([]byte, error)
	Upload(reader io.Reader, contentType string) error
	UploadFile(filename string) error
	GetReader() (io.ReadCloser, error)
}

type ObjectInfo

type ObjectInfo struct {
	Size            uint64    `json:"bytes"`
	ContentType     string    `json:"content_type"`
	Downloaded      uint64    `json:"downloaded"`
	Hash            string    `json:"hash"`
	LastModifiedStr string    `json:"last_modified"`
	LastModified    time.Time `json:"-"`
	Name            string    `json:"name"`
}

ObjectInfo represents object info

type StorageInformation

type StorageInformation struct {
	ObjectCount     uint64
	BytesUsed       uint64
	ContainerCount  uint64
	RecievedBytes   uint64
	TransferedBytes uint64
}

StorageInformation contains some usefull metrics about storage for current user

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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