common

package module
v1.0.910 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2024 License: Apache-2.0 Imports: 34 Imported by: 3,277

Documentation

Index

Constants

View Source
const (
	StateClosed state = iota
	StateHalfOpen
	StateOpen
)

These constants are states of CircuitBreaker.

View Source
const (
	SHA256 = "HmacSHA256"
	SHA1   = "HmacSHA1"
)
View Source
const (
	EnvCredentialFile = "TENCENTCLOUD_CREDENTIALS_FILE"
)
View Source
const ExpiredTimeout = 300

Variables

View Source
var DefaultHttpClient *http.Client

Functions

func BoolPtr

func BoolPtr(v bool) *bool

func BoolPtrs

func BoolPtrs(vals []bool) []*bool

func Float64Ptr

func Float64Ptr(v float64) *float64

func Float64Ptrs

func Float64Ptrs(vals []float64) []*float64

func Int64Ptr

func Int64Ptr(v int64) *int64

func Int64Ptrs

func Int64Ptrs(vals []int64) []*int64

func IntPtr

func IntPtr(v int) *int

func IntPtrs

func IntPtrs(vals []int) []*int

func Sign

func Sign(s, secretKey, method string) string

func StringPtr

func StringPtr(v string) *string

func StringPtrs

func StringPtrs(vals []string) []*string

func StringValues

func StringValues(ptrs []*string) []string

func Uint64Ptr

func Uint64Ptr(v uint64) *uint64

func Uint64Ptrs

func Uint64Ptrs(vals []uint64) []*uint64

func UintPtr

func UintPtr(v uint) *uint

func UintPtrs

func UintPtrs(vals []uint) []*uint

Types

type Client

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

func NewClientWithProviders added in v1.0.216

func NewClientWithProviders(region string, providers ...Provider) (client *Client, err error)

NewClientWithProviders build client with your custom providers; If you don't specify the providers, it will use the DefaultProviderChain to find credential

func NewClientWithSecretId

func NewClientWithSecretId(secretId, secretKey, region string) (client *Client, err error)

func NewCommonClient added in v1.0.192

func NewCommonClient(cred CredentialIface, region string, clientProfile *profile.ClientProfile) (c *Client)

func (*Client) GetCredential added in v1.0.361

func (c *Client) GetCredential() CredentialIface

func (*Client) GetRegion

func (c *Client) GetRegion() string

func (*Client) Init

func (c *Client) Init(region string) *Client

func (*Client) Send

func (c *Client) Send(request tchttp.Request, response tchttp.Response) (err error)

func (*Client) SendOctetStream added in v1.0.210

func (c *Client) SendOctetStream(request tchttp.Request, response tchttp.Response) (err error)

SendOctetStream Invoke API with application/octet-stream content-type.

Note:

  1. only specific API can be invoked in such manner.
  2. only TC3-HMAC-SHA256 signature method can be specified.
  3. only POST request method can be specified
  4. the request Must be a CommonRequest and called SetOctetStreamParameters

func (*Client) WithCredential

func (c *Client) WithCredential(cred CredentialIface) *Client

func (*Client) WithDebug

func (c *Client) WithDebug(flag bool) *Client

func (*Client) WithHttpTransport

func (c *Client) WithHttpTransport(transport http.RoundTripper) *Client

func (*Client) WithLogger added in v1.0.636

func (c *Client) WithLogger(logger Logger) *Client

func (*Client) WithProfile

func (c *Client) WithProfile(clientProfile *profile.ClientProfile) *Client

func (*Client) WithProvider added in v1.0.216

func (c *Client) WithProvider(provider Provider) (*Client, error)

WithProvider use specify provider to get a credential and use it to build a client

func (*Client) WithRequestClient added in v1.0.499

func (c *Client) WithRequestClient(rc string) *Client

func (*Client) WithSecretId

func (c *Client) WithSecretId(secretId, secretKey string) *Client

func (*Client) WithSignatureMethod

func (c *Client) WithSignatureMethod(method string) *Client

type Credential

type Credential struct {
	SecretId  string
	SecretKey string
	Token     string
}

func NewCredential

func NewCredential(secretId, secretKey string) *Credential

func NewTokenCredential

func NewTokenCredential(secretId, secretKey, token string) *Credential

func (*Credential) GetCredential added in v1.0.829

func (c *Credential) GetCredential() (string, string, string)

func (*Credential) GetSecretId added in v1.0.216

func (c *Credential) GetSecretId() string

func (*Credential) GetSecretKey added in v1.0.216

func (c *Credential) GetSecretKey() string

func (*Credential) GetToken added in v1.0.216

func (c *Credential) GetToken() string

type CredentialIface added in v1.0.216

type CredentialIface interface {
	GetSecretId() string
	GetToken() string
	GetSecretKey() string
	GetCredential() (string, string, string)
}

type CvmRoleCredential added in v1.0.216

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

func (*CvmRoleCredential) GetCredential added in v1.0.829

func (c *CvmRoleCredential) GetCredential() (string, string, string)

func (*CvmRoleCredential) GetSecretId added in v1.0.216

func (c *CvmRoleCredential) GetSecretId() string

func (*CvmRoleCredential) GetSecretKey added in v1.0.216

func (c *CvmRoleCredential) GetSecretKey() string

func (*CvmRoleCredential) GetToken added in v1.0.216

func (c *CvmRoleCredential) GetToken() string

type CvmRoleProvider added in v1.0.216

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

func DefaultCvmRoleProvider added in v1.0.216

