Merge pull request #5779 from swordqiu/automated-cherry-pick-of-#5756-upstream-release-3.1

Automated cherry pick of #5756: fix: 1. allow share proxysetting 2. claim proxsetting as domain resources
This commit is contained in:
Zexi Li
2020-04-13 15:45:16 +08:00
committed by GitHub
15 changed files with 202 additions and 27 deletions
+5
View File
@@ -40,6 +40,11 @@ func (ps *SProxySetting) IsZero() bool {
return false
}
type ProxySettingResourceInput struct {
// 代理配置
ProxySettingId string `json:"proxy_setting_id"`
}
type ProxySettingTestInput struct {
HttpProxy string
HttpsProxy string
+1 -2
View File
@@ -80,8 +80,7 @@ type CloudaccountCreateInput struct {
// 额外信息,例如账单的access key
Options *jsonutils.JSONObject `json:"options"`
// 代理配置
ProxySettingId string `json:"proxy_setting_id"`
proxyapi.ProxySettingResourceInput
cloudprovider.SCloudaccount
cloudprovider.SCloudaccountCredential
+14
View File
@@ -12,6 +12,7 @@ import (
"golang.org/x/net/http/httpproxy"
"yunion.io/x/jsonutils"
"yunion.io/x/pkg/errors"
proxyapi "yunion.io/x/onecloud/pkg/apis/cloudcommon/proxy"
"yunion.io/x/onecloud/pkg/cloudcommon/db"
@@ -203,3 +204,16 @@ var referrersMen []db.IModelManager
func RegisterReferrer(man db.IModelManager) {
referrersMen = append(referrersMen, man)
}
func ValidateProxySettingResourceInput(userCred mcclient.TokenCredential, input proxyapi.ProxySettingResourceInput) (*SProxySetting, proxyapi.ProxySettingResourceInput, error) {
m, err := ProxySettingManager.FetchByIdOrName(userCred, input.ProxySettingId)
if err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, input, errors.Wrapf(httperrors.ErrResourceNotFound, "%s %s", ProxySettingManager.Keyword(), input.ProxySettingId)
} else {
return nil, input, errors.Wrapf(err, "ProxySettingManager.FetchByIdOrName")
}
}
input.ProxySettingId = m.GetId()
return m.(*SProxySetting), input, nil
}
+23 -6
View File
@@ -318,11 +318,30 @@ func (self *SCloudaccount) ValidateUpdateData(ctx context.Context, userCred mccl
"proxy_setting",
proxy.ProxySettingManager.Keyword(),
userCred,
).Optional(true)
)
v.Optional(true)
if err := v.Validate(data); err != nil {
return nil, err
}
proxySetting := v.Model.(*proxy.SProxySetting)
if proxySetting != nil {
// updated proxy setting, so do the check
proxyFunc := proxySetting.HttpTransportProxyFunc()
secret, _ := self.getPassword()
_, err := cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{
Vendor: self.Provider,
URL: self.AccessUrl,
Account: self.Account,
Secret: secret,
ProxyFunc: proxyFunc,
})
if err != nil {
return nil, httperrors.NewInputParameterError("invalid proxy setting %s", err)
}
}
return self.SEnabledStatusStandaloneResourceBase.ValidateUpdateData(ctx, userCred, query, data)
}
@@ -385,13 +404,11 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
if input.ProxySettingId == "" {
input.ProxySettingId = proxyapi.ProxySettingId_DIRECT
}
m, err := proxy.ProxySettingManager.FetchByIdOrName(userCred, input.ProxySettingId)
var proxySetting *proxy.SProxySetting
proxySetting, input.ProxySettingResourceInput, err = proxy.ValidateProxySettingResourceInput(userCred, input.ProxySettingResourceInput)
if err != nil {
return input, httperrors.NewInputParameterError("fetch proxysetting %s: %s",
input.ProxySettingId, err)
return input, httperrors.NewInputParameterError("ValidateProxySettingResourceInput %s", err)
}
proxySetting := m.(*proxy.SProxySetting)
input.ProxySettingId = proxySetting.Id
proxyFunc = proxySetting.HttpTransportProxyFunc()
}
accountId, err := cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{
+3 -1
View File
@@ -83,6 +83,8 @@ type SCloudAccountCreateBaseOptions struct {
SyncIntervalSeconds int `help:"Interval to synchronize if auto sync is enable" metavar:"SECONDS"`
ProjectDomain string `help:"domain for this account"`
ProxySettingId string `help:"proxy setting id or name" json:"proxy_setting_id"`
}
type SVMwareCloudAccountCreateOptions struct {
@@ -229,7 +231,7 @@ type SCloudAccountUpdateBaseOptions struct {
SyncIntervalSeconds int `help:"auto synchornize interval in seconds"`
AutoCreateProject *bool `help:"automatically create local project for new remote project"`
ProxySetting string `help:"proxy setting name or id"`
ProxySettingId string `help:"proxy setting name or id" json:"proxy_setting_id"`
Desc string `help:"Description" json:"description" token:"desc"`
}