mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-10 21:33:19 +00:00
Get accountID from b2_authorize_account and supply it to b2_list_buckets
This commit is contained in:
@@ -40,6 +40,7 @@ var B2AuthorizationURL = "https://api.backblazeb2.com/b2api/v1/b2_authorize_acco
|
|||||||
type B2Client struct {
|
type B2Client struct {
|
||||||
HTTPClient *http.Client
|
HTTPClient *http.Client
|
||||||
AccountID string
|
AccountID string
|
||||||
|
ApplicationKeyID string
|
||||||
ApplicationKey string
|
ApplicationKey string
|
||||||
AuthorizationToken string
|
AuthorizationToken string
|
||||||
APIURL string
|
APIURL string
|
||||||
@@ -53,10 +54,10 @@ type B2Client struct {
|
|||||||
TestMode bool
|
TestMode bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewB2Client(accountID string, applicationKey string) *B2Client {
|
func NewB2Client(applicationKeyID string, applicationKey string) *B2Client {
|
||||||
client := &B2Client{
|
client := &B2Client{
|
||||||
HTTPClient: http.DefaultClient,
|
HTTPClient: http.DefaultClient,
|
||||||
AccountID: accountID,
|
ApplicationKeyID: applicationKeyID,
|
||||||
ApplicationKey: applicationKey,
|
ApplicationKey: applicationKey,
|
||||||
}
|
}
|
||||||
return client
|
return client
|
||||||
@@ -119,7 +120,7 @@ func (client *B2Client) call(url string, method string, requestHeaders map[strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if url == B2AuthorizationURL {
|
if url == B2AuthorizationURL {
|
||||||
request.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(client.AccountID+":"+client.ApplicationKey)))
|
request.Header.Set("Authorization", "Basic "+base64.StdEncoding.EncodeToString([]byte(client.ApplicationKeyID+":"+client.ApplicationKey)))
|
||||||
} else {
|
} else {
|
||||||
request.Header.Set("Authorization", client.AuthorizationToken)
|
request.Header.Set("Authorization", client.AuthorizationToken)
|
||||||
}
|
}
|
||||||
@@ -225,6 +226,10 @@ func (client *B2Client) AuthorizeAccount() (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The account id may be different from the application key id so we're getting the account id from the returned
|
||||||
|
// json object here, which is needed by the b2_list_buckets call.
|
||||||
|
client.AccountID = output.AccountID
|
||||||
|
|
||||||
client.AuthorizationToken = output.AuthorizationToken
|
client.AuthorizationToken = output.AuthorizationToken
|
||||||
client.APIURL = output.APIURL
|
client.APIURL = output.APIURL
|
||||||
client.DownloadURL = output.DownloadURL
|
client.DownloadURL = output.DownloadURL
|
||||||
@@ -233,7 +238,7 @@ func (client *B2Client) AuthorizeAccount() (err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type ListBucketOutput struct {
|
type ListBucketOutput struct {
|
||||||
AccoundID string
|
AccountID string
|
||||||
BucketID string
|
BucketID string
|
||||||
BucketName string
|
BucketName string
|
||||||
BucketType string
|
BucketType string
|
||||||
|
|||||||
Reference in New Issue
Block a user