From ae600d8ea0a4822c9731a91b7aaadba586d12010 Mon Sep 17 00:00:00 2001 From: 00Kai0 Date: Tue, 15 Jun 2021 17:19:23 +0800 Subject: [PATCH 1/2] update based on feedback --- .../azext_confluent/manual/custom.py | 24 ++++++++++++++----- .../test_confluent_scenario_coverage.md | 12 +++++----- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/confluent/azext_confluent/manual/custom.py b/src/confluent/azext_confluent/manual/custom.py index f849949b057..104fa92e348 100644 --- a/src/confluent/azext_confluent/manual/custom.py +++ b/src/confluent/azext_confluent/manual/custom.py @@ -25,6 +25,7 @@ def confluent_organization_create(cmd, no_wait=False): import jwt from azure.cli.core._profile import Profile + from azure.cli.core.azclierror import UnauthorizedError from azure.cli.command_modules.role.custom import list_role_assignments token_info = Profile(cli_ctx=cmd.cli_ctx).get_raw_token()[0][2] @@ -36,7 +37,7 @@ def confluent_organization_create(cmd, body['user_detail']['last_name'] = decode['family_name'] body['user_detail']['email_address'] = decode['email'] if 'email' in decode else decode['unique_name'] except KeyError as ex: - raise Exception(f'Cannot create the organization as CLI cannot get the right value for {str(ex)} from access ' + raise UnauthorizedError(f'Cannot create the organization as CLI cannot get the right value for {str(ex)} from access ' 'token.') from ex # Check owner or contributor role of subscription @@ -44,7 +45,7 @@ def confluent_organization_create(cmd, role_assignments = list_role_assignments(cmd, assignee=user_object_id, role='Owner') + \ list_role_assignments(cmd, assignee=user_object_id, role='Contributor') if not role_assignments: - raise Exception('You must have Owner or Contributor role of the subscription to create an organization.') + raise UnauthorizedError('You must have Owner or Contributor role of the subscription to create an organization.') body['tags'] = tags body['location'] = location @@ -75,7 +76,9 @@ def confluent_organization_delete(client, '- Stop billing for the selected Confluent organization through Azure Marketplace.\n' \ 'Do you want to proceed' - if org.offer_detail.plan_id.lower() == 'commit': + if org.offer_detail.plan_id in ['confluent-cloud-azure-payg-prod', 'confluent-cloud-azure-payg-stag']: + user_confirmation(default_msg) + else: user_confirmation('- The action cannot be undone and will permanently delete this resource.\n' '- Resource deletion is a permanent action. All the resources, contract purchased ' 'and its Azure integration will be permanently deleted and will unsubscribe you ' @@ -90,8 +93,6 @@ def confluent_organization_delete(client, 'deletion process and timeline, please contact Confluent Support: ' 'https://support.confluent.io/\n' 'Do you want to proceed') - else: - user_confirmation(default_msg) return sdk_no_wait(no_wait, client.begin_delete, @@ -109,9 +110,20 @@ def confluent_offer_detail_show(cmd, publisher_id=None, offer_id=None): plans = response.json()['plans'] plans = [{'planId': plan['planId'], 'planName': plan['displayName'], - 'termUnits':[item for a in plan['availabilities'] for item in a['terms']] + 'offerId': offer_id, + 'publisherId': publisher_id, + 'termUnits':[{ + 'price': item['price'], + 'termDescription': item['termDescription'], + 'termUnits': item['termUnits'] + } for a in plan['availabilities'] for item in a['terms']] } for plan in plans] except KeyError as ex: raise ArgumentUsageError('Not able to get offer details for the provided publisher id and offer id.') from ex + for plan in plans: + for term in plan['termUnits']: + if term['termUnits'] not in ['P1M', 'P1Y']: + del term['termUnits'] + return plans diff --git a/src/confluent/azext_confluent/tests/latest/test_confluent_scenario_coverage.md b/src/confluent/azext_confluent/tests/latest/test_confluent_scenario_coverage.md index b77602afc5b..bde546fdaa6 100644 --- a/src/confluent/azext_confluent/tests/latest/test_confluent_scenario_coverage.md +++ b/src/confluent/azext_confluent/tests/latest/test_confluent_scenario_coverage.md @@ -1,8 +1,8 @@ |Scenario|Result|ErrorMessage|ErrorStack|ErrorNormalized|StartDt|EndDt| -|step_terms_list|successed||||2021-05-24 07:38:55.834022|2021-05-24 07:38:55.963383| -|step_organization_show|successed||||2021-05-24 07:38:56.149089|2021-05-24 07:38:56.202278| -|step_organization_list|successed||||2021-05-24 07:38:56.202490|2021-05-24 07:38:56.259075| -|step_organization_list2|successed||||2021-05-24 07:38:56.259292|2021-05-24 07:38:56.313915| -|step_organization_update|successed||||2021-05-24 07:38:56.314167|2021-05-24 07:38:56.367895| -|step_organization_delete|successed||||2021-05-24 07:38:56.368122|2021-05-24 07:38:56.538469| +|step_terms_list|successed||||2021-06-15 09:17:45.214872|2021-06-15 09:17:45.372821| +|step_organization_show|successed||||2021-06-15 09:17:45.680822|2021-06-15 09:17:45.774822| +|step_organization_list|successed||||2021-06-15 09:17:45.774822|2021-06-15 09:17:45.869822| +|step_organization_list2|successed||||2021-06-15 09:17:45.869822|2021-06-15 09:17:45.962821| +|step_organization_update|successed||||2021-06-15 09:17:45.962821|2021-06-15 09:17:46.060822| +|step_organization_delete|successed||||2021-06-15 09:17:46.060822|2021-06-15 09:17:46.280822| Coverage: 6/6 From dbb23a3a733e5d48aebeaa4e15d96d2ddba40ee4 Mon Sep 17 00:00:00 2001 From: 00Kai0 Date: Mon, 21 Jun 2021 10:47:29 +0800 Subject: [PATCH 2/2] add some checks --- .../tests/latest/test_confluent_scenario.py | 14 ++++++++++++-- .../latest/test_confluent_scenario_coverage.md | 12 ++++++------ 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/confluent/azext_confluent/tests/latest/test_confluent_scenario.py b/src/confluent/azext_confluent/tests/latest/test_confluent_scenario.py index 8184ba4d142..f855240a37a 100644 --- a/src/confluent/azext_confluent/tests/latest/test_confluent_scenario.py +++ b/src/confluent/azext_confluent/tests/latest/test_confluent_scenario.py @@ -34,10 +34,20 @@ def step_offer_detail_show(test, rg, checks=None): if checks is None: checks = [] - test.cmd('az confluent offer-detail show ' + result = test.cmd('az confluent offer-detail show ' '--publisher-id confluentinc ' '--offer-id confluent-cloud-azure-stag', - checks=checks) + checks=checks).get_output_in_json() + + # check + for plan in result: + assert plan.get('offerId', None) is not None + assert plan.get('publisherId', None) is not None + for term_unit in plan['termUnits']: + if term_unit.get('termUnits', None): + assert term_unit['termUnits'] in ['P1M', 'P1Y'] + assert term_unit.get('price', None) is not None + assert term_unit.get('termDescription', None) is not None orig_decode = jwt.decode diff --git a/src/confluent/azext_confluent/tests/latest/test_confluent_scenario_coverage.md b/src/confluent/azext_confluent/tests/latest/test_confluent_scenario_coverage.md index bde546fdaa6..789db8ad7d9 100644 --- a/src/confluent/azext_confluent/tests/latest/test_confluent_scenario_coverage.md +++ b/src/confluent/azext_confluent/tests/latest/test_confluent_scenario_coverage.md @@ -1,8 +1,8 @@ |Scenario|Result|ErrorMessage|ErrorStack|ErrorNormalized|StartDt|EndDt| -|step_terms_list|successed||||2021-06-15 09:17:45.214872|2021-06-15 09:17:45.372821| -|step_organization_show|successed||||2021-06-15 09:17:45.680822|2021-06-15 09:17:45.774822| -|step_organization_list|successed||||2021-06-15 09:17:45.774822|2021-06-15 09:17:45.869822| -|step_organization_list2|successed||||2021-06-15 09:17:45.869822|2021-06-15 09:17:45.962821| -|step_organization_update|successed||||2021-06-15 09:17:45.962821|2021-06-15 09:17:46.060822| -|step_organization_delete|successed||||2021-06-15 09:17:46.060822|2021-06-15 09:17:46.280822| +|step_terms_list|successed||||2021-06-21 02:44:44.694501|2021-06-21 02:44:44.946485| +|step_organization_show|successed||||2021-06-21 02:44:45.356491|2021-06-21 02:44:45.449457| +|step_organization_list|successed||||2021-06-21 02:44:45.449457|2021-06-21 02:44:45.571478| +|step_organization_list2|successed||||2021-06-21 02:44:45.572449|2021-06-21 02:44:45.670480| +|step_organization_update|successed||||2021-06-21 02:44:45.671479|2021-06-21 02:44:45.766477| +|step_organization_delete|successed||||2021-06-21 02:44:45.767451|2021-06-21 02:44:45.991454| Coverage: 6/6