module ChefConfig::Mixin::Credentials

def credentials_file_path

Returns:
  • (String) -

Other tags:
    Since: - 14.4
def credentials_file_path
  PathHelper.home(ChefUtils::Dist::Infra::USER_CONF_DIR, "credentials").freeze
end

def credentials_profile(profile = nil)

Returns:
  • (String) -

Parameters:
  • profile (String, nil) -- Optional override for the active profile,

Other tags:
    Since: - 14.4
def credentials_profile(profile = nil)
  context_file = PathHelper.home(ChefUtils::Dist::Infra::USER_CONF_DIR, "context").freeze
  if !profile.nil?
    profile
  elsif ENV.include?("CHEF_PROFILE")
    ENV["CHEF_PROFILE"]
  elsif File.file?(context_file)
    File.read(context_file).strip
  else
    "default"
  end
end

def load_credentials(profile = nil)

Returns:
  • (void) -

Parameters:
  • profile (String, nil) -- Optional override for the active profile,

Other tags:
    See: WorkstationConfigLoader#apply_credentials -
def load_credentials(profile = nil)
  profile = credentials_profile(profile)
  cred_config = parse_credentials_file
  return if cred_config.nil? # No credentials, nothing to do here.
  if cred_config[profile].nil?
    # Unknown profile name. For "default" just silently ignore, otherwise
    # raise an error.
    return if profile == "default"
    raise ChefConfig::ConfigurationError, "Profile #{profile} doesn't exist. Please add it to #{credentials_file_path}."
  end
  apply_credentials(cred_config[profile], profile)
end

def parse_credentials_file

Returns:
  • (String, nil) -

Other tags:
    Since: - 14.4
def parse_credentials_file
  credentials_file = credentials_file_path
  return nil unless File.file?(credentials_file)
  begin
    Tomlrb.load_file(credentials_file)
  rescue => e
    # TOML's error messages are mostly rubbish, so we'll just give a generic one
    message = "Unable to parse Credentials file: #{credentials_file}\n"
    message << e.message
    raise ChefConfig::ConfigurationError, message
  end
end