Skip to content

Commit

Permalink
Merge pull request Azure#1 from 00Kai0/confluent_improvement
Browse files Browse the repository at this point in the history
update based on feedback
  • Loading branch information
fengzhou-msft authored Jun 21, 2021
2 parents e744ad0 + dbb23a3 commit 76851d7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
24 changes: 18 additions & 6 deletions src/confluent/azext_confluent/manual/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -36,15 +37,15 @@ 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
user_object_id = decode['oid']
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
Expand Down Expand Up @@ -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 '
Expand All @@ -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,
Expand All @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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-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

0 comments on commit 76851d7

Please sign in to comment.