From b22e77b1f4784041e8180b676ef55a50f66faa9a Mon Sep 17 00:00:00 2001 From: Yousong Zhou Date: Tue, 31 Mar 2020 18:05:15 +0800 Subject: [PATCH] cloudcommon: proxysetting: make it infra resource --- pkg/apis/cloudcommon/proxy/proxy.go | 10 +++++++-- pkg/cloudcommon/db/proxy/proxysetting.go | 27 ++++++++++++++++++------ 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/pkg/apis/cloudcommon/proxy/proxy.go b/pkg/apis/cloudcommon/proxy/proxy.go index 13c2557f2b..321e98ab25 100644 --- a/pkg/apis/cloudcommon/proxy/proxy.go +++ b/pkg/apis/cloudcommon/proxy/proxy.go @@ -25,14 +25,20 @@ const ( ) type ProxySettingCreateInput struct { - apis.VirtualResourceCreateInput + apis.InfrasResourceBaseCreateInput HttpProxy string HttpsProxy string NoProxy string } -type ProxySettingUpdateInput ProxySettingCreateInput +type ProxySettingUpdateInput struct { + apis.InfrasResourceBaseUpdateInput + + HttpProxy string + HttpsProxy string + NoProxy string +} // String implements ISerializable interface func (ps *SProxySetting) String() string { diff --git a/pkg/cloudcommon/db/proxy/proxysetting.go b/pkg/cloudcommon/db/proxy/proxysetting.go index f1a72aba1d..534e1d03e9 100644 --- a/pkg/cloudcommon/db/proxy/proxysetting.go +++ b/pkg/cloudcommon/db/proxy/proxysetting.go @@ -33,14 +33,14 @@ import ( ) type SProxySettingManager struct { - db.SStandaloneResourceBaseManager + db.SInfrasResourceBaseManager } var ProxySettingManager *SProxySettingManager func init() { ProxySettingManager = &SProxySettingManager{ - SStandaloneResourceBaseManager: db.NewStandaloneResourceBaseManager( + SInfrasResourceBaseManager: db.NewInfrasResourceBaseManager( SProxySetting{}, "proxysettings_tbl", "proxysetting", @@ -51,7 +51,7 @@ func init() { } type SProxySetting struct { - db.SStandaloneResourceBase + db.SInfrasResourceBase HTTPProxy string `create:"admin_optional" list:"admin" update:"admin"` HTTPSProxy string `create:"admin_optional" list:"admin" update:"admin"` @@ -59,14 +59,29 @@ type SProxySetting struct { } func (man *SProxySettingManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerId mcclient.IIdentityProvider, query jsonutils.JSONObject, data proxyapi.ProxySettingCreateInput) (proxyapi.ProxySettingCreateInput, error) { - return data, nil + var err error + data.InfrasResourceBaseCreateInput, err = man.SInfrasResourceBaseManager.ValidateCreateData( + ctx, + userCred, + ownerId, + query, + data.InfrasResourceBaseCreateInput, + ) + return data, err } func (ps *SProxySetting) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data proxyapi.ProxySettingUpdateInput) (proxyapi.ProxySettingUpdateInput, error) { if ps.Id == proxyapi.ProxySettingId_DIRECT { return data, httperrors.NewConflictError("DIRECT setting cannot be changed") } - return data, nil + var err error + data.InfrasResourceBaseUpdateInput, err = ps.SInfrasResourceBase.ValidateUpdateData( + ctx, + userCred, + query, + data.InfrasResourceBaseUpdateInput, + ) + return data, err } func (ps *SProxySetting) HttpTransportProxyFunc() httputils.TransportProxyFunc { @@ -95,7 +110,7 @@ func (ps *SProxySetting) ValidateDeleteCondition(ctx context.Context) error { ps.Id, n, man.KeywordPlural()) } } - return nil + return ps.SInfrasResourceBase.ValidateDeleteCondition(ctx) } func (man *SProxySettingManager) InitializeData() error {