Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,23 @@ def get_source_display_name(sourcename):
else:
auth_params = get_auth_info_params(auth_types[0])

if target in {RESOURCE.MongoDbAtlas}:
auth_params = '--secret secret=xx'

# auth info params in help message
secret_param = ''
if AUTH_TYPE.Secret in auth_types:
if source.value != RESOURCE.KubernetesCluster.value:
if target in {RESOURCE.MongoDbAtlas}:
secret_param = '''
- name: --secret
short-summary: The connection string for secret auth
long-summary: |
Usage: --secret secret=XX
Comment thread
qianwens marked this conversation as resolved.

secret : Connection string for secret auth.
Example: mongodb+srv://myUser:myPassword@cluster0.a12345.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0
'''
elif source.value != RESOURCE.KubernetesCluster.value:
secret_param = '''
- name: --secret
short-summary: The secret auth info
Expand Down Expand Up @@ -402,7 +415,7 @@ def get_source_display_name(sourcename):
target_id=target_id,
auth_params=auth_params,
source_display_name=source_display_name
) if target is not RESOURCE.NeonPostgres else ''
) if target not in [RESOURCE.NeonPostgres, RESOURCE.MongoDbAtlas] else ''

helps['{source} connection create {target}'.format(source=source.value, target=target.value)] = """
type: command
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def add_target_resource_block(context, target):
context.argument(arg, options_list=content.get('options'), type=str,
help='{}. Required if \'--target-id\' is not specified.'.format(content.get('help')))
required_args.append(content.get('options')[0])
if target == RESOURCE.NeonPostgres:
if target == RESOURCE.NeonPostgres or target == RESOURCE.MongoDbAtlas:
context.ignore('target_id')
else:
context.argument('target_id', type=str,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class RESOURCE(Enum):
AppInsights = 'app-insights'
CognitiveServices = 'cognitiveservices'
NeonPostgres = 'neon-postgres'
MongoDbAtlas = 'mongodb-atlas'

@classmethod
def value_of(cls, value):
Expand Down Expand Up @@ -157,7 +158,8 @@ class CLIENT_TYPE(Enum):
RESOURCE.ContainerApp: '/subscriptions/{subscription}/resourceGroups/{target_resource_group}/providers/Microsoft.App/containerApps/{target_app_name}',

RESOURCE.FabricSql: 'https://api.fabric.microsoft.com/v1/workspaces/{fabric_workspace_uuid}/SqlDatabases/{fabric_sql_db_uuid}',
RESOURCE.NeonPostgres: '/subscriptions/aaaabbbb-0000-cccc-1111-dddd2222eeee/resourceGroups/testrg/providers/Neon.Postgres/organizations/neontest'
RESOURCE.NeonPostgres: '/subscriptions/aaaabbbb-0000-cccc-1111-dddd2222eeee/resourceGroups/testrg/providers/Neon.Postgres/organizations/neontest',
RESOURCE.MongoDbAtlas: '/subscriptions/aaaabbbb-0000-cccc-1111-dddd2222eeee/resourceGroups/{target_resource_group}/providers/MongoDB.Atlas/organizations/{server}'

}

Expand Down Expand Up @@ -696,6 +698,18 @@ class CLIENT_TYPE(Enum):
'help': 'Name of the sql database',
'placeholder': 'MyDB'
}
},
RESOURCE.MongoDbAtlas: {
'target_resource_group': {
'options': ['--target-resource-group', '--tg'],
'help': 'The resource group which contains the MongoDB Atlas',
'placeholder': 'MongoDBAtlasRG'
},
'server': {
Comment thread
qianwens marked this conversation as resolved.
'options': ['--server'],
'help': 'Name of the MongoDB Atlas server',
'placeholder': 'MongoDBAtlasServer'
}
}
}

Expand Down Expand Up @@ -862,7 +876,8 @@ class CLIENT_TYPE(Enum):
RESOURCE.AppInsights: [AUTH_TYPE.SecretAuto],

RESOURCE.CognitiveServices: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret]
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret],
RESOURCE.MongoDbAtlas: [AUTH_TYPE.Secret]
},
RESOURCE.SpringCloud: {
RESOURCE.Postgres: [AUTH_TYPE.Secret, AUTH_TYPE.SystemIdentity, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
Expand Down Expand Up @@ -895,7 +910,8 @@ class CLIENT_TYPE(Enum):
RESOURCE.AppInsights: [AUTH_TYPE.SecretAuto],

RESOURCE.CognitiveServices: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret]
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret],
RESOURCE.MongoDbAtlas: [AUTH_TYPE.Secret]
},
RESOURCE.KubernetesCluster: {
RESOURCE.Postgres: [AUTH_TYPE.Secret],
Expand Down Expand Up @@ -927,7 +943,8 @@ class CLIENT_TYPE(Enum):
RESOURCE.AppInsights: [AUTH_TYPE.SecretAuto],

RESOURCE.CognitiveServices: [AUTH_TYPE.WorkloadIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.ServicePrincipalSecret],
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret]
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret],
RESOURCE.MongoDbAtlas: [AUTH_TYPE.Secret]
},
RESOURCE.ContainerApp: {
RESOURCE.Postgres: [AUTH_TYPE.Secret, AUTH_TYPE.SystemIdentity, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
Expand Down Expand Up @@ -961,7 +978,7 @@ class CLIENT_TYPE(Enum):

RESOURCE.CognitiveServices: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret],

RESOURCE.MongoDbAtlas: [AUTH_TYPE.Secret],
RESOURCE.ContainerApp: [AUTH_TYPE.Null]
},
}
Expand Down Expand Up @@ -1012,6 +1029,19 @@ class CLIENT_TYPE(Enum):
CLIENT_TYPE.SpringBoot,
CLIENT_TYPE.Blank
],
RESOURCE.MongoDbAtlas: [
CLIENT_TYPE.Dotnet,
CLIENT_TYPE.DotnetInternal,
CLIENT_TYPE.Java,
CLIENT_TYPE.Python,
CLIENT_TYPE.Nodejs,
CLIENT_TYPE.Go,
CLIENT_TYPE.Php,
CLIENT_TYPE.Ruby,
CLIENT_TYPE.Django,
CLIENT_TYPE.SpringBoot,
CLIENT_TYPE.Blank
],
RESOURCE.Mysql: [
CLIENT_TYPE.Dotnet,
CLIENT_TYPE.DotnetInternal,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,23 +232,35 @@ def _infer_springcloud(source_id):
return client_type.value


def interactive_input(arg, hint):
def interactive_input(arg, hint, cmd):
'''Get interactive inputs from users
'''
value = None
cmd_value = None
if arg == 'secret_auth_info':
name = prompt('User name of database (--secret name=): ')
secret = prompt_pass('Password of database (--secret secret=): ')
value = {
'name': name,
'secret_info': {
'secret_type': 'rawValue',
'value': secret
},
'auth_type': 'secret'
}
cmd_value = 'name={} secret={}'.format(name, '*' * len(secret))
if 'mongodb-atlas' in cmd.name:
secret = prompt_pass('Connection string of cluster (--secret secret=): ')
value = {
'name': 'NA',
'secret_info': {
'secret_type': 'rawValue',
'value': secret
},
'auth_type': 'secret'
}
cmd_value = 'secret={}'.format('*' * len(secret))
else:
name = prompt('User name of database (--secret name=): ')
secret = prompt_pass('Password of database (--secret secret=): ')
value = {
'name': name,
'secret_info': {
'secret_type': 'rawValue',
'value': secret
},
'auth_type': 'secret'
}
cmd_value = 'name={} secret={}'.format(name, '*' * len(secret))
elif arg == 'service_principal_auth_info_secret':
client_id = prompt('ServicePrincipal client-id (--service-principal client_id=): ')
object_id = prompt('Enterprise Application object-id (--service-principal object-id=): ')
Expand Down Expand Up @@ -373,7 +385,7 @@ def intelligent_experience(cmd, namespace, missing_args):
for arg in missing_args:
if arg not in cmd_arg_values:
hint = '{} ({})'.format(missing_args[arg].get('help'), '/'.join(missing_args[arg].get('options')))
value, cmd_value = interactive_input(arg, hint)
value, cmd_value = interactive_input(arg, hint, cmd)
cmd_arg_values[arg] = value

# show applied params
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def get_action(self, values, option_string, command_name): # pylint: disable=no
else:
raise ValidationError('Unsupported Key {} is provided for parameter secret_auth_info. All possible '
'keys are: name, secret/secret-uri/secret-name'.format(k))
if is_mongodb_atlas_target(command_name):
d['name'] = 'NA'
if len(d) != 2:
raise ValidationError('Required keys missing for parameter --secret.'
' All possible keys are: name, secret/secret-uri/secret-name')
Expand Down Expand Up @@ -120,6 +122,11 @@ def is_mysql_target(command_name):
return target_name.lower() == "mysql-flexible"


def is_mongodb_atlas_target(command_name):
target_name = command_name.split(' ')[-1]
return target_name.lower() == "mongodb-atlas"


class AddUserAssignedIdentityAuthInfo(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
action = self.get_action(values, option_string, namespace.command)
Expand Down
Loading