repository.go 14 KB

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