Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Data lake store account service added #296

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions fog-azure-rm.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ Gem::Specification.new do |spec|
spec.add_dependency 'azure_mgmt_key_vault', '~> 0.9.0'
spec.add_dependency 'azure-storage', '>= 0.11.5.preview', '< 1.0'
spec.add_dependency 'vhd', '0.0.4'
spec.add_dependency 'azure_mgmt_datalake_store', '~> 0.9.0'
end
6 changes: 6 additions & 0 deletions lib/fog/azurerm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ module AzureRM
autoload :AsyncResponse, File.expand_path('azurerm/async_response', __dir__)
end

#Autoload Module for Data Lake Store
module DataLakeStore
autoload :AzureRM, File.expand_path('azurerm/data_lake_store', __dir__)
end

# Main AzureRM fog Provider Module
module AzureRM
extend Fog::Provider
Expand All @@ -85,5 +90,6 @@ module AzureRM
service(:traffic_manager, 'TrafficManager')
service(:sql, 'Sql')
service(:key_vault, 'KeyVault')
service(:data_lake_store, 'DataLakeStore')
end
end
57 changes: 57 additions & 0 deletions lib/fog/azurerm/data_lake_store.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
module Fog
module DataLakeStore
# This class registers models, requests and collections
class AzureRM < Fog::Service
requires :tenant_id
requires :client_id
requires :client_secret
requires :subscription_id

request_path 'fog/azurerm/requests/data_lake_store'
request :create_data_lake_store_account
request :update_data_lake_store_account
request :delete_data_lake_store_account
request :check_for_data_lake_store_account
request :list_data_lake_store_accounts
request :get_data_lake_store_account

model_path 'fog/azurerm/models/data_lake_store'
model :data_lake_store_account
collection :data_lake_store_accounts
model :encryption_config
model :key_vault_meta_info
model :firewall_rule

# This class provides the mock implementation for unit tests.
class Mock
def initialize(_options = {})
end
end

# This class provides the actual implemention for service calls.
class Real
def initialize(options)
begin
require 'azure_mgmt_datalake_store'
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])
@data_lake_store_account_client = ::Azure::ARM::DataLakeStore::DataLakeStoreAccountManagementClient.new(credentials)
@data_lake_store_account_client.subscription_id = options[:subscription_id]
@tenant_id = options[:tenant_id]
@client_id = options[:client_id]
@client_secret = options[:client_secret]
@resources = Fog::Resources::AzureRM.new(
tenant_id: options[:tenant_id],
client_id: options[:client_id],
client_secret: options[:client_secret],
subscription_id: options[:subscription_id]
)
end
end
end
end
end
103 changes: 103 additions & 0 deletions lib/fog/azurerm/docs/data_lake_store.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
#Data Lake Store

This document explains how to get started using Azure Data Lake Store Service with Fog.

## Usage

First of all, you need to require the Fog library by executing:

```ruby
require 'fog/azurerm'
```

## Create Connection

Next, create a connection to the Data Lake Store Service:

```ruby
azure_data_lake_store_service = Fog::DataLakeStore::AzureRM.new(
tenant_id: '<Tenantid>', # Tenant id of Azure Active Directory Application
client_id: '<Clientid>', # Client id of Azure Active Directory Application
client_secret: '<ClientSecret>', # Client Secret of Azure Active Directory Application
subscription_id: '<Subscriptionid>', # Subscription id of an Azure Account
:environment => '<AzureCloud/AzureChinaCloud/AzureUSGovernment/AzureGermanCloud>' # Azure cloud environment. Default is AzureCloud.
)
```

## Check Store Account Existence

```ruby
azure_data_lake_store_service.data_lake_store_accounts.check_for_data_lake_store_account(<Resource Group name>, <Zone name>)
```

## Create Data Lake Store Account

Create a new Data Lake Store Account

