Module: Dependabot::Hex::CredentialHelpers

Extended by:
T::Sig
Defined in:
lib/dependabot/hex/credential_helpers.rb

Class Method Summary collapse

Class Method Details

.hex_credentials(credentials) ⇒ Object



12
13
14
# File 'lib/dependabot/hex/credential_helpers.rb', line 12

def self.hex_credentials(credentials)
  organization_credentials(credentials) + repo_credentials(credentials)
end

.organization_credentials(credentials) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/dependabot/hex/credential_helpers.rb', line 17

def self.organization_credentials(credentials)
  defaults = Dependabot::Credential.new({ "organization" => "", "token" => "" })
  keys = %w(type organization token)

  credentials
    .select { |cred| cred["type"] == "hex_organization" }
    .flat_map { |cred| defaults.merge(cred).slice(*keys).values }
end

.repo_credentials(credentials) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/dependabot/hex/credential_helpers.rb', line 26

def self.repo_credentials(credentials)
  # Credentials are serialized as an array that may not have optional fields. Using a
  # default ensures that the array is always the same length, even if values are empty.
  defaults = Dependabot::Credential.new({ "url" => "", "auth_key" => "", "public_key_fingerprint" => "" })
  keys = %w(type repo url auth_key public_key_fingerprint)

  credentials
    .select { |cred| cred["type"] == "hex_repository" }
    .flat_map { |cred| defaults.merge(cred).slice(*keys).values }
end