Class: S3ToolParameters
- Inherits:
-
ParametersBase
- Object
- OptionParser
- ParametersBase
- S3ToolParameters
- Defined in:
- lib/ec2/amitools/s3toolparameters.rb
Overview
——————————————————————————#
Direct Known Subclasses
DeleteBundleParameters, DownloadBundleParameters, UploadBundleParameters
Constant Summary collapse
- BUCKET_DESCRIPTION =
["The bucket to use. This is an S3 bucket,", "followed by an optional S3 key prefix using '/' as a delimiter."]
- MANIFEST_DESCRIPTION =
"The path to the manifest file."
- DELEGATION_TOKEN_DESCRIPTION =
"The delegation token pass along to the AWS request."
- URL_DESCRIPTION =
"The S3 service URL. Defaults to https://s3.amazonaws.com."
- REGION_DESCRIPTION =
"The S3 region. Defaults to us-east-1."
- SIGV2_DESCRIPTION =
"Use old signature version 2 signing"
- PROFILE_PATH =
'/latest/meta-data/iam/security-credentials/'
- PROFILE_HOST =
'169.254.169.254'
- REGION_MAP =
{ 'us-east-1' => 'https://s3.amazonaws.com', 'us-west-2' => 'https://s3-us-west-2.amazonaws.com', 'us-west-1' => 'https://s3-us-west-1.amazonaws.com', 'eu-west-1' => 'https://s3-eu-west-1.amazonaws.com', 'eu-central-1' => 'https://s3.eu-central-1.amazonaws.com', 'ap-southeast-1' => 'https://s3-ap-southeast-1.amazonaws.com', 'ap-southeast-2' => 'https://s3-ap-southeast-2.amazonaws.com', 'ap-northeast-1' => 'https://s3-ap-northeast-1.amazonaws.com', 'sa-east-1' => 'https://s3-sa-east-1.amazonaws.com', 'cn-north-1' => 'https://s3.cn-north-1.amazonaws.com.cn', 'us-gov-west-1' => 'https://s3-us-gov-west-1.amazonaws.com' }
- VALID_SIGV =
['2', '4']
- DEFAULT_URL =
'https://s3.amazonaws.com'
- DEFAULT_REGION =
'us-east-1'
Constants inherited from ParametersBase
ParametersBase::BATCH_DESCRIPTION, ParametersBase::DEBUG_DESCRIPTION, ParametersBase::HELP_DESCRIPTION, ParametersBase::MANUAL_DESCRIPTION, ParametersBase::PASS_DESCRIPTION, ParametersBase::USER_ACCOUNT_DESCRIPTION, ParametersBase::USER_CERT_PATH_DESCRIPTION, ParametersBase::USER_DESCRIPTION, ParametersBase::USER_PK_PATH_DESCRIPTION, ParametersBase::VERSION_DESCRIPTION
Instance Attribute Summary collapse
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#keyprefix ⇒ Object
Returns the value of attribute keyprefix.
-
#pass ⇒ Object
Returns the value of attribute pass.
-
#region ⇒ Object
Returns the value of attribute region.
-
#sigv ⇒ Object
Returns the value of attribute sigv.
-
#url ⇒ Object
Returns the value of attribute url.
-
#user ⇒ Object
Returns the value of attribute user.
Attributes inherited from ParametersBase
#batch_mode, #debug, #manual, #show_help, #version
Instance Method Summary collapse
-
#get_creds_from_instance_profile ⇒ Object
—————————————————————————-#.
-
#mandatory_params ⇒ Object
—————————————————————————-#.
-
#optional_params ⇒ Object
—————————————————————————-#.
-
#set_defaults ⇒ Object
—————————————————————————-#.
-
#split_container(container) ⇒ Object
——————————————————————————#.
- #validate_params ⇒ Object
Methods inherited from ParametersBase
#assert_directory_exists, #assert_exists, #assert_file_executable, #assert_file_exists, #assert_glob_expands, #assert_good_key, #assert_option_in, #common_params, #early_exit?, #initialize, #interactive?, #version_copyright_string
Constructor Details
This class inherits a constructor from ParametersBase
Instance Attribute Details
#bucket ⇒ Object
Returns the value of attribute bucket.
49 50 51 |
# File 'lib/ec2/amitools/s3toolparameters.rb', line 49 def bucket @bucket end |
#keyprefix ⇒ Object
Returns the value of attribute keyprefix.
49 50 51 |
# File 'lib/ec2/amitools/s3toolparameters.rb', line 49 def keyprefix @keyprefix end |
#pass ⇒ Object
Returns the value of attribute pass.
49 50 51 |
# File 'lib/ec2/amitools/s3toolparameters.rb', line 49 def pass @pass end |
#region ⇒ Object
Returns the value of attribute region.
49 50 51 |
# File 'lib/ec2/amitools/s3toolparameters.rb', line 49 def region @region end |
#sigv ⇒ Object
Returns the value of attribute sigv.
49 50 51 |
# File 'lib/ec2/amitools/s3toolparameters.rb', line 49 def sigv @sigv end |
#url ⇒ Object
Returns the value of attribute url.
49 50 51 |
# File 'lib/ec2/amitools/s3toolparameters.rb', line 49 def url @url end |
#user ⇒ Object
Returns the value of attribute user.
49 50 51 |
# File 'lib/ec2/amitools/s3toolparameters.rb', line 49 def user @user end |
Instance Method Details
#get_creds_from_instance_profile ⇒ Object
—————————————————————————-#
111 112 |
# File 'lib/ec2/amitools/s3toolparameters.rb', line 111 def get_creds_from_instance_profile end |
#mandatory_params ⇒ Object
—————————————————————————-#
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 ⇒ Object
—————————————————————————-#
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# 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 ⇒ Object
—————————————————————————-#
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# 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) ⇒ Object
——————————————————————————#
59 60 61 62 63 64 65 66 |
# 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 ⇒ Object
134 135 136 137 138 139 140 141 142 143 144 |
# 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 |