2
0

policy.go 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. DeploymentTargetScope PermissionScope = "target"
  9. RegistryScope PermissionScope = "registry"
  10. InviteScope PermissionScope = "invite"
  11. HelmRepoScope PermissionScope = "helm_repo"
  12. InfraScope PermissionScope = "infra"
  13. OperationScope PermissionScope = "operation"
  14. GitInstallationScope PermissionScope = "git_installation"
  15. NamespaceScope PermissionScope = "namespace"
  16. SettingsScope PermissionScope = "settings"
  17. ReleaseScope PermissionScope = "release"
  18. StackScope PermissionScope = "stack"
  19. GitlabIntegrationScope PermissionScope = "gitlab_integration"
  20. PreviewEnvironmentScope PermissionScope = "preview_environment"
  21. APIContractRevisionScope PermissionScope = "contract_revision"
  22. )
  23. type NameOrUInt struct {
  24. Name string `json:"name"`
  25. UInt uint `json:"uint"`
  26. }
  27. type PolicyDocument struct {
  28. Scope PermissionScope `json:"scope"`
  29. Resources []NameOrUInt `json:"resources"`
  30. Verbs []APIVerb `json:"verbs"`
  31. Children map[PermissionScope]*PolicyDocument `json:"children"`
  32. }
  33. type ScopeTree map[PermissionScope]ScopeTree
  34. /*
  35. ScopeHeirarchy describes the tree of scopes, i.e. Cluster, Registry, and Settings
  36. are children of Project, Namespace is a child of Cluster, etc.
  37. */
  38. var ScopeHeirarchy = ScopeTree{
  39. ProjectScope: {
  40. ClusterScope: {
  41. NamespaceScope: {
  42. StackScope: {},
  43. ReleaseScope: {},
  44. },
  45. PreviewEnvironmentScope: {},
  46. },
  47. RegistryScope: {},
  48. HelmRepoScope: {},
  49. GitInstallationScope: {},
  50. InfraScope: {
  51. OperationScope: {},
  52. },
  53. SettingsScope: {},
  54. APIContractRevisionScope: {},
  55. },
  56. }
  57. type Policy []*PolicyDocument
  58. var AdminPolicy = []*PolicyDocument{
  59. {
  60. Scope: ProjectScope,
  61. Verbs: ReadWriteVerbGroup(),
  62. Children: map[PermissionScope]*PolicyDocument{
  63. ClusterScope: {
  64. Scope: ClusterScope,
  65. Verbs: ReadWriteVerbGroup(),
  66. },
  67. RegistryScope: {
  68. Scope: RegistryScope,
  69. Verbs: ReadWriteVerbGroup(),
  70. },
  71. HelmRepoScope: {
  72. Scope: HelmRepoScope,
  73. Verbs: ReadWriteVerbGroup(),
  74. },
  75. GitInstallationScope: {
  76. Scope: GitInstallationScope,
  77. Verbs: ReadWriteVerbGroup(),
  78. },
  79. InfraScope: {
  80. Scope: InfraScope,
  81. Verbs: ReadWriteVerbGroup(),
  82. },
  83. SettingsScope: {
  84. Scope: SettingsScope,
  85. Verbs: ReadWriteVerbGroup(),
  86. },
  87. APIContractRevisionScope: {
  88. Scope: APIContractRevisionScope,
  89. Verbs: ReadWriteVerbGroup(),
  90. },
  91. },
  92. },
  93. }
  94. var DeveloperPolicy = []*PolicyDocument{
  95. {
  96. Scope: ProjectScope,
  97. Verbs: ReadWriteVerbGroup(),
  98. Children: map[PermissionScope]*PolicyDocument{
  99. ClusterScope: {
  100. Scope: ClusterScope,
  101. Verbs: ReadWriteVerbGroup(),
  102. },
  103. RegistryScope: {
  104. Scope: RegistryScope,
  105. Verbs: ReadWriteVerbGroup(),
  106. },
  107. HelmRepoScope: {
  108. Scope: HelmRepoScope,
  109. Verbs: ReadWriteVerbGroup(),
  110. },
  111. GitInstallationScope: {
  112. Scope: GitInstallationScope,
  113. Verbs: ReadWriteVerbGroup(),
  114. },
  115. InfraScope: {
  116. Scope: InfraScope,
  117. Verbs: ReadWriteVerbGroup(),
  118. },
  119. SettingsScope: {
  120. Scope: SettingsScope,
  121. Verbs: ReadVerbGroup(),
  122. },
  123. APIContractRevisionScope: {
  124. Scope: APIContractRevisionScope,
  125. Verbs: ReadWriteVerbGroup(),
  126. },
  127. },
  128. },
  129. }
  130. var ViewerPolicy = []*PolicyDocument{
  131. {
  132. Scope: ProjectScope,
  133. Verbs: ReadVerbGroup(),
  134. Children: map[PermissionScope]*PolicyDocument{
  135. ClusterScope: {
  136. Scope: ClusterScope,
  137. Verbs: ReadVerbGroup(),
  138. },
  139. RegistryScope: {
  140. Scope: RegistryScope,
  141. Verbs: ReadVerbGroup(),
  142. },
  143. HelmRepoScope: {
  144. Scope: HelmRepoScope,
  145. Verbs: ReadVerbGroup(),
  146. },
  147. GitInstallationScope: {
  148. Scope: GitInstallationScope,
  149. Verbs: ReadVerbGroup(),
  150. },
  151. InfraScope: {
  152. Scope: InfraScope,
  153. Verbs: ReadVerbGroup(),
  154. },
  155. SettingsScope: {
  156. Scope: SettingsScope,
  157. Verbs: []APIVerb{},
  158. },
  159. APIContractRevisionScope: {
  160. Scope: APIContractRevisionScope,
  161. Verbs: ReadVerbGroup(),
  162. },
  163. },
  164. },
  165. }
  166. type CreatePolicy struct {
  167. Name string `json:"name" form:"required"`
  168. Policy []*PolicyDocument `json:"policy" form:"required"`
  169. }
  170. const URLParamPolicyID URLParam = "policy_id"
  171. type APIPolicyMeta struct {
  172. CreatedAt time.Time `json:"created_at"`
  173. UpdatedAt time.Time `json:"updated_at"`
  174. ProjectID uint `json:"project_id"`
  175. UID string `json:"uid"`
  176. Name string `json:"name"`
  177. }
  178. type APIPolicy struct {
  179. *APIPolicyMeta
  180. Policy []*PolicyDocument `json:"policy"`
  181. }