Class: KmsTools::Base
- Inherits:
-
Object
- Object
- KmsTools::Base
- Defined in:
- lib/kms-tools/base.rb
Overview
Helper class for Aws::KMS::Client.
Constant Summary collapse
- DEFAULT_REGION =
Default region if nothing is provided because we all use N. Virginia, don’t we?
'us-east-1'
Instance Attribute Summary collapse
-
#kms ⇒ Object
readonly
InstantiatedAws::KMS::Client object.
-
#master_key ⇒ Object
Customer master key used for ann encryption operations.
Instance Method Summary collapse
-
#available_aliases ⇒ Array
Lists all master key aliases available to the current client (Ignores built-aws keys that should not be used by user code).
-
#from_64(blob) ⇒ String
Short function to decode a blob from Base64.
-
#initialize(options = {}) ⇒ Base
constructor
Instantiates a Aws::KMS::Client object with provided options.
-
#master_key_arn ⇒ String
Key ARN of the currently selected master key.
-
#master_key_id ⇒ String
Returns the key ID of the currently selected master key.
-
#region ⇒ String
Current client region.
-
#to_64(blob) ⇒ String
Short function to encode a blob to Base64.
-
#to_s64(blob) ⇒ String
Short function to strict encode a blob to Base64.
-
#use_key_alias=(key_alias) ⇒ String
Sets the current master key using a key alias.
Constructor Details
#initialize(options = {}) ⇒ Base
Instantiates a Aws::KMS::Client object with provided options.
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/kms-tools/base.rb', line 22 def initialize( = {}) @master_key = [:master_key] || Config.master_key @region = [:region] || Config.region @profile = [:profile] || Config.profile @kms = Aws::KMS::Client.new({ :region => region, :profile => @profile, }) end |
Instance Attribute Details
#kms ⇒ Object (readonly)
InstantiatedAws::KMS::Client object
12 13 14 |
# File 'lib/kms-tools/base.rb', line 12 def kms @kms end |
#master_key ⇒ Object
Customer master key used for ann encryption operations
9 10 11 |
# File 'lib/kms-tools/base.rb', line 9 def master_key @master_key end |
Instance Method Details
#available_aliases ⇒ Array
Lists all master key aliases available to the current client (Ignores built-aws keys that should not be used by user code).
35 36 37 38 |
# File 'lib/kms-tools/base.rb', line 35 def available_aliases aliases = kms.list_aliases.aliases.delete_if { |a| a.alias_name.include? "alias/aws/"} aliases.map{ |a| a.alias_name } end |
#from_64(blob) ⇒ String
Short function to decode a blob from Base64
83 84 85 |
# File 'lib/kms-tools/base.rb', line 83 def from_64(blob) Base64.decode64(blob) end |
#master_key_arn ⇒ String
Key ARN of the currently selected master key
42 43 44 |
# File 'lib/kms-tools/base.rb', line 42 def master_key_arn master_key ? kms.describe_key({:key_id => master_key})..arn : nil end |
#master_key_id ⇒ String
Returns the key ID of the currently selected master key
48 49 50 |
# File 'lib/kms-tools/base.rb', line 48 def master_key_id master_key ? kms.describe_key({:key_id => master_key})..key_id : nil end |
#region ⇒ String
Current client region
65 66 67 |
# File 'lib/kms-tools/base.rb', line 65 def region @region ||= DEFAULT_REGION end |
#to_64(blob) ⇒ String
Short function to encode a blob to Base64
71 72 73 |
# File 'lib/kms-tools/base.rb', line 71 def to_64(blob) Base64.encode64(blob) end |
#to_s64(blob) ⇒ String
Short function to strict encode a blob to Base64
77 78 79 |
# File 'lib/kms-tools/base.rb', line 77 def to_s64(blob) Base64.strict_encode64(blob) end |
#use_key_alias=(key_alias) ⇒ String
Sets the current master key using a key alias. Verifies that the provided key is available prior to setting.
55 56 57 58 59 60 61 |
# File 'lib/kms-tools/base.rb', line 55 def use_key_alias=(key_alias) if available_aliases.include? key_alias @master_key = key_alias else raise "Requested key alias not available with current credentials!" end end |