auth

package
v0.0.0-...-ee1b036 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2016 License: Apache-2.0 Imports: 8 Imported by: 39

Documentation

Overview

Package auth provides easy methods to authenticate with Object Storage

The main fixture of the auth package is the Destination interface. Destination provides all of the features needed by the rest of swiftlygo to manipulate object storage. The default implementation, SwiftDestination, essentially wraps the github.com/ncw/swift.Connection. We did this to make it easy to write tests against mock implementations of the Destination interface. Those mock implementations can be found in the mock subpackage.

The intended use of auth is to call either Authenticate() or AuthenticateWithToken with your credentials to set up a Destination.

The names of the parameters to Authenticate may not match the names of the credentials that your OpenStack Object Store provides. In general, password and API Key are the same thing. Also domain may be called domanName and tenant may be projectID. Domain and tenant are optional parameters in some auth versions.

For IBM Bluemix object stores, you can follow the following pattern. Assuming that your service credentials look as follow:

{
  "auth_url": "https://identity.open.softlayer.com",
  "project": "project_string",
  "projectId": "project_id",
  "region": "dallas",
  "userId": "user_id",
  "username": "user_name",
  "password": "password",
  "domainId": "domain_id",
  "domainName": "domain_name",
  "role": "admin"
}

You can authenticate with:

Authenticate("user_name", "password", "https://identity.open.softlayer.com/v3", "domain_name", "")

Please note that we had to append "/v3" to the auth URL.

For Softlayer object stores, you can find your credentials in the user interface by clicking "View Credentials" when viewing an Object Storage instance in the Web UI.

You should see something like:

Authentication Endpoint:
Public: https://public-url.com.../v1.0/
Private: https://private-url.com.../v1.0/

Username:
username...

API Key (Password):
password...

You can authenticate with:

Authenticate("username...", "password...", "https:public-url.com.../v1.0/", "", "")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Destination

type Destination interface {
	CreateFile(container string, objectName string, checkHash bool, Hash string) (WriteCloseHeader, error)
	CreateSLO(containerName, manifestName, manifestEtag string, sloManifestJSON []byte) error
	CreateDLO(manifestContainer, manifestName, objectContainer, filenamePrefix string) error
	FileNames(container string) ([]string, error)
	Objects(container string) ([]swift.Object, error)
}

Destination defines a valid upload destination for files.

func Authenticate

func Authenticate(username, apiKey, authURL, domain, tenant string) (Destination, error)

Authenticate logs in to OpenStack object storage and returns a connection to the object store. The url MUST have its auth version at the end: https://example.com/v{1,2,3}

func AuthenticateWithToken

func AuthenticateWithToken(authToken, storageUrl string) (Destination, error)

AuthenticateWithToken logs in to OpenStack object storage using the authentication token and storage url and returns a connection to the object store. It also checks that the connection is valid.

type SwiftDestination

type SwiftDestination struct {
	SwiftConnection *swift.Connection
}

SwiftDestination implements the Destination interface for OpenStack Swift.

func (*SwiftDestination) CreateDLO

func (s *SwiftDestination) CreateDLO(manifestContainer, manifestName, objectContainer, filenamePrefix string) error

CreateDLO creates a dlo with the provided name and prefix in the given container.

func (*SwiftDestination) CreateFile

func (s *SwiftDestination) CreateFile(container, objectName string, checkHash bool, Hash string) (WriteCloseHeader, error)

CreateFile begins the process of creating a file in the destination. Write data to the returned WriteCloser and then close it to upload the data. Be sure to handle errors.

func (*SwiftDestination) CreateSLO

func (s *SwiftDestination) CreateSLO(containerName, manifestName, manifestEtag string, sloManifestJSON []byte) error

CreateSLO sends the provided json to the destination as an SLO manifest.

func (*SwiftDestination) FileNames

func (s *SwiftDestination) FileNames(container string) ([]string, error)

FileNames returns a slice of the names of all files already in the destination container.

func (*SwiftDestination) Objects

func (s *SwiftDestination) Objects(container string) ([]swift.Object, error)

Objects returns a slice of swift Objects that container information about the container's contents.

type WriteCloseHeader

type WriteCloseHeader interface {
	io.WriteCloser
	Headers() (swift.Headers, error)
}

WriteCloseHeader extends the io.WriteCloser with an additional method for getting a set of HTTP headers back from the WriteCloser after it is closed.

Directories

Path Synopsis
Package mock provides fake object storage endpoints for testing The structs defined here all implement the github.com/ibmjstart/swiftlygo/auth.Destination interface and are therefore useful for testing any code that uploads data via a destination.
Package mock provides fake object storage endpoints for testing The structs defined here all implement the github.com/ibmjstart/swiftlygo/auth.Destination interface and are therefore useful for testing any code that uploads data via a destination.

Jump to

Keyboard shortcuts

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