-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(bingocloud):improve bingocloud driver
- Loading branch information
李锐
committed
Apr 26, 2023
1 parent
41c7099
commit ba71d68
Showing
15 changed files
with
347 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,63 @@ | ||
package bingocloud | ||
|
||
import ( | ||
"crypto/aes" | ||
"crypto/cipher" | ||
"encoding/base64" | ||
"fmt" | ||
"unicode/utf8" | ||
) | ||
|
||
type SAccount struct { | ||
AccessKeyId string | ||
SecretAccessKey string | ||
Arn string | ||
DeptId string | ||
DeptName string | ||
IsEncrypted string | ||
UserId string | ||
UserName string | ||
Id string `json:"Id"` | ||
AccessKeyId string `json:"AccessKeyId"` | ||
Arn string `json:"Arn"` | ||
FullName string `json:"FullName"` | ||
IsAdmin string `json:"IsAdmin"` | ||
IsEncrypted string `json:"IsEncrypted"` | ||
SecurityKey string `json:"SecurityKey"` | ||
Status string `json:"Status"` | ||
Type string `json:"Type"` | ||
UserId string `json:"UserId"` | ||
UserName string `json:"UserName"` | ||
} | ||
|
||
func (self *SAccount) decryptKeys(masterSecretKey string) (string, string) { | ||
if len(self.SecurityKey) == len(masterSecretKey) { | ||
return self.AccessKeyId, self.SecurityKey | ||
} | ||
|
||
secretKeyBytes, err := base64.StdEncoding.DecodeString(self.SecurityKey) | ||
if err != nil { | ||
return "", "" | ||
} | ||
var adminSecretKey = "" | ||
if len(masterSecretKey) >= 32 { | ||
adminSecretKey = masterSecretKey[0:32] | ||
} else { | ||
adminSecretKey = fmt.Sprintf("%s%032s", masterSecretKey, "")[0:32] | ||
} | ||
decryptVal, err := aesCrtCrypt([]byte(secretKeyBytes), []byte(adminSecretKey), make([]byte, 16)) | ||
if err != nil { | ||
return "", "" | ||
} | ||
|
||
decryptSecret := fmt.Sprintf("%s", decryptVal) | ||
|
||
if !utf8.ValidString(decryptSecret) { | ||
return self.AccessKeyId, self.SecurityKey | ||
} | ||
|
||
return self.AccessKeyId, decryptSecret | ||
} | ||
|
||
func aesCrtCrypt(val, key, iv []byte) ([]byte, error) { | ||
block, err := aes.NewCipher(key) | ||
if err != nil { | ||
return nil, err | ||
} | ||
blockMode := cipher.NewCTR(block, iv) | ||
body := make([]byte, len(val)) | ||
blockMode.XORKeyStream(body, val) | ||
return body, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2019 Yunion | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package bingocloud | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
var bingoCloudClient, _ = NewBingoCloudClient(&BingoCloudConfig{ | ||
endpoint: "http://10.203.136.11", | ||
accessKey: "373ABE5836BB9E82FCFB", | ||
secretKey: "WzkzNzk0Mzg2ODQxODQ5REJEN0U4QTg1NTY5NzA2", | ||
debug: true, | ||
}) | ||
|
||
func TestNewBingoCloudClient(t *testing.T) { | ||
bingoCloudClient.managerClient = bingoCloudClient | ||
regions, _ := bingoCloudClient.GetRegions() | ||
regions[0].client = bingoCloudClient | ||
t.Log(regions[0].getStorages()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.