class S3ToolParameters
Constants
- BUCKET_DESCRIPTION
- DEFAULT_REGION
- DEFAULT_URL
- DELEGATION_TOKEN_DESCRIPTION
- MANIFEST_DESCRIPTION
- PROFILE_HOST
- PROFILE_PATH
- REGION_DESCRIPTION
- REGION_MAP
- SIGV2_DESCRIPTION
- URL_DESCRIPTION
- VALID_SIGV
Attributes
bucket[RW]
keyprefix[RW]
pass[RW]
region[RW]
sigv[RW]
url[RW]
user[RW]
Public Instance Methods
get_creds_from_instance_profile()
click to toggle source
# File lib/ec2/amitools/s3toolparameters.rb, line 111 def get_creds_from_instance_profile end
mandatory_params()
click to toggle source
# File lib/ec2/amitools/s3toolparameters.rb, line 70 def mandatory_params() on('-b', '--bucket BUCKET', String, *BUCKET_DESCRIPTION) do |container| @container = container split_container(@container) end on('-a', '--access-key USER', String, USER_DESCRIPTION) do |user| @user = {} if @user.nil? @user['aws_access_key_id'] = user end on('-s', '--secret-key PASSWORD', String, PASS_DESCRIPTION) do |pass| @user = {} if @user.nil? @user['aws_secret_access_key'] = pass @pass = pass end on('-t', '--delegation-token TOKEN', String, DELEGATION_TOKEN_DESCRIPTION) do |token| @user = {} if @user.nil? @user['aws_delegation_token'] = token end end
optional_params()
click to toggle source
# File lib/ec2/amitools/s3toolparameters.rb, line 95 def optional_params() on('--url URL', String, URL_DESCRIPTION) do |url| @url = url end on('--region REGION', REGION_DESCRIPTION) do |region| @region = region end on('--sigv VERSION', SIGV2_DESCRIPTION) do |version_number| @sigv = version_number end end
set_defaults()
click to toggle source
# File lib/ec2/amitools/s3toolparameters.rb, line 148 def set_defaults() # We need three values to be set after this point: # region - which will specify the region of the endpoint used for sigv4 # url - the url of the endpoint # location - the S3 bucket location # # We allow the user to override any of these values. The client only has # to specify the region value. if @region @url ||= REGION_MAP[@region] elsif @location @region = case @location when "EU" then "eu-west-1" when "US", :unconstrained then "us-east-1" else @location end @url ||= REGION_MAP[@region] elsif @url STDERR.puts "Specifying url has been deprecated, please use only --region" uri = URI.parse(@url) if @region.nil? begin @region = AwsRegion::determine_region_from_host uri.host STDERR.puts "Region determined to be #{@region}" rescue => e STDERR.puts "No region specified and could not determine region from given url" @region = nil end end else @url ||= DEFAULT_URL @region ||= DEFAULT_REGION end @sigv ||= EC2::Common::SIGV4 end
split_container(container)
click to toggle source
# File lib/ec2/amitools/s3toolparameters.rb, line 59 def split_container(container) splitbits = container.sub(%r{^/*},'').sub(%r{/*$},'').split("/") bucket = splitbits.shift keyprefix = splitbits.join("/") keyprefix += "/" unless keyprefix.empty? @keyprefix = keyprefix @bucket = bucket end
validate_params()
click to toggle source
# File lib/ec2/amitools/s3toolparameters.rb, line 134 def validate_params() unless @user get_creds_from_instance_profile end raise MissingMandatory.new('--access-key') unless @user && @user['aws_access_key_id'] raise MissingMandatory.new('--secret-key') unless @pass raise MissingMandatory.new('--bucket') unless @container if @sigv && !VALID_SIGV.include?(@sigv) raise InvalidValue.new('--sigv', @sigv, "Please specify one of these values: #{VALID_SIGV.join(', ')}") end end