repository.go 12 KB

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