lib/rubygems/s3_uri_signer.rb
##
# Extracts S3 configuration for S3 bucket
Extracts S3 configuration for S3 bucket
Extracts S3 configuration for S3 bucket
def fetch_s3_config
    return S3Config.new(uri.user, uri.password, nil, "us-east-1") if uri.user && uri.password
    s3_source = Gem.configuration[:s3_source] || Gem.configuration["s3_source"]
    host = uri.host
    raise ConfigurationError.new("no s3_source key exists in .gemrc") unless s3_source
    auth = s3_source[host] || s3_source[host.to_sym]
    raise ConfigurationError.new("no key for host #{host} in s3_source in .gemrc") unless auth
    provider = auth[:provider] || auth["provider"]
    case provider
    when "env"
      id = ENV["AWS_ACCESS_KEY_ID"]
      secret = ENV["AWS_SECRET_ACCESS_KEY"]
      security_token = ENV["AWS_SESSION_TOKEN"]
    when "instance_profile"
      credentials = ec2_metadata_credentials_json
      id = credentials["AccessKeyId"]
      secret = credentials["SecretAccessKey"]
      security_token = credentials["Token"]
    else
      id = auth[:id] || auth["id"]
      secret = auth[:secret] || auth["secret"]
      security_token = auth[:security_token] || auth["security_token"]
    end
    raise ConfigurationError.new("s3_source for #{host} missing id or secret") unless id && secret
    region = auth[:region] || auth["region"] || "us-east-1"
    S3Config.new(id, secret, security_token, region)
  end
def fetch_s3_config return S3Config . new ( uri . user , uri . password , nil , "us-east-1" ) if uri . user && uri . password s3_source = Gem . configuration [ :s3_source ] || Gem . configuration [ "s3_source" ] host = uri . host raise ConfigurationError . new ( "no s3_source key exists in .gemrc" ) unless s3_source auth = s3_source [ host ] || s3_source [ host . to_sym ] raise ConfigurationError . new ( "no key for host #{host} in s3_source in .gemrc" ) unless auth provider = auth [ :provider ] || auth [ "provider" ] case provider when "env" id = ENV [ "AWS_ACCESS_KEY_ID" ] secret = ENV [ "AWS_SECRET_ACCESS_KEY" ] security_token = ENV [ "AWS_SESSION_TOKEN" ] when "instance_profile" credentials = ec2_metadata_credentials_json id = credentials [ "AccessKeyId" ] secret = credentials [ "SecretAccessKey" ] security_token = credentials [ "Token" ] else id = auth [ :id ] || auth [ "id" ] secret = auth [ :secret ] || auth [ "secret" ] security_token = auth [ :security_token ] || auth [ "security_token" ] end raise ConfigurationError . new ( "s3_source for #{host} missing id or secret" ) unless id && secret region = auth [ :region ] || auth [ "region" ] || "us-east-1" S3Config . new ( id , secret , security_token , region ) end
Extracts S3 configuration for S3 bucket
Extracts S3 configuration for S3 bucket