| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
from __future__ import absolute_import, division, print_function |
| 8 |
__metaclass__ = type |
| 9 |
|
| 10 |
|
| 11 |
DOCUMENTATION = ''' |
| 12 |
--- |
| 13 |
module: azure_rm_webappaccessrestriction_info |
| 14 |
version_added: "1.8.0" |
| 15 |
short_description: Retrieve web app network access restriction facts |
| 16 |
description: |
| 17 |
- Get facts for a web app's network access restrictions. |
| 18 |
options: |
| 19 |
name: |
| 20 |
description: |
| 21 |
- Name of the web app. |
| 22 |
required: true |
| 23 |
type: str |
| 24 |
resource_group: |
| 25 |
description: |
| 26 |
- Resource group of the web app. |
| 27 |
required: true |
| 28 |
type: str |
| 29 |
|
| 30 |
extends_documentation_fragment: |
| 31 |
- azure.azcollection.azure |
| 32 |
|
| 33 |
author: |
| 34 |
- Ross Bender (@l3ender) |
| 35 |
''' |
| 36 |
|
| 37 |
EXAMPLES = ''' |
| 38 |
- name: View web app access restrictions. |
| 39 |
azure.azcollection.azure_rm_webappaccessrestriction_info: |
| 40 |
name: "MyWebapp" |
| 41 |
resource_group: "MyResourceGroup" |
| 42 |
''' |
| 43 |
|
| 44 |
RETURN = ''' |
| 45 |
ip_security_restrictions: |
| 46 |
description: |
| 47 |
- The web app's HTTP access restrictions. |
| 48 |
returned: always |
| 49 |
type: list |
| 50 |
elements: dict |
| 51 |
contains: |
| 52 |
name: |
| 53 |
description: |
| 54 |
- Name of the access restriction. |
| 55 |
returned: always |
| 56 |
type: str |
| 57 |
sample: my-access-restriction |
| 58 |
description: |
| 59 |
description: |
| 60 |
- Description of the access restriction. |
| 61 |
returned: always |
| 62 |
type: str |
| 63 |
sample: my-access-restriction-description |
| 64 |
action: |
| 65 |
description: |
| 66 |
- Traffic action of the access restriction. |
| 67 |
returned: always |
| 68 |
type: str |
| 69 |
sample: Allow |
| 70 |
priority: |
| 71 |
description: |
| 72 |
- Numerical priority of the access restriction. |
| 73 |
returned: always |
| 74 |
type: int |
| 75 |
sample: 1 |
| 76 |
ip_address: |
| 77 |
description: |
| 78 |
- IP address of the access restriction. |
| 79 |
returned: always |
| 80 |
type: str |
| 81 |
sample: 1.1.1.1/32 |
| 82 |
subnet_traffic_tag: |
| 83 |
description: |
| 84 |
- (internal) Subnet traffic tags. |
| 85 |
type: int |
| 86 |
returned: always |
| 87 |
sample: int |
| 88 |
vnet_traffic_tag: |
| 89 |
description: |
| 90 |
- (internal) Vnet traffic tag. |
| 91 |
type: int |
| 92 |
returned: always |
| 93 |
sample: 3 |
| 94 |
tags: |
| 95 |
description: |
| 96 |
- IP restriction rule description. |
| 97 |
type: str |
| 98 |
returned: always |
| 99 |
sample: default |
| 100 |
vnet_subnet_resource_id: |
| 101 |
description: |
| 102 |
- The Virtual network relaste subnet resource id. |
| 103 |
type: str |
| 104 |
returned: always |
| 105 |
sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Network/virtualNetworks/vnet01/subnets/subnet01" |
| 106 |
scm_ip_security_restrictions: |
| 107 |
description: |
| 108 |
- The web app's SCM access restrictions. |
| 109 |
returned: always |
| 110 |
type: list |
| 111 |
elements: dict |
| 112 |
contains: |
| 113 |
name: |
| 114 |
description: |
| 115 |
- Name of the access restriction. |
| 116 |
returned: always |
| 117 |
type: str |
| 118 |
sample: my-access-restriction |
| 119 |
description: |
| 120 |
description: |
| 121 |
- Description of the access restriction. |
| 122 |
returned: always |
| 123 |
type: str |
| 124 |
sample: my-access-restriction-description |
| 125 |
action: |
| 126 |
description: |
| 127 |
- Traffic action of the access restriction. |
| 128 |
returned: always |
| 129 |
type: str |
| 130 |
sample: Allow |
| 131 |
priority: |
| 132 |
description: |
| 133 |
- Numerical priority of the access restriction. |
| 134 |
returned: always |
| 135 |
type: int |
| 136 |
sample: 1 |
| 137 |
ip_address: |
| 138 |
description: |
| 139 |
- IP address of the access restriction. |
| 140 |
returned: always |
| 141 |
type: str |
| 142 |
sample: 1.1.1.1/32 |
| 143 |
subnet_traffic_tag: |
| 144 |
description: |
| 145 |
- (internal) Subnet traffic tags. |
| 146 |
type: int |
| 147 |
returned: always |
| 148 |
sample: int |
| 149 |
vnet_traffic_tag: |
| 150 |
description: |
| 151 |
- (internal) Vnet traffic tag. |
| 152 |
type: int |
| 153 |
returned: always |
| 154 |
sample: 3 |
| 155 |
tag: |
| 156 |
description: |
| 157 |
- IP restriction rule description. |
| 158 |
type: str |
| 159 |
returned: always |
| 160 |
sample: default |
| 161 |
vnet_subnet_resource_id: |
| 162 |
description: |
| 163 |
- The Virtual network relaste subnet resource id. |
| 164 |
type: str |
| 165 |
returned: always |
| 166 |
sample: "/subscriptions/xxx-xxx/resourceGroups/testRG/providers/Microsoft.Network/virtualNetworks/vnet01/subnets/subnet01" |
| 167 |
scm_ip_security_restrictions_use_main: |
| 168 |
description: |
| 169 |
- Whether the HTTP access restrictions are used for SCM access. |
| 170 |
returned: always |
| 171 |
type: bool |
| 172 |
sample: false |
| 173 |
''' |
| 174 |
|
| 175 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 176 |
|
| 177 |
|
| 178 |
class AzureRMWebAppAccessRestrictionInfo(AzureRMModuleBase): |
| 179 |
|
| 180 |
def __init__(self): |
| 181 |
|
| 182 |
self.module_arg_spec = dict( |
| 183 |
name=dict(type='str', required=True), |
| 184 |
resource_group=dict(type='str', required=True), |
| 185 |
) |
| 186 |
|
| 187 |
self.results = dict( |
| 188 |
changed=False, |
| 189 |
ip_security_restrictions=[], |
| 190 |
scm_ip_security_restrictions=[], |
| 191 |
scm_ip_security_restrictions_use_main=False, |
| 192 |
) |
| 193 |
|
| 194 |
self.name = None |
| 195 |
self.resource_group = None |
| 196 |
|
| 197 |
super(AzureRMWebAppAccessRestrictionInfo, self).__init__(self.module_arg_spec, |
| 198 |
supports_check_mode=True, |
| 199 |
supports_tags=False, |
| 200 |
facts_module=True) |
| 201 |
|
| 202 |
def exec_module(self, **kwargs): |
| 203 |
for key in self.module_arg_spec: |
| 204 |
setattr(self, key, kwargs[key]) |
| 205 |
|
| 206 |
site_config = self.get_webapp_config() |
| 207 |
self.results.update(self.set_results(site_config)) |
| 208 |
|
| 209 |
return self.results |
| 210 |
|
| 211 |
def get_webapp_config(self): |
| 212 |
try: |
| 213 |
return self.web_client.web_apps.get_configuration(resource_group_name=self.resource_group, name=self.name) |
| 214 |
except Exception as exc: |
| 215 |
self.fail("Error getting webapp config {0} (rg={1}) - {2}".format(self.name, self.resource_group, str(exc))) |
| 216 |
|
| 217 |
def set_results(self, site_config): |
| 218 |
output = dict() |
| 219 |
if site_config.ip_security_restrictions: |
| 220 |
output['ip_security_restrictions'] = self.to_restriction_dict_list(site_config.ip_security_restrictions) |
| 221 |
if site_config.scm_ip_security_restrictions: |
| 222 |
output['scm_ip_security_restrictions'] = self.to_restriction_dict_list(site_config.scm_ip_security_restrictions) |
| 223 |
output['scm_ip_security_restrictions_use_main'] = site_config.scm_ip_security_restrictions_use_main |
| 224 |
return output |
| 225 |
|
| 226 |
def to_restriction_dict_list(self, restriction_obj_list): |
| 227 |
restrictions = [] |
| 228 |
if restriction_obj_list: |
| 229 |
for r in restriction_obj_list: |
| 230 |
restriction = self.to_restriction_dict(r) |
| 231 |
if not self.is_azure_default_restriction(restriction): |
| 232 |
restrictions.append(restriction) |
| 233 |
|
| 234 |
return restrictions |
| 235 |
|
| 236 |
def is_azure_default_restriction(self, restriction_obj): |
| 237 |
return (restriction_obj["action"] == "Allow" and restriction_obj["ip_address"] == "Any" and restriction_obj["priority"] == 1) or \ |
| 238 |
(restriction_obj["action"] == "Deny" and restriction_obj["ip_address"] == "Any" and restriction_obj["priority"] == 2147483647) |
| 239 |
|
| 240 |
def to_restriction_dict(self, restriction_obj): |
| 241 |
return dict( |
| 242 |
name=restriction_obj.name, |
| 243 |
description=restriction_obj.description, |
| 244 |
action=restriction_obj.action, |
| 245 |
priority=restriction_obj.priority, |
| 246 |
ip_address=restriction_obj.ip_address, |
| 247 |
vnet_subnet_resource_id=restriction_obj.vnet_subnet_resource_id, |
| 248 |
vnet_traffic_tag=restriction_obj.vnet_traffic_tag, |
| 249 |
subnet_traffic_tag=restriction_obj.subnet_traffic_tag, |
| 250 |
tag=restriction_obj.tag, |
| 251 |
) |
| 252 |
|
| 253 |
|
| 254 |
def main(): |
| 255 |
AzureRMWebAppAccessRestrictionInfo() |
| 256 |
|
| 257 |
|
| 258 |
if __name__ == '__main__': |
| 259 |
main() |