resources.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/utils"
  17. )
  18. var (
  19. itsmSystemResources = []string{
  20. "process-definitions",
  21. }
  22. itsmDomainResources = []string{}
  23. itsmUserResources = []string{}
  24. systemResources = map[string][]string{
  25. "itsm": itsmSystemResources,
  26. }
  27. domainResources = map[string][]string{
  28. "itsm": itsmDomainResources,
  29. }
  30. userResources = map[string][]string{
  31. "itsm": itsmUserResources,
  32. }
  33. )
  34. func GetSystemResources() map[string][]string {
  35. return systemResources
  36. }
  37. func GetResources() map[string]map[string][]string {
  38. return map[string]map[string][]string{
  39. "system": systemResources,
  40. "domain": domainResources,
  41. "user": userResources,
  42. }
  43. }
  44. func isSystemResource(service string, resource string) bool {
  45. resList, ok := systemResources[service]
  46. if ok {
  47. if utils.IsInStringArray(resource, resList) {
  48. return true
  49. }
  50. }
  51. return false
  52. }
  53. func isDomainResource(service string, resource string) bool {
  54. resList, ok := domainResources[service]
  55. if ok {
  56. if utils.IsInStringArray(resource, resList) {
  57. return true
  58. }
  59. }
  60. return false
  61. }
  62. func isUserResource(service string, resource string) bool {
  63. resList, ok := userResources[service]
  64. if ok {
  65. if utils.IsInStringArray(resource, resList) {
  66. return true
  67. }
  68. }
  69. return false
  70. }
  71. func isProjectResource(service string, resource string) bool {
  72. if isSystemResource(service, resource) {
  73. return false
  74. }
  75. if isDomainResource(service, resource) {
  76. return false
  77. }
  78. if isUserResource(service, resource) {
  79. return false
  80. }
  81. return true
  82. }
  83. func RegisterSystemResources(service string, resources []string) {
  84. systemResources[service] = resources
  85. }
  86. func RegisterDomainResources(service string, resources []string) {
  87. domainResources[service] = resources
  88. }
  89. func RegisterUserResources(service string, resources []string) {
  90. userResources[service] = resources
  91. }