cdmi

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: Apache-2.0 Imports: 9 Imported by: 6

README

cdmi-client-go

Go Report Card go.dev reference GitHub

A basic Go library to perform the core container and object operations defined in the Cloud Data Management Interface (CDMI) specification.

Installation

go get github.com/grycap/cdmi-client-go

Example

package main

import (
    "io"
    "net/url"
    "os"

    "github.com/grycap/cdmi-client-go"
)

func main() {
    // CDMI Server endpoint
    endpoint, _ := url.Parse("https://my-cdmi-server.example")
    // Bearer auth token (if not required set an empty string)
    token := "my-token"
    // Verify SSL certificates
    verify := true

    // Create a new CDMI client
    client := cdmi.New(endpoint, token, verify)

    // Create a container (directory)
    err := client.CreateContainer("newcontainerName/anotherContainer", true)
    if err != nil {
        // Example: ignore error 400 (folder already exists)
        if err != cdmi.ErrBadRequest {
            // Manage error
        }
    }

    // Upload a file
    file, _ := os.Open("/path/to/file")
    defer file.Close()
    err = client.CreateObject("containerName/objectName", file, true)
    if err != nil {
        // Manage error
    }

    // Download a file
    newFile, _ := os.Create("/path/to/new/file")
    defer newFile.Close()
    content, err := client.GetObject("containerName/objectName")
    if err != nil {
        // Manage error
    }
    defer content.Close()
    io.Copy(newFile, content)
}

All available methods can be found at pkg.go.dev reference.

Documentation

Overview

Package cdmi provides a client to perform the core container and object operations defined in the Cloud Data Management Interface specification.

Index

Constants

View Source
const (
	// Version default CDMI version used.
	Version = "1.1.1"

	// VersionHeader CDMI version header key.
	VersionHeader = "X-CDMI-Specification-Version"

	// ObjectHeader HTTP header for CDMI objects.
	ObjectHeader = "application/cdmi-object"

	// ContainerHeader HTTP header for CDMI containers.
	ContainerHeader = "application/cdmi-container"
)

Variables

View Source
var (
	// ErrBadRequest error thrown when request contains invalid parameters or field names (HTTP status code 400).
	ErrBadRequest = errors.New("The request contains invalid parameters or field names")

	// ErrUnauthorized error thrown when authentication credentials are missing or invalid (HTTP status code 401).
	ErrUnauthorized = errors.New("The authentication credentials are missing or invalid")

	// ErrForbidden error thrown when client lacks the proper authorization to perform this request (HTTP status code 403).
	ErrForbidden = errors.New("The client lacks the proper authorization to perform this request")

	// ErrNotFound error thrown when resource was not found at the specified URI (HTTP status code 404).
	ErrNotFound = errors.New("The resource was not found at the specified URI")

	// ErrNotAcceptable error thrown when server is unable to provide the object in the content type specified in the Accept header (HTTP status code 406).
	ErrNotAcceptable = errors.New("The server is unable to provide the object in the content type specified in the Accept header")

	// ErrConflict error thrown when operation conflicts with a non-CDMI access protocol lock or has caused a state transition error on the server (HTTP status code 409).
	ErrConflict = errors.New("The operation conflicts with a non-CDMI access protocol lock or has caused a state transition error on the server")

	// ErrInternalServer error thrown when server fails (HTTP status code 500).
	ErrInternalServer = errors.New("Internal server error")
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Endpoint   *url.URL
	HTTPClient *http.Client
}

Client represents a CDMI client.

func New

func New(endpoint *url.URL, token string, verify bool) *Client

New creates a new CDMI client. If the CDMI server doesn't implement auth, token must be an empty string.

func (*Client) CreateContainer

func (c *Client) CreateContainer(containerPath string, parents bool) error

CreateContainer creates a new container on the specified path. If parents is set to true, it creates the required parent directories.

func (*Client) CreateObject

func (c *Client) CreateObject(objectPath string, data io.Reader, createContainer bool) error

CreateObject creates a new object with the io.Reader data in the specified path. If createContainer is set to true it creates all required parent directories.

func (*Client) DeleteContainer

func (c *Client) DeleteContainer(containerPath string) error

DeleteContainer deletes a container including all its children.

func (*Client) DeleteObject

func (c *Client) DeleteObject(objectPath string) error

DeleteObject deletes the specified object.

func (*Client) GetObject

func (c *Client) GetObject(objectPath string) (io.ReadCloser, error)

GetObject GetObject returns an io.ReadCloser with the content of the specified object.

func (*Client) ReadContainer

func (c *Client) ReadContainer(containerPath string) ([]string, error)

ReadContainer returns a slice with children (containers and objects) of the specified container.

Jump to

Keyboard shortcuts

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