func DefaultCvmRoleProvider() *CvmRoleProvider

DefaultCvmRoleProvider will auto get the cvm role name by accessing the metadata api more info please lookup: https://cloud.tencent.com/document/product/213/4934

func NewCvmRoleProvider added in v1.0.216

func NewCvmRoleProvider(roleName string) *CvmRoleProvider

NewCvmRoleProvider need you to specify the roleName of the cvm currently in use

func (*CvmRoleProvider) GetCredential added in v1.0.216

func (r *CvmRoleProvider) GetCredential() (CredentialIface, error)

type EnvProvider added in v1.0.216

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

func DefaultEnvProvider added in v1.0.216

func DefaultEnvProvider() *EnvProvider

DefaultEnvProvider return a default provider The default environment variable name are TENCENTCLOUD_SECRET_ID and TENCENTCLOUD_SECRET_KEY

func NewEnvProvider added in v1.0.216

func NewEnvProvider(secretIdEnvName, secretKeyEnvName string) *EnvProvider

NewEnvProvider uses the name of the environment variable you specified to get the credentials

func (*EnvProvider) GetCredential added in v1.0.216

func (p *EnvProvider) GetCredential() (CredentialIface, error)

type Logger added in v1.0.636

type Logger interface {
	Printf(format string, args ...interface{})
}

type OIDCRoleArnProvider added in v1.0.486

type OIDCRoleArnProvider struct {
	Endpoint string
	// contains filtered or unexported fields
}

func DefaultTkeOIDCRoleArnProvider added in v1.0.486

func DefaultTkeOIDCRoleArnProvider() (*OIDCRoleArnProvider, error)

DefaultTkeOIDCRoleArnProvider returns a OIDCRoleArnProvider with some default options:

  1. providerId will be environment var TKE_PROVIDER_ID
  2. webIdentityToken will be the content of file specified by env TKE_WEB_IDENTITY_TOKEN_FILE
  3. roleArn will be env TKE_ROLE_ARN
  4. roleSessionName will be "tencentcloud-go-sdk-" + timestamp
  5. durationSeconds will be 7200s

func NewOIDCRoleArnProvider added in v1.0.486

func NewOIDCRoleArnProvider(region, providerId, webIdentityToken, roleArn, roleSessionName string, durationSeconds int64) *OIDCRoleArnProvider

func (*OIDCRoleArnProvider) GetCredential added in v1.0.486

func (r *OIDCRoleArnProvider) GetCredential() (CredentialIface, error)

type ProfileProvider added in v1.0.216

type ProfileProvider struct {
}

func DefaultProfileProvider added in v1.0.216

func DefaultProfileProvider() *ProfileProvider

DefaultProfileProvider return a default Profile provider profile path :

  1. The value of the environment variable TENCENTCLOUD_CREDENTIALS_FILE
  2. linux: ~/.tencentcloud/credentials windows: \c:\Users\NAME\.tencentcloud\credentials

func (*ProfileProvider) GetCredential added in v1.0.216

func (p *ProfileProvider) GetCredential() (CredentialIface, error)

type Provider added in v1.0.216

type Provider interface {
	// GetCredential get the credential interface
	GetCredential() (CredentialIface, error)
}

Provider provide credential to build client.

Now there are four kinds provider:

 EnvProvider : get credential from your Variable environment
 ProfileProvider : get credential from your profile
	CvmRoleProvider : get credential from your cvm role
 RoleArnProvider : get credential from your role arn

func DefaultProviderChain added in v1.0.216

func DefaultProviderChain() Provider

DefaultProviderChain returns a default provider chain and try to get credentials in the following order:

  1. Environment variable
  2. Profile
  3. CvmRole

If you want to customize the search order, please use the function NewProviderChain

func NewProviderChain added in v1.0.216

func NewProviderChain(providers []Provider) Provider

NewProviderChain returns a provider chain in your custom order

type ProviderChain added in v1.0.216

type ProviderChain struct {
	Providers []Provider
}

func (*ProviderChain) GetCredential added in v1.0.216

func (c *ProviderChain) GetCredential() (CredentialIface, error)

type RoleArnCredential added in v1.0.216

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

func (*RoleArnCredential) GetCredential added in v1.0.829

func (c *RoleArnCredential) GetCredential() (string, string, string)

func (*RoleArnCredential) GetSecretId added in v1.0.216

func (c *RoleArnCredential) GetSecretId() string

func (*RoleArnCredential) GetSecretKey added in v1.0.216

func (c *RoleArnCredential) GetSecretKey() string

func (*RoleArnCredential) GetToken added in v1.0.216

func (c *RoleArnCredential) GetToken() string

type RoleArnProvider added in v1.0.216

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

func DefaultRoleArnProvider added in v1.0.216

func DefaultRoleArnProvider(secretId, secretKey, roleArn string) *RoleArnProvider

DefaultRoleArnProvider returns a RoleArnProvider that use some default options:

  1. roleSessionName will be "tencentcloud-go-sdk-" + timestamp
  2. durationSeconds will be 7200s

func NewRoleArnProvider added in v1.0.216

func NewRoleArnProvider(secretId, secretKey, roleArn, sessionName string, duration int64) *RoleArnProvider

func (*RoleArnProvider) GetCredential added in v1.0.216

func (r *RoleArnProvider) GetCredential() (CredentialIface, error)

Directories

Path Synopsis
Package json implements encoding and decoding of JSON as defined in RFC 7159.
Package json implements encoding and decoding of JSON as defined in RFC 7159.

Jump to

Keyboard shortcuts

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