mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
后端对公有云账号密码信息重组
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package cloudprovider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"errors"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/log"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -17,6 +19,7 @@ type ICloudProviderFactory interface {
|
||||
GetProvider(providerId, providerName, url, account, secret string) (ICloudProvider, error)
|
||||
GetId() string
|
||||
ValidateChangeBandwidth(instanceId string, bandwidth int64) error
|
||||
ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error
|
||||
}
|
||||
|
||||
type ICloudProvider interface {
|
||||
|
||||
@@ -142,6 +142,10 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
|
||||
if !cloudprovider.IsSupported(provider) {
|
||||
return nil, httperrors.NewInputParameterError("Unsupported provider %s", provider)
|
||||
}
|
||||
providerDriver, _ := cloudprovider.GetProviderDriver(provider)
|
||||
if err := providerDriver.ValidateCreateCloudaccountData(ctx, userCred, data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// check duplication
|
||||
// url, account, provider must be unique
|
||||
account, _ := data.GetString("account")
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/aliyun"
|
||||
)
|
||||
|
||||
@@ -19,6 +23,20 @@ func (self *SAliyunProviderFactory) ValidateChangeBandwidth(instanceId string, b
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAliyunProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
accessKeyID, _ := data.GetString("access_key_id")
|
||||
if len(accessKeyID) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_id")
|
||||
}
|
||||
accessKeySecret, _ := data.GetString("access_key_secret")
|
||||
if len(accessKeySecret) == 0 {
|
||||
return httperrors.NewMissingParameterError("access_key_secret")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(accessKeyID))
|
||||
data.Set("secret", jsonutils.NewString(accessKeySecret))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAliyunProviderFactory) GetProvider(providerId, providerName, url, account, secret string) (cloudprovider.ICloudProvider, error) {
|
||||
/* provider, ok := self.providerTable[providerId]
|
||||
if ok {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/aws"
|
||||
)
|
||||
|
||||
@@ -17,6 +20,10 @@ func (self *SAwsProviderFactory) ValidateChangeBandwidth(instanceId string, band
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAwsProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAwsProviderFactory) GetProvider(providerId, providerName, url, account, secret string) (cloudprovider.ICloudProvider, error) {
|
||||
client, err := aws.NewAwsClient(providerId, providerName, url, account, secret)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/azure"
|
||||
// "yunion.io/x/log"
|
||||
)
|
||||
@@ -20,6 +23,29 @@ func (self *SAzureProviderFactory) ValidateChangeBandwidth(instanceId string, ba
|
||||
return fmt.Errorf("Changing %s bandwidth is not supported", azure.CLOUD_PROVIDER_AZURE)
|
||||
}
|
||||
|
||||
func (self *SAzureProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
tenantID, _ := data.GetString("tenant_id")
|
||||
if len(tenantID) == 0 {
|
||||
return httperrors.NewMissingParameterError("tenant_id")
|
||||
}
|
||||
clientID, _ := data.GetString("client_id")
|
||||
if len(clientID) == 0 {
|
||||
return httperrors.NewMissingParameterError("client_id")
|
||||
}
|
||||
clientSecret, _ := data.GetString("client_secret")
|
||||
if len(clientSecret) == 0 {
|
||||
return httperrors.NewMissingParameterError("client_secret")
|
||||
}
|
||||
environment, _ := data.GetString("environment")
|
||||
if len(environment) == 0 {
|
||||
return httperrors.NewMissingParameterError("environment")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(tenantID))
|
||||
data.Set("secret", jsonutils.NewString(fmt.Sprintf("%s/%s", clientID, clientSecret)))
|
||||
data.Set("access_url", jsonutils.NewString(environment))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SAzureProviderFactory) GetProvider(providerId, providerName, url, account, secret string) (cloudprovider.ICloudProvider, error) {
|
||||
if client, err := azure.NewAzureClient(providerId, providerName, account, secret, url); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strconv"
|
||||
@@ -10,6 +11,8 @@ import (
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/esxi"
|
||||
)
|
||||
|
||||
@@ -24,6 +27,25 @@ func (self *SESXiProviderFactory) ValidateChangeBandwidth(instanceId string, ban
|
||||
return fmt.Errorf("Changing %s bandwidth is not supported", esxi.CLOUD_PROVIDER_VMWARE)
|
||||
}
|
||||
|
||||
func (self *SESXiProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
username, _ := data.GetString("username")
|
||||
if len(username) == 0 {
|
||||
return httperrors.NewMissingParameterError("username")
|
||||
}
|
||||
password, _ := data.GetString("password")
|
||||
if len(password) == 0 {
|
||||
return httperrors.NewMissingParameterError("password")
|
||||
}
|
||||
host, _ := data.GetString("host")
|
||||
if len(host) == 0 {
|
||||
return httperrors.NewMissingParameterError("host")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(username))
|
||||
data.Set("secret", jsonutils.NewString(password))
|
||||
data.Set("access_url", jsonutils.NewString(host))
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseHostPort(host string, defPort int) (string, int, error) {
|
||||
colonPos := strings.IndexByte(host, ':')
|
||||
if colonPos > 0 {
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/huawei"
|
||||
)
|
||||
|
||||
@@ -14,6 +17,10 @@ func (self *SHuaweiProviderFactory) ValidateChangeBandwidth(instanceId string, b
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaweiProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SHuaweiProviderFactory) GetProvider(providerId, providerName, url, account, secret string) (cloudprovider.ICloudProvider, error) {
|
||||
client, err := huawei.NewHuaweiClient(providerId, providerName, url, account, secret)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/openstack"
|
||||
)
|
||||
|
||||
@@ -21,6 +23,10 @@ func (self *SOpenStackProviderFactory) ValidateChangeBandwidth(instanceId string
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SOpenStackProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SOpenStackProviderFactory) GetProvider(providerId, providerName, url, account, password string) (cloudprovider.ICloudProvider, error) {
|
||||
accountInfo := strings.Split(account, "/")
|
||||
username, project := accountInfo[0], ""
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
package provider
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
"yunion.io/x/onecloud/pkg/httperrors"
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/util/qcloud"
|
||||
)
|
||||
|
||||
@@ -23,6 +26,24 @@ func (self *SQcloudProviderFactory) ValidateChangeBandwidth(instanceId string, b
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQcloudProviderFactory) ValidateCreateCloudaccountData(ctx context.Context, userCred mcclient.TokenCredential, data *jsonutils.JSONDict) error {
|
||||
appID, _ := data.GetString("app_id")
|
||||
if len(appID) == 0 {
|
||||
return httperrors.NewMissingParameterError("app_id")
|
||||
}
|
||||
secretID, _ := data.GetString("secret_id")
|
||||
if len(secretID) == 0 {
|
||||
return httperrors.NewMissingParameterError("secret_id")
|
||||
}
|
||||
secretKey, _ := data.GetString("secret_key")
|
||||
if len(secretKey) == 0 {
|
||||
return httperrors.NewMissingParameterError("secret_key")
|
||||
}
|
||||
data.Set("account", jsonutils.NewString(appID))
|
||||
data.Set("secret", jsonutils.NewString(fmt.Sprintf("%s/%s", secretID, secretKey)))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SQcloudProviderFactory) GetProvider(providerId, providerName, url, account, secret string) (cloudprovider.ICloudProvider, error) {
|
||||
client, err := qcloud.NewQcloudClient(providerId, providerName, account, secret)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user