ec2_amitools 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +54 -0
  3. data/bin/console +14 -0
  4. data/bin/ec2-ami-tools-version +6 -0
  5. data/bin/ec2-bundle-image +6 -0
  6. data/bin/ec2-bundle-vol +6 -0
  7. data/bin/ec2-delete-bundle +6 -0
  8. data/bin/ec2-download-bundle +6 -0
  9. data/bin/ec2-migrate-bundle +6 -0
  10. data/bin/ec2-migrate-manifest +6 -0
  11. data/bin/ec2-unbundle +6 -0
  12. data/bin/ec2-upload-bundle +6 -0
  13. data/bin/setup +8 -0
  14. data/etc/ec2/amitools/cert-ec2-cn-north-1.pem +28 -0
  15. data/etc/ec2/amitools/cert-ec2-gov.pem +17 -0
  16. data/etc/ec2/amitools/cert-ec2.pem +23 -0
  17. data/etc/ec2/amitools/mappings.csv +9 -0
  18. data/lib/ec2/amitools/bundle.rb +251 -0
  19. data/lib/ec2/amitools/bundle_base.rb +58 -0
  20. data/lib/ec2/amitools/bundleimage.rb +94 -0
  21. data/lib/ec2/amitools/bundleimageparameters.rb +42 -0
  22. data/lib/ec2/amitools/bundlemachineparameters.rb +60 -0
  23. data/lib/ec2/amitools/bundleparameters.rb +120 -0
  24. data/lib/ec2/amitools/bundlevol.rb +240 -0
  25. data/lib/ec2/amitools/bundlevolparameters.rb +164 -0
  26. data/lib/ec2/amitools/crypto.rb +379 -0
  27. data/lib/ec2/amitools/decryptmanifest.rb +20 -0
  28. data/lib/ec2/amitools/defaults.rb +12 -0
  29. data/lib/ec2/amitools/deletebundle.rb +212 -0
  30. data/lib/ec2/amitools/deletebundleparameters.rb +78 -0
  31. data/lib/ec2/amitools/downloadbundle.rb +161 -0
  32. data/lib/ec2/amitools/downloadbundleparameters.rb +84 -0
  33. data/lib/ec2/amitools/exception.rb +86 -0
  34. data/lib/ec2/amitools/fileutil.rb +219 -0
  35. data/lib/ec2/amitools/format.rb +127 -0
  36. data/lib/ec2/amitools/instance-data.rb +97 -0
  37. data/lib/ec2/amitools/manifest_wrapper.rb +132 -0
  38. data/lib/ec2/amitools/manifestv20070829.rb +361 -0
  39. data/lib/ec2/amitools/manifestv20071010.rb +403 -0
  40. data/lib/ec2/amitools/manifestv3.rb +331 -0
  41. data/lib/ec2/amitools/mapids.rb +148 -0
  42. data/lib/ec2/amitools/migratebundle.rb +222 -0
  43. data/lib/ec2/amitools/migratebundleparameters.rb +173 -0
  44. data/lib/ec2/amitools/migratemanifest.rb +225 -0
  45. data/lib/ec2/amitools/migratemanifestparameters.rb +118 -0
  46. data/lib/ec2/amitools/minimalec2.rb +116 -0
  47. data/lib/ec2/amitools/parameter_exceptions.rb +34 -0
  48. data/lib/ec2/amitools/parameters_base.rb +168 -0
  49. data/lib/ec2/amitools/region.rb +93 -0
  50. data/lib/ec2/amitools/s3toolparameters.rb +183 -0
  51. data/lib/ec2/amitools/showversion.rb +12 -0
  52. data/lib/ec2/amitools/syschecks.rb +27 -0
  53. data/lib/ec2/amitools/tool_base.rb +224 -0
  54. data/lib/ec2/amitools/unbundle.rb +107 -0
  55. data/lib/ec2/amitools/unbundleparameters.rb +65 -0
  56. data/lib/ec2/amitools/uploadbundle.rb +361 -0
  57. data/lib/ec2/amitools/uploadbundleparameters.rb +108 -0
  58. data/lib/ec2/amitools/util.rb +532 -0
  59. data/lib/ec2/amitools/version.rb +33 -0
  60. data/lib/ec2/amitools/xmlbuilder.rb +237 -0
  61. data/lib/ec2/amitools/xmlutil.rb +55 -0
  62. data/lib/ec2/common/constants.rb +16 -0
  63. data/lib/ec2/common/curl.rb +110 -0
  64. data/lib/ec2/common/headers.rb +95 -0
  65. data/lib/ec2/common/headersv4.rb +173 -0
  66. data/lib/ec2/common/http.rb +333 -0
  67. data/lib/ec2/common/s3support.rb +231 -0
  68. data/lib/ec2/common/signature.rb +68 -0
  69. data/lib/ec2/oem/LICENSE.txt +58 -0
  70. data/lib/ec2/oem/open4.rb +399 -0
  71. data/lib/ec2/platform/base/architecture.rb +26 -0
  72. data/lib/ec2/platform/base/constants.rb +54 -0
  73. data/lib/ec2/platform/base/pipeline.rb +181 -0
  74. data/lib/ec2/platform/base.rb +57 -0
  75. data/lib/ec2/platform/current.rb +55 -0
  76. data/lib/ec2/platform/linux/architecture.rb +35 -0
  77. data/lib/ec2/platform/linux/constants.rb +23 -0
  78. data/lib/ec2/platform/linux/fstab.rb +99 -0
  79. data/lib/ec2/platform/linux/identity.rb +16 -0
  80. data/lib/ec2/platform/linux/image.rb +811 -0
  81. data/lib/ec2/platform/linux/mtab.rb +74 -0
  82. data/lib/ec2/platform/linux/pipeline.rb +40 -0
  83. data/lib/ec2/platform/linux/rsync.rb +114 -0
  84. data/lib/ec2/platform/linux/tar.rb +124 -0
  85. data/lib/ec2/platform/linux/uname.rb +50 -0
  86. data/lib/ec2/platform/linux.rb +83 -0
  87. data/lib/ec2/platform/solaris/architecture.rb +28 -0
  88. data/lib/ec2/platform/solaris/constants.rb +30 -0
  89. data/lib/ec2/platform/solaris/fstab.rb +43 -0
  90. data/lib/ec2/platform/solaris/identity.rb +16 -0
  91. data/lib/ec2/platform/solaris/image.rb +327 -0
  92. data/lib/ec2/platform/solaris/mtab.rb +29 -0
  93. data/lib/ec2/platform/solaris/pipeline.rb +40 -0
  94. data/lib/ec2/platform/solaris/rsync.rb +24 -0
  95. data/lib/ec2/platform/solaris/tar.rb +36 -0
  96. data/lib/ec2/platform/solaris/uname.rb +21 -0
  97. data/lib/ec2/platform/solaris.rb +38 -0
  98. data/lib/ec2/platform.rb +69 -0
  99. data/lib/ec2/version.rb +8 -0
  100. data/lib/ec2_amitools +1 -0
  101. data/lib/ec2_amitools.rb +7 -0
  102. metadata +184 -0
