Skip to content

Commit 5fe8e5f

Browse files
runefaHaroon Feisal
authored andcommitted
Fixed style issues, various bug fixes (Azure#27)
* Moved dapr arguments to env as a subgroup. * Added env variable options. * Changed revision mode set to revision set-mode. * Added env var options to revision copy. * Fixed revision copy bug related to env secret refs. * Changed registry and secret delete to remove. Added registry param helps. Removed replica from table output and added trafficWeight. * Updating warning text. * Updated warning text once more. * Made name optional for revision copy if from-revision flag is passed. * Fixed whitespace style issues. * Styled clients and utils to pass pylint. * Finished client.py pylint fixes. * Fixed pylint issues. * Fixed flake8 commands and custom. * Fixed flake issues in src. * Added license header to _sdk_models. * Added confirmation for containerapp delete. Co-authored-by: Haroon Feisal <[email protected]>
1 parent ddc07c0 commit 5fe8e5f

File tree

12 files changed

+383
-373
lines changed

12 files changed

+383
-373
lines changed

src/containerapp/azext_containerapp/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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=super-with-arguments
56

67
from azure.cli.core import AzCommandsLoader
78

@@ -16,7 +17,7 @@ def __init__(self, cli_ctx=None):
1617
operations_tmpl='azext_containerapp.custom#{}',
1718
client_factory=None)
1819
super(ContainerappCommandsLoader, self).__init__(cli_ctx=cli_ctx,
19-
custom_command_type=containerapp_custom)
20+
custom_command_type=containerapp_custom)
2021

2122
def load_command_table(self, args):
2223
from azext_containerapp.commands import load_command_table

src/containerapp/azext_containerapp/_client_factory.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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, consider-using-f-string
56

67
from azure.cli.core.commands.client_factory import get_mgmt_service_client
78
from azure.cli.core.profiles import ResourceType
@@ -13,7 +14,6 @@
1314
def ex_handler_factory(no_throw=False):
1415
def _polish_bad_errors(ex):
1516
import json
16-
from knack.util import CLIError
1717
try:
1818
content = json.loads(ex.response.content)
1919
if 'message' in content:
@@ -63,11 +63,13 @@ def cf_resource_groups(cli_ctx, subscription_id=None):
6363
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES,
6464
subscription_id=subscription_id).resource_groups
6565

66+
6667
def log_analytics_client_factory(cli_ctx):
6768
from azure.mgmt.loganalytics import LogAnalyticsManagementClient
6869

6970
return get_mgmt_service_client(cli_ctx, LogAnalyticsManagementClient).workspaces
7071

72+
7173
def log_analytics_shared_key_client_factory(cli_ctx):
7274
from azure.mgmt.loganalytics import LogAnalyticsManagementClient
7375

src/containerapp/azext_containerapp/_clients.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
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+
57
import json
68
import time
79
import sys
810

9-
from sys import api_version
1011
from azure.cli.core.util import send_raw_request
1112
from azure.cli.core.commands.client_factory import get_subscription_id
1213
from knack.log import get_logger
@@ -15,8 +16,8 @@
1516

1617
API_VERSION = "2021-03-01"
1718
NEW_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

2223
class 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

7170
class 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+
341339
class 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+
509508
class 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+
591590
class 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-

src/containerapp/azext_containerapp/_github_oauth.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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=consider-using-f-string
56

67
from azure.cli.core.azclierror import (ValidationError, CLIInternalError, UnclassifiedUserFault)
78
from knack.log import get_logger
@@ -22,6 +23,7 @@
2223
"workflow"
2324
]
2425

26+
2527
def get_github_access_token(cmd, scope_list=None): # pylint: disable=unused-argument
2628
if scope_list:
2729
for scope in scope_list:
@@ -81,6 +83,6 @@ def get_github_access_token(cmd, scope_list=None): # pylint: disable=unused-arg
8183
return parsed_confirmation_response['access_token'][0]
8284
except Exception as e:
8385
raise CLIInternalError(
84-
'Error: {}. Please try again, or retrieve personal access token from the Github website'.format(e))
86+
'Error: {}. Please try again, or retrieve personal access token from the Github website'.format(e)) from e
8587

86-
raise UnclassifiedUserFault('Activation did not happen in time. Please try again')
88+
raise UnclassifiedUserFault('Activation did not happen in time. Please try again')

src/containerapp/azext_containerapp/_help.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
examples:
152152
- name: Set a container app to single revision mode.
153153
text: |
154-
az containerapp revision set-mode -n MyContainerapp -g MyResourceGroup --mode Single
154+
az containerapp revision set-mode -n MyContainerapp -g MyResourceGroup --mode Single
155155
"""
156156

157157
helps['containerapp revision copy'] = """
@@ -368,7 +368,7 @@
368368
examples:
369369
- name: Show a container app's ingress traffic configuration.
370370
text: |
371-
az containerapp ingress traffic show -n MyContainerapp -g MyResourceGroup
371+
az containerapp ingress traffic show -n MyContainerapp -g MyResourceGroup
372372
"""
373373

374374
# Registry Commands
@@ -392,7 +392,7 @@
392392
examples:
393393
- name: List container registries configured in a container app.
394394
text: |
395-
az containerapp registry list -n MyContainerapp -g MyResourceGroup
395+
az containerapp registry list -n MyContainerapp -g MyResourceGroup
396396
"""
397397

398398
helps['containerapp registry set'] = """
@@ -403,7 +403,6 @@
403403
text: |
404404
az containerapp registry set -n MyContainerapp -g MyResourceGroup \\
405405
--server MyExistingContainerappRegistry.azurecr.io --username MyRegistryUsername --password MyRegistryPassword
406-
407406
"""
408407

409408
helps['containerapp registry remove'] = """
@@ -454,10 +453,10 @@
454453
examples:
455454
- name: Add secrets to a container app.
456455
text: |
457-
az containerapp secret set -n MyContainerapp -g MyResourceGroup --secrets MySecretName1=MySecretValue1 MySecretName2=MySecretValue2
456+
az containerapp secret set -n MyContainerapp -g MyResourceGroup --secrets MySecretName1=MySecretValue1 MySecretName2=MySecretValue2
458457
- name: Update a secret.
459458
text: |
460-
az containerapp secret set -n MyContainerapp -g MyResourceGroup --secrets MyExistingSecretName=MyNewSecretValue
459+
az containerapp secret set -n MyContainerapp -g MyResourceGroup --secrets MyExistingSecretName=MyNewSecretValue
461460
"""
462461

463462
helps['containerapp github-action'] = """

0 commit comments

Comments
 (0)