Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

botservice cli extension #155

Merged
merged 17 commits into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@

/src/eventgrid/ @kalyanaj

/src/botservice/ @swagatmishra2007

/src/storage-preview/ @williexu
6 changes: 6 additions & 0 deletions src/botservice/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Release History
===============

0.1.0 (2018-02-16)
------------------
* inital bot service CLI
2 changes: 2 additions & 0 deletions src/botservice/MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include azext_bot\functionapp.template.json
include azext_bot\webapp.template.json
7 changes: 7 additions & 0 deletions src/botservice/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Microsoft Azure CLI 'bot service' Command Module
=======================================================

This package is for the 'bot service' module.
i.e. 'az botservice'


32 changes: 32 additions & 0 deletions src/botservice/azext_bot/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core import AzCommandsLoader
from azext_bot._help import helps # pylint: disable=unused-import
from azext_bot._client_factory import get_botservice_management_client


class BotServiceCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_type = CliCommandType(
operations_tmpl='azext_bot.custom#{}',
client_factory=get_botservice_management_client)
super(BotServiceCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=custom_type,
min_profile='2017-03-10-profile')

def load_command_table(self, args):
from azext_bot.commands import load_command_table
load_command_table(self, args)
return self.command_table

def load_arguments(self, command):
from azext_bot._params import load_arguments
load_arguments(self, command)


COMMAND_LOADER_CLS = BotServiceCommandsLoader
26 changes: 26 additions & 0 deletions src/botservice/azext_bot/_client_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------


