defaults.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package policy
  15. import (
  16. "yunion.io/x/pkg/util/rbacscope"
  17. api "yunion.io/x/onecloud/pkg/apis/logger"
  18. "yunion.io/x/onecloud/pkg/cloudcommon/consts"
  19. common_policy "yunion.io/x/onecloud/pkg/cloudcommon/policy"
  20. "yunion.io/x/onecloud/pkg/util/rbacutils"
  21. )
  22. const (
  23. PolicyActionGet = common_policy.PolicyActionGet
  24. PolicyActionList = common_policy.PolicyActionList
  25. PolicyActionCreate = common_policy.PolicyActionCreate
  26. )
  27. var (
  28. predefinedDefaultPolicies = []rbacutils.SRbacPolicy{
  29. {
  30. Auth: true,
  31. Scope: rbacscope.ScopeUser,
  32. Rules: []rbacutils.SRbacRule{
  33. {
  34. Service: api.SERVICE_TYPE,
  35. Resource: "actions",
  36. Action: PolicyActionList,
  37. Result: rbacutils.Allow,
  38. },
  39. {
  40. Service: api.SERVICE_TYPE,
  41. Resource: "actions",
  42. Action: PolicyActionGet,
  43. Result: rbacutils.Allow,
  44. },
  45. {
  46. Service: api.SERVICE_TYPE,
  47. Resource: "actions",
  48. Action: PolicyActionCreate,
  49. Result: rbacutils.Allow,
  50. },
  51. },
  52. },
  53. }
  54. )
  55. func Init() {
  56. if consts.IsEnableDefaultPolicy() {
  57. common_policy.AppendDefaultPolicies(predefinedDefaultPolicies)
  58. }
  59. }