fog-internet-archive 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +53 -0
  3. data/.travis.yml +16 -0
  4. data/Gemfile +3 -0
  5. data/README.md +6 -0
  6. data/Rakefile +19 -0
  7. data/fog-internet-archive.gemspec +32 -0
  8. data/lib/fog/bin/internet_archive.rb +32 -0
  9. data/lib/fog/internet_archive.rb +1 -0
  10. data/lib/fog/internet_archive/core.rb +291 -0
  11. data/lib/fog/internet_archive/models/storage/directories.rb +39 -0
  12. data/lib/fog/internet_archive/models/storage/directory.rb +105 -0
  13. data/lib/fog/internet_archive/models/storage/file.rb +254 -0
  14. data/lib/fog/internet_archive/models/storage/files.rb +119 -0
  15. data/lib/fog/internet_archive/models/storage/ia_attributes.rb +36 -0
  16. data/lib/fog/internet_archive/parsers/storage/access_control_list.rb +42 -0
  17. data/lib/fog/internet_archive/parsers/storage/complete_multipart_upload.rb +20 -0
  18. data/lib/fog/internet_archive/parsers/storage/copy_object.rb +18 -0
  19. data/lib/fog/internet_archive/parsers/storage/cors_configuration.rb +38 -0
  20. data/lib/fog/internet_archive/parsers/storage/delete_multiple_objects.rb +45 -0
  21. data/lib/fog/internet_archive/parsers/storage/get_bucket.rb +58 -0
  22. data/lib/fog/internet_archive/parsers/storage/get_bucket_lifecycle.rb +64 -0
  23. data/lib/fog/internet_archive/parsers/storage/get_bucket_location.rb +16 -0
  24. data/lib/fog/internet_archive/parsers/storage/get_bucket_logging.rb +36 -0
  25. data/lib/fog/internet_archive/parsers/storage/get_bucket_website.rb +22 -0
  26. data/lib/fog/internet_archive/parsers/storage/get_request_payment.rb +16 -0
  27. data/lib/fog/internet_archive/parsers/storage/get_service.rb +28 -0
  28. data/lib/fog/internet_archive/parsers/storage/initiate_multipart_upload.rb +20 -0
  29. data/lib/fog/internet_archive/parsers/storage/list_multipart_uploads.rb +52 -0
  30. data/lib/fog/internet_archive/parsers/storage/list_parts.rb +36 -0
  31. data/lib/fog/internet_archive/requests/storage/abort_multipart_upload.rb +27 -0
  32. data/lib/fog/internet_archive/requests/storage/acl_utils.rb +60 -0
  33. data/lib/fog/internet_archive/requests/storage/complete_multipart_upload.rb +46 -0
  34. data/lib/fog/internet_archive/requests/storage/copy_object.rb +77 -0
  35. data/lib/fog/internet_archive/requests/storage/cors_utils.rb +39 -0
  36. data/lib/fog/internet_archive/requests/storage/delete_bucket.rb +42 -0
  37. data/lib/fog/internet_archive/requests/storage/delete_bucket_cors.rb +26 -0
  38. data/lib/fog/internet_archive/requests/storage/delete_bucket_lifecycle.rb +26 -0
  39. data/lib/fog/internet_archive/requests/storage/delete_bucket_policy.rb +26 -0
  40. data/lib/fog/internet_archive/requests/storage/delete_bucket_website.rb +26 -0
  41. data/lib/fog/internet_archive/requests/storage/delete_multiple_objects.rb +88 -0
  42. data/lib/fog/internet_archive/requests/storage/delete_object.rb +46 -0
  43. data/lib/fog/internet_archive/requests/storage/get_bucket.rb +108 -0
  44. data/lib/fog/internet_archive/requests/storage/get_bucket_acl.rb +65 -0
  45. data/lib/fog/internet_archive/requests/storage/get_bucket_cors.rb +61 -0
  46. data/lib/fog/internet_archive/requests/storage/get_bucket_lifecycle.rb +35 -0
  47. data/lib/fog/internet_archive/requests/storage/get_bucket_location.rb +54 -0
  48. data/lib/fog/internet_archive/requests/storage/get_bucket_logging.rb +45 -0
  49. data/lib/fog/internet_archive/requests/storage/get_bucket_policy.rb +31 -0
  50. data/lib/fog/internet_archive/requests/storage/get_bucket_website.rb +38 -0
  51. data/lib/fog/internet_archive/requests/storage/get_object.rb +163 -0
  52. data/lib/fog/internet_archive/requests/storage/get_object_acl.rb +72 -0
  53. data/lib/fog/internet_archive/requests/storage/get_object_http_url.rb +48 -0
  54. data/lib/fog/internet_archive/requests/storage/get_object_https_url.rb +30 -0
  55. data/lib/fog/internet_archive/requests/storage/get_object_torrent.rb +45 -0
  56. data/lib/fog/internet_archive/requests/storage/get_object_url.rb +49 -0
  57. data/lib/fog/internet_archive/requests/storage/get_request_payment.rb +45 -0
  58. data/lib/fog/internet_archive/requests/storage/get_service.rb +50 -0
  59. data/lib/fog/internet_archive/requests/storage/head_object.rb +57 -0
  60. data/lib/fog/internet_archive/requests/storage/initiate_multipart_upload.rb +42 -0
  61. data/lib/fog/internet_archive/requests/storage/list_multipart_uploads.rb +52 -0
  62. data/lib/fog/internet_archive/requests/storage/list_parts.rb +53 -0
  63. data/lib/fog/internet_archive/requests/storage/post_object_hidden_fields.rb +36 -0
  64. data/lib/fog/internet_archive/requests/storage/put_bucket.rb +70 -0
  65. data/lib/fog/internet_archive/requests/storage/put_bucket_acl.rb +69 -0
  66. data/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb +47 -0
  67. data/lib/fog/internet_archive/requests/storage/put_bucket_lifecycle.rb +76 -0
  68. data/lib/fog/internet_archive/requests/storage/put_bucket_logging.rb +79 -0
  69. data/lib/fog/internet_archive/requests/storage/put_bucket_policy.rb +25 -0
  70. data/lib/fog/internet_archive/requests/storage/put_bucket_website.rb +59 -0
  71. data/lib/fog/internet_archive/requests/storage/put_object.rb +94 -0
  72. data/lib/fog/internet_archive/requests/storage/put_object_acl.rb +73 -0
  73. data/lib/fog/internet_archive/requests/storage/put_object_url.rb +43 -0
  74. data/lib/fog/internet_archive/requests/storage/put_request_payment.rb +45 -0
  75. data/lib/fog/internet_archive/requests/storage/sync_clock.rb +24 -0
  76. data/lib/fog/internet_archive/requests/storage/upload_part.rb +39 -0
  77. data/lib/fog/internet_archive/signaturev4.rb +71 -0
  78. data/lib/fog/internet_archive/storage.rb +381 -0
  79. data/lib/fog/internet_archive/version.rb +5 -0
  80. data/tasks/bundler.rake +3 -0
  81. data/tasks/console.rake +17 -0
  82. data/tasks/lint.rake +3 -0
  83. data/tasks/test.rake +7 -0
  84. data/tests/helper.rb +36 -0
  85. data/tests/helpers/collection_helper.rb +88 -0
  86. data/tests/helpers/formats_helper.rb +98 -0
  87. data/tests/helpers/formats_helper_tests.rb +106 -0
  88. data/tests/helpers/mock_helper.rb +13 -0
  89. data/tests/helpers/model_helper.rb +29 -0
  90. data/tests/helpers/responds_to_helper.rb +11 -0
  91. data/tests/helpers/schema_validator_tests.rb +101 -0
  92. data/tests/helpers/succeeds_helper.rb +9 -0
  93. data/tests/internet_archive/models/storage/directory_tests.rb +42 -0
  94. data/tests/internet_archive/models/storage/file_tests.rb +61 -0
  95. data/tests/internet_archive/models/storage/files_tests.rb +60 -0
  96. data/tests/internet_archive/models/storage/url_tests.rb +28 -0
  97. data/tests/internet_archive/requests/storage/acl_utils_tests.rb +209 -0
  98. data/tests/internet_archive/requests/storage/bucket_tests.rb +324 -0
  99. data/tests/internet_archive/requests/storage/cors_utils_tests.rb +108 -0
  100. data/tests/internet_archive/requests/storage/multipart_upload_tests.rb +132 -0
  101. data/tests/internet_archive/requests/storage/object_tests.rb +166 -0
  102. data/tests/internet_archive/signaturev4_tests.rb +41 -0
  103. data/tests/internet_archive/signed_params_tests.rb +5 -0
  104. data/tests/lorem.txt +1 -0
  105. metadata +322 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 94710d784c47b28d190892fdf284515b6382ac64
