Merge pull request #839 in YUNIONIO/onecloud from ~QIUJIAN/onecloud:hotfix/qj-avoid-empty-policy-rules to release/2.4.0

* commit 'd008d47f52e5a603f940740066e550322d554859':
  Avoid empty policy rules
This commit is contained in:
邱剑
2018-12-25 16:34:16 +08:00
4 changed files with 13 additions and 6 deletions
+3 -3
View File
@@ -21,9 +21,9 @@ func getUpdate(d []interface{}) ([]string, error) {
func defaultSyncItems() []cache.CachedItem {
return []cache.CachedItem{
//newGlanceCache(),
//newNetworkCache(),
//newNetworksDataCache(),
//newGlanceCache(),
//newNetworkCache(),
//newNetworksDataCache(),
}
}
+2 -2
View File
@@ -200,8 +200,8 @@ type TaskManager struct {
func NewTaskManager(stopCh <-chan struct{}) *TaskManager {
return &TaskManager{
taskExecutorQueueManager: NewTaskExecutorQueueManager(stopCh),
stopCh: stopCh,
lock: sync.Mutex{},
stopCh: stopCh,
lock: sync.Mutex{},
}
}
+1 -1
View File
@@ -46,7 +46,7 @@ func (self *SAliyunProviderFactory) GetProvider(providerId, providerName, url, a
func init() {
factory := SAliyunProviderFactory{
// providerTable: make(map[string]*SAliyunProvider),
// providerTable: make(map[string]*SAliyunProvider),
}
cloudprovider.RegisterFactory(&factory)
}
+7
View File
@@ -163,6 +163,9 @@ func (policy *SRbacPolicy) GetMatchRule(service string, resource string, action
}
func CompactRules(rules []SRbacRule) []SRbacRule {
if len(rules) == 0 {
return nil
}
output := make([]SRbacRule, 1)
output[0] = rules[0]
for i := 1; i < len(rules); i += 1 {
@@ -199,6 +202,10 @@ func (policy *SRbacPolicy) Decode(policyJson jsonutils.JSONObject) error {
return err
}
if len(rules) == 0 {
return fmt.Errorf("empty policy")
}
policy.Rules = CompactRules(rules)
return nil