@@ -0,0 +1,34 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ module ParameterExceptions
12
+ class Error < RuntimeError
13
+ end
14
+
15
+ class MissingMandatory < Error
16
+ def initialize(name)
17
+ super("missing mandatory parameter: #{name}")
18
+ end
19
+ end
20
+
21
+ class InvalidCombination < Error
22
+ def initialize(name1, name2)
23
+ super("#{name1} and #{name2} may not both be provided")
24
+ end
25
+ end
26
+
27
+ class InvalidValue < Error
28
+ def initialize(name, value, msg=nil)
29
+ message = "#{name} has invalid value '#{value.to_s}'"
30
+ message += ": #{msg}" unless msg.nil?
31
+ super(message)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,168 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ require 'optparse'
12
+ require 'ec2/amitools/parameter_exceptions'
13
+ require 'ec2/amitools/version'
14
+ require 'ec2/common/s3support'
15
+
16
+ class ParametersBase < OptionParser
17
+ include ParameterExceptions
18
+
19
+ # Descriptions for common parameters:
20
+ USER_CERT_PATH_DESCRIPTION = "The path to the user's PEM encoded RSA public key certificate file."
21
+ USER_PK_PATH_DESCRIPTION = "The path to the user's PEM encoded RSA private key file."
22
+ USER_DESCRIPTION = "The user's AWS access key ID."
23
+ PASS_DESCRIPTION = "The user's AWS secret access key."
24
+ USER_ACCOUNT_DESCRIPTION = "The user's EC2 user ID (Note: AWS account number, NOT Access Key ID)."
25
+ HELP_DESCRIPTION = "Display this help message and exit."
26
+ MANUAL_DESCRIPTION = "Display the user manual and exit."
27
+ DEBUG_DESCRIPTION = "Display debug messages."
28
+ VERSION_DESCRIPTION = "Display the version and copyright notice and then exit."
29
+ BATCH_DESCRIPTION = "Run in batch mode. No interactive prompts."
30
+
31
+ attr_accessor(:show_help,
32
+ :manual,
33
+ :version,
34
+ :batch_mode,
35
+ :debug)
36
+
37
+ #------------------------------------------------------------------------------#
38
+ # Methods to override in subclasses
39
+ #------------------------------------------------------------------------------#
40
+
41
+ def mandatory_params()
42
+ # Override this for mandatory parameters
43
+ end
44
+
45
+ def optional_params()
46
+ # Override this for optional parameters
47
+ end
48
+
49
+ def validate_params()
50
+ # Override this for parameter validation
51
+ end
52
+
53
+ def set_defaults()
54
+ # Override this for parameter validation
55
+ end
56
+
57
+ #------------------------------------------------------------------------------#
58
+ # Useful utility methods
59
+ #------------------------------------------------------------------------------#
60
+
61
+ def early_exit?()
62
+ @show_help or @manual or @version
63
+ end
64
+
65
+ def interactive?()
66
+ not (early_exit? or @batch_mode)
67
+ end
68
+
69
+ def version_copyright_string()
70
+ EC2Version::version_copyright_string()
71
+ end
72
+
73
+ #------------------------------------------------------------------------------#
74
+ # Validation utility methods
75
+ #------------------------------------------------------------------------------#
76
+
77
+ def assert_exists(path, param)
78
+ unless File::exist?(path)
79
+ raise InvalidValue.new(param, path, "File or directory does not exist.")
80
+ end
81
+ end
82
+
83
+ def assert_glob_expands(path, param)
84
+ if Dir::glob(path).empty?
85
+ raise InvalidValue.new(param, path, "File or directory does not exist.")
86
+ end
87
+ end
88
+
89
+ def assert_file_exists(path, param)
90
+ unless (File::exist?(path) and File::file?(path))
91
+ raise InvalidValue.new(param, path, "File does not exist or is not a file.")
92
+ end
93
+ end
94
+
95
+ def assert_file_executable(path, param)
96
+ unless (File::executable?(path) and File::file?(path))
97
+ raise InvalidValue.new(param, path, "File not executable.")
98
+ end
99
+ end
100
+
101
+ def assert_directory_exists(path, param)
102
+ unless (File::exist?(path) and File::directory?(path))
103
+ raise InvalidValue.new(param, path, "Directory does not exist or is not a directory.")
104
+ end
105
+ end
106
+
107
+ def assert_option_in(option, choices, param)
108
+ unless choices.include?(option)
109
+ raise InvalidValue.new(param, option)
110
+ end
111
+ end
112
+
113
+ def assert_good_key(key, param)
114
+ if key.include?("/")
115
+ raise InvalidValue.new(param, key, "'/' character not allowed.")
116
+ end
117
+ end
118
+
119
+ #------------------------------------------------------------------------------#
120
+ # Parameters common to all tools
121
+ #------------------------------------------------------------------------------#
122
+
123
+ def common_params()
124
+ on('-h', '--help', HELP_DESCRIPTION) do
125
+ @show_help = true
126
+ end
127
+
128
+ on('--version', VERSION_DESCRIPTION) do
129
+ @version = true
130
+ end
131
+
132
+ on('--manual', MANUAL_DESCRIPTION) do
133
+ @manual = true
134
+ end
135
+
136
+ on('--batch', BATCH_DESCRIPTION) do
137
+ @batch_mode = true
138
+ end
139
+
140
+ on('--debug', DEBUG_DESCRIPTION) do
141
+ @debug = true
142
+ end
143
+ end
144
+
145
+
146
+ def initialize(argv, name=nil)
147
+ super(argv)
148
+
149
+ # Mandatory parameters.
150
+ separator("")
151
+ separator("MANDATORY PARAMETERS")
152
+ mandatory_params()
153
+
154
+ # Optional parameters.
155
+ separator("")
156
+ separator("OPTIONAL PARAMETERS")
157
+ common_params()
158
+ optional_params()
159
+
160
+ # Parse the command line parameters.
161
+ parse!(argv)
162
+
163
+ unless early_exit?
164
+ validate_params()
165
+ set_defaults()
166
+ end
167
+ end
168
+ end
@@ -0,0 +1,93 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ # Module to hold region informations
12
+ #
13
+
14
+ module AwsRegion
15
+
16
+ AWS_REGIONS = [
17
+ 'eu-west-1',
18
+ 'eu-central-1',
19
+ 'us-east-1',
20
+ 'us-gov-west-1',
21
+ 'cn-north-1',
22
+ 'us-west-1',
23
+ 'us-west-2',
24
+ 'ap-southeast-1',
25
+ 'ap-southeast-2',
26
+ 'ap-northeast-1',
27
+ 'sa-east-1',
28
+ ]
29
+
30
+ S3_LOCATIONS = [
31
+ 'EU', 'eu-west-1',
32
+ 'eu-central-1',
33
+ 'US',
34
+ 'us-gov-west-1',
35
+ 'cn-north-1',
36
+ 'us-west-1',
37
+ 'us-west-2',
38
+ 'ap-southeast-1',
39
+ 'ap-southeast-2',
40
+ 'ap-northeast-1',
41
+ 'sa-east-1',
42
+ ]
43
+
44
+ module_function
45
+
46
+ def determine_region_from_host host
47
+ # http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
48
+ if host == "s3.amazonaws.com" || host == "s3-external-1.amazonaws.com"
49
+ "us-east-1"
50
+ elsif
51
+ domains = host.split(".")
52
+ # handle s3-$REGION.amazonaws.something
53
+ if domains.length >= 3 && domains[0].start_with?("s3-")
54
+ domains[0].sub("s3-", "")
55
+ # handle s3.$REGION.amazonaws.something, this is specific to the cn-north-1 endpoint
56
+ elsif domains.length >= 3 && domains[0] == "s3"
57
+ domains[1]
58
+ else
59
+ "us-east-1"
60
+ end
61
+ end
62
+ end
63
+
64
+ def guess_region_from_s3_bucket(location)
65
+ if (location == "EU")
66
+ return "eu-west-1"
67
+ elsif ((location == "US") || (location == "") || (location.nil?))
68
+ return "us-east-1"
69
+ else
70
+ return location
71
+ end
72
+ end
73
+
74
+ def get_s3_location(region)
75
+ if (region == "eu-west-1")
76
+ return 'EU'
77
+ elsif (region == "us-east-1")
78
+ return :unconstrained
79
+ else
80
+ return region
81
+ end
82
+ end
83
+
84
+ def regions
85
+ AWS_REGIONS
86
+ end
87
+
88
+ def s3_locations
89
+ S3_LOCATIONS
90
+ end
91
+
92
+ end
93
+
@@ -0,0 +1,183 @@
1
+ # Copyright 2008-2014 Amazon.com, Inc. or its affiliates. All Rights
2
+ # Reserved. Licensed under the Amazon Software License (the
3
+ # "License"). You may not use this file except in compliance with the
4
+ # License. A copy of the License is located at
5
+ # http://aws.amazon.com/asl or in the "license" file accompanying this
6
+ # file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
+ # the License for the specific language governing permissions and
9
+ # limitations under the License.
10
+
11
+ require 'ec2/common/constants'
12
+ require 'ec2/amitools/parameters_base'
13
+ require 'ec2/amitools/region'
14
+
15
+ #------------------------------------------------------------------------------#
16
+
17
+ class S3ToolParameters < ParametersBase
18
+
19
+ BUCKET_DESCRIPTION = ["The bucket to use. This is an S3 bucket,",
20
+ "followed by an optional S3 key prefix using '/' as a delimiter."]
21
+ MANIFEST_DESCRIPTION = "The path to the manifest file."
22
+ DELEGATION_TOKEN_DESCRIPTION = "The delegation token pass along to the AWS request."
23
+ URL_DESCRIPTION = "The S3 service URL. Defaults to https://s3.amazonaws.com."
24
+ REGION_DESCRIPTION = "The S3 region. Defaults to us-east-1."
25
+ SIGV2_DESCRIPTION = "Use old signature version 2 signing"
26
+ PROFILE_PATH = '/latest/meta-data/iam/security-credentials/'
27
+ PROFILE_HOST = '169.254.169.254'
28
+
29
+ REGION_MAP = {
30
+ 'us-east-1' => 'https://s3.amazonaws.com',
31
+ 'us-west-2' => 'https://s3-us-west-2.amazonaws.com',
32
+ 'us-west-1' => 'https://s3-us-west-1.amazonaws.com',
33
+ 'eu-west-1' => 'https://s3-eu-west-1.amazonaws.com',
34
+ 'eu-central-1' => 'https://s3.eu-central-1.amazonaws.com',
35
+ 'ap-southeast-1' => 'https://s3-ap-southeast-1.amazonaws.com',
36
+ 'ap-southeast-2' => 'https://s3-ap-southeast-2.amazonaws.com',
37
+ 'ap-northeast-1' => 'https://s3-ap-northeast-1.amazonaws.com',
38
+ 'sa-east-1' => 'https://s3-sa-east-1.amazonaws.com',
39
+ 'cn-north-1' => 'https://s3.cn-north-1.amazonaws.com.cn',
40
+ 'us-gov-west-1' => 'https://s3-us-gov-west-1.amazonaws.com'
41
+ }
42
+
43
+ VALID_SIGV = ['2', '4']
44
+
45
+ DEFAULT_URL = 'https://s3.amazonaws.com'
46
+ DEFAULT_REGION = 'us-east-1'
47
+
48
+
49
+ attr_accessor :bucket,
50
+ :keyprefix,
51
+ :user, # This now contains all the creds.
52
+ :pass, # pass is just kept for backwards compatibility.
53
+ :url,
54
+ :region,
55
+ :sigv
56
+
57
+ #------------------------------------------------------------------------------#
58
+
59
+ def split_container(container)
60
+ splitbits = container.sub(%r{^/*},'').sub(%r{/*$},'').split("/")
61
+ bucket = splitbits.shift
62
+ keyprefix = splitbits.join("/")
63
+ keyprefix += "/" unless keyprefix.empty?
64
+ @keyprefix = keyprefix
65
+ @bucket = bucket
66
+ end
67
+
68
+ #----------------------------------------------------------------------------#
69
+
70
+ def mandatory_params()
71
+ on('-b', '--bucket BUCKET', String, *BUCKET_DESCRIPTION) do |container|
72
+ @container = container
73
+ split_container(@container)
74
+ end
75
+
76
+ on('-a', '--access-key USER', String, USER_DESCRIPTION) do |user|
77
+ @user = {} if @user.nil?
78
+ @user['aws_access_key_id'] = user
79
+ end
80
+
81
+ on('-s', '--secret-key PASSWORD', String, PASS_DESCRIPTION) do |pass|
82
+ @user = {} if @user.nil?
83
+ @user['aws_secret_access_key'] = pass
84
+ @pass = pass
85
+ end
86
+
87
+ on('-t', '--delegation-token TOKEN', String, DELEGATION_TOKEN_DESCRIPTION) do |token|
88
+ @user = {} if @user.nil?
89
+ @user['aws_delegation_token'] = token
90
+ end
91
+ end
92
+
93
+ #----------------------------------------------------------------------------#
94
+
95
+ def optional_params()
96
+ on('--url URL', String, URL_DESCRIPTION) do |url|
97
+ @url = url
98
+ end
99
+
100
+ on('--region REGION', REGION_DESCRIPTION) do |region|
101
+ @region = region
102
+ end
103
+
104
+ on('--sigv VERSION', SIGV2_DESCRIPTION) do |version_number|
105
+ @sigv = version_number
106
+ end
107
+ end
108
+
109
+ #----------------------------------------------------------------------------#
110
+
111
+ def get_creds_from_instance_profile
112
+ end
113
+
114
+ def get_creds_from_instance_profile
115
+ begin
116
+ require 'json'
117
+ require 'net/http'
118
+ profile_name = Net::HTTP.get(PROFILE_HOST, PROFILE_PATH)
119
+ unless (profile_name.nil? || profile_name.strip.empty?)
120
+ creds_blob = Net::HTTP.get(PROFILE_HOST, PROFILE_PATH + profile_name.strip)
121
+ creds = JSON.parse(creds_blob)
122
+ @user = {
123
+ 'aws_access_key_id' => creds['AccessKeyId'],
124
+ 'aws_secret_access_key' => creds['SecretAccessKey'],
125
+ 'aws_delegation_token' => creds['Token'],
126
+ }
127
+ @pass = creds['SecretAccessKey']
128
+ end
129
+ rescue Exception => e
130
+ @user = nil
131
+ end
132
+ end
133
+
134
+ def validate_params()
135
+ unless @user
136
+ get_creds_from_instance_profile
137
+ end
138
+ raise MissingMandatory.new('--access-key') unless @user && @user['aws_access_key_id']
139
+ raise MissingMandatory.new('--secret-key') unless @pass
140
+ raise MissingMandatory.new('--bucket') unless @container
141
+ if @sigv && !VALID_SIGV.include?(@sigv)
142
+ raise InvalidValue.new('--sigv', @sigv, "Please specify one of these values: #{VALID_SIGV.join(', ')}")
143
+ end
144
+ end
145
+
146
+ #----------------------------------------------------------------------------#
147
+
148
+ def set_defaults()
149
+ # We need three values to be set after this point:
150
+ # region - which will specify the region of the endpoint used for sigv4
151
+ # url - the url of the endpoint
152
+ # location - the S3 bucket location
153
+ #
154
+ # We allow the user to override any of these values. The client only has
155
+ # to specify the region value.
156
+ if @region
157
+ @url ||= REGION_MAP[@region]
158
+ elsif @location
159
+ @region = case @location
160
+ when "EU" then "eu-west-1"
161
+ when "US", :unconstrained then "us-east-1"
162
+ else @location
163
+ end
164
+ @url ||= REGION_MAP[@region]
165
+ elsif @url
166
+ STDERR.puts "Specifying url has been deprecated, please use only --region"
167
+ uri = URI.parse(@url)
168
+ if @region.nil?
169
+ begin
170
+ @region = AwsRegion::determine_region_from_host uri.host
171
+ STDERR.puts "Region determined to be #{@region}"
172
+ rescue => e
173
+ STDERR.puts "No region specified and could not determine region from given url"
174
+ @region = nil
175
+ end
176
+ end
177
+ else
178
+ @url ||= DEFAULT_URL
179
+ @region ||= DEFAULT_REGION
180
+ end
181
+ @sigv ||= EC2::Common::SIGV4
182
+ end
183
+ end