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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
/src/azure-cli/azure/cli/command_modules/natgateway/ @jsntcy @kairu-ms @necusjz @khannarheams
/src/azure-cli/azure/cli/command_modules/network/ @jsntcy @kairu-ms @wangzelin007 @necusjz
/src/azure-cli/azure/cli/command_modules/policyinsights/ @jsntcy @cheggert
/src/azure-cli/azure/cli/command_modules/postgresql/ @evelyn-ys @calvinhzy @arde0708
/src/azure-cli/azure/cli/command_modules/privatedns/ @jsntcy @kairu-ms @necusjz
/src/azure-cli/azure/cli/command_modules/profile/ @jiasli @evelyn-ys @bebound
/src/azure-cli/azure/cli/command_modules/rdbms/ @evelyn-ys @calvinhzy @arde0708 @alanenriqueo
Expand Down
1 change: 1 addition & 0 deletions doc/sphinx/azhelpgen/doc_source_map.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"network": "src/azure-cli/azure/cli/command_modules/network/_help.py",
"policy": "src/azure-cli/azure/cli/command_modules/resource/_help.py",
"policyinsights": "src/azure-cli/azure/cli/command_modules/policyinsights/_help.py",
"postgresql": "src/azure-cli/azure/cli/command_modules/postgresql/_help.py",
"privatedns": "src/azure-cli/azure/cli/command_modules/privatedns/_help.py",
"provider": "src/azure-cli/azure/cli/command_modules/resource/_help.py",
"rdbms": "src/azure-cli/azure/cli/command_modules/rdbms/_help.py",
Expand Down
6 changes: 6 additions & 0 deletions scripts/live_test/CLITest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ stages:
Target: network
policyinsights:
Target: policyinsights
postgresql:
Target: postgresql
privatedns:
Target: privatedns
profile:
Expand Down Expand Up @@ -754,6 +756,8 @@ stages:
Target: network
policyinsights:
Target: policyinsights
postgresql:
Target: postgresql
privatedns:
Target: privatedns
profile:
Expand Down Expand Up @@ -1329,6 +1333,8 @@ stages:
Target: network
policyinsights:
Target: policyinsights
postgresql:
Target: postgresql
privatedns:
Target: privatedns
profile:
Expand Down
1 change: 1 addition & 0 deletions src/azure-cli-core/azure/cli/core/profiles/_shared.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ class ResourceType(Enum): # pylint: disable=too-few-public-methods
MGMT_MAPS = ('azure.mgmt.maps', None)
MGMT_POLICYINSIGHTS = ('azure.mgmt.policyinsights', None)
MGMT_RDBMS = ('azure.mgmt.rdbms', None)
MGMT_POSTGRESQL = ('azure.mgmt.postgresql', None)
MGMT_REDIS = ('azure.mgmt.redis', None)
MGMT_SEARCH = ('azure.mgmt.search', None)
MGMT_SERVICEFABRIC = ('azure.mgmt.servicefabric', None)
Expand Down
54 changes: 54 additions & 0 deletions src/azure-cli/azure/cli/command_modules/postgresql/__init__.py
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 azure.cli.core import AzCommandsLoader
from azure.cli.core import ModExtensionSuppress
from azure.cli.core.commands import CliCommandType
from azure.cli.core.profiles import ResourceType
from azure.cli.command_modules.postgresql._util import PostgreSQLArgumentContext
from azure.cli.command_modules.postgresql.flexible_server_commands import load_flexibleserver_command_table
from azure.cli.command_modules.postgresql._params import load_arguments
import azure.cli.command_modules.postgresql._help # pylint: disable=unused-import


# pylint: disable=import-outside-toplevel
class PostgreSQLCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):

postgresql_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.postgresql.custom#{}')
super().__init__(
cli_ctx=cli_ctx,
resource_type=ResourceType.MGMT_POSTGRESQL,
custom_command_type=postgresql_custom,
argument_context_cls=PostgreSQLArgumentContext,
suppress_extension=ModExtensionSuppress(
__name__,
'postgresql-vnet',
'10.0.1',
reason='These commands are now in the CLI.',
recommend_remove=True))

def load_command_table(self, args):
from azure.cli.core.aaz import load_aaz_command_table
try:
from . import aaz
except ImportError:
aaz = None
if aaz:
load_aaz_command_table(
loader=self,
aaz_pkg_name=aaz.__name__,
args=args
)

load_flexibleserver_command_table(self, args)
return self.command_table

def load_arguments(self, command):
load_arguments(self, command)


