summaryrefslogtreecommitdiffstats
path: root/ansible_collections/azure/azcollection/plugins/modules/azure_rm_apimanagement.py
blob: 4e7e359bbcc8293f96e67e3b361405605b8a6a25 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
#!/usr/bin/python
#
# Copyright (c) 2020 Sakar Mehra (@sakar97), Nikhil Patne (@nikhilpatne)
#
# 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


DOCUMENTATION = '''
---
module: azure_rm_apimanagement
version_added: "1.6.0"
short_description: Manage Azure api instances
description:
    - Create azure api instance.
    - Update the existing azure api instance.
    - Delete azure api instance.

options:
    resource_group:
        description:
          - The name of the resource group.
        required: true
        type: str
    service_name:
        description:
            - The name of the API Management service.
        required: true
        type: str
    api_id:
        description:
            - API revision identifier. It must be unique in the current API Management service instance.
        required: true
        type: str
    description:
        description:
            - Description of the API.
        type: str
    authentication_settings:
        description:
            - Collection of authentication settings included into this API.
        type: dict
        suboptions:
            o_auth2:
                description:
                    - OAuth2 Authentication settings
                type: dict
                suboptions:
                    authorization_server_id:
                        description:
                            - OAuth authorization server identifier.
                        type: str
                    scope:
                        description:
                            - operations scope.
                        type: str
            openid:
                description:
                    - OpenID Connect Authentication Settings
                type: dict
                suboptions:
                    openid_provider_id:
                        description:
                            - OAuth authorization server identifier.
                        type: str
                    bearer_token_sending_methods:
                        description:
                            - How to send token to the server.
                        type: list
                        elements: str
                        choices:
                            - authorizationHeader
                            - query
    subscription_key_parameter_names:
        description:
            - Protocols over which API is made available.
        type: dict
        suboptions:
            header:
                description:
                    - Subscription key header name.
                type: str
            query:
                description:
                    - Subscription key query string parameter name.
                type: str
    type:
        description:
            - Type of API
        type: str
        choices:
            - http
            - soap
    api_revision:
        description:
            - Describes the Revision of the Api.
            - If no value is provided, default revision 1 is created
        type: str
    api_version:
        description:
            - Indicates the Version identifier of the API if the API is versioned
        type: str
    is_current:
        description:
            - Indicates if API revision is current api revision.
        type: bool
    api_revision_description:
        description:
            - Description of the Api Revision.
        type: str
    api_version_description:
        description:
            - Description of the Api Version.
        type: str
    api_version_set_id:
        description:
            - A resource identifier for the related ApiVersionSet.
        type: str
    subscription_required:
        description:
            - Specifies whether an API or Product subscription is required for accessing the API.
        type: bool
    source_api_id:
        description:
            - API identifier of the source API.
        type: str
    display_name:
        description:
            - API Name to be displayed. It must be 1 to 300 characters long.
        type: str
    service_url:
        description:
            - Absolute URL of the backend service implementing this API
            - Cannot be more than 2000 characters long.
        type: str
    path:
        description:
            - Relative URL uniquely identifying this API.
        type: str
    protocols:
        description:
            - Describes on which protocols the operations in this API can be invoked.
        type: list
        elements: str
        choices:
            - http
            - https
    api_version_set:
        description:
            - Version set details
        type: dict
        suboptions:
            id:
                description:
                    - Identifier for existing API Version Set
                    - Omit this value to create a new Version Set.
                type: str
            name:
                description:
                    - The display Name of the API Version Set.
                type: str
            description:
                description:
                    - Description of API Version Set.
                type: str
            versioning_scheme:
                description:
                    - An value that determines where the API Version identifer will be located in a HTTP request.
                type: str
                choices:
                    - Segment
                    - Query
                    - Header
            version_query_name:
                description:
                    - Name of query parameter that indicates the API Version if versioningScheme is set to `query`.
                type: str
            version_header_name:
                description:
                    - Name of HTTP header parameter that indicates the API Version if versioningScheme is set to `header`.
                type: str
    value:
        description:
            - Content value when Importing an API.
        type: str
    format:
        description:
            - Format of the Content in which the API is getting imported.
        type: str
        choices:
            - wadl-xml
            - wadl-link-json
            - swagger-json
            - swagger-link-json
            - wsdl
            - wsdl-link
            - openapi
            - openapi+json
            - openapi-link
    wsdl_selector:
        description:
            - Criteria to limit import of WSDL to a subset of the document.
        type: dict
        suboptions:
            wsdl_service_name:
                description:
                    - Name of service to import from WSDL.
                type: str
            wsdl_endpoint_name:
                description:
                    - Name of endpoint(port) to import from WSDL.
                type: str
    api_type:
        description:
            - Type of Api to create.
            - C(http) creates a SOAP to REST API.
            - C(soap) creates a SOAP pass-through API.
        type: str
        choices:
            - soap
            - http
    state:
        description:
            - State of the Api.
            - Use C(present) to create or update an Api and C(absent) to delete it.
        type: str
        default: present
        choices:
            - absent
            - present

extends_documentation_fragment:
    - azure.azcollection.azure
    - azure.azcollection.azure_tags

author:
    - Sakar Mehra (@sakar97)
    - Nikhil Patne (@nikhilpatne)

'''

