policy.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. package types
  2. type PermissionScope string
  3. const (
  4. UserScope PermissionScope = "user"
  5. ProjectScope PermissionScope = "project"
  6. ClusterScope PermissionScope = "cluster"
  7. NamespaceScope PermissionScope = "namespace"
  8. SettingsScope PermissionScope = "settings"
  9. ApplicationScope PermissionScope = "application"
  10. )
  11. type NameOrUInt struct {
  12. Name string `json:"name"`
  13. UInt uint `json:"uint"`
  14. }
  15. type PolicyDocument struct {
  16. Scope PermissionScope `json:"scope"`
  17. Resources []NameOrUInt `json:"resources"`
  18. Verbs []APIVerb `json:"verbs"`
  19. Children map[PermissionScope]*PolicyDocument `json:"children"`
  20. }
  21. type ScopeTree map[PermissionScope]ScopeTree
  22. /* ScopeHeirarchy describes the scope tree:
  23. Project
  24. / \
  25. Cluster Settings
  26. /
  27. Namespace
  28. |
  29. Release
  30. */
  31. var ScopeHeirarchy = ScopeTree{
  32. ProjectScope: {
  33. ClusterScope: {
  34. NamespaceScope: {
  35. ApplicationScope: {},
  36. },
  37. },
  38. SettingsScope: {},
  39. },
  40. }
  41. type Policy []*PolicyDocument
  42. type APIVerb string
  43. const (
  44. APIVerbGet APIVerb = "get"
  45. APIVerbCreate APIVerb = "create"
  46. APIVerbList APIVerb = "list"
  47. APIVerbUpdate APIVerb = "update"
  48. APIVerbDelete APIVerb = "delete"
  49. )
  50. type APIVerbGroup []APIVerb
  51. func ReadVerbGroup() APIVerbGroup {
  52. return []APIVerb{APIVerbGet, APIVerbList}
  53. }
  54. func ReadWriteVerbGroup() APIVerbGroup {
  55. return []APIVerb{APIVerbGet, APIVerbList, APIVerbCreate, APIVerbUpdate, APIVerbDelete}
  56. }
  57. var AdminPolicy = []*PolicyDocument{
  58. {
  59. Scope: ProjectScope,
  60. Verbs: ReadWriteVerbGroup(),
  61. },
  62. }
  63. var DeveloperPolicy = []*PolicyDocument{
  64. {
  65. Scope: ProjectScope,
  66. Verbs: ReadWriteVerbGroup(),
  67. Children: map[PermissionScope]*PolicyDocument{
  68. SettingsScope: {
  69. Scope: SettingsScope,
  70. Verbs: ReadVerbGroup(),
  71. },
  72. },
  73. },
  74. }
  75. var ViewerPolicy = []*PolicyDocument{
  76. {
  77. Scope: ProjectScope,
  78. Verbs: ReadVerbGroup(),
  79. Children: map[PermissionScope]*PolicyDocument{
  80. SettingsScope: {
  81. Scope: SettingsScope,
  82. Verbs: []APIVerb{},
  83. },
  84. },
  85. },
  86. }