repository.go 14 KB

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