```ruby
azure_data_lake_store_service.data_lake_store_accounts.create(
name: '<Store Account Name>',
location: '<Location>', # (Possible values: Central US, East US 2, North Europe)
resource_group: '<Resource Group name>',
encryption_state: '<Encryption State>', # Optional Parameter (Possible values: Enabled,Disabled)
firewall_state: '<Firewall State>', # Optional Parameter (Possible values: Enabled,Disabled)
firewall_allow_azure_ips:'<Allow Azure Ips>', # Optional Parameter (Possible values: Enabled,Disabled)
new_tier: '<Next Month Package>', # Optional Parameter
current_tier: '<This Month Package>', # Optional Parameter
firewall_rules: [
{
name: 'Rule One',
start_ip_address: 'x.x.x.x',
end_ip_address: 'x.x.x.x'
},
{
name: 'Rule Two',
start_ip_address: 'x.x.x.x',
end_ip_address: 'x.x.x.x'
}
] # Optional Parameter
)
```

## List Data Lake Store Accounts

```ruby
azure_data_lake_store_service.data_lake_store_accounts.each do |account|
puts "#{account.name}"
puts "#{account.resource_group}"
end
```

## Retrieve a single Data Lake Store Account

Get a single record of Data Lake Store Account

```ruby
account = azure_data_lake_store_service
.data_lake_store_accounts
.get('<Resource Group name>', '<Store Account name>')
puts "#{account.name}"
```

## Update Data Lake Store Account

Get Data Lake Store Account object from the get method(described above) and then update that Data Lake Store Account.

```ruby
account.update(
firewall_state: '<Firewall State>', # Optional Parameter (Possible values: Enabled,Disabled)
firewall_allow_azure_ips:'<Allow Azure Ips>', # Optional Parameter (Possible values: Enabled,Disabled)
new_tier: '<Next Month Package>' # Optional Parameter
)
```

## Destroy a single Data Lake Store Account

Get Data Lake Store Account object from the get method(described above) and then destroy that Data Lake Store Account.

```ruby
account.destroy
```

## Support and Feedback
Your feedback is appreciated! If you have specific issues with the fog ARM, you should file an issue via Github.
80 changes: 80 additions & 0 deletions lib/fog/azurerm/models/data_lake_store/data_lake_store_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
module Fog
module DataLakeStore
class AzureRM
# This class is giving implementation of create/save and
# delete/destroy for Data Lake Store Account.
class DataLakeStoreAccount < Fog::Model
attribute :id
identity :name
attribute :resource_group
attribute :location
attribute :type
attribute :tags
attribute :firewall_state
attribute :firewall_allow_azure_ips
attribute :firewall_rules
attribute :encryption_state
attribute :encryption_config
attribute :new_tier
attribute :current_tier

def self.parse(account)
hash = get_hash_from_object(account)
hash['resource_group'] = get_resource_group_from_id(account.id)
unless account.encryption_config.nil?
encryption_config = Fog::DataLakeStore::AzureRM::EncryptionConfig.new
hash['encryption_config'] = encryption_config.merge_attributes(Fog::DataLakeStore::AzureRM::EncryptionConfig.parse(account.encryption_config))
end
hash['firewall_rules'] = []
account.firewall_rules.each do |rule|
firewall_rule = Fog::DataLakeStore::AzureRM::FirewallRule.new
hash['firewall_rules'] << firewall_rule.merge_attributes(Fog::DataLakeStore::AzureRM::FirewallRule.parse(rule))
end unless account.firewall_rules.nil?
hash
end

def save
requires :name, :resource_group, :location
account = service.create_data_lake_store_account(data_lake_store_params)
merge_attributes(Fog::DataLakeStore::AzureRM::DataLakeStoreAccount.parse(account))
end

def update(input_hash)
validate_input(input_hash)
merge_attributes(input_hash)
account = service.update_data_lake_store_account(data_lake_store_params)
merge_attributes(Fog::DataLakeStore::AzureRM::DataLakeStoreAccount.parse(account))
end

