repository.go 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. package gorm
  2. import (
  3. "github.com/porter-dev/porter/internal/repository"
  4. "github.com/porter-dev/porter/internal/repository/credentials"
  5. "gorm.io/gorm"
  6. )
  7. type GormRepository struct {
  8. user repository.UserRepository
  9. session repository.SessionRepository
  10. project repository.ProjectRepository
  11. cluster repository.ClusterRepository
  12. database repository.DatabaseRepository
  13. helmRepo repository.HelmRepoRepository
  14. registry repository.RegistryRepository
  15. gitRepo repository.GitRepoRepository
  16. gitActionConfig repository.GitActionConfigRepository
  17. invite repository.InviteRepository
  18. release repository.ReleaseRepository
  19. environment repository.EnvironmentRepository
  20. authCode repository.AuthCodeRepository
  21. dnsRecord repository.DNSRecordRepository
  22. pwResetToken repository.PWResetTokenRepository
  23. infra repository.InfraRepository
  24. kubeIntegration repository.KubeIntegrationRepository
  25. basicIntegration repository.BasicIntegrationRepository
  26. oidcIntegration repository.OIDCIntegrationRepository
  27. oauthIntegration repository.OAuthIntegrationRepository
  28. gcpIntegration repository.GCPIntegrationRepository
  29. awsIntegration repository.AWSIntegrationRepository
  30. azIntegration repository.AzureIntegrationRepository
  31. githubAppInstallation repository.GithubAppInstallationRepository
  32. githubAppOAuthIntegration repository.GithubAppOAuthIntegrationRepository
  33. slackIntegration repository.SlackIntegrationRepository
  34. gitlabIntegration repository.GitlabIntegrationRepository
  35. gitlabAppOAuthIntegration repository.GitlabAppOAuthIntegrationRepository
  36. notificationConfig repository.NotificationConfigRepository
  37. jobNotificationConfig repository.JobNotificationConfigRepository
  38. buildEvent repository.BuildEventRepository
  39. kubeEvent repository.KubeEventRepository
  40. projectUsage repository.ProjectUsageRepository
  41. onboarding repository.ProjectOnboardingRepository
  42. ceToken repository.CredentialsExchangeTokenRepository
  43. buildConfig repository.BuildConfigRepository
  44. allowlist repository.AllowlistRepository
  45. apiToken repository.APITokenRepository
  46. policy repository.PolicyRepository
  47. tag repository.TagRepository
  48. stack repository.StackRepository
  49. }
  50. func (t *GormRepository) User() repository.UserRepository {
  51. return t.user
  52. }
  53. func (t *GormRepository) Session() repository.SessionRepository {
  54. return t.session
  55. }
  56. func (t *GormRepository) Project() repository.ProjectRepository {
  57. return t.project
  58. }
  59. func (t *GormRepository) Cluster() repository.ClusterRepository {
  60. return t.cluster
  61. }
  62. func (t *GormRepository) Database() repository.DatabaseRepository {
  63. return t.database
  64. }
  65. func (t *GormRepository) HelmRepo() repository.HelmRepoRepository {
  66. return t.helmRepo
  67. }
  68. func (t *GormRepository) Registry() repository.RegistryRepository {
  69. return t.registry
  70. }
  71. func (t *GormRepository) GitRepo() repository.GitRepoRepository {
  72. return t.gitRepo
  73. }
  74. func (t *GormRepository) GitActionConfig() repository.GitActionConfigRepository {
  75. return t.gitActionConfig
  76. }
  77. func (t *GormRepository) Invite() repository.InviteRepository {
  78. return t.invite
  79. }
  80. func (t *GormRepository) Release() repository.ReleaseRepository {
  81. return t.release
  82. }
  83. func (t *GormRepository) Environment() repository.EnvironmentRepository {
  84. return t.environment
  85. }
  86. func (t *GormRepository) AuthCode() repository.AuthCodeRepository {
  87. return t.authCode
  88. }
  89. func (t *GormRepository) DNSRecord() repository.DNSRecordRepository {
  90. return t.dnsRecord
  91. }
  92. func (t *GormRepository) PWResetToken() repository.PWResetTokenRepository {
  93. return t.pwResetToken
  94. }
  95. func (t *GormRepository) Infra() repository.InfraRepository {
  96. return t.infra
  97. }
  98. func (t *GormRepository) KubeIntegration() repository.KubeIntegrationRepository {
  99. return t.kubeIntegration
  100. }
  101. func (t *GormRepository) BasicIntegration() repository.BasicIntegrationRepository {
  102. return t.basicIntegration
  103. }
  104. func (t *GormRepository) OIDCIntegration() repository.OIDCIntegrationRepository {
  105. return t.oidcIntegration
  106. }
  107. func (t *GormRepository) OAuthIntegration() repository.OAuthIntegrationRepository {
  108. return t.oauthIntegration
  109. }
  110. func (t *GormRepository) GCPIntegration() repository.GCPIntegrationRepository {
  111. return t.gcpIntegration
  112. }
  113. func (t *GormRepository) AWSIntegration() repository.AWSIntegrationRepository {
  114. return t.awsIntegration
  115. }
  116. func (t *GormRepository) AzureIntegration() repository.AzureIntegrationRepository {
  117. return t.azIntegration
  118. }
  119. func (t *GormRepository) GithubAppInstallation() repository.GithubAppInstallationRepository {
  120. return t.githubAppInstallation
  121. }
  122. func (t *GormRepository) GithubAppOAuthIntegration() repository.GithubAppOAuthIntegrationRepository {
  123. return t.githubAppOAuthIntegration
  124. }
  125. func (t *GormRepository) SlackIntegration() repository.SlackIntegrationRepository {
  126. return t.slackIntegration
  127. }
  128. func (t *GormRepository) GitlabIntegration() repository.GitlabIntegrationRepository {
  129. return t.gitlabIntegration
  130. }
  131. func (t *GormRepository) GitlabAppOAuthIntegration() repository.GitlabAppOAuthIntegrationRepository {
  132. return t.gitlabAppOAuthIntegration
  133. }
  134. func (t *GormRepository) NotificationConfig() repository.NotificationConfigRepository {
  135. return t.notificationConfig
  136. }
  137. func (t *GormRepository) JobNotificationConfig() repository.JobNotificationConfigRepository {
  138. return t.jobNotificationConfig
  139. }
  140. func (t *GormRepository) BuildEvent() repository.BuildEventRepository {
  141. return t.buildEvent
  142. }
  143. func (t *GormRepository) KubeEvent() repository.KubeEventRepository {
  144. return t.kubeEvent
  145. }
  146. func (t *GormRepository) ProjectUsage() repository.ProjectUsageRepository {
  147. return t.projectUsage
  148. }
  149. func (t *GormRepository) Onboarding() repository.ProjectOnboardingRepository {
  150. return t.onboarding
  151. }
  152. func (t *GormRepository) CredentialsExchangeToken() repository.CredentialsExchangeTokenRepository {
  153. return t.ceToken
  154. }
  155. func (t *GormRepository) BuildConfig() repository.BuildConfigRepository {
  156. return t.buildConfig
  157. }
  158. func (t *GormRepository) Allowlist() repository.AllowlistRepository {
  159. return t.allowlist
  160. }
  161. func (t *GormRepository) APIToken() repository.APITokenRepository {
  162. return t.apiToken
  163. }
  164. func (t *GormRepository) Policy() repository.PolicyRepository {
  165. return t.policy
  166. }
  167. func (t *GormRepository) Tag() repository.TagRepository {
  168. return t.tag
  169. }
  170. func (t *GormRepository) Stack() repository.StackRepository {
  171. return t.stack
  172. }
  173. // NewRepository returns a Repository which persists users in memory
  174. // and accepts a parameter that can trigger read/write errors
  175. func NewRepository(db *gorm.DB, key *[32]byte, storageBackend credentials.CredentialStorage) repository.Repository {
  176. return &GormRepository{
  177. user: NewUserRepository(db),
  178. session: NewSessionRepository(db),
  179. project: NewProjectRepository(db),
  180. cluster: NewClusterRepository(db, key),
  181. database: NewDatabaseRepository(db, key),
  182. helmRepo: NewHelmRepoRepository(db, key),
  183. registry: NewRegistryRepository(db, key),
  184. gitRepo: NewGitRepoRepository(db, key),
  185. gitActionConfig: NewGitActionConfigRepository(db),
  186. invite: NewInviteRepository(db),
  187. release: NewReleaseRepository(db),
  188. environment: NewEnvironmentRepository(db),
  189. authCode: NewAuthCodeRepository(db),
  190. dnsRecord: NewDNSRecordRepository(db),
  191. pwResetToken: NewPWResetTokenRepository(db),
  192. infra: NewInfraRepository(db, key),
  193. kubeIntegration: NewKubeIntegrationRepository(db, key),
  194. basicIntegration: NewBasicIntegrationRepository(db, key),
  195. oidcIntegration: NewOIDCIntegrationRepository(db, key),
  196. oauthIntegration: NewOAuthIntegrationRepository(db, key, storageBackend),
  197. gcpIntegration: NewGCPIntegrationRepository(db, key, storageBackend),
  198. awsIntegration: NewAWSIntegrationRepository(db, key, storageBackend),
  199. azIntegration: NewAzureIntegrationRepository(db, key, storageBackend),
  200. githubAppInstallation: NewGithubAppInstallationRepository(db),
  201. githubAppOAuthIntegration: NewGithubAppOAuthIntegrationRepository(db),
  202. slackIntegration: NewSlackIntegrationRepository(db, key),
  203. gitlabIntegration: NewGitlabIntegrationRepository(db, key, storageBackend),
  204. gitlabAppOAuthIntegration: NewGitlabAppOAuthIntegrationRepository(db, key, storageBackend),
  205. notificationConfig: NewNotificationConfigRepository(db),
  206. jobNotificationConfig: NewJobNotificationConfigRepository(db),
  207. buildEvent: NewBuildEventRepository(db),
  208. kubeEvent: NewKubeEventRepository(db, key),
  209. projectUsage: NewProjectUsageRepository(db),
  210. onboarding: NewProjectOnboardingRepository(db),
  211. ceToken: NewCredentialsExchangeTokenRepository(db),
  212. buildConfig: NewBuildConfigRepository(db),
  213. allowlist: NewAllowlistRepository(db),
  214. apiToken: NewAPITokenRepository(db),
  215. policy: NewPolicyRepository(db),
  216. tag: NewTagRepository(db),
  217. stack: NewStackRepository(db),
  218. }
  219. }