Skip to content

Commit

Permalink
codebase cleanup: update format (#131)
Browse files Browse the repository at this point in the history
* Update format
  • Loading branch information
Fred-sun authored May 27, 2020
1 parent 4a9c723 commit 8aad2a0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 14 deletions.
3 changes: 3 additions & 0 deletions plugins/doc_fragments/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Copyright: (c) 2016 Chris Houseknecht, <house@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


class ModuleDocFragment(object):

Expand Down
3 changes: 3 additions & 0 deletions plugins/doc_fragments/azure_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
# Copyright: (c) 2016, Chris Houseknecht, <house@redhat.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import absolute_import, division, print_function
__metaclass__ = type


class ModuleDocFragment(object):

Expand Down
27 changes: 16 additions & 11 deletions plugins/modules/azure_rm_storageaccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@
description:
- When I(default_action=Deny) this controls which Azure components can still reach the Storage Account.
- The list is comma separated.
- It can be any combination of the following: AzureServices, Logging, Metrics.
- It can be any combination of the example C(AzureServices), C(Logging), C(Metrics).
- If no Azure components are allowed, explicitly set I(bypass="").
default: AzureServices
suboptions:
Expand Down Expand Up @@ -207,7 +207,7 @@
tags:
testing: testing
- name: configure firewall and virtual networks
- name: configure firewall and virtual networks
azure_rm_storageaccount:
resource_group: myResourceGroup
name: clh0002
Expand Down Expand Up @@ -305,7 +305,8 @@
"virtual_network_rules": [
{
"action": "Allow",
"id": "/subscriptions/mySubscriptionId/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"
"id": "/subscriptions/mySubscriptionId/resourceGroups/myResourceGroup/ \
providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"
}
],
"ip_rules": [
Expand Down Expand Up @@ -631,7 +632,7 @@ def update_network_rule_set(self):
self.fail("Failed to update account type: {0}".format(str(exc)))

def sort_list_of_dicts(self, rule_set, dict_key):
return sorted(rule_set, key = lambda i: i[dict_key])
return sorted(rule_set, key=lambda i: i[dict_key])

def update_account(self):
self.log('Update storage account {0}'.format(self.name))
Expand All @@ -642,26 +643,29 @@ def update_account(self):
self.update_network_rule_set()

if self.network_acls.get('default_action', 'Allow') == 'Deny':
if sorted(self.network_acls['bypass'].replace(' ','').split(',')) != sorted(self.account_dict['network_acls']['bypass'].replace(' ','').split(',')):
if sorted(self.network_acls['bypass'].replace(" ',' ").split(',')) != \
sorted(self.account_dict['network_acls']['bypass'].replace(" ',' ").split(',')):
self.results['changed'] = True
self.account_dict['network_acls']['bypass'] = self.network_acls['bypass']
self.update_network_rule_set()

if self.network_acls.get('virtual_network_rules', None) != None and self.account_dict['network_acls']['virtual_network_rules'] != []:
if self.sort_list_of_dicts(self.network_acls['virtual_network_rules'], 'id') != self.sort_list_of_dicts(self.account_dict['network_acls']['virtual_network_rules'], 'id'):
if self.network_acls.get('virtual_network_rules', None) is not None and self.account_dict['network_acls']['virtual_network_rules'] != []:
if self.sort_list_of_dicts(self.network_acls['virtual_network_rules'], 'id') != \
self.sort_list_of_dicts(self.account_dict['network_acls']['virtual_network_rules'], 'id'):
self.results['changed'] = True
self.account_dict['network_acls']['virtual_network_rules'] = self.network_acls['virtual_network_rules']
self.update_network_rule_set()
if self.network_acls.get('virtual_network_rules', None) != None and self.account_dict['network_acls']['virtual_network_rules'] == []:
if self.network_acls.get('virtual_network_rules', None) is not None and self.account_dict['network_acls']['virtual_network_rules'] == []:
self.results['changed'] = True
self.update_network_rule_set()

if self.network_acls.get('ip_rules', None) != None and self.account_dict['network_acls']['ip_rules'] != []:
if self.sort_list_of_dicts(self.network_acls['ip_rules'], 'value') != self.sort_list_of_dicts(self.account_dict['network_acls']['ip_rules'], 'value'):
if self.network_acls.get('ip_rules', None) is not None and self.account_dict['network_acls']['ip_rules'] != []:
if self.sort_list_of_dicts(self.network_acls['ip_rules'], 'value') != \
self.sort_list_of_dicts(self.account_dict['network_acls']['ip_rules'], 'value'):
self.results['changed'] = True
self.account_dict['network_acls']['ip_rules'] = self.network_acls['ip_rules']
self.update_network_rule_set()
if self.network_acls.get('ip_rules', None) != None and self.account_dict['network_acls']['ip_rules'] == []:
if self.network_acls.get('ip_rules', None) is not None and self.account_dict['network_acls']['ip_rules'] == []:
self.results['changed'] = True
self.update_network_rule_set()

Expand Down Expand Up @@ -852,6 +856,7 @@ def set_network_acls(self):
except Exception as exc:
self.fail("Failed to update account type: {0}".format(str(exc)))


def main():
AzureRMStorageAccount()

Expand Down
3 changes: 2 additions & 1 deletion plugins/modules/azure_rm_storageaccount_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@
"virtual_network_rules": [
{
"action": "Allow",
"id": "/subscriptions/mySubscriptionId/resourceGroups/myResourceGroup/providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"
"id": "/subscriptions/mySubscriptionId/resourceGroups/myResourceGroup/ \
providers/Microsoft.Network/virtualNetworks/myVnet/subnets/mySubnet"
}
],
"ip_rules": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
tags:
test: test
galaxy: galaxy
http_only: yes
https_only: yes
network_acls:
bypass: AzureServices
default_action: Deny
Expand Down Expand Up @@ -84,7 +84,7 @@
tags:
test: test
galaxy: galaxy
http_only: yes
https_only: yes
network_acls:
bypass: AzureServices
default_action: Deny
Expand Down

0 comments on commit 8aad2a0

Please sign in to comment.