Skip to content

Commit 7cb57a3

Browse files
authored
[ServiceConnector] az {} connection create neon-postgres: Add command for Neon Postgres Serverless (#30938)
* add az connection create neon-postgres * lint
1 parent 2f6a6fc commit 7cb57a3

File tree

6 files changed

+1532
-13
lines changed

6 files changed

+1532
-13
lines changed

src/azure-cli/azure/cli/command_modules/serviceconnector/_help.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,19 @@ def get_source_display_name(sourcename):
391391
source_display_name=source_display_name
392392
) if source is RESOURCE.KubernetesCluster and target is RESOURCE.KeyVault else ''
393393

394+
id_example = '''
395+
- name: Create a connection between {source_display_name} and {target} with resource id
396+
text: |-
397+
az {source} connection create {target} --source-id {source_id} --target-id {target_id} {auth_params}
398+
'''.format(
399+
source=source.value,
400+
target=target.value,
401+
source_id=source_id,
402+
target_id=target_id,
403+
auth_params=auth_params,
404+
source_display_name=source_display_name
405+
) if target is not RESOURCE.NeonPostgres else ''
406+
394407
helps['{source} connection create {target}'.format(source=source.value, target=target.value)] = """
395408
type: command
396409
short-summary: Create a {source_display_name} connection to {target}.
@@ -409,15 +422,11 @@ def get_source_display_name(sourcename):
409422
text: |-
410423
az {source} connection create {target} {source_params} {target_params} {auth_params}
411424
{webappslot_example}
412-
- name: Create a connection between {source_display_name} and {target} with resource id
413-
text: |-
414-
az {source} connection create {target} --source-id {source_id} --target-id {target_id} {auth_params}
425+
{id_example}
415426
{provision_example}
416427
""".format(
417428
source=source.value,
418429
target=target.value,
419-
source_id=source_id,
420-
target_id=target_id,
421430
secret_param=secret_param,
422431
secret_auto_param=secret_auto_param,
423432
system_identity_param=system_identity_param,
@@ -429,6 +438,7 @@ def get_source_display_name(sourcename):
429438
auth_params=auth_params,
430439
provision_example=provision_example,
431440
webappslot_example=webappslot_example,
441+
id_example=id_example,
432442
source_display_name=source_display_name)
433443

