Module: Dependabot::Cargo::Helpers

Extended by:
T::Sig
Defined in:
lib/dependabot/cargo/helpers.rb

Class Method Summary collapse

Class Method Details

.setup_credentials_in_environment(credentials) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dependabot/cargo/helpers.rb', line 12

def self.setup_credentials_in_environment(credentials)
  credentials.each do |cred|
    next if cred["type"] != "cargo_registry"
    next if cred["registry"].nil? # this will not be present for org-level registries
    next if cred["token"].nil?

    # If there is a 'token' property, then apply it.
    # In production Dependabot-Action or Dependabot-CLI will inject the real token via the Proxy.
    token_env_var = "CARGO_REGISTRIES_#{T.must(cred['registry']).upcase.tr('-', '_')}_TOKEN"
    ENV[token_env_var] ||= cred["token"]
  end

  # And set CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS here as well, so Cargo will expect tokens
  ENV["CARGO_REGISTRY_GLOBAL_CREDENTIAL_PROVIDERS"] ||= "cargo:token"
end