4
+ data.tar.gz: 375d275354e6ace2c9d0ad949d94cf5bceb39901
5
+ SHA512:
6
+ metadata.gz: 158d67cec65a44cfab9ca2ff9064f01ce115eb2fd955190a8fffb5cf14ac59b39b11880ba11e894b89d281f2ce6c317cd7c5fd76deef062bc46192586c739bc2
7
+ data.tar.gz: 26ffb37c02a94dda853a8d399f930305bffd4f2b2d0474d8b07e6a1a9c2159ced1e4d76b37185fbddab970dd73d13ee27e30fbdb4eed628d2a291c8975b02050
@@ -0,0 +1,53 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ Gemfile.lock
46
+ .ruby-version
47
+ .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
51
+
52
+ # Fog specific stuff
53
+ .fog
@@ -0,0 +1,16 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+ matrix:
5
+ fast_finish: true
6
+ include:
7
+ - rvm: 2.1
8
+ - rvm: 2.2
9
+ - rvm: 2.3.0
10
+ - rvm: 2.3.1
11
+ - rvm: 2.4.0
12
+ - rvm: jruby-head
13
+ allow_failures:
14
+ - rvm: jruby-head
15
+ notifications:
16
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,6 @@
1
+ # fog-internet-archive
2
+
3
+ Internet Archive Storage support for Fog
4
+
5
+
6
+ Go to https://archive.org/account/s3.php to generate keys.
@@ -0,0 +1,19 @@
1
+ require "rubygems"
2
+ require "bundler/setup"
3
+
4
+ # Immediately sync all stdout so that tools like buildbot can
5
+ # immediately load in the output.
6
+ $stdout.sync = true
7
+ $stderr.sync = true
8
+
9
+ # Load all the rake tasks from the "tasks" folder. This folder
10
+ # allows us to nicely separate rake tasks into individual files
11
+ # based on their role, which makes development and debugging easier
12
+ # than one monolithic file.
13
+ task_dir = File.expand_path("../tasks", __FILE__)
14
+ Dir["#{task_dir}/**/*.rake"].each do |task_file|
15
+ load task_file
16
+ end
17
+
18
+ desc "Default Task"
19
+ task :default => "test:travis"
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "fog/internet_archive/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "fog-internet-archive"
8
+ spec.version = Fog::InternetArchive::VERSION
9
+ spec.authors = ["Nat Welch"]
10
+ spec.email = ["nat@natwelch.com"]
11
+ spec.summary = "Module for the 'fog' gem to support Internet Archive."
12
+ spec.homepage = "https://github.com/fog/fog-internet-archive"
13
+ spec.license = "MIT"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0")
16
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|feature)s?/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "fog-core"
21
+ spec.add_dependency "fog-json"
22
+ spec.add_dependency "fog-xml"
23
+
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "shindo"
26
+ spec.add_development_dependency "pry"
27
+ spec.add_development_dependency "vcr"
28
+ spec.add_development_dependency "webmock"
29
+ spec.add_development_dependency "coveralls"
30
+ spec.add_development_dependency "rubocop"
31
+ spec.add_development_dependency "mime-types"
32
+ end
@@ -0,0 +1,32 @@
1
+ class InternetArchive < Fog::Bin
2
+ class << self
3
+ def class_for(key)
4
+ case key
5
+ when :storage
6
+ Fog::Storage::InternetArchive
7
+ else
8
+ # @todo Replace most instances of ArgumentError with NotImplementedError
9
+ # @todo For a list of widely supported Exceptions, see:
10
+ # => http://www.zenspider.com/Languages/Ruby/QuickRef.html#35
11
+ raise ArgumentError, "Unsupported #{self} service: #{key}"
12
+ end
13
+ end
14
+
15
+ def [](service)
16
+ @@connections ||= Hash.new do |hash, key|
17
+ hash[key] = case key
18
+ when :storage
19
+ Fog::Logger.warning("InternetArchive[:storage] is not recommended, use Storage[:aws] for portability")
20
+ Fog::Storage.new(:provider => 'InternetArchive')
21
+ else
22
+ raise ArgumentError, "Unrecognized service: #{key.inspect}"
23
+ end
24
+ end
25
+ @@connections[service]
26
+ end
27
+
28
+ def services
29
+ Fog::InternetArchive.services
30
+ end
31
+ end
32
+ end
@@ -0,0 +1 @@
1
+ require 'fog/internet_archive/storage'
@@ -0,0 +1,291 @@
1
+ require 'fog/core'
2
+ require 'fog/xml'
3
+ require 'fog/internet_archive/signaturev4'
4
+
5
+ module Fog
6
+ module InternetArchive
7
+ COMPLIANT_BUCKET_NAMES = /^(?:[a-z]|\d(?!\d{0,2}(?:\.\d{1,3}){3}$))(?:[a-z0-9]|\-(?![\.])){1,61}[a-z0-9]$/
8
+
9
+ DOMAIN_NAME = 'archive.org'
10
+
11
+ API_DOMAIN_NAME = 's3.us.' + DOMAIN_NAME
12
+
13
+ extend Fog::Provider
14
+
15
+ service(:storage, 'Storage')
16
+
17
+ def self.indexed_param(key, values)
18
+ params = {}
19
+ unless key.include?('%d')
20
+ key << '.%d'
21
+ end
22
+ [*values].each_with_index do |value, index|
23
+ if value.respond_to?('keys')
24
+ k = format(key, index + 1)
25
+ value.each do | vkey, vvalue |
26
+ params["#{k}.#{vkey}"] = vvalue
27
+ end
28
+ else
29
+ params[format(key, index + 1)] = value
30
+ end
31
+ end
32
+ params
33
+ end
34
+
35
+ def self.serialize_keys(key, value, options = {})
36
+ case value
37
+ when Hash
38
+ value.each do | k, v |
39
+ options.merge!(serialize_keys("#{key}.#{k}", v))
40
+ end
41
+ return options
42
+ when Array
43
+ value.each_with_index do | it, idx |
44
+ options.merge!(serialize_keys("#{key}.member.#{(idx + 1)}", it))
45
+ end
46
+ return options
47
+ else
48
+ return {key => value}
49
+ end
50
+ end
51
+
52
+ def self.indexed_request_param(name, values)
53
+ idx = -1
54
+ Array(values).reduce({}) do |params, value|
55
+ params["#{name}.#{idx += 1}"] = value
56
+ params
57
+ end
58
+ end
59
+
60
+ def self.indexed_filters(filters)
61
+ params = {}
62
+ filters.keys.each_with_index do |key, key_index|
63
+ key_index += 1
64
+ params[format('Filter.%d.Name', key_index)] = key
65
+ [*filters[key]].each_with_index do |value, value_index|
66
+ value_index += 1
67
+ params[format('Filter.%d.Value.%d', key_index, value_index)] = value
68
+ end
69
+ end
70
+ params
71
+ end
72
+
73
+ def self.escape(string)
74
+ string.gsub(/([^a-zA-Z0-9_.\-~]+)/) {
75
+ "%" + $1.unpack("H2" * $1.bytesize).join("%").upcase
76
+ }
77
+ end
78
+
79
+ def self.signed_params(params, options = {})
80
+ params.merge!({
81
+ 'AWSAccessKeyId' => options[:ia_access_key_id],
82
+ 'SignatureMethod' => 'HmacSHA256',
83
+ 'SignatureVersion' => '2',
84
+ 'Timestamp' => Time.now.utc.strftime("%Y-%m-%dT%H:%M:%SZ"),
85
+ 'Version' => options[:version]
86
+ })
87
+
88
+ params.merge!({
89
+ 'SecurityToken' => options[:ia_session_token]
90
+ }) if options[:ia_session_token]
91
+
92
+ body = ''
93
+ for key in params.keys.sort
94
+ unless (value = params[key]).nil?
95
+ body << "#{key}=#{escape(value.to_s)}&"
96
+ end
97
+ end
98
+ string_to_sign = "POST\n#{options[:host]}:#{options[:port]}\n#{options[:path]}\n" << body.chop
99
+ signed_string = options[:hmac].sign(string_to_sign)
100
+ body << "Signature=#{escape(Base64.encode64(signed_string).chomp!)}"
101
+
102
+ body
103
+ end
104
+
105
+ class Mock
106
+ def self.arn(vendor, account_id, path, region = nil)
107
+ "arn:aws:#{vendor}:#{region}:#{account_id}:#{path}"
108
+ end
109
+
110
+ def self.availability_zone(region)
111
+ "#{region}#{Fog::Mock.random_selection('abcd', 1)}"
112
+ end
113
+
114
+ def self.box_usage
115
+ sprintf("%0.10f", rand / 100).to_f
116
+ end
117
+
118
+ def self.console_output
119
+ # "[ 0.000000] Linux version 2.6.18-xenU-ec2-v1.2 (root@domU-12-31-39-07-51-82) (gcc version 4.1.2 20070626 (Red Hat 4.1.2-13)) #2 SMP Wed Aug 19 09:04:38 EDT 2009"
120
+ Base64.decode64("WyAwLjAwMDAwMF0gTGludXggdmVyc2lvbiAyLjYuMTgteGVuVS1lYzItdjEu\nMiAocm9vdEBkb21VLTEyLTMxLTM5LTA3LTUxLTgyKSAoZ2NjIHZlcnNpb24g\nNC4xLjIgMjAwNzA2MjYgKFJlZCBIYXQgNC4xLjItMTMpKSAjMiBTTVAgV2Vk\nIEF1ZyAxOSAwOTowNDozOCBFRFQgMjAwOQ==\n")
121
+ end
122
+
123
+ def self.dns_name_for(ip_address)
124
+ "ec2-#{ip_address.gsub('.','-')}.compute-1.amazonaws.com"
125
+ end
126
+
127
+ def self.private_dns_name_for(ip_address)
128
+ "ip-#{ip_address.gsub('.','-')}.ec2.internal"
129
+ end
130
+
131
+ def self.image
132
+ path = []
133
+ (rand(3) + 2).times do
134
+ path << Fog::Mock.random_letters(rand(9) + 8)
135
+ end
136
+ {
137
+ "imageOwnerId" => Fog::Mock.random_letters(rand(5) + 4),
138
+ "blockDeviceMapping" => [],
139
+ "productCodes" => [],
140
+ "kernelId" => kernel_id,
141
+ "ramdiskId" => ramdisk_id,
142
+ "imageState" => "available",
143
+ "imageId" => image_id,
144
+ "architecture" => "i386",
145
+ "isPublic" => true,
146
+ "imageLocation" => path.join('/'),
147
+ "imageType" => "machine",
148
+ "rootDeviceType" => ["ebs","instance-store"][rand(2)],
149
+ "rootDeviceName" => "/dev/sda1"
150
+ }
151
+ end
152
+
153
+ def self.image_id
154
+ "ami-#{Fog::Mock.random_hex(8)}"
155
+ end
156
+
157
+ def self.key_fingerprint
158
+ fingerprint = []
159
+ 20.times do
160
+ fingerprint << Fog::Mock.random_hex(2)
161
+ end
162
+ fingerprint.join(':')
163
+ end
164
+
165
+ def self.instance_id
166
+ "i-#{Fog::Mock.random_hex(8)}"
167
+ end
168
+
169
+ def self.ip_address
170
+ ip = []
171
+ 4.times do
172
+ ip << Fog::Mock.random_numbers(rand(3) + 1).to_i.to_s # remove leading 0
173
+ end
174
+ ip.join('.')
175
+ end
176
+
177
+ def self.private_ip_address
178
+ ip_address.gsub(/^\d{1,3}\./,"10.")
179
+ end
180
+
181
+ def self.kernel_id
182
+ "aki-#{Fog::Mock.random_hex(8)}"
183
+ end
184
+
185
+ def self.key_material
186
+ OpenSSL::PKey::RSA.generate(1024).to_s
187
+ end
188
+
189
+ def self.owner_id
190
+ Fog::Mock.random_numbers(12)
191
+ end
192
+
193
+ def self.ramdisk_id
194
+ "ari-#{Fog::Mock.random_hex(8)}"
195
+ end
196
+
197
+ def self.request_id
198
+ request_id = []
199
+ request_id << Fog::Mock.random_hex(8)
200
+ 3.times do
201
+ request_id << Fog::Mock.random_hex(4)
202
+ end
203
+ request_id << Fog::Mock.random_hex(12)
204
+ request_id.join('-')
205
+ end
206
+ class << self
207
+ alias_method :reserved_instances_id, :request_id
208
+ alias_method :reserved_instances_offering_id, :request_id
209
+ alias_method :sqs_message_id, :request_id
210
+ alias_method :sqs_sender_id, :request_id
211
+ end
212
+
213
+ def self.reservation_id
214
+ "r-#{Fog::Mock.random_hex(8)}"
215
+ end
216
+
217
+ def self.snapshot_id
218
+ "snap-#{Fog::Mock.random_hex(8)}"
219
+ end
220
+
221
+ def self.volume_id
222
+ "vol-#{Fog::Mock.random_hex(8)}"
223
+ end
224
+
225
+ def self.security_group_id
226
+ "sg-#{Fog::Mock.random_hex(8)}"
227
+ end
228
+
229
+ def self.network_interface_id
230
+ "eni-#{Fog::Mock.random_hex(8)}"
231
+ end
232
+ def self.internet_gateway_id
233
+ "igw-#{Fog::Mock.random_hex(8)}"
234
+ end
235
+ def self.dhcp_options_id
236
+ "dopt-#{Fog::Mock.random_hex(8)}"
237
+ end
238
+ def self.vpc_id
239
+ "vpc-#{Fog::Mock.random_hex(8)}"
240
+ end
241
+ def self.subnet_id
242
+ "subnet-#{Fog::Mock.random_hex(8)}"
243
+ end
244
+ def self.zone_id
245
+ "zone-#{Fog::Mock.random_hex(8)}"
246
+ end
247
+ def self.change_id
248
+ "change-#{Fog::Mock.random_hex(8)}"
249
+ end
250
+ def self.nameservers
251
+ [
252
+ 'ns-2048.awsdns-64.com',
253
+ 'ns-2049.awsdns-65.net',
254
+ 'ns-2050.awsdns-66.org',
255
+ 'ns-2051.awsdns-67.co.uk'
256
+ ]
257
+ end
258
+
259
+ def self.key_id(length=21)
260
+ #Probably close enough
261
+ Fog::Mock.random_selection('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789',length)
262
+ end
263
+
264
+ def self.rds_address(db_name,region)
265
+ "#{db_name}.#{Fog::Mock.random_letters(rand(12) + 4)}.#{region}.rds.amazonaws.com"
266
+ end
267
+ end
268
+
269
+ def self.parse_security_group_options(group_name, options)
270
+ options ||= Hash.new
271
+ if group_name.is_a?(Hash)
272
+ options = group_name
273
+ elsif group_name
274
+ if options.key?('GroupName')
275
+ raise Fog::Compute::InternetArchive::Error, 'Arguments specified both group_name and GroupName in options'
276
+ end
277
+ options = options.clone
278
+ options['GroupName'] = group_name
279
+ end
280
+ name_specified = options.key?('GroupName') && !options['GroupName'].nil?
281
+ group_id_specified = options.key?('GroupId') && !options['GroupId'].nil?
282
+ unless name_specified || group_id_specified
283
+ raise Fog::Compute::InternetArchive::Error, 'Neither GroupName nor GroupId specified'
284
+ end
285
+ if name_specified && group_id_specified
286
+ options.delete('GroupName')
287
+ end
288
+ options
289
+ end
290
+ end
291
+ end