repository.go 14 KB

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