policy.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. package types
  2. import "time"
  3. type PermissionScope string
  4. const (
  5. UserScope PermissionScope = "user"
  6. ProjectScope PermissionScope = "project"
  7. ClusterScope PermissionScope = "cluster"
  8. RegistryScope PermissionScope = "registry"
  9. InviteScope PermissionScope = "invite"
  10. HelmRepoScope PermissionScope = "helm_repo"
  11. InfraScope PermissionScope = "infra"
  12. OperationScope PermissionScope = "operation"
  13. GitInstallationScope PermissionScope = "git_installation"
  14. NamespaceScope PermissionScope = "namespace"
  15. SettingsScope PermissionScope = "settings"
  16. ReleaseScope PermissionScope = "release"
  17. )
  18. type NameOrUInt struct {
  19. Name string `json:"name"`
  20. UInt uint `json:"uint"`
  21. }
  22. type PolicyDocument struct {
  23. Scope PermissionScope `json:"scope"`
  24. Resources []NameOrUInt `json:"resources"`
  25. Verbs []APIVerb `json:"verbs"`
  26. Children map[PermissionScope]*PolicyDocument `json:"children"`
  27. }
  28. type ScopeTree map[PermissionScope]ScopeTree
  29. /* ScopeHeirarchy describes the tree of scopes, i.e. Cluster, Registry, and Settings
  30. are children of Project, Namespace is a child of Cluster, etc.
  31. */
  32. var ScopeHeirarchy = ScopeTree{
  33. ProjectScope: {
  34. ClusterScope: {
  35. NamespaceScope: {
  36. ReleaseScope: {},
  37. },
  38. },
  39. RegistryScope: {},
  40. HelmRepoScope: {},
  41. GitInstallationScope: {},
  42. InfraScope: {
  43. OperationScope: {},
  44. },
  45. SettingsScope: {},
  46. },
  47. }
  48. type Policy []*PolicyDocument
  49. var AdminPolicy = []*PolicyDocument{
  50. {
  51. Scope: ProjectScope,
  52. Verbs: ReadWriteVerbGroup(),
  53. },
  54. }
  55. var DeveloperPolicy = []*PolicyDocument{
  56. {
  57. Scope: ProjectScope,
  58. Verbs: ReadWriteVerbGroup(),
  59. Children: map[PermissionScope]*PolicyDocument{
  60. SettingsScope: {
  61. Scope: SettingsScope,
  62. Verbs: ReadVerbGroup(),
  63. },
  64. },
  65. },
  66. }
  67. var ViewerPolicy = []*PolicyDocument{
  68. {
  69. Scope: ProjectScope,
  70. Verbs: ReadVerbGroup(),
  71. Children: map[PermissionScope]*PolicyDocument{
  72. SettingsScope: {
  73. Scope: SettingsScope,
  74. Verbs: []APIVerb{},
  75. },
  76. },
  77. },
  78. }
  79. type CreatePolicy struct {
  80. Name string `json:"name" form:"required"`
  81. Policy []*PolicyDocument `json:"policy" form:"required"`
  82. }
  83. const URLParamPolicyID URLParam = "policy_id"
  84. type APIPolicyMeta struct {
  85. CreatedAt time.Time `json:"created_at"`
  86. UpdatedAt time.Time `json:"updated_at"`
  87. ProjectID uint `json:"project_id"`
  88. UID string `json:"uid"`
  89. Name string `json:"name"`
  90. }
  91. type APIPolicy struct {
  92. *APIPolicyMeta
  93. Policy []*PolicyDocument `json:"policy"`
  94. }