Class: Fog::AWS::KMS::Mock
- Inherits:
-
Object
- Object
- Fog::AWS::KMS::Mock
- Defined in:
- lib/fog/aws/kms.rb,
lib/fog/aws/requests/kms/list_keys.rb,
lib/fog/aws/requests/kms/create_key.rb,
lib/fog/aws/requests/kms/describe_key.rb
Instance Attribute Summary collapse
-
#account_id ⇒ Object
readonly
Returns the value of attribute account_id.
Class Method Summary collapse
Instance Method Summary collapse
- #create_key(policy = nil, description = nil, usage = "ENCRYPT_DECRYPT") ⇒ Object
- #data ⇒ Object
- #describe_key(identifier) ⇒ Object
-
#initialize(options = {}) ⇒ Mock
constructor
A new instance of Mock.
- #list_keys(options = {}) ⇒ Object
- #reset_data ⇒ Object
- #setup_credentials(options) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Mock
Returns a new instance of Mock.
45 46 47 48 49 50 51 52 53 |
# File 'lib/fog/aws/kms.rb', line 45 def initialize(={}) @use_iam_profile = [:use_iam_profile] @account_id = Fog::AWS::Mock.owner_id @region = [:region] || 'us-east-1' setup_credentials() Fog::AWS.validate_region!(@region) end |
Instance Attribute Details
#account_id ⇒ Object (readonly)
Returns the value of attribute account_id.
43 44 45 |
# File 'lib/fog/aws/kms.rb', line 43 def account_id @account_id end |
Class Method Details
.data ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/fog/aws/kms.rb', line 29 def self.data @data ||= Hash.new do |hash, region| hash[region] = Hash.new do |region_hash, access_key| region_hash[access_key] = { :keys => {}, } end end end |
.reset ⇒ Object
39 40 41 |
# File 'lib/fog/aws/kms.rb', line 39 def self.reset data.clear end |
Instance Method Details
#create_key(policy = nil, description = nil, usage = "ENCRYPT_DECRYPT") ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/fog/aws/requests/kms/create_key.rb', line 37 def create_key(policy = nil, description = nil, usage = "ENCRYPT_DECRYPT") response = Excon::Response.new key_id = UUID.uuid key_arn = Fog::AWS::Mock.arn("kms", self.account_id, "key/#{key_id}", @region) key = { "KeyUsage" => usage, "AWSAccountId" => self.account_id, "KeyId" => key_id, "Description" => description, "CreationDate" => Time.now, "Arn" => key_arn, "Enabled" => true, } # @todo use default policy self.data[:keys][key_id] = key response.body = { "KeyMetadata" => key } response end |
#data ⇒ Object
62 63 64 |
# File 'lib/fog/aws/kms.rb', line 62 def data self.class.data[@region][@aws_access_key_id] end |
#describe_key(identifier) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/fog/aws/requests/kms/describe_key.rb', line 17 def describe_key(identifier) response = Excon::Response.new key = self.data[:keys][identifier] response.body = { "KeyMetadata" => key } response end |
#list_keys(options = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/fog/aws/requests/kms/list_keys.rb', line 27 def list_keys(={}) limit = [:limit] marker = [:marker] if limit if limit > 1_000 raise Fog::AWS::KMS::Error.new( "ValidationError => 1 validation error detected: Value '#{limit}' at 'limit' failed to satisfy constraint: Member must have value less than or equal to 1000" ) elsif limit < 1 raise Fog::AWS::KMS::Error.new( "ValidationError => 1 validation error detected: Value '#{limit}' at 'limit' failed to satisfy constraint: Member must have value greater than or equal to 1" ) end end key_set = if marker self.data[:markers][marker] || [] else self.data[:keys].inject([]) { |r,(k,v)| r << { "KeyId" => k, "KeyArn" => v["Arn"] } } end keys = if limit key_set.slice!(0, limit) else key_set end truncated = keys.size < key_set.size marker = truncated && "metadata/l/#{account_id}/#{UUID.uuid}" response = Excon::Response.new body = { 'Keys' => keys, 'Truncated' => truncated, 'RequestId' => Fog::AWS::Mock.request_id } if marker self.data[:markers][marker] = key_set body.merge!('Marker' => marker) end response.body = body response.status = 200 response end |
#reset_data ⇒ Object
66 67 68 |
# File 'lib/fog/aws/kms.rb', line 66 def reset_data self.class.data[@region].delete(@aws_access_key_id) end |
#setup_credentials(options) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/fog/aws/kms.rb', line 55 def setup_credentials() @aws_access_key_id = [:aws_access_key_id] @aws_secret_access_key = [:aws_secret_access_key] @signer = Fog::AWS::SignatureV4.new(@aws_access_key_id, @aws_secret_access_key, @region, 'kms') end |