repository.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  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. monitor repository.MonitorTestResultRepository
  50. apiContractRevisions repository.APIContractRevisioner
  51. awsAssumeRoleChainer repository.AWSAssumeRoleChainer
  52. porterApp repository.PorterAppRepository
  53. porterAppEvent repository.PorterAppEventRepository
  54. deploymentTarget repository.DeploymentTargetRepository
  55. appRevision repository.AppRevisionRepository
  56. appTemplate repository.AppTemplateRepository
  57. githubWebhook repository.GithubWebhookRepository
  58. }
  59. func (t *GormRepository) User() repository.UserRepository {
  60. return t.user
  61. }
  62. func (t *GormRepository) Session() repository.SessionRepository {
  63. return t.session
  64. }
  65. func (t *GormRepository) Project() repository.ProjectRepository {
  66. return t.project
  67. }
  68. func (t *GormRepository) Cluster() repository.ClusterRepository {
  69. return t.cluster
  70. }
  71. func (t *GormRepository) Database() repository.DatabaseRepository {
  72. return t.database
  73. }
  74. func (t *GormRepository) HelmRepo() repository.HelmRepoRepository {
  75. return t.helmRepo
  76. }
  77. func (t *GormRepository) Registry() repository.RegistryRepository {
  78. return t.registry
  79. }
  80. func (t *GormRepository) GitRepo() repository.GitRepoRepository {
  81. return t.gitRepo
  82. }
  83. func (t *GormRepository) GitActionConfig() repository.GitActionConfigRepository {
  84. return t.gitActionConfig
  85. }
  86. func (t *GormRepository) Invite() repository.InviteRepository {
  87. return t.invite
  88. }
  89. func (t *GormRepository) Release() repository.ReleaseRepository {
  90. return t.release
  91. }
  92. func (t *GormRepository) Environment() repository.EnvironmentRepository {
  93. return t.environment
  94. }
  95. func (t *GormRepository) AuthCode() repository.AuthCodeRepository {
  96. return t.authCode
  97. }
  98. func (t *GormRepository) DNSRecord() repository.DNSRecordRepository {
  99. return t.dnsRecord
  100. }
  101. func (t *GormRepository) PWResetToken() repository.PWResetTokenRepository {
  102. return t.pwResetToken
  103. }
  104. func (t *GormRepository) Infra() repository.InfraRepository {
  105. return t.infra
  106. }
  107. func (t *GormRepository) KubeIntegration() repository.KubeIntegrationRepository {
  108. return t.kubeIntegration
  109. }
  110. func (t *GormRepository) BasicIntegration() repository.BasicIntegrationRepository {
  111. return t.basicIntegration
  112. }
  113. func (t *GormRepository) OIDCIntegration() repository.OIDCIntegrationRepository {
  114. return t.oidcIntegration
  115. }
  116. func (t *GormRepository) OAuthIntegration() repository.OAuthIntegrationRepository {
  117. return t.oauthIntegration
  118. }
  119. func (t *GormRepository) GCPIntegration() repository.GCPIntegrationRepository {
  120. return t.gcpIntegration
  121. }
  122. func (t *GormRepository) AWSIntegration() repository.AWSIntegrationRepository {
  123. return t.awsIntegration
  124. }
  125. func (t *GormRepository) AzureIntegration() repository.AzureIntegrationRepository {
  126. return t.azIntegration
  127. }
  128. func (t *GormRepository) GithubAppInstallation() repository.GithubAppInstallationRepository {
  129. return t.githubAppInstallation
  130. }
  131. func (t *GormRepository) GithubAppOAuthIntegration() repository.GithubAppOAuthIntegrationRepository {
  132. return t.githubAppOAuthIntegration
  133. }
  134. func (t *GormRepository) SlackIntegration() repository.SlackIntegrationRepository {
  135. return t.slackIntegration
  136. }
  137. func (t *GormRepository) GitlabIntegration() repository.GitlabIntegrationRepository {
  138. return t.gitlabIntegration
  139. }
  140. func (t *GormRepository) GitlabAppOAuthIntegration() repository.GitlabAppOAuthIntegrationRepository {
  141. return t.gitlabAppOAuthIntegration
  142. }
  143. func (t *GormRepository) NotificationConfig() repository.NotificationConfigRepository {
  144. return t.notificationConfig
  145. }
  146. func (t *GormRepository) JobNotificationConfig() repository.JobNotificationConfigRepository {
  147. return t.jobNotificationConfig
  148. }
  149. func (t *GormRepository) BuildEvent() repository.BuildEventRepository {
  150. return t.buildEvent
  151. }
  152. func (t *GormRepository) KubeEvent() repository.KubeEventRepository {
  153. return t.kubeEvent
  154. }
  155. func (t *GormRepository) ProjectUsage() repository.ProjectUsageRepository {
  156. return t.projectUsage
  157. }
  158. func (t *GormRepository) Onboarding() repository.ProjectOnboardingRepository {
  159. return t.onboarding
  160. }
  161. func (t *GormRepository) CredentialsExchangeToken() repository.CredentialsExchangeTokenRepository {
  162. return t.ceToken
  163. }
  164. func (t *GormRepository) BuildConfig() repository.BuildConfigRepository {
  165. return t.buildConfig
  166. }
  167. func (t *GormRepository) Allowlist() repository.AllowlistRepository {
  168. return t.allowlist
  169. }
  170. func (t *GormRepository) APIToken() repository.APITokenRepository {
  171. return t.apiToken
  172. }
  173. func (t *GormRepository) Policy() repository.PolicyRepository {
  174. return t.policy
  175. }
  176. func (t *GormRepository) Tag() repository.TagRepository {
  177. return t.tag
  178. }
  179. func (t *GormRepository) Stack() repository.StackRepository {
  180. return t.stack
  181. }
  182. func (t *GormRepository) PorterApp() repository.PorterAppRepository {
  183. return t.porterApp
  184. }
  185. func (t *GormRepository) MonitorTestResult() repository.MonitorTestResultRepository {
  186. return t.monitor
  187. }
  188. func (t *GormRepository) APIContractRevisioner() repository.APIContractRevisioner {
  189. return t.apiContractRevisions
  190. }
  191. func (t *GormRepository) AWSAssumeRoleChainer() repository.AWSAssumeRoleChainer {
  192. return t.awsAssumeRoleChainer
  193. }
  194. func (t *GormRepository) PorterAppEvent() repository.PorterAppEventRepository {
  195. return t.porterAppEvent
  196. }
  197. // DeploymentTarget returns the DeploymentTargetRepository interface implemented by gorm
  198. func (t *GormRepository) DeploymentTarget() repository.DeploymentTargetRepository {
  199. return t.deploymentTarget
  200. }
  201. // AppRevision returns the AppRevisionRepository interface implemented by gorm
  202. func (t *GormRepository) AppRevision() repository.AppRevisionRepository {
  203. return t.appRevision
  204. }
  205. // AppTemplate returns the AppTemplateRepository interface implemented by gorm
  206. func (t *GormRepository) AppTemplate() repository.AppTemplateRepository {
  207. return t.appTemplate
  208. }
  209. // GithubWebhook returns the GithubWebhookRepository interface implemented by gorm
  210. func (t *GormRepository) GithubWebhook() repository.GithubWebhookRepository {
  211. return t.githubWebhook
  212. }
  213. // NewRepository returns a Repository which persists users in memory
  214. // and accepts a parameter that can trigger read/write errors
  215. func NewRepository(db *gorm.DB, key *[32]byte, storageBackend credentials.CredentialStorage) repository.Repository {
  216. return &GormRepository{
  217. user: NewUserRepository(db),
  218. session: NewSessionRepository(db),
  219. project: NewProjectRepository(db),
  220. cluster: NewClusterRepository(db, key),
  221. database: NewDatabaseRepository(db, key),
  222. helmRepo: NewHelmRepoRepository(db, key),
  223. registry: NewRegistryRepository(db, key),
  224. gitRepo: NewGitRepoRepository(db, key),
  225. gitActionConfig: NewGitActionConfigRepository(db),
  226. invite: NewInviteRepository(db),
  227. release: NewReleaseRepository(db),
  228. environment: NewEnvironmentRepository(db),
  229. authCode: NewAuthCodeRepository(db),
  230. dnsRecord: NewDNSRecordRepository(db),
  231. pwResetToken: NewPWResetTokenRepository(db),
  232. infra: NewInfraRepository(db, key),
  233. kubeIntegration: NewKubeIntegrationRepository(db, key),
  234. basicIntegration: NewBasicIntegrationRepository(db, key),
  235. oidcIntegration: NewOIDCIntegrationRepository(db, key),
  236. oauthIntegration: NewOAuthIntegrationRepository(db, key, storageBackend),
  237. gcpIntegration: NewGCPIntegrationRepository(db, key, storageBackend),
  238. awsIntegration: NewAWSIntegrationRepository(db, key, storageBackend),
  239. azIntegration: NewAzureIntegrationRepository(db, key, storageBackend),
  240. githubAppInstallation: NewGithubAppInstallationRepository(db),
  241. githubAppOAuthIntegration: NewGithubAppOAuthIntegrationRepository(db),
  242. slackIntegration: NewSlackIntegrationRepository(db, key),
  243. gitlabIntegration: NewGitlabIntegrationRepository(db, key, storageBackend),
  244. gitlabAppOAuthIntegration: NewGitlabAppOAuthIntegrationRepository(db, key, storageBackend),
  245. notificationConfig: NewNotificationConfigRepository(db),
  246. jobNotificationConfig: NewJobNotificationConfigRepository(db),
  247. buildEvent: NewBuildEventRepository(db),
  248. kubeEvent: NewKubeEventRepository(db, key),
  249. projectUsage: NewProjectUsageRepository(db),
  250. onboarding: NewProjectOnboardingRepository(db),
  251. ceToken: NewCredentialsExchangeTokenRepository(db),
  252. buildConfig: NewBuildConfigRepository(db),
  253. allowlist: NewAllowlistRepository(db),
  254. apiToken: NewAPITokenRepository(db),
  255. policy: NewPolicyRepository(db),
  256. tag: NewTagRepository(db),
  257. stack: NewStackRepository(db),
  258. monitor: NewMonitorTestResultRepository(db),
  259. apiContractRevisions: NewAPIContractRevisioner(db),
  260. awsAssumeRoleChainer: NewAWSAssumeRoleChainer(db),
  261. porterApp: NewPorterAppRepository(db),
  262. porterAppEvent: NewPorterAppEventRepository(db),
  263. deploymentTarget: NewDeploymentTargetRepository(db),
  264. appRevision: NewAppRevisionRepository(db),
  265. appTemplate: NewAppTemplateRepository(db),
  266. githubWebhook: NewGithubWebhookRepository(db),
  267. }
  268. }