| 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_containerregistrywebhook_info |
| 14 |
version_added: "0.1.2" |
| 15 |
short_description: Get Webhook facts. |
| 16 |
description: |
| 17 |
- Get facts of Webhook. |
| 18 |
|
| 19 |
options: |
| 20 |
resource_group: |
| 21 |
description: |
| 22 |
- The name of the resource group to which the container registry belongs. |
| 23 |
required: True |
| 24 |
type: str |
| 25 |
registry_name: |
| 26 |
description: |
| 27 |
- The name of the container registry. |
| 28 |
required: True |
| 29 |
type: str |
| 30 |
webhook_name: |
| 31 |
description: |
| 32 |
- The name of the webhook. |
| 33 |
required: True |
| 34 |
type: str |
| 35 |
|
| 36 |
extends_documentation_fragment: |
| 37 |
- azure.azcollection.azure |
| 38 |
|
| 39 |
author: |
| 40 |
- "Zim Kalinowski (@zikalino)" |
| 41 |
|
| 42 |
''' |
| 43 |
|
| 44 |
EXAMPLES = ''' |
| 45 |
- name: Get instance of Webhook |
| 46 |
azure_rm_containerregistrywebhook_info: |
| 47 |
resource_group: resource_group_name |
| 48 |
registry_name: registry_name |
| 49 |
webhook_name: webhook_name |
| 50 |
''' |
| 51 |
|
| 52 |
RETURN = ''' |
| 53 |
webhooks: |
| 54 |
description: A list of dict results where the key is the name of the Webhook and the values are the facts for that Webhook. |
| 55 |
returned: always |
| 56 |
type: complex |
| 57 |
contains: |
| 58 |
webhook_name: |
| 59 |
description: The key is the name of the server that the values relate to. |
| 60 |
type: complex |
| 61 |
contains: |
| 62 |
id: |
| 63 |
description: |
| 64 |
- The resource ID. |
| 65 |
returned: always |
| 66 |
type: str |
| 67 |
sample: "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/myResourceGroup/providers/Microsoft.ContainerRegistry/registr |
| 68 |
ies/myRegistry/webhooks/myWebhook" |
| 69 |
name: |
| 70 |
description: |
| 71 |
- The name of the resource. |
| 72 |
returned: always |
| 73 |
type: str |
| 74 |
sample: myWebhook |
| 75 |
type: |
| 76 |
description: |
| 77 |
- The type of the resource. |
| 78 |
returned: always |
| 79 |
type: str |
| 80 |
sample: Microsoft.ContainerRegistry/registries/webhooks |
| 81 |
location: |
| 82 |
description: |
| 83 |
- The location of the resource. This cannot be changed after the resource is created. |
| 84 |
returned: always |
| 85 |
type: str |
| 86 |
sample: westus |
| 87 |
status: |
| 88 |
description: |
| 89 |
- "The status of the webhook at the time the operation was called. Possible values include: 'enabled', 'disabled'" |
| 90 |
returned: always |
| 91 |
type: str |
| 92 |
sample: enabled |
| 93 |
scope: |
| 94 |
description: |
| 95 |
- "The scope of repositories where the event can be triggered. For example, 'foo:*' means events for all tags under repository 'foo'. |
| 96 |
'foo:bar' means events for 'foo:bar' only. 'foo' is equivalent to 'foo:latest'. Empty means all events." |
| 97 |
returned: always |
| 98 |
type: str |
| 99 |
sample: myRepository |
| 100 |
actions: |
| 101 |
description: |
| 102 |
- The list of actions that trigger the webhook to post notifications. |
| 103 |
returned: always |
| 104 |
type: str |
| 105 |
sample: "[\n\n 'push'\n\n]" |
| 106 |
''' |
| 107 |
|
| 108 |
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common import AzureRMModuleBase |
| 109 |
|
| 110 |
try: |
| 111 |
from azure.core.exceptions import ResourceNotFoundError |
| 112 |
except ImportError: |
| 113 |
|
| 114 |
pass |
| 115 |
|
| 116 |
|
| 117 |
class AzureRMWebhooksFacts(AzureRMModuleBase): |
| 118 |
def __init__(self): |
| 119 |
|
| 120 |
self.module_arg_spec = dict( |
| 121 |
resource_group=dict( |
| 122 |
type='str', |
| 123 |
required=True |
| 124 |
), |
| 125 |
registry_name=dict( |
| 126 |
type='str', |
| 127 |
required=True |
| 128 |
), |
| 129 |
webhook_name=dict( |
| 130 |
type='str', |
| 131 |
required=True |
| 132 |
) |
| 133 |
) |
| 134 |
|
| 135 |
self.results = dict( |
| 136 |
changed=False, |
| 137 |
ansible_facts=dict() |
| 138 |
) |
| 139 |
self.resource_group = None |
| 140 |
self.registry_name = None |
| 141 |
self.webhook_name = None |
| 142 |
super(AzureRMWebhooksFacts, self).__init__(self.module_arg_spec, supports_tags=False, supports_check_mode=True) |
| 143 |
|
| 144 |
def exec_module(self, **kwargs): |
| 145 |
for key in self.module_arg_spec: |
| 146 |
setattr(self, key, kwargs[key]) |
| 147 |
|
| 148 |
if (self.resource_group is not None and |
| 149 |
self.registry_name is not None and |
| 150 |
self.webhook_name is not None): |
| 151 |
self.results['webhooks'] = self.get() |
| 152 |
return self.results |
| 153 |
|
| 154 |
def get(self): |
| 155 |
''' |
| 156 |
Gets facts of the specified Webhook. |
| 157 |
|
| 158 |
:return: deserialized Webhookinstance state dictionary |
| 159 |
''' |
| 160 |
response = None |
| 161 |
results = {} |
| 162 |
try: |
| 163 |
response = self.containerregistry_client.webhooks.get(resource_group_name=self.resource_group, |
| 164 |
registry_name=self.registry_name, |
| 165 |
webhook_name=self.webhook_name) |
| 166 |
self.log("Response : {0}".format(response)) |
| 167 |
except ResourceNotFoundError as e: |
| 168 |
self.log('Could not get facts for Webhooks: {0}'.format(str(e))) |
| 169 |
|
| 170 |
if response is not None: |
| 171 |
results[response.name] = response.as_dict() |
| 172 |
|
| 173 |
return results |
| 174 |
|
| 175 |
|
| 176 |
def main(): |
| 177 |
AzureRMWebhooksFacts() |
| 178 |
|
| 179 |
|
| 180 |
if __name__ == '__main__': |
| 181 |
main() |