22# Copyright (c) Microsoft Corporation. All rights reserved.
33# Licensed under the MIT License. See License.txt in the project root for license information.
44# --------------------------------------------------------------------------------------------
5+ # pylint: disable=line-too-long, super-with-arguments, too-many-instance-attributes, consider-using-f-string, no-else-return, no-self-use
6+
57import json
68import time
79import sys
810
9- from sys import api_version
1011from azure .cli .core .util import send_raw_request
1112from azure .cli .core .commands .client_factory import get_subscription_id
1213from knack .log import get_logger
1516
1617API_VERSION = "2021-03-01"
1718NEW_API_VERSION = "2022-01-01-preview"
18- POLLING_TIMEOUT = 60 # how many seconds before exiting
19- POLLING_SECONDS = 2 # how many seconds between requests
19+ POLLING_TIMEOUT = 60 # how many seconds before exiting
20+ POLLING_SECONDS = 2 # how many seconds between requests
2021
2122
2223class PollingAnimation ():
@@ -37,7 +38,7 @@ def flush(self):
3738 sys .stdout .write ("\033 [K" )
3839
3940
40- def poll (cmd , request_url , poll_if_status ):
41+ def poll (cmd , request_url , poll_if_status ): # pylint: disable=inconsistent-return-statements
4142 try :
4243 start = time .time ()
4344 end = time .time () + POLLING_TIMEOUT
@@ -53,19 +54,17 @@ def poll(cmd, request_url, poll_if_status):
5354 r = send_raw_request (cmd .cli_ctx , "GET" , request_url )
5455 r2 = r .json ()
5556
56- if not "properties" in r2 or not "provisioningState" in r2 ["properties" ] or not r2 ["properties" ]["provisioningState" ].lower () == poll_if_status :
57+ if "properties" not in r2 or "provisioningState" not in r2 ["properties" ] or not r2 ["properties" ]["provisioningState" ].lower () == poll_if_status :
5758 break
5859 start = time .time ()
5960
6061 animation .flush ()
6162 return r .json ()
62- except Exception as e :
63+ except Exception as e : # pylint: disable=broad-except
6364 animation .flush ()
6465
65- if poll_if_status == "scheduledfordelete" : # Catch "not found" errors if polling for delete
66- return
67-
68- raise e
66+ if not poll_if_status == "scheduledfordelete" : # Catch "not found" errors if polling for delete
67+ raise e
6968
7069
7170class ContainerAppClient ():
@@ -144,7 +143,6 @@ def delete(cls, cmd, resource_group_name, name):
144143
145144 if r .status_code == 202 :
146145 logger .warning ('Containerapp successfully deleted' )
147- return
148146
149147 @classmethod
150148 def show (cls , cmd , resource_group_name , name ):
@@ -222,7 +220,6 @@ def list_by_resource_group(cls, cmd, resource_group_name, formatter=lambda x: x)
222220
223221 @classmethod
224222 def list_secrets (cls , cmd , resource_group_name , name ):
225- secrets = []
226223
227224 management_hostname = cmd .cli_ctx .cloud .endpoints .resource_manager
228225 api_version = NEW_API_VERSION
@@ -338,6 +335,7 @@ def deactivate_revision(cls, cmd, resource_group_name, container_app_name, name)
338335 r = send_raw_request (cmd .cli_ctx , "POST" , request_url )
339336 return r .json ()
340337
338+
341339class ManagedEnvironmentClient ():
342340 @classmethod
343341 def create (cls , cmd , resource_group_name , name , managed_environment_envelope , no_wait = False ):
@@ -413,7 +411,7 @@ def delete(cls, cmd, resource_group_name, name, no_wait=False):
413411 r = send_raw_request (cmd .cli_ctx , "DELETE" , request_url )
414412
415413 if no_wait :
416- return # API doesn't return JSON (it returns no content)
414+ return # API doesn't return JSON (it returns no content)
417415 elif r .status_code in [200 , 201 , 202 , 204 ]:
418416 url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}?api-version={}"
419417 request_url = url_fmt .format (
@@ -506,6 +504,7 @@ def list_by_resource_group(cls, cmd, resource_group_name, formatter=lambda x: x)
506504
507505 return env_list
508506
507+
509508class GitHubActionClient ():
510509 @classmethod
511510 def create_or_update (cls , cmd , resource_group_name , name , github_action_envelope , headers , no_wait = False ):
@@ -552,7 +551,6 @@ def show(cls, cmd, resource_group_name, name):
552551 r = send_raw_request (cmd .cli_ctx , "GET" , request_url )
553552 return r .json ()
554553
555- #TODO
556554 @classmethod
557555 def delete (cls , cmd , resource_group_name , name , headers , no_wait = False ):
558556 management_hostname = cmd .cli_ctx .cloud .endpoints .resource_manager
@@ -569,7 +567,7 @@ def delete(cls, cmd, resource_group_name, name, headers, no_wait=False):
569567 r = send_raw_request (cmd .cli_ctx , "DELETE" , request_url , headers = headers )
570568
571569 if no_wait :
572- return # API doesn't return JSON (it returns no content)
570+ return # API doesn't return JSON (it returns no content)
573571 elif r .status_code in [200 , 201 , 202 , 204 ]:
574572 url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/containerApps/{}/sourcecontrols/current?api-version={}"
575573 request_url = url_fmt .format (
@@ -588,10 +586,10 @@ def delete(cls, cmd, resource_group_name, name, headers, no_wait=False):
588586 logger .warning ('Containerapp github action successfully deleted' )
589587 return
590588
589+
591590class DaprComponentClient ():
592591 @classmethod
593592 def create_or_update (cls , cmd , resource_group_name , environment_name , name , dapr_component_envelope , no_wait = False ):
594- #create_or_update.metadata = {'url': '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.App/managedEnvironments/{environmentName}/daprComponents/{name}'}
595593
596594 management_hostname = cmd .cli_ctx .cloud .endpoints .resource_manager
597595 api_version = NEW_API_VERSION
@@ -639,7 +637,7 @@ def delete(cls, cmd, resource_group_name, environment_name, name, no_wait=False)
639637 r = send_raw_request (cmd .cli_ctx , "DELETE" , request_url )
640638
641639 if no_wait :
642- return # API doesn't return JSON (it returns no content)
640+ return # API doesn't return JSON (it returns no content)
643641 elif r .status_code in [200 , 201 , 202 , 204 ]:
644642 url_fmt = "{}/subscriptions/{}/resourceGroups/{}/providers/Microsoft.App/managedEnvironments/{}/daprComponents/{}?api-version={}"
645643 request_url = url_fmt .format (
@@ -705,4 +703,3 @@ def list(cls, cmd, resource_group_name, environment_name, formatter=lambda x: x)
705703 app_list .append (formatted )
706704
707705 return app_list
708-
0 commit comments