2009-08-07 03:28:53 -04:00
|
|
|
require 'rubygems'
|
|
|
|
require 'base64'
|
|
|
|
require 'cgi'
|
|
|
|
require 'digest/md5'
|
|
|
|
require 'hmac-sha1'
|
2009-08-10 23:43:31 -04:00
|
|
|
require 'hmac-sha2'
|
2009-08-07 03:28:53 -04:00
|
|
|
require 'mime/types'
|
|
|
|
|
2009-07-12 18:20:46 -04:00
|
|
|
current_directory = File.dirname(__FILE__)
|
|
|
|
require "#{current_directory}/aws/ec2"
|
|
|
|
require "#{current_directory}/aws/simpledb"
|
|
|
|
require "#{current_directory}/aws/s3"
|
2009-08-10 11:30:28 -04:00
|
|
|
|
|
|
|
module Fog
|
|
|
|
module AWS
|
|
|
|
|
|
|
|
def self.reload
|
|
|
|
current_directory = File.dirname(__FILE__)
|
|
|
|
load "#{current_directory}/aws/ec2.rb"
|
2009-08-10 23:43:31 -04:00
|
|
|
Fog::AWS::EC2.reload
|
2009-08-10 11:30:28 -04:00
|
|
|
load "#{current_directory}/aws/simpledb.rb"
|
2009-08-10 23:43:31 -04:00
|
|
|
Fog::AWS::SimpleDB.reload
|
2009-08-10 11:30:28 -04:00
|
|
|
load "#{current_directory}/aws/s3.rb"
|
|
|
|
Fog::AWS::S3.reload
|
|
|
|
end
|
|
|
|
|
2009-08-14 12:18:55 -04:00
|
|
|
if Fog.mocking?
|
|
|
|
srand(Time.now.to_i)
|
|
|
|
|
|
|
|
class Mock
|
|
|
|
|
2009-08-14 13:35:16 -04:00
|
|
|
def self.etag
|
|
|
|
hex(32)
|
|
|
|
end
|
|
|
|
|
2009-08-17 01:19:35 -04:00
|
|
|
def self.key_fingerprint
|
|
|
|
fingerprint = []
|
|
|
|
20.times do
|
|
|
|
fingerprint << hex(2)
|
|
|
|
end
|
|
|
|
fingerprint.join(':')
|
|
|
|
end
|
|
|
|
|
2009-08-14 13:35:16 -04:00
|
|
|
def self.instance_id
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.ip_address
|
|
|
|
ip = []
|
|
|
|
4.times do
|
|
|
|
ip << numbers(rand(3) + 1).to_i.to_s # remove leading 0
|
|
|
|
end
|
|
|
|
ip.join('.')
|
|
|
|
end
|
|
|
|
|
2009-08-17 01:19:35 -04:00
|
|
|
def self.key_material
|
|
|
|
key_material = ['-----BEGIN RSA PRIVATE KEY-----']
|
|
|
|
20.times do
|
|
|
|
key_material << base64(76)
|
|
|
|
end
|
|
|
|
key_material << base64(67) + '='
|
|
|
|
key_material << '-----END RSA PRIVATE KEY-----'
|
|
|
|
key_material.join("\n")
|
|
|
|
end
|
|
|
|
|
2009-08-14 13:35:16 -04:00
|
|
|
def self.request_id
|
|
|
|
request_id = []
|
|
|
|
request_id << hex(8)
|
|
|
|
3.times do
|
|
|
|
request_id << hex(4)
|
|
|
|
end
|
|
|
|
request_id << hex(12)
|
|
|
|
request_id.join('-')
|
|
|
|
end
|
|
|
|
|
2009-08-15 18:19:07 -04:00
|
|
|
def self.snapshot_id
|
|
|
|
"snap-#{hex(8)}"
|
|
|
|
end
|
|
|
|
|
2009-08-14 13:35:16 -04:00
|
|
|
def self.volume_id
|
2009-08-15 18:19:07 -04:00
|
|
|
"vol-#{hex(8)}"
|
2009-08-14 13:35:16 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def self.random_selection(characters, length)
|
|
|
|
selection = ''
|
|
|
|
length.times do
|
|
|
|
position = rand(characters.length)
|
|
|
|
selection << characters[position..position]
|
|
|
|
end
|
|
|
|
selection
|
|
|
|
end
|
|
|
|
|
2009-08-14 12:18:55 -04:00
|
|
|
def self.letters(length)
|
|
|
|
random_selection(
|
|
|
|
'abcdefghijklmnopqrstuvwxyz',
|
|
|
|
length
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.numbers(length)
|
|
|
|
random_selection(
|
|
|
|
'0123456789',
|
|
|
|
length
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.hex(length)
|
|
|
|
random_selection(
|
|
|
|
'0123456789abcdef',
|
|
|
|
length
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2009-08-17 01:19:35 -04:00
|
|
|
def self.base64(length)
|
|
|
|
random_selection(
|
|
|
|
"ABCDEFGHIJKLMNOP QRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
|
|
|
|
length
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2009-08-14 12:18:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-08-10 11:30:28 -04:00
|
|
|
end
|
|
|
|
end
|