Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add resource interfaces and improve bingocloud driver #275

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions cmd/bingocli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,11 @@ func newClient(options *BaseOptions) (*bingocloud.SRegion, error) {
options.Endpoint,
options.AccessKey,
options.SecretKey,
).Debug(options.Debug).
CloudproviderConfig(
cloudprovider.ProviderConfig{
ProxyFunc: proxyFunc,
},
),
).Debug(options.Debug).SetCloudproviderConfig(
cloudprovider.ProviderConfig{
ProxyFunc: proxyFunc,
},
),
)
if err != nil {
return nil, err
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloudprovider/cloudprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ type ProviderConfig struct {

AliyunResourceGroupIds []string

ManagerProviderConfig *ProviderConfig

UpdatePermission func(service, permission string)
}

Expand Down
1 change: 1 addition & 0 deletions pkg/cloudprovider/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ type DiskCreateConfig struct {
SizeGb int
Desc string
ProjectId string
ZoneId string
}
2 changes: 2 additions & 0 deletions pkg/cloudprovider/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ type ICloudRegion interface {
GetISecurityGroupById(secgroupId string) (ICloudSecurityGroup, error)
GetISecurityGroupByName(opts *SecurityGroupFilterOptions) (ICloudSecurityGroup, error)
CreateISecurityGroup(conf *SecurityGroupCreateInput) (ICloudSecurityGroup, error)
GetISecurityGroups() ([]ICloudSecurityGroup, error)

CreateIVpc(opts *VpcCreateOptions) (ICloudVpc, error)
CreateInternetGateway() (ICloudInternetGateway, error)
Expand Down Expand Up @@ -607,6 +608,7 @@ type ICloudVpc interface {
ProposeJoinICloudInterVpcNetwork(opts *SVpcJointInterVpcNetworkOption) error

GetICloudIPv6Gateways() ([]ICloudIPv6Gateway, error)
IsPublic() bool
}

type ICloudInternetGateway interface {
Expand Down
3 changes: 3 additions & 0 deletions pkg/cloudprovider/subaccount.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,16 @@ import (
)

type SSubAccount struct {
Id string // ID
// 若Account不为空,可不传
Name string
// 描述信息
Desc string
// 输入必填,若为空,需要指定子账号名称
Account string
Secret string // 子账号SK
HealthStatus string // 云端服务健康状态。例如欠费、项目冻结都属于不健康状态。
IsSubAccount bool // 是否子账号
DefaultProjectId string // 默认云订阅项目Id
}

Expand Down
6 changes: 5 additions & 1 deletion pkg/multicloud/aliyun/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ func (self *SRegion) GetOssClient() (*oss.Client, error) {
return self.ossClient, nil
}

func (self *SRegion) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
return nil, nil
}

func (self *SRegion) ecsRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
client, err := self.getSdkClient()
if err != nil {
Expand Down Expand Up @@ -297,7 +301,7 @@ func (self *SRegion) _lbRequest(client *sdk.Client, apiName string, domain strin
return jsonRequest(client, domain, ALIYUN_API_VERSION_LB, apiName, params, self.client.debug)
}

/////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////
func (self *SRegion) GetId() string {
return self.RegionId
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/multicloud/aliyun/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func (self *SVpc) IsEmulated() bool {
return false
}

func (self *SVpc) IsPublic() bool {
return false
}

func (self *SVpc) GetIsDefault() bool {
return self.IsDefault
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/multicloud/apsara/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ func (self *SRegion) tagRequest(serviceType string, action string, params map[st
}
}

func (self *SRegion) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
return nil, nil
}

func (self *SRegion) lbRequest(apiName string, params map[string]string) (jsonutils.JSONObject, error) {
client, err := self.getSdkClient()
if err != nil {
Expand All @@ -158,7 +162,7 @@ func (self *SRegion) lbRequest(apiName string, params map[string]string) (jsonut
return self.productRequest(client, APSARA_PRODUCT_SLB, domain, APSARA_API_VERSION_LB, apiName, params, self.client.debug)
}

/////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////
func (self *SRegion) GetId() string {
return self.RegionId
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/multicloud/apsara/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (self *SVpc) IsEmulated() bool {
return false
}

func (self *SVpc) IsPublic() bool {
return false
}

func (self *SVpc) GetIsDefault() bool {
return self.IsDefault
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/multicloud/aws/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ func (self *SAwsClient) monitorRequest(regionId, apiName string, params map[stri
return self.request(regionId, CLOUDWATCH_SERVICE_NAME, CLOUDWATCH_SERVICE_ID, "2010-08-01", apiName, params, retval, true)
}

/////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////
func (self *SRegion) fetchZones() error {
ec2Client, err := self.getEc2Client()
if err != nil {
Expand Down Expand Up @@ -416,6 +416,10 @@ func (self *SRegion) GetIZones() ([]cloudprovider.ICloudZone, error) {
return self.izones, nil
}

func (self *SRegion) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
return nil, nil
}

func (self *SRegion) GetIVpcs() ([]cloudprovider.ICloudVpc, error) {
if self.ivpcs == nil {
err := self.fetchInfrastructure()
Expand Down
4 changes: 4 additions & 0 deletions pkg/multicloud/aws/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ func (self *SVpc) IsEmulated() bool {
return false
}

func (self *SVpc) IsPublic() bool {
return false
}

func (self *SVpc) GetRegion() cloudprovider.ICloudRegion {
return self.region
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/multicloud/azure/classic_vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ func (self *SClassicVpc) GetIsDefault() bool {
return false
}

func (self *SClassicVpc) IsPublic() bool {
return false
}

func (self *SClassicVpc) GetCidrBlock() string {
if len(self.Properties.AddressSpace.AddressPrefixes) > 0 {
return self.Properties.AddressSpace.AddressPrefixes[0]
Expand Down
6 changes: 5 additions & 1 deletion pkg/multicloud/azure/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type SRegion struct {
Longitude string
}

/////////////////////////////////////////////////////////////////////////////
// ///////////////////////////////////////////////////////////////////////////
func (self *SRegion) Refresh() error {
// do nothing
return nil
Expand Down Expand Up @@ -104,6 +104,10 @@ func (self *SRegion) GetName() string {
return fmt.Sprintf("%s %s", CLOUD_PROVIDER_AZURE_CN, self.DisplayName)
}

func (self *SRegion) GetISecurityGroups() ([]cloudprovider.ICloudSecurityGroup, error) {
return nil, nil
}

func (self *SRegion) GetI18n() cloudprovider.SModelI18nTable {
en := fmt.Sprintf("%s %s", CLOUD_PROVIDER_AZURE_EN, self.DisplayName)
table := cloudprovider.SModelI18nTable{}
Expand Down
4 changes: 4 additions & 0 deletions pkg/multicloud/azure/vpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ func (self *SVpc) IsEmulated() bool {
return false
}

func (self *SVpc) IsPublic() bool {
return false
}

func (self *SVpc) GetIsDefault() bool {
return true
}
Expand Down
67 changes: 59 additions & 8 deletions pkg/multicloud/bingocloud/account.go
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
}
Loading