Skip to content

Commit

Permalink
BotService: Bugfixing, code refactoring, reorganization and UX revamp…
Browse files Browse the repository at this point in the history
…ing (#7924)
  • Loading branch information
carlosscastro authored and yugangw-msft committed Nov 28, 2018
1 parent adcb813 commit 0729c9f
Show file tree
Hide file tree
Showing 31 changed files with 223,577 additions and 491 deletions.
2 changes: 2 additions & 0 deletions azure-cli.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -1160,13 +1160,15 @@
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\tests\latest\recordings\test_webapp_bot.yaml" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\tests\latest\recordings\test_webchat_channel.yaml" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\webapp.template.json" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\webappv4.template.json" />
<Content Include="command_modules\azure-cli-botservice\azure_cli_botservice.egg-info\dependency_links.txt" />
<Content Include="command_modules\azure-cli-botservice\azure_cli_botservice.egg-info\PKG-INFO" />
<Content Include="command_modules\azure-cli-botservice\azure_cli_botservice.egg-info\requires.txt" />
<Content Include="command_modules\azure-cli-botservice\azure_cli_botservice.egg-info\SOURCES.txt" />
<Content Include="command_modules\azure-cli-botservice\azure_cli_botservice.egg-info\top_level.txt" />
<Content Include="command_modules\azure-cli-botservice\build\lib.linux-x86_64-2.7\azure\cli\command_modules\botservice\functionapp.template.json" />
<Content Include="command_modules\azure-cli-botservice\build\lib.linux-x86_64-2.7\azure\cli\command_modules\botservice\webapp.template.json" />
<Content Include="command_modules\azure-cli-botservice\build\lib.linux-x86_64-2.7\azure\cli\command_modules\botservice\webappv4.template.json" />
<Content Include="command_modules\azure-cli-botservice\dist\azure_cli_botservice-0.1.0-py2.py3-none-any.whl" />
<Content Include="command_modules\azure-cli-botservice\HISTORY.rst" />
<Content Include="command_modules\azure-cli-botservice\MANIFEST.in" />
Expand Down
5 changes: 3 additions & 2 deletions azure-cli2017.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,7 @@
<Content Include="command_modules\azure-cli-billing\MANIFEST.in" />
<Content Include="command_modules\azure-cli-billing\README.rst" />
<Content Include="command_modules\azure-cli-billing\setup.cfg" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\functionapp.template.json" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\bot\templates\functionapp.template.json" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\tests\latest\recordings\test_auth_setting.yaml" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\tests\latest\recordings\test_directline_channel.yaml" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\tests\latest\recordings\test_msteams_channel.yaml" />
Expand All @@ -1497,7 +1497,8 @@
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\tests\latest\recordings\test_skype_channel.yaml" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\tests\latest\recordings\test_webapp_bot.yaml" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\tests\latest\recordings\test_webchat_channel.yaml" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\webapp.template.json" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\bot\templates\webapp.template.json" />
<Content Include="command_modules\azure-cli-botservice\azure\cli\command_modules\botservice\bot\templates\webappv4.template.json" />
<Content Include="command_modules\azure-cli-botservice\HISTORY.rst" />
<Content Include="command_modules\azure-cli-botservice\MANIFEST.in" />
<Content Include="command_modules\azure-cli-botservice\README.rst" />
Expand Down
5 changes: 5 additions & 0 deletions src/command_modules/azure-cli-botservice/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
Release History
===============

0.1.2
+++++
* Major refactoring
* Improvements to test coverage

0.1.1
+++++
* Minor fixes
Expand Down
5 changes: 3 additions & 2 deletions src/command_modules/azure-cli-botservice/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include *.rst
include azure\cli\command_modules\botservice\functionapp.template.json
include azure\cli\command_modules\botservice\webapp.template.json
include azure/cli/command_modules/botservice/functionapp.template.json
include azure/cli/command_modules/botservice/webapp.template.json
include azure/cli/command_modules/botservice/webappv4.template.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class BotServiceCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):

