Documentation
¶
Overview ¶
Package bce defined a set of core data structure and functions for Baidu Cloud API.
Index ¶
- Constants
- Variables
- func GenerateAuthorization(credentials Credentials, req Request, option *SignOption) string
- type AccessControlListItem
- type Billing
- type Client
- func (client *Client) GenerateClientToken() string
- func (c *Client) GetSessionToken(sessionTokenRequest SessionTokenRequest, option *SignOption) (*SessionTokenResponse, error)
- func (c *Client) GetURL(host, uriPath string, params map[string]string) string
- func (c *Client) SendRequest(req *Request, option *SignOption) (bceResponse *Response, err error)
- func (c *Client) SetDebug(debug bool)
- type Config
- type Credentials
- type DefaultRetryPolicy
- type Error
- type GenerateAuthorizationFunc
- type Request
- type Reservation
- type Response
- type RetryPolicy
- type SessionTokenRequest
- type SessionTokenResponse
- type SignOption
Constants ¶
const ( Version = "0.0.1" // ExpirationPeriodInSeconds 1800s is the default expiration period. ExpirationPeriodInSeconds = 1800 )
Variables ¶
var DefaultUserAgent = strings.Join([]string{ "baidubce-sdk-go", Version, runtime.GOOS, runtime.Version(), }, "/")
DefaultUserAgent is the default value of http request UserAgent header.
We can change it by specifying the UserAgent field of bce.Config.
var Region = map[string]string{
"bj": "bj",
"gz": "gz",
"hk": "hk",
"su": "su",
"bd": "bd",
}
Region contains all regions of Baidu Cloud.
Functions ¶
func GenerateAuthorization ¶
func GenerateAuthorization(credentials Credentials, req Request, option *SignOption) string
GenerateAuthorization generates authorization code for authorization process of Baidu Cloud API.
Types ¶
type AccessControlListItem ¶
type AccessControlListItem struct {
Eid string `json:"eid"`
Service string `json:"service"`
Region string `json:"region"`
Effect string `json:"effect"`
Resource []string `json:"resource"`
Permission []string `json:"permission"`
}
AccessControlListItem contains sub options for bce.SessionTokenRequest
For details, please refer https://cloud.baidu.com/doc/BOS/API.html#STS.E7.AE.80.E4.BB.8B
type Billing ¶
type Client ¶
type Client struct {
*Config
// contains filtered or unexported fields
}
Client is the base client implemention for Baidu Cloud API.
func (*Client) GenerateClientToken ¶
GenerateClientToken generates the Client Token with random string
func (*Client) GetSessionToken ¶
func (c *Client) GetSessionToken(sessionTokenRequest SessionTokenRequest, option *SignOption) (*SessionTokenResponse, error)
GetSessionToken gets response for STS(Security Token Service)of Baidu Cloud API.
For details, please refer https://cloud.baidu.com/doc/BOS/API.html#STS.E7.AE.80.E4.BB.8B
func (*Client) GetURL ¶
GetURL generates the full URL of http request for Baidu Cloud API.
type Config ¶
type Config struct {
*Credentials
Region string `json:"region"`
Endpoint string
APIVersion string
Protocol string
UserAgent string
ProxyHost string
ProxyPort int
//ConnectionTimeoutInMillis time.Duration // default value: 10 * time.Second in http.DefaultTransport
MaxConnections int // default value: 2 in http.DefaultMaxIdleConnsPerHost
Timeout time.Duration // default value: 0 in http.Client
RetryPolicy RetryPolicy
Checksum bool
}
Config contains all options for bce.Client.
func NewConfig ¶
func NewConfig(credentials *Credentials) *Config
NewConfig create a config from credentials
func NewConfigFromFile ¶
NewConfigFromFile create a new config from cloud config.
func NewConfigWithParams ¶
NewConfigWithParams creates a new config from filled info
func (*Config) GetRegion ¶
GetRegion gets region from bce.Config.
If no region specified in bce.Config, the bj region will be return.
type Credentials ¶
type Credentials struct {
AccessKeyID string `json:"AccessKeyID"`
SecretAccessKey string `json:"SecretAccessKey"`
}
func NewCredentials ¶
func NewCredentials(AccessKeyID, secretAccessKey string) *Credentials
func NewCredentialsFromFile ¶
func NewCredentialsFromFile(filePath string) (*Credentials, error)
type DefaultRetryPolicy ¶
DefaultRetryPolicy is the default implemention of interface bce.RetryPolicy.
func NewDefaultRetryPolicy ¶
func NewDefaultRetryPolicy(maxErrorRetry int, maxDelay time.Duration) *DefaultRetryPolicy
func (*DefaultRetryPolicy) GetDelayBeforeNextRetry ¶
func (policy *DefaultRetryPolicy) GetDelayBeforeNextRetry(err error, retriesAttempted int) time.Duration
GetDelayBeforeNextRetry specifies the delay time for next retry.
func (*DefaultRetryPolicy) GetMaxDelay ¶
func (policy *DefaultRetryPolicy) GetMaxDelay() time.Duration
GetMaxDelay specifies the max delay time for retrying.
func (*DefaultRetryPolicy) GetMaxErrorRetry ¶
func (policy *DefaultRetryPolicy) GetMaxErrorRetry() int
GetMaxErrorRetry specifies the max retry count.
type Error ¶
Error implements the error interface
Most methods in the SDK will return bce.Error instance.
type GenerateAuthorizationFunc ¶
type GenerateAuthorizationFunc func(req *Request, option *SignOption)
type Request ¶
Request is http request, but has some custom functions.
func (*Request) AddHeaders ¶
Add headers to http request
type Reservation ¶
type Response ¶
Response holds an instance of type `http response`, and has some custom data and functions.
type RetryPolicy ¶
type RetryPolicy interface {
GetMaxErrorRetry() int // GetMaxErrorRetry specifies the max retry count.
GetMaxDelay() time.Duration // GetMaxDelay specifies the max delay time for retrying.
// GetDelayBeforeNextRetry specifies the delay time for next retry.
GetDelayBeforeNextRetry(err error, retriesAttempted int) time.Duration
}
RetryPolicy defined an interface for retrying of bce.Client.
type SessionTokenRequest ¶
type SessionTokenRequest struct {
DurationSeconds int `json:"durationSeconds"`
Id string `json:"id"`
AccessControlList []AccessControlListItem `json:"accessControlList"`
}
SessionTokenRequest contains all options for STS(Security Token Service)of Baidu Cloud API.
For details, please refer https://cloud.baidu.com/doc/BOS/API.html#STS.E7.AE.80.E4.BB.8B
type SessionTokenResponse ¶
type SessionTokenResponse struct {
AccessKeyId string `json:"accessKeyId"`
SecretAccessKey string `json:"secretAccessKey"`
SessionToken string `json:"sessionToken"`
CreateTime string `json:"createTime"`
Expiration string `json:"expiration"`
UserId string `json:"userId"`
}
SessionTokenResponse contains all response fields for STS(Security Token Service)of Baidu Cloud API.
For details, please refer https://cloud.baidu.com/doc/BOS/API.html#STS.E7.AE.80.E4.BB.8B
type SignOption ¶
type SignOption struct {
Timestamp string
ExpirationPeriodInSeconds int
Headers map[string]string
HeadersToSign []string
Credentials *Credentials // for STS(Security Token Service) only
CustomUserAgent string
CustomSignFunc GenerateAuthorizationFunc
// contains filtered or unexported fields
}
SignOption contains all signature options of Baidu Cloud API.
func CheckSignOption ¶
func CheckSignOption(option *SignOption) *SignOption
CheckSignOption returns a new empty bce.SignOption instance if no option specified.
func NewSignOption ¶
func (*SignOption) AddHeader ¶
func (option *SignOption) AddHeader(key, value string)
AddHeader adds a header and it's value for authentication process of Baidu Cloud API.
For details, please refer https://cloud.baidu.com/doc/Reference/AuthenticationMechanism.html#1.1.20.E6.A6.82.E8.BF.B0
func (*SignOption) AddHeaders ¶
func (option *SignOption) AddHeaders(headers map[string]string)
AddHeaders adds some headers for authentication process of Baidu Cloud API.
For details, please refer https://cloud.baidu.com/doc/Reference/AuthenticationMechanism.html#1.1.20.E6.A6.82.E8.BF.B0
func (*SignOption) AddHeadersToSign ¶
func (option *SignOption) AddHeadersToSign(headers ...string)
AddHeadersToSign adds some headers for authentication process of Baidu Cloud API.
For details, please refer https://cloud.baidu.com/doc/Reference/AuthenticationMechanism.html#1.1.20.E6.A6.82.E8.BF.B0
Source Files
¶
- core.go
- error.go
- request.go
- response.go
- types.go