Class: Fog::KeyVault::AzureRM::Real

Inherits:
Object
  • Object
show all
Defined in:
lib/fog/azurerm/key_vault.rb,
lib/fog/azurerm/requests/key_vault/get_vault.rb,
lib/fog/azurerm/requests/key_vault/list_vaults.rb,
lib/fog/azurerm/requests/key_vault/delete_vault.rb,
lib/fog/azurerm/requests/key_vault/check_vault_exists.rb,
lib/fog/azurerm/requests/key_vault/create_or_update_vault.rb

Overview

This class provides the actual implementation for service calls.

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Real

Returns a new instance of Real.



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/fog/azurerm/key_vault.rb', line 36

def initialize(options)
  begin
    require 'azure_mgmt_key_vault'
  rescue LoadError => e
    retry if require('rubygems')
    raise e.message
  end

  credentials = Fog::Credentials::AzureRM.get_credentials(options[:tenant_id], options[:client_id], options[:client_secret])
  @key_vault_client = ::Azure::ARM::KeyVault::KeyVaultManagementClient.new(credentials)
  @key_vault_client.subscription_id = options[:subscription_id]
end

Instance Method Details

#check_vault_exists(resource_group, vault_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fog/azurerm/requests/key_vault/check_vault_exists.rb', line 6

def check_vault_exists(resource_group, vault_name)
  msg = "Checking Vault #{vault_name}"
  Fog::Logger.debug msg
  begin
    @key_vault_client.vaults.get(resource_group, vault_name)
    Fog::Logger.debug "Vault #{vault_name} exists."
    true
  rescue MsRestAzure::AzureOperationError => e
    if resource_not_found?(e)
      Fog::Logger.debug "Vault #{vault_name} doesn't exist."
      false
    else
      raise_azure_exception(e, msg)
    end
  end
end

#create_or_update_vault(vault_hash) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/fog/azurerm/requests/key_vault/create_or_update_vault.rb', line 6

def create_or_update_vault(vault_hash)
  msg = "Creating Vault: #{vault_hash[:name]}."
  Fog::Logger.debug msg
  vault_parameters = get_vault_param_object(vault_hash)
  begin
    vault = @key_vault_client.vaults.create_or_update(vault_hash[:resource_group], vault_hash[:name], vault_parameters)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Vault: #{vault_hash[:name]} created successfully."
  vault
end

#delete_vault(resource_group, vault_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/azurerm/requests/key_vault/delete_vault.rb', line 6

def delete_vault(resource_group, vault_name)
  msg = "Deleting Vault: #{vault_name}."
  Fog::Logger.debug msg
  begin
    @key_vault_client.vaults.delete(resource_group, vault_name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Vault: #{vault_name} deleted successfully."
  true
end

#get_vault(resource_group, vault_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/azurerm/requests/key_vault/get_vault.rb', line 6

def get_vault(resource_group, vault_name)
  msg = "Getting Vault => #{vault_name} from Resource Group => #{resource_group}..."
  Fog::Logger.debug msg
  begin
    vault = @key_vault_client.vaults.get(resource_group, vault_name)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Vault fetched successfully from Resource Group => #{resource_group}"
  vault
end

#list_vaults(resource_group) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fog/azurerm/requests/key_vault/list_vaults.rb', line 6

def list_vaults(resource_group)
  msg = "Listing Vaults in Resource Group: #{resource_group}."
  Fog::Logger.debug msg
  begin
    vaults = @key_vault_client.vaults.list_by_resource_group_as_lazy(resource_group)
  rescue MsRestAzure::AzureOperationError => e
    raise_azure_exception(e, msg)
  end
  Fog::Logger.debug "Vaults listed successfully in Resource Group: #{resource_group}"
  vaults.value
end