Update 'croc/croc_client.go'
This commit is contained in:
parent
2719fccce0
commit
46106d07e2
1 changed files with 9 additions and 9 deletions
|
@ -21,16 +21,16 @@ const Version string = "2013-02-01"
|
||||||
type Config struct {
|
type Config struct {
|
||||||
client *http.Client
|
client *http.Client
|
||||||
api_url string
|
api_url string
|
||||||
project string
|
Region string
|
||||||
access_key string
|
AccessKey string
|
||||||
secret_key string
|
SecretKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (c Config) signRequest(query string) string {
|
func (c Config) signRequest(query string) string {
|
||||||
u, _ := url.Parse(c.api_url)
|
u, _ := url.Parse(c.api_url)
|
||||||
var string_to_sign string = "GET\n" + strings.Split(u.Host, ":")[0] + "\n" + u.Path + "\n" + query
|
var string_to_sign string = "GET\n" + strings.Split(u.Host, ":")[0] + "\n" + u.Path + "\n" + query
|
||||||
mac := hmac.New(sha256.New, []byte(c.secret_key))
|
mac := hmac.New(sha256.New, []byte(c.SecretKey))
|
||||||
mac.Write([]byte(string_to_sign))
|
mac.Write([]byte(string_to_sign))
|
||||||
return base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
return base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ func (c Config) sendRequest(params map[string]string) {
|
||||||
var buffer bytes.Buffer
|
var buffer bytes.Buffer
|
||||||
var i int = 0
|
var i int = 0
|
||||||
default_params := map[string]string{
|
default_params := map[string]string{
|
||||||
"AWSAccessKeyId" : c.project + ":" + c.access_key,
|
"AWSAccessKeyId" : c.AccessKey,
|
||||||
"SignatureMethod" : SignatureMethod,
|
"SignatureMethod" : SignatureMethod,
|
||||||
"SignatureVersion" : SignatureVersion,
|
"SignatureVersion" : SignatureVersion,
|
||||||
"Timestamp" : time.Now().UTC().Format(time.RFC3339),
|
"Timestamp" : time.Now().UTC().Format(time.RFC3339),
|
||||||
|
@ -77,14 +77,14 @@ func (c Config) sendRequest(params map[string]string) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newCrocClient(api_url, access_key, secret_key, project string) *Config{
|
func newCrocClient(api_url, AccessKey, SecretKey, Region string) *Config{
|
||||||
return &Config{
|
return &Config{
|
||||||
client : &http.Client{
|
client : &http.Client{
|
||||||
Timeout: time.Second * 10,
|
Timeout: time.Second * 10,
|
||||||
},
|
},
|
||||||
api_url: api_url,
|
api_url: api_url,
|
||||||
project: project,
|
Region: Region,
|
||||||
access_key: access_key,
|
AccessKey: AccessKey,
|
||||||
secret_key: secret_key,
|
SecretKey: SecretKey,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue