common

package
v3.0.1015+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

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

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

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

func (*Client) GetCredential

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

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

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

func (*Client) WithProfile

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

func (*Client) WithProvider

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

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

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

func (*Credential) GetSecretId

func (c *Credential) GetSecretId() string

func (*Credential) GetSecretKey

func (c *Credential) GetSecretKey() string

func (*Credential) GetToken

func (c *Credential) GetToken() string

type CredentialIface

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

type CvmRoleCredential

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

func (*CvmRoleCredential) GetCredential

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

func (*CvmRoleCredential) GetSecretId

func (c *CvmRoleCredential) GetSecretId() string

func (*CvmRoleCredential) GetSecretKey

func (c *CvmRoleCredential) GetSecretKey() string

func (*CvmRoleCredential) GetToken

func (c *CvmRoleCredential) GetToken() string

type CvmRoleProvider

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

func DefaultCvmRoleProvider

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

func NewCvmRoleProvider(roleName string) *CvmRoleProvider

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

func (*CvmRoleProvider) GetCredential

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

type EnvProvider

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

func DefaultEnvProvider

func DefaultEnvProvider() *EnvProvider

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

func NewEnvProvider

func NewEnvProvider(secretIdEnvName, secretKeyEnvName string) *EnvProvider

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

func (*EnvProvider) GetCredential

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

type Logger

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

type OIDCRoleArnProvider

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

func DefaultTkeOIDCRoleArnProvider

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

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

func (*OIDCRoleArnProvider) GetCredential

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

type ProfileProvider

type ProfileProvider struct {
}

func DefaultProfileProvider

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

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

type Provider

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

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

func NewProviderChain(providers []Provider) Provider

NewProviderChain returns a provider chain in your custom order

type ProviderChain

type ProviderChain struct {
	Providers []Provider
}

func (*ProviderChain) GetCredential

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

type RoleArnCredential

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

func (*RoleArnCredential) GetCredential

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

func (*RoleArnCredential) GetSecretId

func (c *RoleArnCredential) GetSecretId() string

func (*RoleArnCredential) GetSecretKey

func (c *RoleArnCredential) GetSecretKey() string

func (*RoleArnCredential) GetToken

func (c *RoleArnCredential) GetToken() string

type RoleArnProvider

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

func DefaultRoleArnProvider

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

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

func (*RoleArnProvider) GetCredential

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