mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-24 16:03:43 +08:00
fix: 1. allow share proxysetting 2. claim proxsetting as domain resources
This commit is contained in:
@@ -15,6 +15,8 @@
|
||||
package shell
|
||||
|
||||
import (
|
||||
"yunion.io/x/jsonutils"
|
||||
|
||||
"yunion.io/x/onecloud/pkg/mcclient"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/modules"
|
||||
"yunion.io/x/onecloud/pkg/mcclient/options"
|
||||
@@ -78,4 +80,22 @@ func init() {
|
||||
printObject(proxysetting)
|
||||
return nil
|
||||
})
|
||||
R(&options.ProxySettingPublicOptions{}, "proxysetting-public", "Make proxysetting public", func(s *mcclient.ClientSession, opts *options.ProxySettingPublicOptions) error {
|
||||
params := jsonutils.Marshal(opts)
|
||||
result, err := modules.ProxySettings.PerformAction(s, opts.ID, "public", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
R(&options.ProxySettingPrivateOptions{}, "proxysetting-private", "Make proxysetting private", func(s *mcclient.ClientSession, opts *options.ProxySettingPrivateOptions) error {
|
||||
params := jsonutils.Marshal(opts)
|
||||
result, err := modules.ProxySettings.PerformAction(s, opts.ID, "private", params)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
printObject(result)
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
@@ -40,6 +40,14 @@ func (ps *SProxySetting) IsZero() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
type ProxySettingResourceInput struct {
|
||||
// 代理配置
|
||||
ProxySetting string `json:"proxy_setting"`
|
||||
// Deprecated
|
||||
// swagger:ignore
|
||||
ProxySettingId string `json:"proxy_setting_id" deprecated-by:"proxy_setting"`
|
||||
}
|
||||
|
||||
type ProxySettingTestInput struct {
|
||||
HttpProxy string
|
||||
HttpsProxy string
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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.ProxySetting)
|
||||
if err != nil {
|
||||
if errors.Cause(err) == sql.ErrNoRows {
|
||||
return nil, input, errors.Wrapf(httperrors.ErrResourceNotFound, "%s %s", ProxySettingManager.Keyword(), input.ProxySetting)
|
||||
} else {
|
||||
return nil, input, errors.Wrapf(err, "ProxySettingManager.FetchByIdOrName")
|
||||
}
|
||||
}
|
||||
input.ProxySetting = m.GetId()
|
||||
return m.(*SProxySetting), input, nil
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -382,16 +401,14 @@ func (manager *SCloudaccountManager) ValidateCreateData(ctx context.Context, use
|
||||
|
||||
var proxyFunc httputils.TransportProxyFunc
|
||||
{
|
||||
if input.ProxySettingId == "" {
|
||||
input.ProxySettingId = proxyapi.ProxySettingId_DIRECT
|
||||
if input.ProxySetting == "" {
|
||||
input.ProxySetting = 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("fetch proxysetting %s: %s", input.ProxySetting, err)
|
||||
}
|
||||
proxySetting := m.(*proxy.SProxySetting)
|
||||
input.ProxySettingId = proxySetting.Id
|
||||
proxyFunc = proxySetting.HttpTransportProxyFunc()
|
||||
}
|
||||
accountId, err := cloudprovider.IsValidCloudAccount(cloudprovider.ProviderConfig{
|
||||
|
||||
@@ -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"`
|
||||
|
||||
ProxySetting string `help:"proxy setting id or name" json:"proxy_setting"`
|
||||
}
|
||||
|
||||
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"`
|
||||
ProxySetting string `help:"proxy setting name or id" json:"proxy_setting"`
|
||||
|
||||
Desc string `help:"Description" json:"description" token:"desc"`
|
||||
}
|
||||
|
||||
@@ -46,3 +46,13 @@ type ProxySettingTestOptions struct {
|
||||
type ProxySettingListOptions struct {
|
||||
BaseListOptions
|
||||
}
|
||||
|
||||
type ProxySettingPublicOptions struct {
|
||||
ProxySettingGetOptions
|
||||
Scope string `json:"scope" help:"share scope" choices:"domain|system"`
|
||||
SharedDomain []string `json:"share"`
|
||||
}
|
||||
|
||||
type ProxySettingPrivateOptions struct {
|
||||
ProxySettingGetOptions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user