Module: UffizziCore::CredentialService

Defined in:
app/services/uffizzi_core/credential_service.rb

Class Method Summary collapse

Class Method Details

.correct_credentials?(credential) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/uffizzi_core/credential_service.rb', line 5

def correct_credentials?(credential)
  status = case credential.type
           when UffizziCore::Credential::DockerHub.name
             UffizziCore::DockerHub::CredentialService.credential_correct?(credential)
           when UffizziCore::Credential::GithubContainerRegistry.name
             UffizziCore::GithubContainerRegistry::CredentialService.credential_correct?(credential)
           when UffizziCore::Credential::Azure.name
             UffizziCore::Azure::CredentialService.credential_correct?(credential)
           when UffizziCore::Credential::Google.name
             UffizziCore::Google::CredentialService.credential_correct?(credential)
           when UffizziCore::Credential::Amazon.name
             UffizziCore::Amazon::CredentialService.credential_correct?(credential)
           else
             false
  end

  if credential.persisted? && credential.active? && !status
    Rails.logger.warn("broken credentials, credential_correct? credential_id=#{credential.id}")
    credential.unauthorize!
  end

  status
end

.update_expired_credentialsObject



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/services/uffizzi_core/credential_service.rb', line 29

def update_expired_credentials
  currect_date = DateTime.now
  credentials = UffizziCore::Credential::Amazon.active.where('updated_at < ?', currect_date - 10.hours)

  credentials.each do |credential|
    deployments = UffizziCore::Deployment.where(project_id: credential..projects.select(:id)).with_amazon_repos

    deployments.each do |deployment|
      UffizziCore::Deployment::CreateCredentialJob.perform_async(deployment.id, credential.id)
    end

    credential.update(updated_at: currect_date)
  end
end