from azure.cli.core.commands import CliCommandType
custom_type = CliCommandType(
operations_tmpl='azure.cli.command_modules.botservice.custom#{}',
Expand All @@ -21,7 +22,7 @@ def __init__(self, cli_ctx=None):
suppress_extension=ModExtensionSuppress(
__name__,
'botservice',
'0.4.0',
'0.4.1',
reason='These commands are now in the CLI',
recommend_remove=True))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def bot_exception_handler(ex):
from msrestazure.azure_exceptions import CloudError
from msrest.exceptions import ClientRequestError # pylint: disable=import-error
if isinstance(ex, ErrorException):
message = 'an error occurred with code:{0} and message:{1}'.format(
message = 'An error occurred. {0}: {1}'.format(
ex.error.error.code,
ex.error.error.message
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

name_arg_type = CLIArgumentType(metavar='NAME', configured_default='botname', id_part='Name')

supported_languages = ['Csharp', 'Node']


# pylint: disable=line-too-long,too-many-statements
def load_arguments(self, _):
Expand All @@ -30,13 +32,16 @@ def load_arguments(self, _):
c.argument('password', options_list=['-p', '--password'], help='The Microsoft account (MSA) password for the bot.')
c.argument('storageAccountName', options_list=['-s', '--storage'], help='Storage account name to be used with the bot. If not provided, a new account will be created.', arg_group='Web/Function bot Specific')
c.argument('tags', arg_type=tags_type)
c.argument('language', help='The language to be used to create the bot.', options_list=['--lang'], arg_type=get_enum_type(['Csharp', 'Node']), arg_group='Web/Function bot Specific')
c.argument('language', help='The language to be used to create the bot.', options_list=['--lang'], arg_type=get_enum_type(supported_languages), arg_group='Web/Function bot Specific')
c.argument('appInsightsLocation', help='The location for the app insights to be used with the bot.', options_list=['--insights-location'], arg_group='Web/Function bot Specific',
arg_type=get_enum_type(['South Central US', 'East US', 'West US 2', 'North Europe', 'West Europe', 'Southeast Asia']))
c.argument('version', options_list=['-v', '--version'], help='The Microsoft Bot Builder SDK version to be used to create the bot', arg_type=get_enum_type(['v3', 'v4']), arg_group='Web/Function bot Specific')

with self.argument_context('bot publish') as c:
c.argument('code_dir', options_list=['--code-dir'], help='The directory to upload bot code from.')
c.argument('proj_name', help='Name of the start up project file name.')
c.argument('version', options_list=['-v', '--version'],
help='The Microsoft Bot Builder SDK version by the bot.')

with self.argument_context('bot download') as c:
c.argument('file_save_path', options_list=['--save-path'], help='The directory to download bot code to.')
Expand All @@ -48,6 +53,9 @@ def load_arguments(self, _):
c.argument('proj_name', help='Name of the start up project file name. Required only for C#.')
c.argument('sln_name', help='Name of the start up solution file name. Required only for C#.')
c.argument('code_dir', options_list=['--code-dir'], help='The directory to download deployment scripts to.')
c.argument('version', options_list=['-v', '--version'], help='The Microsoft Bot Builder SDK version to be used '
'in the bot template that will be created.',
arg_type=get_enum_type(['v3', 'v4']), arg_group='Web/Function bot Specific')

with self.argument_context('bot facebook create') as c:
c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state')
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import adal
from knack.log import get_logger

logger = get_logger(__name__)


class AdalAuthenticator: # pylint:disable=too-few-public-methods

bot_first_party_app_id = 'f3723d34-6ff5-4ceb-a148-d99dcd2511fc'
aad_client_id = '1950a258-227b-4e31-a9cf-717495945fc2'
login_url = 'https://login.windows.net/common'

@staticmethod
def acquire_token():

# Create ADAL Authentication Context to acquire tokens
context = adal.AuthenticationContext(
authority=AdalAuthenticator.login_url,
validate_authority=True,
api_version=None
)

# Acquire a device code
code = context.acquire_user_code(
resource=AdalAuthenticator.bot_first_party_app_id,
client_id=AdalAuthenticator.aad_client_id,
)

# Request the user to perform device login
logger.warning(code['message'])

# Use the device code to retrieve a token
token = context.acquire_token_with_device_code(
resource=AdalAuthenticator.bot_first_party_app_id,
user_code_info=code,
client_id=AdalAuthenticator.aad_client_id
)

# Return the entire token object including the access token plus expiration date and other info
return token
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.log import get_logger

logger = get_logger(__name__)


class AzureRegionMapper: # pylint:disable=too-few-public-methods

@staticmethod
def get_app_insights_location(key):
region_map = {
'australiaeast': 'southeastasia',
'australiacentral': 'southeastasia',
'australiacentral2': 'southeastasia',
'australiasoutheast': 'southeastasia',
'eastasia': 'southeastasia',
'southeastasia': 'westus',
'eastus': 'eastus',
'eastus2': 'eastus',
'southcentralus': 'southcentralus',
'westcentralus': 'westus2',
'westus': 'westus2',
'westus2': 'westus2',
'brazilsouth': 'southcentralus',
'centralus': 'southcentralus',
'northcentralus': 'southcentralus',
'japanwest': 'southeastasia',
'japaneast': 'southeastasia',
'southindia': 'southeastasia',
'centralindia': 'southeastasia',
'westindia': 'southeastasia',
'canadacentral': 'southcentralus',
'canadaeast': 'eastus',
'koreacentral': 'southeastasia',
'koreasouth': 'southeastasia',
'northeurope': 'northeurope',
'westeurope': 'westeurope',
'uksouth': 'westeurope',
'ukwest': 'westeurope',
'francecentral': 'westeurope',
'francesouth': 'westeurope'
}
region = region_map.get(key)

if not region:
logger.warning('Warning: provided region ("%s") for Application Insights does not exist. Defaulting to '
'"southcentralus"', key)
region = 'southcentralus'

return region
Loading

0 comments on commit 0729c9f

Please sign in to comment.