|
| 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 | + |
| 6 | +from azure.cli.core.commands.client_factory import get_mgmt_service_client |
| 7 | +from azure.cli.core.profiles import ResourceType |
| 8 | +from azure.cli.core.auth.identity import get_environment_credential, AZURE_CLIENT_ID |
| 9 | + |
| 10 | +# pylint: disable=import-outside-toplevel |
| 11 | + |
| 12 | +RM_URI_OVERRIDE = 'AZURE_CLI_POSTGRESQL_FLEXIBLE_RM_URI' |
| 13 | +SUB_ID_OVERRIDE = 'AZURE_CLI_POSTGRESQL_FLEXIBLE_SUB_ID' |
| 14 | + |
| 15 | + |
| 16 | +def get_postgresql_flexible_management_client(cli_ctx, subscription_id=None, **_): |
| 17 | + from os import getenv |
| 18 | + from azure.mgmt.postgresqlflexibleservers import PostgreSQLManagementClient |
| 19 | + # Allow overriding resource manager URI using environment variable |
| 20 | + # for testing purposes. Subscription id is also determined by environment |
| 21 | + # variable. |
| 22 | + rm_uri_override = getenv(RM_URI_OVERRIDE) |
| 23 | + subscription = subscription_id if subscription_id is not None else getenv(SUB_ID_OVERRIDE) |
| 24 | + if rm_uri_override: |
| 25 | + client_id = getenv(AZURE_CLIENT_ID) |
| 26 | + if client_id: |
| 27 | + credentials = get_environment_credential() |
| 28 | + else: |
| 29 | + from msrest.authentication import Authentication # pylint: disable=import-error |
| 30 | + credentials = Authentication() |
| 31 | + |
| 32 | + return PostgreSQLManagementClient( |
| 33 | + subscription_id=subscription, |
| 34 | + base_url=rm_uri_override, |
| 35 | + credential=credentials) |
| 36 | + # Normal production scenario. |
| 37 | + return get_mgmt_service_client(cli_ctx, PostgreSQLManagementClient, subscription_id=subscription) |
| 38 | + |
| 39 | + |
| 40 | +def cf_postgres_flexible_servers(cli_ctx, _): |
| 41 | + return get_postgresql_flexible_management_client(cli_ctx).servers |
| 42 | + |
| 43 | + |
| 44 | +def cf_postgres_flexible_firewall_rules(cli_ctx, _): |
| 45 | + return get_postgresql_flexible_management_client(cli_ctx).firewall_rules |
| 46 | + |
| 47 | + |
| 48 | +def cf_postgres_flexible_virtual_endpoints(cli_ctx, _): |
| 49 | + return get_postgresql_flexible_management_client(cli_ctx).virtual_endpoints |
| 50 | + |
| 51 | + |
| 52 | +def cf_postgres_flexible_config(cli_ctx, _): |
| 53 | + return get_postgresql_flexible_management_client(cli_ctx).configurations |
| 54 | + |
| 55 | + |
| 56 | +def cf_postgres_flexible_replica(cli_ctx, _): |
| 57 | + return get_postgresql_flexible_management_client(cli_ctx).replicas |
| 58 | + |
| 59 | + |
| 60 | +def cf_postgres_flexible_location_capabilities(cli_ctx, _): |
| 61 | + return get_postgresql_flexible_management_client(cli_ctx).capabilities_by_location |
| 62 | + |
| 63 | + |
| 64 | +def cf_postgres_flexible_server_capabilities(cli_ctx, _): |
| 65 | + return get_postgresql_flexible_management_client(cli_ctx).capabilities_by_server |
| 66 | + |
| 67 | + |
| 68 | +def cf_postgres_flexible_backups(cli_ctx, _): |
| 69 | + return get_postgresql_flexible_management_client(cli_ctx).backups_automatic_and_on_demand |
| 70 | + |
| 71 | + |
| 72 | +def cf_postgres_flexible_ltr_backups(cli_ctx, _): |
| 73 | + return get_postgresql_flexible_management_client(cli_ctx).backups_long_term_retention |
| 74 | + |
| 75 | + |
| 76 | +def cf_postgres_flexible_operations(cli_ctx, _): |
| 77 | + return get_postgresql_flexible_management_client(cli_ctx).operations |
| 78 | + |
| 79 | + |
| 80 | +def cf_postgres_flexible_admin(cli_ctx, _): |
| 81 | + return get_postgresql_flexible_management_client(cli_ctx).administrators_microsoft_entra |
| 82 | + |
| 83 | + |
| 84 | +def cf_postgres_flexible_migrations(cli_ctx, _): |
| 85 | + return get_postgresql_flexible_management_client(cli_ctx).migrations |
| 86 | + |
| 87 | + |
| 88 | +def cf_postgres_flexible_server_threat_protection_settings(cli_ctx, _): |
| 89 | + return get_postgresql_flexible_management_client(cli_ctx).server_threat_protection_settings |
| 90 | + |
| 91 | + |
| 92 | +def cf_postgres_flexible_advanced_threat_protection_settings(cli_ctx, _): |
| 93 | + return get_postgresql_flexible_management_client(cli_ctx).advanced_threat_protection_settings |
| 94 | + |
| 95 | + |
| 96 | +def cf_postgres_flexible_server_log_files(cli_ctx, _): |
| 97 | + return get_postgresql_flexible_management_client(cli_ctx).captured_logs |
| 98 | + |
| 99 | + |
| 100 | +def cf_postgres_check_resource_availability(cli_ctx, _): |
| 101 | + return get_postgresql_flexible_management_client(cli_ctx).name_availability |
| 102 | + |
| 103 | + |
| 104 | +def cf_postgres_flexible_db(cli_ctx, _): |
| 105 | + return get_postgresql_flexible_management_client(cli_ctx).databases |
| 106 | + |
| 107 | + |
| 108 | +def cf_postgres_flexible_private_dns_zone_suffix_operations(cli_ctx, _): |
| 109 | + return get_postgresql_flexible_management_client(cli_ctx).private_dns_zone_suffix |
| 110 | + |
| 111 | + |
| 112 | +def cf_postgres_flexible_private_endpoint_connections(cli_ctx, _): |
| 113 | + return get_postgresql_flexible_management_client(cli_ctx).private_endpoint_connections |
| 114 | + |
| 115 | + |
| 116 | +def cf_postgres_flexible_private_link_resources(cli_ctx, _): |
| 117 | + return get_postgresql_flexible_management_client(cli_ctx).private_link_resources |
| 118 | + |
| 119 | + |
| 120 | +def cf_postgres_flexible_tuning_options(cli_ctx, _): |
| 121 | + return get_postgresql_flexible_management_client(cli_ctx).tuning_options |
| 122 | + |
| 123 | + |
| 124 | +def resource_client_factory(cli_ctx, subscription_id=None): |
| 125 | + return get_mgmt_service_client(cli_ctx, ResourceType.MGMT_RESOURCE_RESOURCES, subscription_id=subscription_id) |
| 126 | + |
| 127 | + |
| 128 | +def private_dns_client_factory(cli_ctx, subscription_id=None): |
| 129 | + from azure.mgmt.privatedns import PrivateDnsManagementClient |
| 130 | + return get_mgmt_service_client(cli_ctx, PrivateDnsManagementClient, subscription_id=subscription_id).private_zones |
| 131 | + |
| 132 | + |
| 133 | +def private_dns_link_client_factory(cli_ctx, subscription_id=None): |
| 134 | + from azure.mgmt.privatedns import PrivateDnsManagementClient |
| 135 | + return get_mgmt_service_client(cli_ctx, PrivateDnsManagementClient, |
| 136 | + subscription_id=subscription_id).virtual_network_links |
0 commit comments