From b4fcb63b643d4e751200779b7e71fe75edb9198b Mon Sep 17 00:00:00 2001 From: Qiu Jian Date: Sat, 1 Dec 2018 01:05:13 +0800 Subject: [PATCH] Remove SInfrastructureManager & SInfrasture --- pkg/cloudcommon/policy/policy.go | 24 ++++++++++++++++++ pkg/compute/models/baremetalagents.go | 22 ++++++++++++++-- pkg/compute/models/cachedimages.go | 22 ++++++++++++++-- pkg/compute/models/cloudaccounts.go | 22 ++++++++++++++-- pkg/compute/models/cloudproviders.go | 22 ++++++++++++++-- pkg/compute/models/cloudregions.go | 18 +++++++++++-- pkg/compute/models/dynamicschedtags.go | 22 ++++++++++++++-- pkg/compute/models/hosts.go | 31 +++++++++++++---------- pkg/compute/models/inframanagers.go | 30 ++-------------------- pkg/compute/models/loadbalanceragents.go | 27 +++++++++++++++----- pkg/compute/models/schedpolicies.go | 22 ++++++++++++++-- pkg/compute/models/schedtags.go | 16 ++++++++++-- pkg/compute/models/storagecachedimages.go | 22 ++++++++++++++-- pkg/compute/models/storagecaches.go | 22 ++++++++++++++-- pkg/compute/models/storages.go | 25 ++++++++++++++---- pkg/compute/models/vcenters.go | 2 -- pkg/compute/models/vpcs.go | 22 ++++++++++++++-- pkg/compute/models/wires.go | 24 ++++++++++++++++-- pkg/compute/models/zones.go | 20 +++++++++++++-- 19 files changed, 335 insertions(+), 80 deletions(-) diff --git a/pkg/cloudcommon/policy/policy.go b/pkg/cloudcommon/policy/policy.go index 2431c64ea5..019f2c4284 100644 --- a/pkg/cloudcommon/policy/policy.go +++ b/pkg/cloudcommon/policy/policy.go @@ -48,6 +48,30 @@ var ( Action: PolicyActionGet, Result: rbacutils.UserAllow, }, + { + Service: "compute", + Resource: "storages", + Action: PolicyActionList, + Result: rbacutils.UserAllow, + }, + { + Service: "compute", + Resource: "storages", + Action: PolicyActionGet, + Result: rbacutils.UserAllow, + }, + { + Service: "compute", + Resource: "schedtags", + Action: PolicyActionList, + Result: rbacutils.UserAllow, + }, + { + Service: "compute", + Resource: "schedtags", + Action: PolicyActionGet, + Result: rbacutils.UserAllow, + }, { Service: "compute", Resource: "cloudregions", diff --git a/pkg/compute/models/baremetalagents.go b/pkg/compute/models/baremetalagents.go index 606333ea67..5bbf758354 100644 --- a/pkg/compute/models/baremetalagents.go +++ b/pkg/compute/models/baremetalagents.go @@ -21,12 +21,10 @@ const ( type SBaremetalagentManager struct { db.SStandaloneResourceBaseManager - SInfrastructureManager } type SBaremetalagent struct { db.SStandaloneResourceBase - SInfrastructure Status string `width:"36" charset:"ascii" nullable:"false" default:"disable" list:"user" create:"optional"` AccessIp string `width:"16" charset:"ascii" nullable:"false" list:"admin" update:"admin" create:"admin_required"` @@ -40,6 +38,26 @@ func init() { BaremetalagentManager = &SBaremetalagentManager{SStandaloneResourceBaseManager: db.NewStandaloneResourceBaseManager(SBaremetalagent{}, "baremetalagents_tbl", "baremetalagent", "baremetalagents")} } +func (self *SBaremetalagentManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SBaremetalagentManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SBaremetalagent) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SBaremetalagent) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SBaremetalagent) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (self *SBaremetalagent) ValidateDeleteCondition(ctx context.Context) error { if self.Status == BAREMETAL_AGENT_ENABLED { return fmt.Errorf("Cannot delete in status %s", self.Status) diff --git a/pkg/compute/models/cachedimages.go b/pkg/compute/models/cachedimages.go index 67e0069e25..1a4ac36bfb 100644 --- a/pkg/compute/models/cachedimages.go +++ b/pkg/compute/models/cachedimages.go @@ -30,7 +30,6 @@ const ( type SCachedimageManager struct { db.SStandaloneResourceBaseManager - SInfrastructureManager } var CachedimageManager *SCachedimageManager @@ -48,7 +47,6 @@ func init() { type SCachedimage struct { db.SStandaloneResourceBase - SInfrastructure Size int64 `nullable:"false" list:"admin" update:"admin" create:"admin_required"` // = Column(BigInteger, nullable=False) # in Byte // virtual_size = Column(BigInteger, nullable=False) # in Byte @@ -58,6 +56,26 @@ type SCachedimage struct { RefCount int `default:"0" list:"admin"` // = Column(Integer, default=0, server_default='0') } +func (self *SCachedimageManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SCachedimageManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SCachedimage) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SCachedimage) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SCachedimage) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (self *SCachedimage) ValidateDeleteCondition(ctx context.Context) error { if self.getStoragecacheCount() > 0 { return httperrors.NewNotEmptyError("The image has been cached on storages") diff --git a/pkg/compute/models/cloudaccounts.go b/pkg/compute/models/cloudaccounts.go index 93d0bce62d..9b3b51f2ff 100644 --- a/pkg/compute/models/cloudaccounts.go +++ b/pkg/compute/models/cloudaccounts.go @@ -25,7 +25,6 @@ import ( type SCloudaccountManager struct { db.SEnabledStatusStandaloneResourceBaseManager - SInfrastructureManager } var CloudaccountManager *SCloudaccountManager @@ -43,7 +42,6 @@ func init() { type SCloudaccount struct { db.SEnabledStatusStandaloneResourceBase - SInfrastructure AccessUrl string `width:"64" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` @@ -60,6 +58,26 @@ type SCloudaccount struct { Provider string `width:"64" charset:"ascii" list:"admin" create:"admin_required"` } +func (self *SCloudaccountManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SCloudaccountManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SCloudaccount) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SCloudaccount) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SCloudaccount) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (self *SCloudaccount) GetCloudproviders() []SCloudprovider { cloudproviders := []SCloudprovider{} q := CloudproviderManager.Query().Equals("cloudaccount_id", self.Id) diff --git a/pkg/compute/models/cloudproviders.go b/pkg/compute/models/cloudproviders.go index 9ba07a5600..959166aed1 100644 --- a/pkg/compute/models/cloudproviders.go +++ b/pkg/compute/models/cloudproviders.go @@ -40,7 +40,6 @@ const ( type SCloudproviderManager struct { db.SEnabledStatusStandaloneResourceBaseManager - SInfrastructureManager } var CloudproviderManager *SCloudproviderManager @@ -58,7 +57,6 @@ func init() { type SCloudprovider struct { db.SEnabledStatusStandaloneResourceBase - SInfrastructure AccessUrl string `width:"64" charset:"ascii" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // Hostname string `width:"64" charset:"ascii" nullable:"true"` // Column(VARCHAR(64, charset='ascii'), nullable=False) @@ -87,6 +85,26 @@ func (self *SCloudprovider) GetOwnerProjectId() string { return self.ProjectId } +func (self *SCloudproviderManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SCloudproviderManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SCloudprovider) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SCloudprovider) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SCloudprovider) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (self *SCloudprovider) ValidateDeleteCondition(ctx context.Context) error { if self.Enabled { return httperrors.NewInvalidStatusError("provider is enabled") diff --git a/pkg/compute/models/cloudregions.go b/pkg/compute/models/cloudregions.go index 374682c40e..5f6f34c269 100644 --- a/pkg/compute/models/cloudregions.go +++ b/pkg/compute/models/cloudregions.go @@ -25,7 +25,6 @@ const ( type SCloudregionManager struct { db.SEnabledStatusStandaloneResourceBaseManager - SInfrastructureManager } var CloudregionManager *SCloudregionManager @@ -43,7 +42,6 @@ func init() { type SCloudregion struct { db.SEnabledStatusStandaloneResourceBase - SInfrastructure Latitude float32 `list:"user"` Longitude float32 `list:"user"` @@ -54,6 +52,22 @@ func (manager *SCloudregionManager) AllowListItems(ctx context.Context, userCred return true } +func (self *SCloudregionManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SCloudregion) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SCloudregion) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SCloudregion) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (self *SCloudregion) CustomizeCreate(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data jsonutils.JSONObject) error { idstr, _ := data.GetString("id") if len(idstr) > 0 { diff --git a/pkg/compute/models/dynamicschedtags.go b/pkg/compute/models/dynamicschedtags.go index 9770802575..0a1ab9e640 100644 --- a/pkg/compute/models/dynamicschedtags.go +++ b/pkg/compute/models/dynamicschedtags.go @@ -17,7 +17,6 @@ import ( type SDynamicschedtagManager struct { db.SStandaloneResourceBaseManager - SInfrastructureManager } var DynamicschedtagManager *SDynamicschedtagManager @@ -39,7 +38,6 @@ func init() { // type SDynamicschedtag struct { db.SStandaloneResourceBase - SInfrastructure Condition string `width:"256" charset:"ascii" nullable:"false" list:"user" create:"required" update:"admin"` SchedtagId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required" update:"admin"` @@ -47,6 +45,26 @@ type SDynamicschedtag struct { Enabled bool `nullable:"false" default:"true" create:"optional" list:"user" update:"user"` } +func (self *SDynamicschedtagManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SDynamicschedtagManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SDynamicschedtag) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SDynamicschedtag) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SDynamicschedtag) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func validateDynamicSchedtagInputData(data *jsonutils.JSONDict, create bool) error { condStr := jsonutils.GetAnyString(data, []string{"condition"}) if len(condStr) == 0 && create { diff --git a/pkg/compute/models/hosts.go b/pkg/compute/models/hosts.go index 5edbc95027..dc47e1ace2 100644 --- a/pkg/compute/models/hosts.go +++ b/pkg/compute/models/hosts.go @@ -90,7 +90,6 @@ var NIC_TYPES = []string{NIC_TYPE_IPMI, NIC_TYPE_ADMIN} type SHostManager struct { db.SEnabledStatusStandaloneResourceBaseManager - SInfrastructureManager } var HostManager *SHostManager @@ -109,7 +108,6 @@ func init() { type SHost struct { db.SEnabledStatusStandaloneResourceBase - SInfrastructure SManagedResourceBase Rack string `width:"16" charset:"ascii" nullable:"true" get:"admin" update:"admin" create:"admin_optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True) @@ -161,17 +159,24 @@ func (manager *SHostManager) GetContextManager() []db.IModelManager { return []db.IModelManager{ZoneManager} } -func (manager *SHostManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { - // allow create host without zone_id - /*zoneId, err := data.GetString("zone_id") - if err != nil { - return false - } - _, err = ZoneManager.FetchById(zoneId) - if err != nil { - return false - }*/ - return userCred.IsAdminAllow(consts.GetServiceType(), manager.KeywordPlural(), policy.PolicyActionCreate) +func (self *SHostManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SHostManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SHost) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SHost) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SHost) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) } func (manager *SHostManager) ListItemFilter(ctx context.Context, q *sqlchemy.SQuery, userCred mcclient.TokenCredential, query jsonutils.JSONObject) (*sqlchemy.SQuery, error) { diff --git a/pkg/compute/models/inframanagers.go b/pkg/compute/models/inframanagers.go index 96c9a5607f..4a60c48cfb 100644 --- a/pkg/compute/models/inframanagers.go +++ b/pkg/compute/models/inframanagers.go @@ -1,35 +1,9 @@ package models -import ( - "context" - "yunion.io/x/jsonutils" - "yunion.io/x/onecloud/pkg/cloudcommon/consts" - "yunion.io/x/onecloud/pkg/cloudcommon/policy" - "yunion.io/x/onecloud/pkg/mcclient" -) - -type SInfrastructureManager struct { +type TSInfrastructureManager struct { } -type SInfrastructure struct { +type TSInfrastructure struct { } -func (self *SInfrastructureManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { - return userCred.IsAdminAllow(consts.GetServiceType(), "*", policy.PolicyActionList) -} -func (self *SInfrastructureManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { - return userCred.IsAdminAllow(consts.GetServiceType(), "*", policy.PolicyActionCreate) -} - -func (self *SInfrastructure) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { - return userCred.IsAdminAllow(consts.GetServiceType(), "*", policy.PolicyActionGet) -} - -func (self *SInfrastructure) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { - return userCred.IsAdminAllow(consts.GetServiceType(), "*", policy.PolicyActionUpdate) -} - -func (self *SInfrastructure) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { - return userCred.IsAdminAllow(consts.GetServiceType(), "*", policy.PolicyActionDelete) -} diff --git a/pkg/compute/models/loadbalanceragents.go b/pkg/compute/models/loadbalanceragents.go index b7a0a1f455..a92e50513e 100644 --- a/pkg/compute/models/loadbalanceragents.go +++ b/pkg/compute/models/loadbalanceragents.go @@ -22,7 +22,6 @@ import ( type SLoadbalancerAgentManager struct { db.SStandaloneResourceBaseManager - SInfrastructureManager } var LoadbalancerAgentManager *SLoadbalancerAgentManager @@ -48,7 +47,6 @@ func init() { // type SLoadbalancerAgent struct { db.SStandaloneResourceBase - SInfrastructure HbLastSeen time.Time `nullable:"true" list:"admin" update:"admin"` HbTimeout int `nullable:"true" list:"admin" update:"admin" create:"optional" default:"3600"` @@ -239,6 +237,27 @@ func (p *SLoadbalancerAgentParams) IsZero() bool { return false } + +func (self *SLoadbalancerAgentManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SLoadbalancerAgentManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SLoadbalancerAgent) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SLoadbalancerAgent) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SLoadbalancerAgent) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (man *SLoadbalancerAgentManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { { keyV := map[string]validators.IValidator{ @@ -355,10 +374,6 @@ func (man *SLoadbalancerAgentManager) CleanPendingDeleteLoadbalancers(ctx contex } } -func (man *SLoadbalancerAgentManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { - return userCred.IsAdminAllow(consts.GetServiceType(), man.KeywordPlural(), policy.PolicyActionCreate) -} - func (lbagent *SLoadbalancerAgent) ValidateUpdateData(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { { keyV := map[string]validators.IValidator{ diff --git a/pkg/compute/models/schedpolicies.go b/pkg/compute/models/schedpolicies.go index edf88f4832..000445cf14 100644 --- a/pkg/compute/models/schedpolicies.go +++ b/pkg/compute/models/schedpolicies.go @@ -18,7 +18,6 @@ import ( type SSchedpolicyManager struct { db.SStandaloneResourceBaseManager - SInfrastructureManager } var SchedpolicyManager *SSchedpolicyManager @@ -37,7 +36,6 @@ func init() { // sched policy is called before calling scheduler, add additional preferences for schedtags type SSchedpolicy struct { db.SStandaloneResourceBase - SInfrastructure Condition string `width:"256" charset:"ascii" nullable:"false" list:"user" create:"required" update:"user"` SchedtagId string `width:"36" charset:"ascii" nullable:"false" list:"user" create:"required" update:"user"` @@ -64,6 +62,26 @@ func validateSchedpolicyInputData(data *jsonutils.JSONDict, create bool) error { return nil } +func (self *SSchedpolicyManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SSchedpolicyManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SSchedpolicy) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SSchedpolicy) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SSchedpolicy) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (manager *SSchedpolicyManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { err := validateSchedpolicyInputData(data, true) if err != nil { diff --git a/pkg/compute/models/schedtags.go b/pkg/compute/models/schedtags.go index 2c06f65eb8..43557ff2f9 100644 --- a/pkg/compute/models/schedtags.go +++ b/pkg/compute/models/schedtags.go @@ -12,6 +12,8 @@ import ( "yunion.io/x/onecloud/pkg/mcclient" "yunion.io/x/pkg/utils" "yunion.io/x/sqlchemy" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" + "yunion.io/x/onecloud/pkg/cloudcommon/policy" ) type SchedStrategyType string @@ -30,7 +32,6 @@ var STRATEGY_LIST = []string{STRATEGY_REQUIRE, STRATEGY_EXCLUDE, STRATEGY_PREFER type SSchedtagManager struct { db.SStandaloneResourceBaseManager - SInfrastructureManager } var SchedtagManager *SSchedtagManager @@ -48,7 +49,6 @@ func init() { type SSchedtag struct { db.SStandaloneResourceBase - SInfrastructure DefaultStrategy string `width:"16" charset:"ascii" nullable:"true" default:"" list:"user" update:"admin" create:"admin_optional"` // Column(VARCHAR(16, charset='ascii'), nullable=True, default='') } @@ -61,6 +61,18 @@ func (self *SSchedtag) AllowGetDetails(ctx context.Context, userCred mcclient.To return true } +func (self *SSchedtagManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SSchedtag) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SSchedtag) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (manager *SSchedtagManager) ValidateSchedtags(userCred mcclient.TokenCredential, schedtags map[string]string) (map[string]string, error) { ret := make(map[string]string) for tag, act := range schedtags { diff --git a/pkg/compute/models/storagecachedimages.go b/pkg/compute/models/storagecachedimages.go index 29d5889890..693fa088a0 100644 --- a/pkg/compute/models/storagecachedimages.go +++ b/pkg/compute/models/storagecachedimages.go @@ -32,7 +32,6 @@ const ( type SStoragecachedimageManager struct { db.SJointResourceBaseManager - SInfrastructureManager } var StoragecachedimageManager *SStoragecachedimageManager @@ -54,7 +53,6 @@ func init() { type SStoragecachedimage struct { db.SJointResourceBase - SInfrastructure StoragecacheId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"admin_required" key_index:"true"` CachedimageId string `width:"36" charset:"ascii" nullable:"false" list:"admin" create:"admin_required" key_index:"true"` @@ -75,6 +73,26 @@ func (joint *SStoragecachedimage) Slave() db.IStandaloneModel { return db.JointSlave(joint) } +func (self *SStoragecachedimageManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SStoragecachedimageManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SStoragecachedimage) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SStoragecachedimage) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SStoragecachedimage) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (self *SStoragecachedimage) getStorageHostId() (string, error) { var s SStorage storage := StorageManager.Query() diff --git a/pkg/compute/models/storagecaches.go b/pkg/compute/models/storagecaches.go index 78f33ad971..f21faa1dbc 100644 --- a/pkg/compute/models/storagecaches.go +++ b/pkg/compute/models/storagecaches.go @@ -21,7 +21,6 @@ import ( type SStoragecacheManager struct { db.SStandaloneResourceBaseManager - SInfrastructureManager } var StoragecacheManager *SStoragecacheManager @@ -39,12 +38,31 @@ func init() { type SStoragecache struct { db.SStandaloneResourceBase - SInfrastructure SManagedResourceBase Path string `width:"256" charset:"utf8" nullable:"true" list:"admin" update:"admin" create:"admin_optional"` // = Column(VARCHAR(256, charset='utf8'), nullable=True) } +func (self *SStoragecacheManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SStoragecacheManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SStoragecache) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SStoragecache) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SStoragecache) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (self *SStoragecache) getStorages() []SStorage { storages := make([]SStorage, 0) q := StorageManager.Query().Equals("storagecache_id", self.Id) diff --git a/pkg/compute/models/storages.go b/pkg/compute/models/storages.go index 7a76c6e995..2f79e92b27 100644 --- a/pkg/compute/models/storages.go +++ b/pkg/compute/models/storages.go @@ -87,7 +87,6 @@ var ( type SStorageManager struct { db.SEnabledStatusStandaloneResourceBaseManager - SInfrastructureManager } var StorageManager *SStorageManager @@ -105,7 +104,6 @@ func init() { type SStorage struct { db.SEnabledStatusStandaloneResourceBase - SInfrastructure SManagedResourceBase Capacity int `nullable:"false" list:"admin" update:"admin" create:"admin_required"` // Column(Integer, nullable=False) # capacity of disk in MB @@ -124,6 +122,26 @@ func (manager *SStorageManager) GetContextManager() []db.IModelManager { return []db.IModelManager{ZoneManager, StoragecacheManager} } +func (manager *SStorageManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return true +} + +func (self *SStorageManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SStorage) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SStorage) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SStorage) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (manager *SStorageManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { storageType, _ := data.GetString("storage_type") mediumType, _ := data.GetString("medium_type") @@ -181,9 +199,6 @@ func (self *SStorage) IsLocal() bool { return self.StorageType == STORAGE_LOCAL || self.StorageType == STORAGE_BAREMETAL } -func (manager *SStorageManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { - return true -} func (self *SStorage) getMoreDetails(extra *jsonutils.JSONDict) *jsonutils.JSONDict { used := self.GetUsedCapacity(tristate.True) diff --git a/pkg/compute/models/vcenters.go b/pkg/compute/models/vcenters.go index 79b298ccb2..f4ebc43687 100644 --- a/pkg/compute/models/vcenters.go +++ b/pkg/compute/models/vcenters.go @@ -11,7 +11,6 @@ import ( type SVCenterManager struct { db.SEnabledStatusStandaloneResourceBaseManager - SInfrastructureManager } var VCenterManager *SVCenterManager @@ -29,7 +28,6 @@ func init() { type SVCenter struct { db.SEnabledStatusStandaloneResourceBase - SInfrastructure Hostname string `width:"64" charset:"ascii" nullable:"false" list:"admin"` // = Column(VARCHAR(64, charset='ascii'), nullable=False) Port int `nullable:"false" list:"admin"` // = Column(Integer, nullable=False) diff --git a/pkg/compute/models/vpcs.go b/pkg/compute/models/vpcs.go index 532dd2a512..c5fa194e16 100644 --- a/pkg/compute/models/vpcs.go +++ b/pkg/compute/models/vpcs.go @@ -35,7 +35,6 @@ const ( type SVpcManager struct { db.SEnabledStatusStandaloneResourceBaseManager - SInfrastructureManager } var VpcManager *SVpcManager @@ -53,7 +52,6 @@ func init() { type SVpc struct { db.SEnabledStatusStandaloneResourceBase - SInfrastructure SManagedResourceBase IsDefault bool `default:"false" list:"admin" create:"admin_optional"` @@ -67,6 +65,26 @@ func (manager *SVpcManager) GetContextManager() []db.IModelManager { return []db.IModelManager{CloudregionManager} } +func (self *SVpcManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SVpcManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SVpc) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SVpc) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SVpc) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (self *SVpc) GetCloudRegionId() string { if len(self.CloudregionId) == 0 { return "default" diff --git a/pkg/compute/models/wires.go b/pkg/compute/models/wires.go index 61d1da68e3..00364f0dfc 100644 --- a/pkg/compute/models/wires.go +++ b/pkg/compute/models/wires.go @@ -15,11 +15,12 @@ import ( "yunion.io/x/pkg/util/compare" "yunion.io/x/pkg/util/netutils" "yunion.io/x/sqlchemy" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" + "yunion.io/x/onecloud/pkg/cloudcommon/policy" ) type SWireManager struct { db.SStandaloneResourceBaseManager - SInfrastructureManager } var WireManager *SWireManager @@ -39,7 +40,6 @@ func init() { type SWire struct { db.SStandaloneResourceBase - SInfrastructure Bandwidth int `list:"admin" update:"admin" nullable:"false" create:"admin_required"` // = Column(Integer, nullable=False) # bandwidth of network in Mbps ScheduleRank int `list:"admin" update:"admin"` // = Column(Integer, default=0, nullable=True) @@ -51,6 +51,26 @@ func (manager *SWireManager) GetContextManager() []db.IModelManager { return []db.IModelManager{ZoneManager, VpcManager} } +func (self *SWireManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionList) +} + +func (self *SWireManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SWire) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SWire) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SWire) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (manager *SWireManager) ValidateCreateData(ctx context.Context, userCred mcclient.TokenCredential, ownerProjId string, query jsonutils.JSONObject, data *jsonutils.JSONDict) (*jsonutils.JSONDict, error) { bandwidth, err := data.Int("bandwidth") if err != nil || bandwidth == 0 { diff --git a/pkg/compute/models/zones.go b/pkg/compute/models/zones.go index 6f7ff2649c..50b6f5a351 100644 --- a/pkg/compute/models/zones.go +++ b/pkg/compute/models/zones.go @@ -12,6 +12,8 @@ import ( "yunion.io/x/pkg/tristate" "yunion.io/x/pkg/util/compare" "yunion.io/x/sqlchemy" + "yunion.io/x/onecloud/pkg/cloudcommon/consts" + "yunion.io/x/onecloud/pkg/cloudcommon/policy" ) const ( @@ -23,7 +25,6 @@ const ( type SZoneManager struct { db.SStatusStandaloneResourceBaseManager - SInfrastructureManager } var ZoneManager *SZoneManager @@ -42,7 +43,6 @@ func init() { type SZone struct { db.SStatusStandaloneResourceBase - SInfrastructure Location string `width:"256" charset:"utf8" get:"user" update:"admin"` // = Column(VARCHAR(256, charset='utf8')) Contacts string `width:"256" charset:"utf8" get:"user" update:"admin"` // = Column(VARCHAR(256, charset='utf8')) @@ -57,6 +57,22 @@ func (manager *SZoneManager) GetContextManager() []db.IModelManager { return []db.IModelManager{CloudregionManager} } +func (self *SZoneManager) AllowCreateItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionCreate) +} + +func (self *SZone) AllowGetDetails(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionGet) +} + +func (self *SZone) AllowUpdateItem(ctx context.Context, userCred mcclient.TokenCredential) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionUpdate) +} + +func (self *SZone) AllowDeleteItem(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject, data jsonutils.JSONObject) bool { + return userCred.IsAdminAllow(consts.GetServiceType(), self.KeywordPlural(), policy.PolicyActionDelete) +} + func (manager *SZoneManager) AllowListItems(ctx context.Context, userCred mcclient.TokenCredential, query jsonutils.JSONObject) bool { return true }