aksk

package
v1.0.21 Latest Latest
Warning

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

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

Documentation

Overview

Package signer providers functions for sign http request before request cloud.

Index

Constants

View Source
const ContentSha256HeaderKey = "x-sdk-content-sha256"

The header key of content hash value

View Source
const SignAlgorithmHMACSHA256 = "SDK-HMAC-SHA256"

The default sign algorithm

Variables

This section is empty.

Functions

func HashSha256

func HashSha256(msg []byte) []byte

HashSha256 is a wrapper for sha256 implementation.

func HmacSha256

func HmacSha256(data string, key []byte) []byte

HmacSha256 implements the Keyed-Hash Message Authentication Code computation.

func Sign

func Sign(req *http.Request, signOptions SignOptions)

Sign manipulates the http.Request instance with some required authentication headers for SK/SK auth.

Types

type AKSKOptions

type AKSKOptions struct {
	// IdentityEndpoint specifies the HTTP endpoint that is required to work with
	// the Identity API of the appropriate version. While it's ultimately needed by
	// all of the identity services, it will often be populated by a provider-level
	// function.
	//
	// The IdentityEndpoint is typically referred to as the "auth_url" or
	// "OS_AUTH_URL" in the information provided by the cloud operator.
	IdentityEndpoint string `json:"-" required:"true"`

	// user project id
	ProjectID string

	DomainID string `json:"-" required:"true"`

	// region
	Region string

	//Cloud name
	Domain string

	//Cloud name
	Cloud string

	AccessKey string //Access Key
	SecretKey string //Secret key

	SecurityToken string
}

AKSKAuthOptions presents the required information for AK/SK auth

func (AKSKOptions) GetDomainId

func (opts AKSKOptions) GetDomainId() string

GetDomainId,Implements the method of AuthOptionsProvider

func (AKSKOptions) GetIdentityEndpoint

func (opts AKSKOptions) GetIdentityEndpoint() string

GetIdentityEndpoint,Implements the method of AuthOptionsProvider

func (AKSKOptions) GetProjectId

func (opts AKSKOptions) GetProjectId() string

GetProjectId, Implements the method of AuthOptionsProvider

type MemoryCache

type MemoryCache struct {
	sync.Mutex // handling r/w for cache

	MaxCount int // max cache entry count
	// contains filtered or unexported fields
}

MemoryCache presents a thread safe memory cache

func NewCache

func NewCache(maxCount int) *MemoryCache

NewCache inits an new MemoryCache

func (*MemoryCache) Add

func (cache *MemoryCache) Add(cacheKey string, cacheData string)

Add an new cache item

func (*MemoryCache) Get

func (cache *MemoryCache) Get(cacheKey string) string

Get a cache item by its key

type SignOptions

type SignOptions struct {
	AccessKey          string //Access Key
	SecretKey          string //Secret key
	RegionName         string // Region name
	ServiceName        string // Service Name
	EnableCacheSignKey bool   // Cache sign key for one day or not cache, cache is disabled by default

	SignAlgorithm       string //The algorithm used for sign, the default value is "SDK-HMAC-SHA256" if you don't set its value
	TimeOffsetInseconds int64  // TimeOffsetInseconds is used for adjust x-sdk-date if set its value
	// contains filtered or unexported fields
}

SignOptions represents the options during signing http request, it is concurrency safely. Sample code:

client := &http.Client{
	Timeout: time.Duration(3 * time.Second),
}
req, err := http.NewRequest("POST", "https://30030113-3657-4fb6-a7ef-90764239b038.apigw.xxx.yyy.com/app1?name=value",bytes.NewBuffer([]byte("demo")))

signOptions := signer.SignOptions{
	AccessKey: "------------",
	SecretKey: "------------",
}

signer.Sign(req, signOptions)
resp, err := client.Do(req)

type StringBuilder

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

StringBuilder wraps bytes.Buffer to implement a high performance string builder.

func (*StringBuilder) GetBytes

func (buff *StringBuilder) GetBytes() []byte

func (*StringBuilder) ToString

func (buff *StringBuilder) ToString() string

func (*StringBuilder) Write

func (buff *StringBuilder) Write(s string) *StringBuilder

Jump to

Keyboard shortcuts

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