434444
helps['{source} connection update {target}'.format(source=source.value, target=target.value)] = """

src/azure-cli/azure/cli/command_modules/serviceconnector/_params.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ def add_target_resource_block(context, target):
154154
context.argument(arg, options_list=content.get('options'), type=str,
155155
help='{}. Required if \'--target-id\' is not specified.'.format(content.get('help')))
156156
required_args.append(content.get('options')[0])
157-
158-
context.argument('target_id', type=str,
159-
help='The resource id of target service. Required if {required_args} '
160-
'are not specified.'.format(required_args=str(required_args)))
157+
if target == RESOURCE.NeonPostgres:
158+
context.ignore('target_id')
159+
else:
160+
context.argument('target_id', type=str,
161+
help='The resource id of target service. Required if {required_args} '
162+
'are not specified.'.format(required_args=str(required_args)))
161163

162164
if target != RESOURCE.KeyVault:
163165
context.ignore('enable_csi')

src/azure-cli/azure/cli/command_modules/serviceconnector/_resource_config.py

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ class RESOURCE(Enum):
5353
FabricSql = 'fabric-sql'
5454
AppInsights = 'app-insights'
5555
CognitiveServices = 'cognitiveservices'
56+
NeonPostgres = 'neon-postgres'
5657

5758
@classmethod
5859
def value_of(cls, value):
@@ -155,7 +156,9 @@ class CLIENT_TYPE(Enum):
155156

156157
RESOURCE.ContainerApp: '/subscriptions/{subscription}/resourceGroups/{target_resource_group}/providers/Microsoft.App/containerApps/{target_app_name}',
157158

158-
RESOURCE.FabricSql: 'https://api.fabric.microsoft.com/v1/workspaces/{fabric_workspace_uuid}/SqlDatabases/{fabric_sql_db_uuid}'
159+
RESOURCE.FabricSql: 'https://api.fabric.microsoft.com/v1/workspaces/{fabric_workspace_uuid}/SqlDatabases/{fabric_sql_db_uuid}',
160+
RESOURCE.NeonPostgres: '/subscriptions/aaaabbbb-0000-cccc-1111-dddd2222eeee/resourceGroups/testrg/providers/Neon.Postgres/organizations/neontest'
161+
159162
}
160163

161164

@@ -679,6 +682,19 @@ class CLIENT_TYPE(Enum):
679682
'options': ['--fabric-sql-db-uuid'],
680683
'help': 'UUID of the target Fabric SQL database',
681684
'placeholder': 'TargetFabricSQLDatabaseUUID'
685+
},
686+
},
687+
RESOURCE.NeonPostgres: {
688+
'server': {
689+
'configured_default': 'sql-server',
690+
'options': ['--server'],
691+
'help': 'Name of the sql server',
692+
'placeholder': 'MyServer'
693+
},
694+
'database': {
695+
'options': ['--database'],
696+
'help': 'Name of the sql database',
697+
'placeholder': 'MyDB'
682698
}
683699
}
684700
}
@@ -845,7 +861,8 @@ class CLIENT_TYPE(Enum):
845861
RESOURCE.FabricSql: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.UserIdentity],
846862
RESOURCE.AppInsights: [AUTH_TYPE.SecretAuto],
847863

848-
RESOURCE.CognitiveServices: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret]
864+
RESOURCE.CognitiveServices: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
865+
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret]
849866
},
850867
RESOURCE.SpringCloud: {
851868
RESOURCE.Postgres: [AUTH_TYPE.Secret, AUTH_TYPE.SystemIdentity, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
@@ -877,7 +894,8 @@ class CLIENT_TYPE(Enum):
877894
RESOURCE.FabricSql: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.UserIdentity],
878895
RESOURCE.AppInsights: [AUTH_TYPE.SecretAuto],
879896

880-
RESOURCE.CognitiveServices: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret]
897+
RESOURCE.CognitiveServices: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
898+
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret]
881899
},
882900
RESOURCE.KubernetesCluster: {
883901
RESOURCE.Postgres: [AUTH_TYPE.Secret],
@@ -908,7 +926,8 @@ class CLIENT_TYPE(Enum):
908926
RESOURCE.ConfluentKafka: [AUTH_TYPE.Secret],
909927
RESOURCE.AppInsights: [AUTH_TYPE.SecretAuto],
910928

911-
RESOURCE.CognitiveServices: [AUTH_TYPE.WorkloadIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.ServicePrincipalSecret]
929+
RESOURCE.CognitiveServices: [AUTH_TYPE.WorkloadIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.ServicePrincipalSecret],
930+
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret]
912931
},
913932
RESOURCE.ContainerApp: {
914933
RESOURCE.Postgres: [AUTH_TYPE.Secret, AUTH_TYPE.SystemIdentity, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
@@ -941,6 +960,7 @@ class CLIENT_TYPE(Enum):
941960
RESOURCE.AppInsights: [AUTH_TYPE.SecretAuto],
942961

943962
RESOURCE.CognitiveServices: [AUTH_TYPE.SystemIdentity, AUTH_TYPE.SecretAuto, AUTH_TYPE.UserIdentity, AUTH_TYPE.ServicePrincipalSecret],
963+
RESOURCE.NeonPostgres: [AUTH_TYPE.Secret],
944964

945965
RESOURCE.ContainerApp: [AUTH_TYPE.Null]
946966
},
@@ -979,6 +999,19 @@ class CLIENT_TYPE(Enum):
979999
CLIENT_TYPE.SpringBoot,
9801000
CLIENT_TYPE.Blank
9811001
],
1002+
RESOURCE.NeonPostgres: [
1003+
CLIENT_TYPE.Dotnet,
1004+
CLIENT_TYPE.DotnetInternal,
1005+
CLIENT_TYPE.Java,
1006+
CLIENT_TYPE.Python,
1007+
CLIENT_TYPE.Nodejs,
1008+
CLIENT_TYPE.Go,
1009+
CLIENT_TYPE.Php,
1010+
CLIENT_TYPE.Ruby,
1011+
CLIENT_TYPE.Django,
1012+
CLIENT_TYPE.SpringBoot,
1013+
CLIENT_TYPE.Blank
1014+
],
9821015
RESOURCE.Mysql: [
9831016
CLIENT_TYPE.Dotnet,
9841017
CLIENT_TYPE.DotnetInternal,

src/azure-cli/azure/cli/command_modules/serviceconnector/custom.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ def connection_create(cmd, client, # pylint: disable=too-many-locals,too-many-s
369369
opt_out_list=opt_out_list,
370370
app_config_id=app_config_id,
371371
enable_appconfig_extension=enable_appconfig_extension,
372+
server=server, database=database,
372373
connstr_props=connstr_props
373374
)
374375

@@ -442,6 +443,12 @@ def connection_create_func(cmd, client, # pylint: disable=too-many-locals,too-m
442443
"id": target_id
443444
}
444445

446+
if target_type == RESOURCE.NeonPostgres:
447+
if connstr_props is None:
448+
connstr_props = {}
449+
connstr_props['Database'] = database
450+
connstr_props['Server'] = server
451+
445452
parameters = {
446453
'target_service': targetService,
447454
'auth_info': auth_info,

0 commit comments

Comments
 (0)