EXAMPLES = '''
- name: Create a new API instance
  azure_rm_apimanagement:
    resource_group: 'myResourceGroup'
    service_name: myService
    api_id: testApi
    description: testDescription
    display_name: TestAPI
    service_url: 'http://testapi.example.net/api'
    path: myapiPath
    protocols:
      - https
- name: Update an existing API instance.
  azure_rm_apimanagement:
    resource_group: myResourceGroup
    service_name: myService
    api_id: testApi
    display_name: newTestAPI
    service_url: 'http://testapi.example.net/api'
    path: myapiPath
    protocols:
      - https
- name: ApiManagementDeleteApi
  azure_rm_apimanagement:
    resource_group: myResourceGroup
    service_name: myService
    api_id: testApi
    state: absent
'''

RETURN = \
    '''
id:
    description:
        - Resource ID.
    returned: always
    type: str
    sample: null
'''

from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_rest import GenericRestClient
from ansible_collections.azure.azcollection.plugins.module_utils.azure_rm_common_ext import AzureRMModuleBaseExt
import json


class Actions:
    NoAction, Create, Update, Delete = range(4)


class AzureApiManagement(AzureRMModuleBaseExt):
    def __init__(self):
        self.module_arg_spec = dict(
            resource_group=dict(
                type='str',
                required=True
            ),
            service_name=dict(
                type='str',
                required=True
            ),
            api_id=dict(
                type='str',
                required=True
            ),
            description=dict(
                type='str',
            ),
            authentication_settings=dict(
                type='dict',
                options=dict(
                    o_auth2=dict(
                        type='dict',
                        options=dict(
                            authorization_server_id=dict(
                                type='str',
                            ),
                            scope=dict(
                                type='str',
                            )
                        )
                    ),
                    openid=dict(
                        type='dict',
                        options=dict(
                            openid_provider_id=dict(
                                type='str',
                            ),
                            bearer_token_sending_methods=dict(
                                type='list',
                                elements='str',
                                choices=['authorizationHeader', 'query']
                            )
                        )
                    )
                )
            ),
            subscription_key_parameter_names=dict(
                type='dict',
                no_log=True,
                options=dict(
                    header=dict(
                        type='str',
                        required=False
                    ),
                    query=dict(
                        type='str',
                        required=False
                    )
                )
            ),
            type=dict(
                type='str',
                choices=['http', 'soap']
            ),
            api_revision=dict(
                type='str',
            ),
            api_version=dict(
                type='str',
            ),
            is_current=dict(
                type='bool',
            ),
            api_revision_description=dict(
                type='str',
            ),
            api_version_description=dict(
                type='str',
            ),
            api_version_set_id=dict(
                type='str',
            ),
            subscription_required=dict(
                type='bool',
            ),
            source_api_id=dict(
                type='str',
            ),
            display_name=dict(
                type='str',
            ),
            service_url=dict(
                type='str',
            ),
            path=dict(
                type='str',
            ),
            protocols=dict(
                type='list',
                elements='str',
                choices=['http',
                         'https']
            ),
            api_version_set=dict(
                type='dict',
                options=dict(
                    id=dict(
                        type='str'
                    ),
                    name=dict(
                        type='str'
                    ),
                    description=dict(
                        type='str'
                    ),
                    versioning_scheme=dict(
                        type='str',
                        choices=['Segment',
                                 'Query',
                                 'Header']
                    ),
                    version_query_name=dict(
                        type='str',
                    ),
                    version_header_name=dict(
                        type='str',
                    )
                )
            ),
            value=dict(
                type='str',
            ),
            format=dict(
                type='str',
                choices=['wadl-xml',
                         'wadl-link-json',
                         'swagger-json',
                         'swagger-link-json',
                         'wsdl',
                         'wsdl-link',
                         'openapi',
                         'openapi+json',
                         'openapi-link']
            ),
            wsdl_selector=dict(
                type='dict',
                options=dict(
                    wsdl_service_name=dict(
                        type='str',
                    ),
                    wsdl_endpoint_name=dict(
                        type='str',
                    )
                )
            ),
            api_type=dict(
                type='str',
                choices=['http', 'soap']
            ),
            state=dict(
                type='str',
                default='present',
                choices=['present', 'absent']
            )
        )

        self.resource_group = None
        self.service_name = None
        self.api_id = None

        self.results = dict(changed=False)
        self.mgmt_client = None
        self.state = None
        self.url = None
        self.status_code = [200, 201, 202]
        self.to_do = Actions.NoAction

        self.body = {}
        self.body['properties'] = {}
        self.query_parameters = {}
        self.query_parameters['api-version'] = '2022-08-01'
        self.header_parameters = {}
        self.header_parameters['Content-Type'] = 'application/json; charset=utf-8'

        super(AzureApiManagement, self).__init__(derived_arg_spec=self.module_arg_spec,
                                                 supports_check_mode=True,
                                                 supports_tags=True)

    def get_url(self):
        return '/subscriptions' + '/' + self.subscription_id \
               + '/resourceGroups' + '/' + self.resource_group \
               + '/providers' + '/Microsoft.ApiManagement' + '/service' \
               + '/' + self.service_name + '/apis' + '/' + self.api_id

    def exec_module(self, **kwargs):
        for key in list(self.module_arg_spec.keys()):
            if hasattr(self, key):
                setattr(self, key, kwargs[key])
            elif kwargs[key] is not None:
                if key == 'description':
                    self.body['properties']['description'] = kwargs[key]
                elif key == 'authentication_settings':
                    self.body['properties']['authenticationSettings'] = {}
                    if kwargs[key].get('o_auth2') is not None:
                        self.body['properties']['authenticationSettings']['oAuth2'] = {}
                        for item in kwargs[key]['o_auth2'].keys():
                            if item == 'authorization_server_id':
                                authorization_id = kwargs[key]['o_auth2']['authorization_server_id']
                                self.body['properties']['authenticationSettings']['oAuth2']['authorizationServerId'] = authorization_id
                            elif item == 'scope':
                                self.body['properties']['authenticationSettings']['oAuth2']['scope'] = kwargs[key]['o_auth2']['scope']
                    elif kwargs[key].get('openid') is not None:
                        self.body['properties']['authenticationSettings']['openid'] = {}
                        for item in kwargs[key]['openid'].keys():
                            if item == 'openid_provider_id' and kwargs[key]['openid'].get('openid_provider_id') is not None:
                                openid_pro = kwargs[key]['openid'].get('openid_provider_id')
                                self.body['properties']['authenticationSettings']['openid']['openidProviderId'] = openid_pro
                            elif item == 'bearer_token_sending_methods' and kwargs[key]['openid'].get('bearer_token_sending_methods') is not None:
                                bearer_token = kwargs[key]['openid']['bearer_token_sending_methods']
                                self.body['properties']['authenticationSettings']['openid']['bearerTokenSendingMethods'] = bearer_token
                elif key == 'subscription_key_parameter_names':
                    self.body['properties']['subscriptionKeyParameterNames'] = kwargs[key]
                elif key == 'type':
                    self.body['properties']['type'] = kwargs[key]
                elif key == 'api_revision':
                    self.body['properties']['apiRevision'] = kwargs[key]
                elif key == 'api_version':
                    self.body['properties']['apiVersion'] = kwargs[key]
                elif key == 'is_current':
                    self.body['properties']['isCurrent'] = kwargs[key]
                elif key == 'api_revision_description':
                    self.body['properties']['apiRevisionDescription'] = kwargs[key]
                elif key == 'api_version_description':
                    self.body['properties']['apiVersionDescription'] = kwargs[key]
                elif key == 'api_version_set_id':
                    self.body['properties']['apiVersionSetId'] = kwargs[key]
                elif key == 'subscription_required':
                    self.body['properties']['subscriptionRequired'] = kwargs[key]
                elif key == 'source_api_id':
                    self.body['properties']['sourceApiId'] = kwargs[key]
                elif key == 'display_name':
                    self.body['properties']['displayName'] = kwargs[key]
                elif key == 'service_url':
                    self.body['properties']['serviceUrl'] = kwargs[key]
                elif key == 'protocols':
                    self.body['properties']['protocols'] = kwargs[key]
                elif key == 'api_version_set':
                    self.body['properties']['apiVersionSet'] = {}
                    for item in kwargs[key].keys():
                        if item == 'versioning_scheme':
                            self.body['properties']['apiVersionSet'] = kwargs[key].get('versioning_scheme')
                        elif item == 'version_query_name':
                            self.body['properties']['versionQueryName'] = kwargs[key].get('version_query_name')
                        elif item == 'version_header_name':
                            self.body['properties']['versionHeaderName'] = kwargs[key].get('version_header_name')
                        else:
                            self.body['properties'][item] = kwargs[key].get(item)
                elif key == 'wsdl_selector':
                    self.body['properties']['wsdlSelector'] = {}
                    for item in kwargs[key].keys():
                        if item == 'wsdl_service_name':
                            self.body['properties']['wsdlSelector']['wsdlServiceName'] = kwargs[key].get(item)
                        if item == 'wsdl_endpoint_name':
                            self.body['properties']['wsdlSelector']['wsdlEndpointName'] = kwargs[key].get(item)
                elif key == 'api_type':
                    self.body['properties']['apiType'] = kwargs[key]
                else:
                    self.body['properties'][key] = kwargs[key]

        self.url = self.get_url()
        old_response = None
        response = None

        self.mgmt_client = self.get_mgmt_svc_client(GenericRestClient,
                                                    base_url=self._cloud_environment.endpoints.resource_manager)

        old_response = self.get_resource()

        if not old_response:
            self.log("Api instance does not exist in the given service.")
            if self.state == 'present':
                self.to_do = Actions.Create
            else:
                self.log("Old instance didn't exist")
        else:
            self.log("Api instance already exists in the given service.")
            if self.state == 'absent':
                self.to_do = Actions.Delete
            else:
                if self.body['properties'].get('description') is not None and \
                   self.body['properties']['description'] != old_response['properties']['description']:
                    self.to_do = Actions.Update
                elif self.body['properties'].get('authenticationSettings') is not None:
                    if old_response['properties'].get('authenticationSettings') is None:
                        self.to_do = Actions.Update
                    elif (self.body['properties']['authenticationSettings'].get('oAuth2') is not None and
                          self.body['properties']['authenticationSettings']['oAuth2'] != old_response['properties']['authenticationSettings'].get('oAuth2')):
                        self.to_do = Actions.Update
                    elif (self.body['properties']['authenticationSettings'].get('openid') is not None and
                          self.body['properties']['authenticationSettings']['openid'] != old_response['properties']['authenticationSettings'].get('openid')):
                        self.to_do = Actions.Update
                elif self.body['properties'].get('subscriptionKeyParameterNames') is not None:
                    tt = old_response['properties']
                    if old_response['properties'].get('subscriptionKeyParameterNames') is None:
                        self.to_do = Actions.Update
                    elif (not all(self.body['properties']['subscriptionKeyParameterNames'].get(item) == tt['subscriptionKeyParameterNames'].get(item)
                          for item in self.body['properties']['subscriptionKeyParameterNames'].keys())):
                        self.to_do = Actions.Update
                elif (self.body['properties'].get('apiRevision') is not None and
                      self.body['properties']['apiRevision'] != old_response['properties'].get('apiRevision')):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('apiVersion') is not None and
                      self.body['properties']['apiVersion'] != old_response['properties'].get('apiVersion')):
                    self.to_do == Actions.Update
                elif (self.body['properties'].get('isCurrent') is not None and
                      self.body['properties']['isCurrent'] != old_response['properties'].get('isCurrent')):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('apiRevisionDescription') is not None and self.body['properties']['apiRevisionDescription'] !=
                      old_response['properties'].get('apiRevisionDescription')):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('apiVersionDescription') is not None and
                      self.body['properties']['apiVersionDescription'] != old_response['properties'].get('apiVersionDescription')):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('apiVersionSetId') is not None and
                      self.body['properties']['apiVersionSetId'] != old_response['properties'].get('apiVersionSetId')):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('subscriptionRequired') is not None and
                      self.body['properties']['subscriptionRequired'] != old_response['properties'].get('subscriptionRequired')):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('sourceApiId') is not None and
                      self.body['properties']['sourceApiId'] != old_response['properties'].get('sourceApiId')):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('displayName') is not None and
                      self.body['properties']['displayName'] != old_response['properties'].get('displayName')):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('serviceUrl') is not None and
                      self.body['properties']['serviceUrl'] != old_response['properties'].get('serviceUrl')):
                    self.to_do = Actions.Update
                elif self.body['properties'].get('path') is not None and self.body['properties']['path'] != old_response['properties'].get('path'):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('protocols') is not None and
                      self.body['properties']['protocols'] != old_response['properties'].get('protocols')):
                    self.to_do = Actions.Update
                elif self.body['properties'].get('type') is not None and self.body['properties']['type'] != old_response['properties'].get('type'):
                    self.to_do = Actions.Update
                elif self.body['properties'].get('apiType') is not None and self.body['properties']['apiType'] != old_response['properties'].get('apiType'):
                    self.to_do = Actions.Update
                elif self.body['properties'].get('value') is not None and self.body['properties']['value'] != old_response['properties'].get('value'):
                    self.to_do = Actions.Update
                elif self.body['properties'].get('format') is not None and self.body['properties']['format'] != old_response['properties'].get('format'):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('wsdlSelector') is not None and
                      not all(self.body['properties']['wsdlSelector'][item] == old_response['properties']['wsdlSelector'].get(item)
                      for item in self.body['properties']['wsdlSelector'].keys())):
                    self.to_do = Actions.Update
                elif (self.body['properties'].get('apiVersionSet') is not None and
                      not all(self.body['properties']['apiVersionSet'][item] == old_response['properties']['apiVersionSet'].get(item)
                      for item in self.body['properties']['apiVersionSet'].keys())):
                    self.to_do = Actions.Update

        if (self.to_do == Actions.Create) or (self.to_do == Actions.Update):
            self.log('Create and Update the Api instance.')

            if self.check_mode:
                self.results['changed'] = True
                return self.results

            response = self.create_and_update_resource()
            self.results['changed'] = True

        elif self.to_do == Actions.Delete:
            self.log('Api instance deleted.')

            if self.check_mode:
                self.results['changed'] = True
                return self.results

            self.delete_resource()
            self.results['changed'] = True
        else:
            self.log('No change in Api instance.')
            self.results['changed'] = False
            response = old_response

        if response:
            self.results["id"] = response["id"]

        return self.results

    # This function will create and update resource on the api management service.
    def create_and_update_resource(self):

        try:
            response = self.mgmt_client.query(
                self.url,
                'PUT',
                self.query_parameters,
                self.header_parameters,
                self.body,
                self.status_code,
                600,
                30,
            )
        except Exception as exc:
            self.log('Error while creating/updating the Api instance.')
            self.fail('Error creating the Api instance: {0}'.format(str(exc)))
        if hasattr(response, 'body'):
            response = json.loads(response.body())
        elif hasattr(response, 'context'):
            response = response.context['deserialized_data']
        else:
            self.fail("Create or Updating fail, no match message return, return info as {0}".format(response))

        return response

    def delete_resource(self):
        isDeleted = False
        try:
            response = self.mgmt_client.query(
                self.url,
                'DELETE',
                self.query_parameters,
                self.header_parameters,
                None,
                self.status_code,
                600,
                30,
            )
            isDeleted = True
        except Exception as e:
            self.log('Error attempting to delete the Api instance.')
            self.fail('Error deleting the Api instance: {0}'.format(str(e)))

        return isDeleted

    def get_resource(self):
        isFound = False
        try:
            response = self.mgmt_client.query(
                self.url,
                'GET',
                self.query_parameters,
                self.header_parameters,
                None,
                self.status_code,
                600,
                30,
            )
            isFound = True
            response = json.loads(response.body())
            self.log("Response : {0}".format(response))
        except Exception as e:
            self.log('Could not find the Api instance from the given parameters.')
        if isFound is True:
            return response
        return False


def main():
    AzureApiManagement()


if __name__ == '__main__':
    main()