fog-internet-archive 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +53 -0
- data/.travis.yml +16 -0
- data/Gemfile +3 -0
- data/README.md +6 -0
- data/Rakefile +19 -0
- data/fog-internet-archive.gemspec +32 -0
- data/lib/fog/bin/internet_archive.rb +32 -0
- data/lib/fog/internet_archive.rb +1 -0
- data/lib/fog/internet_archive/core.rb +291 -0
- data/lib/fog/internet_archive/models/storage/directories.rb +39 -0
- data/lib/fog/internet_archive/models/storage/directory.rb +105 -0
- data/lib/fog/internet_archive/models/storage/file.rb +254 -0
- data/lib/fog/internet_archive/models/storage/files.rb +119 -0
- data/lib/fog/internet_archive/models/storage/ia_attributes.rb +36 -0
- data/lib/fog/internet_archive/parsers/storage/access_control_list.rb +42 -0
- data/lib/fog/internet_archive/parsers/storage/complete_multipart_upload.rb +20 -0
- data/lib/fog/internet_archive/parsers/storage/copy_object.rb +18 -0
- data/lib/fog/internet_archive/parsers/storage/cors_configuration.rb +38 -0
- data/lib/fog/internet_archive/parsers/storage/delete_multiple_objects.rb +45 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket.rb +58 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket_lifecycle.rb +64 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket_location.rb +16 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket_logging.rb +36 -0
- data/lib/fog/internet_archive/parsers/storage/get_bucket_website.rb +22 -0
- data/lib/fog/internet_archive/parsers/storage/get_request_payment.rb +16 -0
- data/lib/fog/internet_archive/parsers/storage/get_service.rb +28 -0
- data/lib/fog/internet_archive/parsers/storage/initiate_multipart_upload.rb +20 -0
- data/lib/fog/internet_archive/parsers/storage/list_multipart_uploads.rb +52 -0
- data/lib/fog/internet_archive/parsers/storage/list_parts.rb +36 -0
- data/lib/fog/internet_archive/requests/storage/abort_multipart_upload.rb +27 -0
- data/lib/fog/internet_archive/requests/storage/acl_utils.rb +60 -0
- data/lib/fog/internet_archive/requests/storage/complete_multipart_upload.rb +46 -0
- data/lib/fog/internet_archive/requests/storage/copy_object.rb +77 -0
- data/lib/fog/internet_archive/requests/storage/cors_utils.rb +39 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket.rb +42 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket_cors.rb +26 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket_lifecycle.rb +26 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket_policy.rb +26 -0
- data/lib/fog/internet_archive/requests/storage/delete_bucket_website.rb +26 -0
- data/lib/fog/internet_archive/requests/storage/delete_multiple_objects.rb +88 -0
- data/lib/fog/internet_archive/requests/storage/delete_object.rb +46 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket.rb +108 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_acl.rb +65 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_cors.rb +61 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_lifecycle.rb +35 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_location.rb +54 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_logging.rb +45 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_policy.rb +31 -0
- data/lib/fog/internet_archive/requests/storage/get_bucket_website.rb +38 -0
- data/lib/fog/internet_archive/requests/storage/get_object.rb +163 -0
- data/lib/fog/internet_archive/requests/storage/get_object_acl.rb +72 -0
- data/lib/fog/internet_archive/requests/storage/get_object_http_url.rb +48 -0
- data/lib/fog/internet_archive/requests/storage/get_object_https_url.rb +30 -0
- data/lib/fog/internet_archive/requests/storage/get_object_torrent.rb +45 -0
- data/lib/fog/internet_archive/requests/storage/get_object_url.rb +49 -0
- data/lib/fog/internet_archive/requests/storage/get_request_payment.rb +45 -0
- data/lib/fog/internet_archive/requests/storage/get_service.rb +50 -0
- data/lib/fog/internet_archive/requests/storage/head_object.rb +57 -0
- data/lib/fog/internet_archive/requests/storage/initiate_multipart_upload.rb +42 -0
- data/lib/fog/internet_archive/requests/storage/list_multipart_uploads.rb +52 -0
- data/lib/fog/internet_archive/requests/storage/list_parts.rb +53 -0
- data/lib/fog/internet_archive/requests/storage/post_object_hidden_fields.rb +36 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket.rb +70 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_acl.rb +69 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_cors.rb +47 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_lifecycle.rb +76 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_logging.rb +79 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_policy.rb +25 -0
- data/lib/fog/internet_archive/requests/storage/put_bucket_website.rb +59 -0
- data/lib/fog/internet_archive/requests/storage/put_object.rb +94 -0
- data/lib/fog/internet_archive/requests/storage/put_object_acl.rb +73 -0
- data/lib/fog/internet_archive/requests/storage/put_object_url.rb +43 -0
- data/lib/fog/internet_archive/requests/storage/put_request_payment.rb +45 -0
- data/lib/fog/internet_archive/requests/storage/sync_clock.rb +24 -0
- data/lib/fog/internet_archive/requests/storage/upload_part.rb +39 -0
- data/lib/fog/internet_archive/signaturev4.rb +71 -0
- data/lib/fog/internet_archive/storage.rb +381 -0
- data/lib/fog/internet_archive/version.rb +5 -0
- data/tasks/bundler.rake +3 -0
- data/tasks/console.rake +17 -0
- data/tasks/lint.rake +3 -0
- data/tasks/test.rake +7 -0
- data/tests/helper.rb +36 -0
- data/tests/helpers/collection_helper.rb +88 -0
- data/tests/helpers/formats_helper.rb +98 -0
- data/tests/helpers/formats_helper_tests.rb +106 -0
- data/tests/helpers/mock_helper.rb +13 -0
- data/tests/helpers/model_helper.rb +29 -0
- data/tests/helpers/responds_to_helper.rb +11 -0
- data/tests/helpers/schema_validator_tests.rb +101 -0
- data/tests/helpers/succeeds_helper.rb +9 -0
- data/tests/internet_archive/models/storage/directory_tests.rb +42 -0
- data/tests/internet_archive/models/storage/file_tests.rb +61 -0
- data/tests/internet_archive/models/storage/files_tests.rb +60 -0
- data/tests/internet_archive/models/storage/url_tests.rb +28 -0
- data/tests/internet_archive/requests/storage/acl_utils_tests.rb +209 -0
- data/tests/internet_archive/requests/storage/bucket_tests.rb +324 -0
- data/tests/internet_archive/requests/storage/cors_utils_tests.rb +108 -0
- data/tests/internet_archive/requests/storage/multipart_upload_tests.rb +132 -0
- data/tests/internet_archive/requests/storage/object_tests.rb +166 -0
- data/tests/internet_archive/signaturev4_tests.rb +41 -0
- data/tests/internet_archive/signed_params_tests.rb +5 -0
- data/tests/lorem.txt +1 -0
- metadata +322 -0
checksums.yaml
ADDED
@@ -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
|
data/.gitignore
ADDED
@@ -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
|
data/.travis.yml
ADDED
@@ -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
data/README.md
ADDED
data/Rakefile
ADDED
@@ -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
|