COMMAND_LOADER_CLS = PostgreSQLCommandsLoader
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 azure.cli.core.commands.client_factory import get_mgmt_service_client
from azure.cli.core.profiles import ResourceType
from azure.cli.core.auth.identity import get_environment_credential, AZURE_CLIENT_ID

# pylint: disable=import-outside-toplevel

RM_URI_OVERRIDE = 'AZURE_CLI_POSTGRESQL_FLEXIBLE_RM_URI'
SUB_ID_OVERRIDE = 'AZURE_CLI_POSTGRESQL_FLEXIBLE_SUB_ID'


def get_postgresql_flexible_management_client(cli_ctx, subscription_id=None, **_):
from os import getenv
from azure.mgmt.postgresqlflexibleservers import PostgreSQLManagementClient
# Allow overriding resource manager URI using environment variable
# for testing purposes. Subscription id is also determined by environment
# variable.
rm_uri_override = getenv(RM_URI_OVERRIDE)
subscription = subscription_id if subscription_id is not None else getenv(SUB_ID_OVERRIDE)
if rm_uri_override:
client_id = getenv(AZURE_CLIENT_ID)
if client_id:
credentials = get_environment_credential()
else:
from msrest.authentication import Authentication # pylint: disable=import-error
credentials = Authentication()

return PostgreSQLManagementClient(
subscription_id=subscription,
base_url=rm_uri_override,
credential=credentials)
# Normal production scenario.
return get_mgmt_service_client(cli_ctx, PostgreSQLManagementClient, subscription_id=subscription)


def cf_postgres_flexible_servers(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).servers


def cf_postgres_flexible_firewall_rules(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).firewall_rules


def cf_postgres_flexible_virtual_endpoints(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).virtual_endpoints


def cf_postgres_flexible_config(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).configurations


def cf_postgres_flexible_replica(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).replicas


def cf_postgres_flexible_location_capabilities(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).capabilities_by_location


def cf_postgres_flexible_server_capabilities(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).capabilities_by_server


def cf_postgres_flexible_backups(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).backups_automatic_and_on_demand


def cf_postgres_flexible_ltr_backups(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).backups_long_term_retention


def cf_postgres_flexible_operations(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).operations


def cf_postgres_flexible_admin(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).administrators_microsoft_entra


def cf_postgres_flexible_migrations(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).migrations


def cf_postgres_flexible_server_threat_protection_settings(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).server_threat_protection_settings


def cf_postgres_flexible_advanced_threat_protection_settings(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).advanced_threat_protection_settings


def cf_postgres_flexible_server_log_files(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).captured_logs


def cf_postgres_check_resource_availability(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).name_availability


def cf_postgres_flexible_db(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).databases


def cf_postgres_flexible_private_dns_zone_suffix_operations(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).private_dns_zone_suffix


def cf_postgres_flexible_private_endpoint_connections(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).private_endpoint_connections


def cf_postgres_flexible_private_link_resources(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).private_link_resources


def cf_postgres_flexible_tuning_options(cli_ctx, _):
return get_postgresql_flexible_management_client(cli_ctx).tuning_options


def resource_client_factory(cli_ctx, subscription_id=None):
return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id)


def private_dns_client_factory(cli_ctx, subscription_id=None):
from azure.mgmt.privatedns import PrivateDnsManagementClient
return get_mgmt_service_client(cli_ctx, PrivateDnsManagementClient, subscription_id=subscription_id).private_zones


def private_dns_link_client_factory(cli_ctx, subscription_id=None):
from azure.mgmt.privatedns import PrivateDnsManagementClient
return get_mgmt_service_client(cli_ctx, PrivateDnsManagementClient,
subscription_id=subscription_id).virtual_network_links
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import json
import os
from azure.cli.core.azclierror import BadRequestError

_config = None


def get_config_json():
global _config # pylint:disable=global-statement
if _config is not None:
return _config
script_dir = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(script_dir, "config.json"), "r") as f:
try:
_config = json.load(f)
return _config
except ValueError:
raise BadRequestError("Invalid json file. Make sure that the json file content is properly formatted.")


def get_cloud(cmd):
config = get_config_json()
return config[cmd.cli_ctx.cloud.name]


def get_cloud_cluster(cmd, location, subscription_id):
try:
cloud = get_cloud(cmd)
clusters = cloud[location]
except KeyError:
clusters = None
if clusters is not None:
for cluster in clusters:
if cloud[cluster] is not None:
if subscription_id in cloud[cluster]["subscriptions"]:
return cloud[cluster]
return
Loading