1# --------------------------------------------------------------------------------------------
2# Copyright (c) Microsoft Corporation. All rights reserved.
3# Licensed under the MIT License. See License.txt in the project root for license information.
4# --------------------------------------------------------------------------------------------
5
6from knack.arguments import CLIArgumentType
7
8from azure.cli.core.commands.parameters import (
9    resource_group_name_type,
10    get_enum_type,
11    get_three_state_flag,
12    tags_type)
13
14name_arg_type = CLIArgumentType(metavar='NAME', configured_default='botname', id_part='Name')
15
16# supported_languages will be use with get_enum_type after the 'Node' value is completely removed from `az bot`
17# In custom.py we're still supporting 'Node' in __language_validator()
18SUPPORTED_LANGUAGES = ['Csharp', 'Javascript']
19UPCOMING_LANGUAGES = ['Csharp', 'Javascript', 'Typescript']
20SUPPORTED_APP_INSIGHTS_REGIONS = [
21    'Australia East',
22    'Canada Central',
23    'Central India',
24    'East Asia',
25    'East US',
26    'East US 2',
27    'France Central',
28    'Japan East',
29    'Korea Central',
30    'North Europe',
31    'South Central US',
32    'Southeast Asia',
33    'UK South',
34    'West Europe',
35    'West US 2']
36SUPPORTED_SKUS = ['F0', 'S1']
37
38
39# pylint: disable=line-too-long,too-many-statements
40def load_arguments(self, _):
41    with self.argument_context('bot prepare-deploy') as c:
42        c.argument('code_dir', options_list=['--code-dir'], help='The directory to place the generated deployment '
43                                                                 'files in. Defaults to the current directory the '
44                                                                 'command is called from.')
45        c.argument('language', options_list=['--lang'], help='The language or runtime of the bot.',
46                   arg_type=get_enum_type(UPCOMING_LANGUAGES))
47        c.argument('proj_file_path', help='The path to the .csproj file relative to --code-dir.')
48
49    with self.argument_context('bot') as c:
50        c.argument('resource_group_name', arg_type=resource_group_name_type)
51        c.argument('resource_name', options_list=['--name', '-n'],
52                   help='The resource name of the bot. Bot name must be between 4 and 42 characters in length. '
53                        'Bot name can only have the following characters -, a - z, A - Z, 0 - 9, and _.',
54                   arg_type=name_arg_type)
55
56    with self.argument_context('bot create') as c:
57        c.argument('sku_name', options_list=['--sku'], arg_type=get_enum_type(SUPPORTED_SKUS), help='The Sku of the bot.', arg_group='Registration Bot Specific')
58        c.argument('kind', options_list=['--kind', '-k'], arg_type=get_enum_type(['registration', 'webapp']), help='The kind of the bot.')
59        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')
60        c.argument('description', options_list=['--description', '-d'], help='The description of the bot.', arg_group='Registration Bot Specific')
61        c.argument('endpoint', options_list=['-e', '--endpoint'], help='The messaging endpoint of the bot.', arg_group='Registration Bot Specific')
62        c.argument('msa_app_id', options_list=['--appid'], help='The Microsoft account ID (MSA ID) to be used with the bot.')
63        c.argument('password', options_list=['-p', '--password'], help='The Microsoft account (MSA) password for the bot. Used to authorize messages being sent from the bot. Required when "--kind" is "webapp".', arg_group='Web App Bot Specific')
64        c.argument('tags', arg_type=tags_type)
65        c.argument('language', options_list=['--lang'], arg_type=get_enum_type(SUPPORTED_LANGUAGES), help='The language to be used to create the bot.', arg_group='Web App Bot Specific')
66        c.argument('deploy_echo', options_list=['--echo'], arg_type=get_three_state_flag(), help='Deploy an Echo Bot template to the newly created v4 Web App Bot.', arg_group='V4 Bot Templates')
67        c.argument('cmek_key_vault_url', options_list=['--cmk-key-vault-key-url', '--cmk'], help='The key vault key url to enable Customer Managed Keys encryption')
68
69    with self.argument_context('bot publish') as c:
70        c.argument('code_dir', options_list=['--code-dir'], help='The directory to upload bot code from.')
71        c.argument('proj_file_path', options_list=['--proj-file-path', c.deprecate(target='--proj-name',
72                                                                                   redirect='--proj-file-path',
73                                                                                   hide=True, expiration='3.0.0')],
74                   help='Path to the start up project file name. (E.g. "./EchoBotWithCounter.csproj")')
75        c.argument('version', options_list=['-v', '--version'],
76                   help='The Microsoft Bot Builder SDK version of the bot.')
77        c.argument('keep_node_modules', help='Keep node_modules folder and do not run `npm install` on the App Service.'
78                                             ' This can greatly speed up publish commands for Node.js SDK bots.',
79                   arg_type=get_three_state_flag())
80        c.argument('timeout', options_list=['--timeout', '-t'], help='Configurable timeout in seconds for checking the '
81                                                                     'status of deployment.')
82
83    with self.argument_context('bot download') as c:
84        c.argument('file_save_path', options_list=['--save-path'], help='The directory to download bot code to.')
85
86    with self.argument_context('bot show') as c:
87        c.argument('bot_json', options_list=['--msbot'], help='Show the output as JSON compatible with a .bot file.', arg_type=get_three_state_flag())
88
89    with self.argument_context('bot update') as c:
90        c.argument('description', options_list=['--description'], help="The bot's new description.")
91        c.argument('display_name', options_list=['--display-name', '-d'], help="The bot's new display name.")
92        c.argument('endpoint', options_list=['--endpoint', '-e'],
93                   help='The new endpoint of the bot. Must start with "https://"')
94        c.argument('sku_name', options_list=['--sku'], arg_type=get_enum_type(SUPPORTED_SKUS),
95                   help='The Sku of the bot.')
96        c.argument('tags', arg_type=tags_type)
97        c.argument('app_insights_key', options_list=['--app-insights-key', '--ai-key'],
98                   arg_group='Bot Analytics/Application Insights',
99                   help='Azure Application Insights Key used to write bot analytics data. Provide a key if you want '
100                        'to receive bot analytics.')
101        c.argument('app_insights_api_key', options_list=['--app-insights-api-key', '--ai-api-key'],
102                   arg_group='Bot Analytics/Application Insights',
103                   help='Azure Application Insights API Key used to read bot analytics data. Provide a key if you want '
104                        'to view analytics about your bot in the Analytics blade.')
105        c.argument('app_insights_app_id', options_list=['--app-insights-app-id', '--ai-app-id'],
106                   arg_group='Bot Analytics/Application Insights',
107                   help='Azure Application Insights Application ID used to read bot analytics data. Provide an Id if '
108                        'you want to view analytics about your bot in the Analytics blade.')
109        c.argument('icon_url', help='Icon URL for bot avatar. Accepts PNG files with file size limit of 30KB.')
110        c.argument('cmek_key_vault_url', options_list=['--cmk-key-vault-key-url', '--cmk'], help='The key vault key url to enable Customer Managed Keys encryption')
111        c.argument('encryption_off', options_list=['--cmk-off'], help='Set encryption to Microsoft-Managed Keys', action='store_true')
112
113    with self.argument_context('bot prepare-publish') as c:
114        c.argument('proj_file_path', options_list=['--proj-file-path', c.deprecate(target='--proj-name',
115                                                                                   redirect='--proj-file-path',
116                                                                                   hide=True, expiration='3.0.0')],
117                   help='Path to the start up project file name. (E.g. "./EchoBotWithCounter.csproj") '
118                        'Required only for C#.')
119        c.argument('sln_name', help='Name of the start up solution file name. Required only for C#.')
120        c.argument('code_dir', options_list=['--code-dir'], help='The directory to download deployment scripts to.')
121        c.argument('version', options_list=['-v', '--version'], help='The Microsoft Bot Builder SDK version to be used '
122                                                                     'in the bot template that will be created.',
123                   arg_type=get_enum_type(['v3', 'v4']), arg_group='Web/Function bot Specific')
124
125    with self.argument_context('bot facebook create') as c:
126        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state')
127        c.argument('page_id', options_list=['--page-id'], help='Page ID of the Facebook page to be used for the bot.')
128        c.argument('app_id', options_list=['--appid'], help='The Facebook application id.')
129        c.argument('app_secret', options_list=['--secret'], help='The Facebook application secret.')
130        c.argument('access_token', options_list=['--token'], help='The Facebook application access token.')
131
132    with self.argument_context('bot email create') as c:
133        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state')
134        c.argument('email_address', options_list=['--email-address', '-a'], help='The email address for the bot.')
135        c.argument('password', options_list=['--password', '-p'], help='The email password for the bot.')
136
137    with self.argument_context('bot msteams create') as c:
138        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
139        c.argument('enable_calling', help='Enable calling on Microsoft Teams.', arg_type=get_three_state_flag())
140        c.argument('calling_web_hook', help='The calling web hook to use on Microsoft Teams.')
141
142    with self.argument_context('bot skype create') as c:
143        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
144        c.argument('enable_messaging', help='Enable messaging on Skype.', arg_type=get_three_state_flag())
145        c.argument('enable_media_cards', help='Enable media cards on Skype.', arg_type=get_three_state_flag())
146        c.argument('enable_video', help='Enable video on Skype.', arg_type=get_three_state_flag())
147        c.argument('enable_calling', help='Enable calling on Skype.', arg_type=get_three_state_flag())
148        c.argument('enable_screen_sharing', help='Enable screen sharing on Skype.', arg_type=get_three_state_flag())
149        c.argument('enable_groups', help='Enable groups on Skype.', arg_type=get_three_state_flag())
150        c.argument('groups_mode', help='select groups mode on Skype.')
151        c.argument('calling_web_hook', help='The calling web hook to use on Skype.')
152
153    with self.argument_context('bot kik create') as c:
154        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
155        c.argument('user_name', options_list=['--user-name', '-u'], help='Kik user name.')
156        c.argument('is_validated', help='Whether or not the Kik account has been validated for use with the bot.', arg_type=get_three_state_flag())
157        c.argument('api_key', options_list=['--key'], help='The API key for the Kik account.')
158
159    with self.argument_context('bot webchat create') as c:
160        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
161        c.argument('site_name', options_list=['-s', '--site-name'], help='Name of the Webchat channel site.')
162        c.argument('enable_preview', help='Enable preview features on the chat control.', arg_type=get_three_state_flag())
163
164    with self.argument_context('bot directline create') as c:
165        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
166        c.argument('site_name', options_list=['-s', '--site-name'], help='Name of the Directline channel site.')
167        c.argument('is_v1_disabled', options_list=['--disablev1'], help='If true, v1 protocol will be disabled on the channel', arg_type=get_three_state_flag())
168        c.argument('is_v3_disabled', options_list=['--disablev3'], help='If true, v3 protocol will be disabled on the channel.', arg_type=get_three_state_flag())
169        c.argument('enable_enhanced_auth', help='If true, enables enhanced authentication features. Must be true for --trusted-origins parameters to work.', arg_type=get_three_state_flag())
170        c.argument('trusted_origins', nargs='+', help='Space separated Trusted Origins URLs (must use HTTPS) e.g. --trusted-origins https://mybotsite1.azurewebsites.net https://mybotsite2.azurewebsites.net')
171
172    with self.argument_context('bot directline update') as c:
173        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
174        c.argument('site_name', options_list=['-s', '--site-name'], help='Name of the Directline channel site.')
175        c.argument('is_v1_disabled', options_list=['--disablev1'], help='If true, v1 protocol will be disabled on the channel', arg_type=get_three_state_flag())
176        c.argument('is_v3_disabled', options_list=['--disablev3'], help='If true, v3 protocol will be disabled on the channel.', arg_type=get_three_state_flag())
177        c.argument('enable_enhanced_auth', help='If true, enables enhanced authentication features. Must be true for --trusted-origins parameters to work.', arg_type=get_three_state_flag())
178        c.argument('trusted_origins', nargs='+', help='Space separated Trusted Origins URLs (must use HTTPS) e.g. --trusted-origins https://mybotsite1.azurewebsites.net https://mybotsite2.azurewebsites.net')
179
180    with self.argument_context('bot telegram create') as c:
181        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
182        c.argument('access_token', help='The access token for the Telegram account.')
183        c.argument('is_validated', help='Whether or not the Telegram account has been validated for use with the bot.', arg_type=get_three_state_flag())
184
185    with self.argument_context('bot sms create') as c:
186        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
187        c.argument('account_sid', help='The account SID for the Twilio account.')
188        c.argument('auth_token', help='The token token for the Twilio account.')
189        c.argument('is_validated', help='Whether or not the Twilio account has been validated for use with the bot.', arg_type=get_three_state_flag())
190        c.argument('phone', help='The phone number for the Twilio account.')
191
192    with self.argument_context('bot slack create') as c:
193        c.argument('is_disabled', options_list=['--add-disabled'], arg_type=get_three_state_flag(), help='Add the channel in a disabled state.')
194        c.argument('client_secret', help='The client secret from Slack.')
195        c.argument('client_id', help='The client ID from Slack.')
196        c.argument('verification_token', help='The verification token from Slack.')
197        c.argument('landing_page_url', help='The landing page url to redirect to after login.')
198
199    with self.argument_context('bot authsetting') as c:
200        c.argument('connection_name', options_list=['--setting-name', '-c'], help='Name of the oauth connection setting.', id_part='child_name_1')
201
202    with self.argument_context('bot authsetting create') as c:
203        c.argument('client_id', help='Client ID associated with the service provider setting.')
204        c.argument('client_secret', help='Client secret associated with the service provider setting.')
205        c.argument('scopes', options_list=['--provider-scope-string'], help='The scope string associated with the service provider setting.The string should be delimited as needed for the service provider.')
206        c.argument('service_provider_name', options_list=['--service'], help='Name of the service provider. For a list of all service providers, use `az bot connection listserviceproviders`.')
207        c.argument('parameters', help='Parameter values for service provider parameters. Usage: --parameters key=value key1=value1.', nargs='+')
208
209    with self.argument_context('bot authsetting list-providers') as c:
210        c.argument('as_raw_settings', options_list=['--as-raw'], help='Output the raw json for each service provider.', arg_type=get_three_state_flag())
211        c.argument('name', options_list=['--provider-name'], help='Service provider name for which to fetch details.')
212
213    for channel in ['facebook', 'email', 'msteams', 'skype', 'kik', 'webchat', 'directline', 'telegram', 'sms', 'slack']:
214        with self.argument_context('bot {0} show'.format(channel)) as c:
215            c.argument('show_secrets', options_list=['--with-secrets'], help='Show secrets in response for the channel.', arg_type=get_three_state_flag())
216