auth

package
v0.9.7 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package auth implements the authorization functionality for BCE. It use the BCE access key ID and secret access key with the specific sign algorithm to generate the authorization string. It also supports the temporary authorization by the STS token.

Index

Constants

This section is empty.

Variables

View Source
var (
	BCE_AUTH_VERSION        = "bce-auth-v1"
	SIGN_JOINER             = "\n"
	SIGN_HEADER_JOINER      = ";"
	DEFAULT_EXPIRE_SECONDS  = 1800
	DEFAULT_HEADERS_TO_SIGN = map[string]struct{}{
		strings.ToLower(http.HOST):           {},
		strings.ToLower(http.CONTENT_LENGTH): {},
		strings.ToLower(http.CONTENT_TYPE):   {},
		strings.ToLower(http.CONTENT_MD5):    {},
	}
)

Functions

This section is empty.

Types

type BceCredentials

type BceCredentials struct {
	AccessKeyId     string // access key id to the service
	SecretAccessKey string // secret access key to the service
	SessionToken    string // session token generate by the STS service
}

BceCredentials define the data structure for authorization

func NewBceCredentials

func NewBceCredentials(ak, sk string) (*BceCredentials, error)

func NewSessionBceCredentials

func NewSessionBceCredentials(ak, sk, token string) (*BceCredentials, error)

func (*BceCredentials) String

func (b *BceCredentials) String() string

type BceV1Signer

type BceV1Signer struct{}

BceV1Signer implements the v1 sign algorithm

func (*BceV1Signer) Sign

func (b *BceV1Signer) Sign(req *http.Request, cred *BceCredentials, opt *SignOptions)

Sign - generate the authorization string from the BceCredentials and SignOptions

PARAMS:

  • req: *http.Request for this sign
  • cred: *BceCredentials to access the serice
  • opt: *SignOptions for this sign algorithm

type SignOptions

type SignOptions struct {
	HeadersToSign map[string]struct{}
	Timestamp     int64
	ExpireSeconds int
}

SignOptions defines the data structure used by Signer

func (*SignOptions) String

func (opt *SignOptions) String() string

type Signer

type Signer interface {
	// Sign the given Request with the Credentials and SignOptions
	Sign(*http.Request, *BceCredentials, *SignOptions)
}

Signer abstracts the entity that implements the `Sign` method

Jump to

Keyboard shortcuts

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