def destroy
service.delete_data_lake_store_account(resource_group, name)
end

private

def data_lake_store_params
{
name: name,
resource_group: resource_group,
location: location,
type: type,
tags: tags,
encryption_state: encryption_state,
encryption_config: encryption_config,
firewall_state: firewall_state,
firewall_allow_azure_ips: firewall_allow_azure_ips,
firewall_rules: firewall_rules,
new_tier: new_tier,
current_tier: current_tier
}
end

def validate_input(input_hash)
invalid_attr = [:name, :resource_group, :location, :id, :encryption_state, :encryption_config, :current_tier, :firewall_rules]
result = invalid_attr & input_hash.keys
raise 'Cannot modify the given attribute' unless result.empty?
end
end
end
end
end
29 changes: 29 additions & 0 deletions lib/fog/azurerm/models/data_lake_store/data_lake_store_accounts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Fog
module DataLakeStore
class AzureRM
# This class is giving implementation of
# all/get for Data Lake Store Account.
class DataLakeStoreAccounts < Fog::Collection
model DataLakeStoreAccount

def all
accounts = []
service.list_data_lake_store_accounts.each do |account|
accounts << DataLakeStoreAccount.parse(account)
end
load(accounts)
end

def get(resource_group, name)
account = service.get_data_lake_store_account(resource_group, name)
account_obj = DataLakeStoreAccount.new(service: service)
account_obj.merge_attributes(DataLakeStoreAccount.parse(account))
end

def check_for_data_lake_store_account(resource_group, name)
service.check_for_data_lake_store_account(resource_group, name)
end
end
end
end
end
21 changes: 21 additions & 0 deletions lib/fog/azurerm/models/data_lake_store/encryption_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Fog
module DataLakeStore
class AzureRM
# Encryption Config class for Data Lake Store Account Service
class EncryptionConfig < Fog::Model
attribute :type
attribute :key_vault_meta_info

def self.parse(encryption_config)
hash = {}
hash['type'] = encryption_config.type
unless encryption_config.key_vault_meta_info.nil?
key_vault_meta_info = Fog::DataLakeStore::AzureRM::KeyVaultMetaInfo.new
hash['key_vault_meta_info'] = key_vault_meta_info.merge_attributes(Fog::DataLakeStore::AzureRM::KeyVaultMetaInfo.parse(encryption_config.key_vault_meta_info))
end
hash
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/fog/azurerm/models/data_lake_store/firewall_rule.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Fog
module DataLakeStore
class AzureRM
# Key Vault Meta Info class for Data Lake Store Account Service
class FirewallRule < Fog::Model
attribute :name
attribute :start_ip_address
attribute :end_ip_address

def self.parse(firewall_rule)
get_hash_from_object(firewall_rule)
end
end
end
end
end
16 changes: 16 additions & 0 deletions lib/fog/azurerm/models/data_lake_store/key_vault_meta_info.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Fog
module DataLakeStore
class AzureRM
# Key Vault Meta Info class for Data Lake Store Account Service
class KeyVaultMetaInfo < Fog::Model
attribute :key_vault_resource_id
attribute :encryption_key_name
attribute :encryption_key_version

def self.parse(key_vault_meta_info)
get_hash_from_object(key_vault_meta_info)
end
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Fog
module DataLakeStore
class AzureRM
# Real class for Data Lake Store Account
class Real
def check_for_data_lake_store_account(resource_group, name)
msg = "Checking if Data Lake Store Account #{name} exists in Resource Group #{resource_group}."
Fog::Logger.debug msg
begin
account = @data_lake_store_account_client.account.get(resource_group, name)
rescue MsRestAzure::AzureOperationError => e
raise_azure_exception(e, msg)
end
!account.nil?
end
end

# Mock class for Data Lake Store Account
class Mock
def check_for_data_lake_store_account(*)
Fog::Logger.debug 'Data Lake Store Account name is available.'
true
end
end
end
end
end
Loading