Fetch credentials from DB

Do not rely on the entity object to hold updated or detailed credentials,
fetch them from the DB every time.

This change also ensures that we pass in the user context instead of the
runner context to the DB methods.

Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
Gabriel Adrian Samfira 2024-04-24 12:23:45 +00:00
parent c2b974dfa0
commit 1256473089
8 changed files with 88 additions and 20 deletions

View file

@ -127,6 +127,11 @@ func (s *sqlDatabase) sqlToCommonOrganization(org Organization, detailed bool) (
PoolBalancerType: org.PoolBalancerType,
Endpoint: endpoint,
}
if org.CredentialsID != nil {
ret.CredentialsID = *org.CredentialsID
}
if detailed {
creds, err := s.sqlToCommonGithubCredentials(org.Credentials)
if err != nil {
@ -172,6 +177,10 @@ func (s *sqlDatabase) sqlToCommonEnterprise(enterprise Enterprise, detailed bool
Endpoint: endpoint,
}
if enterprise.CredentialsID != nil {
ret.CredentialsID = *enterprise.CredentialsID
}
if detailed {
creds, err := s.sqlToCommonGithubCredentials(enterprise.Credentials)
if err != nil {
@ -278,6 +287,10 @@ func (s *sqlDatabase) sqlToCommonRepository(repo Repository, detailed bool) (par
Endpoint: endpoint,
}
if repo.CredentialsID != nil {
ret.CredentialsID = *repo.CredentialsID
}
if detailed {
creds, err := s.sqlToCommonGithubCredentials(repo.Credentials)
if err != nil {