mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
region: add cloudaccount.ProxySettingId
This commit is contained in:
@@ -185,6 +185,9 @@ type CloudaccountCreateInput struct {
|
||||
// 额外信息,例如账单的access key
|
||||
Options *jsonutils.JSONObject `json:"options"`
|
||||
|
||||
// 代理配置
|
||||
ProxySettingId string `json:"proxy_setting_id"`
|
||||
|
||||
cloudprovider.SCloudaccount
|
||||
cloudprovider.SCloudaccountCredential
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"yunion.io/x/pkg/utils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
proxyapi "yunion.io/x/onecloud/pkg/apis/cloudcommon/proxy"
|
||||
"yunion.io/x/onecloud/pkg/cloudprovider"
|
||||
)
|
||||
|
||||
@@ -120,6 +121,8 @@ type CloudproviderDetails struct {
|
||||
apis.EnabledStatusStandaloneResourceDetails
|
||||
apis.ProjectizedResourceInfo
|
||||
|
||||
ProxySetting proxyapi.SProxySetting `json:"proxy_setting"`
|
||||
|
||||
SCloudprovider
|
||||
|
||||
// 云账号名称
|
||||
|
||||
@@ -194,6 +194,8 @@ type SCloudaccount struct {
|
||||
IsPublic bool `json:"is_public"`
|
||||
// add share_mode field to indicate the share range of this account
|
||||
ShareMode string `json:"share_mode"`
|
||||
// 默认值proxyapi.ProxySettingId_DIRECT
|
||||
ProxySettingId string `json:"proxy_setting_id"`
|
||||
}
|
||||
|
||||
// SCloudprovider is an autogenerated struct via yunion.io/x/onecloud/pkg/compute/models.SCloudprovider.
|
||||
@@ -226,6 +228,7 @@ type SCloudprovider struct {
|
||||
type SCloudproviderCapability struct {
|
||||
apis.SResourceBase
|
||||
CloudproviderId string `json:"cloudprovider_id"`
|
||||
CloudregionId string `json:"cloudregion_id"`
|
||||
Capability string `json:"capability"`
|
||||
}
|
||||
|
||||
|
||||
@@ -33,10 +33,12 @@ import (
|
||||
"yunion.io/x/sqlchemy"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/apis"
|
||||
proxyapi "yunion.io/x/onecloud/pkg/apis/cloudcommon/proxy"
|
||||
api "yunion.io/x/onecloud/pkg/apis/compute"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/consts"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/lockman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/proxy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/policy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/validators"
|
||||
@@ -47,6 +49,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/mcclient/auth"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/util/choices"
|
||||
"yunion.io/x/onecloud/pkg/util/httputils"
|
||||
"yunion.io/x/onecloud/pkg/util/logclient"
|
||||
"yunion.io/x/onecloud/pkg/util/rbacutils"
|
||||
"yunion.io/x/onecloud/pkg/util/stringutils2"
|
||||
@@ -150,7 +153,8 @@ type SCloudaccount struct {
|
||||
// add share_mode field to indicate the share range of this account
|
||||
ShareMode string `width:"32" charset:"ascii" nullable:"true" list:"domain"`
|
||||
|
||||
ProxySettingId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"optional" default:"default"`
|
||||
// 默认值proxyapi.ProxySettingId_DIRECT
|
||||
ProxySettingId string `width:"36" charset:"ascii" nullable:"false" list:"domain" create:"optional" update:"domain" default:"DIRECT"`
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) GetCloudproviders() []SCloudprovider {
|
||||
@@ -288,6 +292,16 @@ func (self *SCloudaccount) ValidateUpdateData(ctx context.Context, userCred mccl
|
||||
}
|
||||
data.Set("options", optionsJson)
|
||||
}
|
||||
|
||||
v := validators.NewModelIdOrNameValidator(
|
||||
"proxy_setting",
|
||||
proxy.ProxySettingManager.KeywordPlural(),
|
||||
userCred,
|
||||
)
|
||||
if err := v.Validate(data); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return self.SEnabledStatusDomainLevelResourceBase.ValidateUpdateData(ctx, userCred, query, data)
|
||||
}
|
||||
|
||||
@@ -345,11 +359,26 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
|
||||
return input, httperrors.NewConflictError("The account has been registered")
|
||||
}
|
||||
|
||||
var proxyFunc httputils.TransportProxyFunc
|
||||
{
|
||||
if input.ProxySettingId == "" {
|
||||
input.ProxySettingId = proxyapi.ProxySettingId_DIRECT
|
||||
}
|
||||
m, err := proxy.ProxySettingManager.FetchByIdOrName(userCred, input.ProxySettingId)
|
||||
if err != nil {
|
||||
return input, httperrors.NewInputParameterError("fetch proxysetting %s: %s",
|
||||
input.ProxySettingId, err)
|
||||
}
|
||||
proxySetting := m.(*proxy.SProxySetting)
|
||||
input.ProxySettingId = proxySetting.Id
|
||||
proxyFunc = proxySetting.HttpTransportProxyFunc()
|
||||
}
|
||||
accountId, err := cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{
|
||||
Vendor: input.Provider,
|
||||
URL: input.AccessUrl,
|
||||
Account: input.Account,
|
||||
Secret: input.Secret,
|
||||
Vendor: input.Provider,
|
||||
URL: input.AccessUrl,
|
||||
Account: input.Account,
|
||||
Secret: input.Secret,
|
||||
ProxyFunc: proxyFunc,
|
||||
})
|
||||
if err != nil {
|
||||
if err == cloudprovider.ErrNoSuchProvder {
|
||||
@@ -482,6 +511,8 @@ func (self *SCloudaccount) PerformTestConnectivity(ctx context.Context, userCred
|
||||
Vendor: self.Provider,
|
||||
Account: account.Account,
|
||||
Secret: account.Secret,
|
||||
|
||||
ProxyFunc: self.proxyFunc(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalid cloud account info error: %s", err.Error())
|
||||
@@ -534,10 +565,11 @@ func (self *SCloudaccount) PerformUpdateCredential(ctx context.Context, userCred
|
||||
originSecret, _ := self.getPassword()
|
||||
|
||||
accountId, err := cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{
|
||||
Vendor: self.Provider,
|
||||
URL: self.AccessUrl,
|
||||
Account: account.Account,
|
||||
Secret: account.Secret,
|
||||
Vendor: self.Provider,
|
||||
URL: self.AccessUrl,
|
||||
Account: account.Account,
|
||||
Secret: account.Secret,
|
||||
ProxyFunc: self.proxyFunc(),
|
||||
})
|
||||
if err != nil {
|
||||
return nil, httperrors.NewInputParameterError("invalid cloud account info error: %s", err.Error())
|
||||
@@ -690,6 +722,25 @@ func (self *SCloudaccount) GetProvider() (cloudprovider.ICloudProvider, error) {
|
||||
return self.getProviderInternal()
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) proxySetting() *proxy.SProxySetting {
|
||||
m, err := proxy.ProxySettingManager.FetchById(self.ProxySettingId)
|
||||
if err != nil {
|
||||
log.Errorf("cloudaccount %s(%s): get proxysetting %s: %v",
|
||||
self.Name, self.Id, self.ProxySettingId, err)
|
||||
return nil
|
||||
}
|
||||
ps := m.(*proxy.SProxySetting)
|
||||
return ps
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) proxyFunc() httputils.TransportProxyFunc {
|
||||
ps := self.proxySetting()
|
||||
if ps != nil {
|
||||
return ps.HttpTransportProxyFunc()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (self *SCloudaccount) getProviderInternal() (cloudprovider.ICloudProvider, error) {
|
||||
secret, err := self.getPassword()
|
||||
if err != nil {
|
||||
@@ -702,6 +753,8 @@ func (self *SCloudaccount) getProviderInternal() (cloudprovider.ICloudProvider,
|
||||
URL: self.AccessUrl,
|
||||
Account: self.Account,
|
||||
Secret: secret,
|
||||
|
||||
ProxyFunc: self.proxyFunc(),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -754,13 +754,17 @@ func (self *SCloudprovider) GetProvider() (cloudprovider.ICloudProvider, error)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
account := self.GetCloudaccount()
|
||||
|
||||
return cloudprovider.GetProvider(cloudprovider.ProviderConfig{
|
||||
Id: self.Id,
|
||||
Name: self.Name,
|
||||
Vendor: self.Provider,
|
||||
URL: accessUrl,
|
||||
Account: self.Account,
|
||||
Secret: passwd,
|
||||
Id: self.Id,
|
||||
Name: self.Name,
|
||||
Vendor: self.Provider,
|
||||
URL: accessUrl,
|
||||
Account: self.Account,
|
||||
Secret: passwd,
|
||||
ProxyFunc: account.proxyFunc(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -852,7 +856,20 @@ func (self *SCloudprovider) GetExtraDetails(
|
||||
query jsonutils.JSONObject,
|
||||
isList bool,
|
||||
) (api.CloudproviderDetails, error) {
|
||||
return api.CloudproviderDetails{}, nil
|
||||
r := api.CloudproviderDetails{}
|
||||
|
||||
account := self.GetCloudaccount()
|
||||
if account != nil {
|
||||
ps := account.proxySetting()
|
||||
if ps != nil {
|
||||
r.ProxySetting.Id = ps.Id
|
||||
r.ProxySetting.Name = ps.Name
|
||||
r.ProxySetting.HTTPProxy = ps.HTTPProxy
|
||||
r.ProxySetting.HTTPSProxy = ps.HTTPSProxy
|
||||
r.ProxySetting.NoProxy = ps.NoProxy
|
||||
}
|
||||
}
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func (manager *SCloudproviderManager) FetchCustomizeColumns(
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"yunion.io/x/log"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/proxy"
|
||||
)
|
||||
|
||||
func InitDB() error {
|
||||
@@ -29,6 +30,8 @@ func InitDB() error {
|
||||
db.TenantCacheManager,
|
||||
db.Metadata,
|
||||
|
||||
proxy.ProxySettingManager,
|
||||
|
||||
QuotaManager,
|
||||
|
||||
CloudproviderManager,
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/appsrv"
|
||||
"yunion.io/x/onecloud/pkg/appsrv/dispatcher"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/proxy"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
"yunion.io/x/onecloud/pkg/compute/capabilities"
|
||||
@@ -81,6 +82,9 @@ func InitHandlers(app *appsrv.Application) {
|
||||
for _, manager := range []db.IModelManager{
|
||||
db.OpsLog,
|
||||
db.Metadata,
|
||||
|
||||
proxy.ProxySettingManager,
|
||||
|
||||
models.BucketManager,
|
||||
models.CloudaccountManager,
|
||||
models.CloudproviderManager,
|
||||
|
||||
Reference in New Issue
Block a user