def get_botservice_management_client(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from azext_bot.botservice import AzureBotService
return get_mgmt_service_client(cli_ctx, AzureBotService)


def get_botOperations_client(cli_ctx, *_):
return get_botservice_management_client(cli_ctx).bots


def get_botServices_client(cli_ctx, *_):
return get_botservice_management_client(cli_ctx).bot_services


def get_botChannels_client(cli_ctx, *_):
return get_botservice_management_client(cli_ctx).channels


def get_operations_client(cli_ctx, *_):
return get_botservice_management_client(cli_ctx).operations
30 changes: 30 additions & 0 deletions src/botservice/azext_bot/_exception_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.util import CLIError


def bot_exception_handler(ex):
from azext_bot.botservice.models import ErrorException
from msrestazure.azure_exceptions import CloudError
from msrest.exceptions import ClientRequestError
if isinstance(ex, ErrorException):
message = 'an error occurred with code:{0} and message:{1}'.format(
ex.error.error.code,
ex.error.error.message
)
raise CLIError(message)
elif isinstance(ex, CloudError) and ex.status_code == 404:
return None
elif isinstance(ex, ClientRequestError):
message = 'Error occurred in sending request. Please file an issue on {0}'.format(
'https://github.com/Microsoft/botbuilder-tools/issues'
)
raise CLIError(message)
else:
message = 'Unknown error during execution. Please file an issue on {0}'.format(
'https://github.com/Microsoft/botbuilder-tools/issues'
)
raise CLIError(message)
136 changes: 136 additions & 0 deletions src/botservice/azext_bot/_help.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.help_files import helps

helps['bot'] = """
type: group
short-summary: Manage Bot Services.
"""
helps['bot create'] = """
type: command
short-summary: Create a new Bot Service.
"""
helps['bot show'] = """
type: command
short-summary: get an existing Bot Service.
"""
helps['bot delete'] = """
type: command
short-summary: delete an existing Bot Service.
"""
helps['bot update'] = """
type: command
short-summary: update an existing Bot Service.
examples:
- name: Update description on a bot
text: |-
az bot update -n botName -g MyResourceGroup --set properties.description="some description"
"""
helps['bot publish'] = """
type: command
short-summary: publish to an existing Bot Service.
long-summary: publish your github or zip code to a bot service.
This lets you overwrite the existing template code on a bot.
"""
helps['bot download'] = """
type: command
short-summary: download an existing Bot Service.
long-summary: download the code deployed to your web/function app for your bot.
You can then make changes to it and publish it back to your app.
"""
helps['bot facebook create'] = """
type: command
short-summary: Create Facebook Channel on a Bot.
"""
helps['bot email create'] = """
type: command
short-summary: Create Email Channel on a Bot.
examples:
- name: Add Email Channel for a Bot
text: |-
az bot email create -n botName -g MyResourceGroup -a [email protected]
-p password --enable
"""
helps['bot msteams create'] = """
type: command
short-summary: Create MsTeams Channel on a Bot.
examples:
- name: Add MsTeams Channel for a Bot with messaging and video enabled
text: |-
az bot msteams -n botName -g MyResourceGroup --enable-messaging
--enable-video --enable
"""
helps['bot skype create'] = """
type: command
short-summary: Create Skype Channel on a Bot.
examples:
- name: Add Skype Channel for a Bot with messaging and screen sharing enabled
text: |-
az bot skype -n botName -g MyResourceGroup --enable-messaging
--enable-screen-sharing --enable
"""
helps['bot kik create'] = """
type: command
short-summary: Create Kik Channel on a Bot.
examples:
- name: Add Kik Channel for a Bot.
text: |-
az bot kik create -n botName -g MyResourceGroup -u mykikname
-p password --key key --is-validated --enable
"""
helps['bot webchat create'] = """
type: command
short-summary: Create WebChat Channel on a Bot.
examples:
- name: Add WebChat Channel for a Bot.
text: |-
az bot webchat create -n botName -g MyResourceGroup --enablev3 --enable
"""
helps['bot directline create'] = """
type: command
short-summary: Create DirectLine Channel on a Bot.
examples:
- name: Add DirectLine Channel for a Bot.
text: |-
az bot webchat create -n botName -g MyResourceGroup --enablev3 --enable
"""
helps['bot telegram create'] = """
type: command
short-summary: Create Telegram Channel on a Bot.
examples:
- name: Add Telegram Channel for a Bot.
text: |-
az bot telegram create -n botName -g MyResourceGroup --access-token token
--is-validated --enable
"""
helps['bot sms create'] = """
type: command
short-summary: Create Sms Channel on a Bot.
examples:
- name: Add Sms Channel for a Bot.
text: |-
az bot sms create -n botName -g MyResourceGroup --account-sid sid
--auth-token token --is-validated --enable
"""
helps['bot slack create'] = """
type: command
short-summary: Create Slack Channel on a Bot.
"""

for channel in ['facebook', 'email', 'msteams', 'skype', 'kik', 'webchat', 'directline', 'telegram', 'sms', 'slack']:
channelTitle = channel[:1].upper() + channel[1:]
helps['bot {0} delete'.format(channel)] = """
type: command
short-summary: Delete {0} Channel on a Bot
""".format(channelTitle)
helps['bot {0} get'.format(channel)] = """
type: command
short-summary: Get details of {0} Channel on a Bot
""".format(channelTitle)
helps['bot {0}'.format(channel)] = """
type: group
short-summary: Manage {0} Channel on a Bot.
""".format(channelTitle)
111 changes: 111 additions & 0 deletions src/botservice/azext_bot/_params.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from knack.arguments import CLIArgumentType

from azure.cli.core.commands.parameters import (
tags_type,
resource_group_name_type,
get_resource_name_completion_list,
get_enum_type,
get_three_state_flag)

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


def load_arguments(self, _):
with self.argument_context('bot') as c:
c.argument('resource_group_name', arg_type=resource_group_name_type)
c.argument('resource_name', options_list=['--name', '-n'], help='the Resource Name of the bot.', arg_type=name_arg_type)

with self.argument_context('bot create') as c:
c.argument('sku_name', options_list=['--sku'], arg_type=get_enum_type(['F0', 'S1']), help='the Sku of the Bot', arg_group='Registration Bot Specific')
c.argument('kind', options_list=['--kind', '-k'], arg_type=get_enum_type(['registration', 'function', 'webapp']), help='The Kind of the Bot.')
c.argument('display_name', help='the Display Name of the bot.If not specified, defaults to the name of the bot.', arg_group='Registration Bot Specific')
c.argument('description', options_list=['--description', '-d'], help='the Description of the bot.', arg_group='Registration Bot Specific')
c.argument('endpoint', options_list=['-e', '--endpoint'], help='the Messaging Endpoint of the bot.', arg_group='Registration Bot Specific')
c.argument('msa_app_id', options_list=['--appid'], help='the msa account id to be used with the bot.')
c.argument('password', options_list=['-p', '--password'], help='the msa password for the bot from developer portal.')
c.argument('storageAccountName', options_list=['-s', '--storage'], help='Storage Account Name to be used with the bot.If one is not provided, a new account will be created.', arg_group='Web/Function Bot Specific')
c.argument('tags', help='set of tags to add to the bot.')
c.argument('bot_json', options_list=['--msbot'], help='show the output as json compatible with a .bot file', arg_type=get_three_state_flag())
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('appInsightsLocation', help='The location for the app insights to be used with the bot.', options_list=['--insights'], arg_group='Web/Function Bot Specific')

with self.argument_context('bot publish') as c:
c.argument('code_dir', options_list=['--code-dir'], help='The root directory to which the code will be downloaded.')
c.argument('git_url', options_list=['--git-url'], help='Url to the git repo containing the code to be published.')
c.argument('branch', options_list=['--branch'], help='Git branch from which code will be published.')

with self.argument_context('bot download') as c:
c.argument('file_save_path', options_list=['--save-path'], help='the root directory to which the file should be saved to.')

with self.argument_context('bot show') as c:
c.argument('bot_json', options_list=['--msbot'], help='show the output as json compatible with a .bot file', arg_type=get_three_state_flag())

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')
c.argument('page_id', options_list=['--page-id'], help='page id of the facebook page to be used for the bot.')
c.argument('app_id', options_list=['--appid'], help='the facebook application id.')
c.argument('app_secret', options_list=['--secret'], help='the facebook application secret.')
c.argument('access_token', options_list=['--token'], help='the facebook application access token.')

with self.argument_context('bot email create') as c:
c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag())
c.argument('email_address', options_list=['--email-address', '-a'], help='the email address for the bot.')
c.argument('password', options_list=['--password', '-p'], help='the email password for the bot.')

with self.argument_context('bot msteams 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')
c.argument('enable_messaging', help='Enable messaging on Skype', arg_type=get_three_state_flag())
c.argument('enable_media_cards', help='Enable media cards on Skype', arg_type=get_three_state_flag())
c.argument('enable_video', help='Enable video on Skype', arg_type=get_three_state_flag())
c.argument('enable_calling', help='Enable calling on Skype', arg_type=get_three_state_flag())

with self.argument_context('bot skype 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')
c.argument('enable_messaging', help='Enable messaging on Skype', arg_type=get_three_state_flag())
c.argument('enable_media_cards', help='Enable media cards on Skype', arg_type=get_three_state_flag())
c.argument('enable_video', help='Enable video on Skype', arg_type=get_three_state_flag())
c.argument('enable_calling', help='Enable calling on Skype', arg_type=get_three_state_flag())
c.argument('enable_screen_sharing', help='Enable screen sharing on Skype', arg_type=get_three_state_flag())
c.argument('enable_groups', help='Enable groups on Skype', arg_type=get_three_state_flag())
c.argument('calling_web_hook', help='The calling web hook to use on Skype')

with self.argument_context('bot kik 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')
c.argument('user_name', options_list=['--user-name', '-u'], help='kik user name')
c.argument('is_validated', help='Has the user name been validated', arg_type=get_three_state_flag())
c.argument('api_key', options_list=['--key'], help='the api key for the kik account')

with self.argument_context('bot webchat 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')
c.argument('site_name', options_list=['-s', '--site-name'], help='name of the webchat channel site')
c.argument('enable_preview', help='Enable preview features on the chat control', arg_type=get_three_state_flag())

with self.argument_context('bot directline 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')
c.argument('site_name', options_list=['-s', '--site-name'], help='name of the webchat channel site')
c.argument('is_v1_disabled', options_list=['--disablev1'], help='Enable v1 channel protocol', arg_type=get_three_state_flag())
c.argument('is_v3_disabled', options_list=['--disablev3'], help='Enable v3 channel protocol', arg_type=get_three_state_flag())

with self.argument_context('bot telegram create') as c:
c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag())
c.argument('access_token', help='The access token for the telegram account')
c.argument('is_validated', help='Has the user name been validated', arg_type=get_three_state_flag())

with self.argument_context('bot sms 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')
c.argument('account_sid', help='The account sid for the twilio account')
c.argument('auth_token', help='The token token for the twilio account.')
c.argument('is_validated', help='Has the user name been validated.', arg_type=get_three_state_flag())
c.argument('phone', help='the phone number for the twilio account.')

with self.argument_context('bot slack 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')
c.argument('client_secret', help='The client secret from slack')
c.argument('client_id', help='The client id from slack')
c.argument('verification_token', help='The verification token from slack')
c.argument('landing_page_url', help='The landing page url to redirect to after login')
4 changes: 4 additions & 0 deletions src/botservice/azext_bot/azext_metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"azext.minCliCoreVersion": "2.0.30",
"azext.isPreview": true
}
17 changes: 17 additions & 0 deletions src/botservice/azext_bot/botservice/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------

from .azure_bot_service import AzureBotService
from .version import VERSION

__all__ = ['AzureBotService']

__version__ = VERSION
Loading