From 6d3154916e23d91cc37cfd51cfb3ea0babcf837c Mon Sep 17 00:00:00 2001 From: Rafael Mendizabal Date: Fri, 20 Nov 2026 13:58:23 -0600 Subject: [PATCH 1/2] [HorizonDB] Add cluster authentication and password commands Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 623396a5-dd46-4d21-9278-63b6e564f9b3 --- src/horizondb/HISTORY.rst | 5 + src/horizondb/README.md | 24 ++ src/horizondb/azext_horizondb/__init__.py | 3 + .../cluster/authentication/__cmd_group.py | 24 ++ .../cluster/authentication/__init__.py | 12 + .../horizondb/cluster/authentication/_list.py | 225 ++++++++++++++ .../authentication/password/__cmd_group.py | 24 ++ .../authentication/password/__init__.py | 15 + .../authentication/password/_create.py | 284 ++++++++++++++++++ .../cluster/authentication/password/_show.py | 216 +++++++++++++ .../authentication/password/_update.py | 275 +++++++++++++++++ .../cluster/authentication/password/_wait.py | 211 +++++++++++++ .../cluster/authentication/password/custom.py | 85 ++++++ .../tests/latest/unittest_authentication.py | 154 ++++++++++ src/horizondb/setup.py | 2 +- 15 files changed, 1558 insertions(+), 1 deletion(-) create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/__cmd_group.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/__init__.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/_list.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/__cmd_group.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/__init__.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_create.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_show.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_update.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_wait.py create mode 100644 src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/custom.py create mode 100644 src/horizondb/azext_horizondb/tests/latest/unittest_authentication.py diff --git a/src/horizondb/HISTORY.rst b/src/horizondb/HISTORY.rst index bdc10cdd359..6280f1a031f 100644 --- a/src/horizondb/HISTORY.rst +++ b/src/horizondb/HISTORY.rst @@ -3,6 +3,11 @@ Release History =============== +1.0.0b10 +++++++++ +* Add ``az horizondb cluster authentication list`` and ``authentication password`` + commands to show, configure, update, and wait for cluster password authentication. + 1.0.0b9 +++++++ * Update the management API to ``2026-10-01-preview`` with PostgreSQL 17 and 18 support. diff --git a/src/horizondb/README.md b/src/horizondb/README.md index 2f83557411e..e0b5d456f3c 100644 --- a/src/horizondb/README.md +++ b/src/horizondb/README.md @@ -54,6 +54,30 @@ For example, scale the pool's vCores: az horizondb cluster pool update --resource-group example-resource-group --cluster-name example-cluster --name example-pool --v-cores 4 ``` +## Manage cluster authentication + +List the cluster's service-created authentication methods, then inspect the password method: + +```powershell +az horizondb cluster authentication list -g example-resource-group --cluster-name example-cluster +az horizondb cluster authentication password show -g example-resource-group --cluster-name example-cluster +``` + +For initial setup, use `password create` with `--state Enabled` and the administrator login. +Pass `--admin-password` (alias `--administrator-login-password`) **without a value** in a terminal to enter and confirm +the password without echo. An inline password can appear in shell history, process arguments, +or CLI debug logs. Passwords are never returned by these commands. + +```powershell +az horizondb cluster authentication password create -g example-resource-group --cluster-name example-cluster --state Enabled --administrator-login exampleadmin --admin-password +az horizondb cluster authentication password update -g example-resource-group --cluster-name example-cluster --admin-password --no-wait +az horizondb cluster authentication password wait -g example-resource-group --cluster-name example-cluster --updated +``` + +`password update` changes only the supplied settings. Use `--state Disabled` alone +to disable password authentication, or `--state Enabled` with a password to +re-enable the method and reset the password. Both create and update accept `--no-wait`. + ## Manage parameter groups Create a parameter group for the cluster's PostgreSQL version, then associate diff --git a/src/horizondb/azext_horizondb/__init__.py b/src/horizondb/azext_horizondb/__init__.py index 2984ce362fe..fad0a96c6ab 100644 --- a/src/horizondb/azext_horizondb/__init__.py +++ b/src/horizondb/azext_horizondb/__init__.py @@ -18,12 +18,15 @@ def load_command_table(self, args): args=args ) from .aaz.latest.horizondb.cluster.custom import ClusterCreate, ClusterUpdate + from .aaz.latest.horizondb.cluster.authentication.password.custom import PasswordCreate, PasswordUpdate from .aaz.latest.horizondb.cluster.custom_restore import ClusterRestore from .aaz.latest.horizondb.cluster.pool.custom import PoolCreate, PoolUpdate from .aaz.latest.horizondb.cluster.private_link_resource.custom import PrivateLinkResourceShow self.command_table['horizondb cluster create'] = ClusterCreate(loader=self) self.command_table['horizondb cluster restore'] = ClusterRestore(loader=self) self.command_table['horizondb cluster update'] = ClusterUpdate(loader=self) + self.command_table['horizondb cluster authentication password create'] = PasswordCreate(loader=self) + self.command_table['horizondb cluster authentication password update'] = PasswordUpdate(loader=self) self.command_table['horizondb cluster pool create'] = PoolCreate(loader=self) self.command_table['horizondb cluster pool update'] = PoolUpdate(loader=self) self.command_table['horizondb cluster private-link-resource show'] = PrivateLinkResourceShow(loader=self) diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/__cmd_group.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/__cmd_group.py new file mode 100644 index 00000000000..06f701e5c5f --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/__cmd_group.py @@ -0,0 +1,24 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command_group( + "horizondb cluster authentication", + is_preview=True, +) +class __CMDGroup(AAZCommandGroup): + """Manage authentication methods for a HorizonDB cluster. + """ + pass + + +__all__ = ["__CMDGroup"] diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/__init__.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/__init__.py new file mode 100644 index 00000000000..d63ae5a6fc9 --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/__init__.py @@ -0,0 +1,12 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from .__cmd_group import * +from ._list import * diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/_list.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/_list.py new file mode 100644 index 00000000000..68610fee1eb --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/_list.py @@ -0,0 +1,225 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "horizondb cluster authentication list", + is_preview=True, +) +class List(AAZCommand): + """List authentication methods for a HorizonDB cluster. + + :example: List cluster authentication methods + az horizondb cluster authentication list --resource-group example-resource-group --cluster-name example-cluster + """ + + _aaz_info = { + "version": "2026-10-01-preview", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.horizondb/clusters/{}/authentications", "2026-10-01-preview"], + ] + } + + AZ_SUPPORT_PAGINATION = True + + def _handler(self, command_args): + super()._handler(command_args) + return self.build_paging(self._execute_operations, self._output) + + _args_schema = None + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + if cls._args_schema is not None: + return cls._args_schema + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.cluster_name = AAZStrArg( + options=["--cluster-name"], + help="The name of the HorizonDB cluster.", + required=True, + fmt=AAZStrArgFormat( + pattern="^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?$", + max_length=63, + min_length=1, + ), + ) + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + self.AuthenticationsList(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance.value, client_flatten=True) + next_link = self.deserialize_output(self.ctx.vars.instance.next_link) + return result, next_link + + class AuthenticationsList(AAZHttpOperation): + CLIENT_TYPE = "MgmtClient" + + def __call__(self, *args, **kwargs): + request = self.make_request() + session = self.client.send_request(request=request, stream=False, **kwargs) + if session.http_response.status_code in [200]: + return self.on_200(session) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HorizonDb/clusters/{clusterName}/authentications", + **self.url_parameters + ) + + @property + def method(self): + return "GET" + + @property + def error_format(self): + return "MgmtErrorFormat" + + @property + def url_parameters(self): + parameters = { + **self.serialize_url_param( + "clusterName", self.ctx.args.cluster_name, + required=True, + ), + **self.serialize_url_param( + "resourceGroupName", self.ctx.args.resource_group, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2026-10-01-preview", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + def on_200(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200 + ) + + _schema_on_200 = None + + @classmethod + def _build_schema_on_200(cls): + if cls._schema_on_200 is not None: + return cls._schema_on_200 + + cls._schema_on_200 = AAZObjectType() + + _schema_on_200 = cls._schema_on_200 + _schema_on_200.next_link = AAZStrType( + serialized_name="nextLink", + ) + _schema_on_200.value = AAZListType( + flags={"required": True}, + ) + + value = cls._schema_on_200.value + value.Element = AAZObjectType() + + _element = cls._schema_on_200.value.Element + _element.id = AAZStrType( + flags={"read_only": True}, + ) + _element.name = AAZStrType( + flags={"read_only": True}, + ) + _element.properties = AAZObjectType() + _element.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _element.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200.value.Element.properties + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.state = AAZStrType( + flags={"read_only": True}, + ) + + system_data = cls._schema_on_200.value.Element.system_data + system_data.created_at = AAZStrType( + serialized_name="createdAt", + ) + system_data.created_by = AAZStrType( + serialized_name="createdBy", + ) + system_data.created_by_type = AAZStrType( + serialized_name="createdByType", + ) + system_data.last_modified_at = AAZStrType( + serialized_name="lastModifiedAt", + ) + system_data.last_modified_by = AAZStrType( + serialized_name="lastModifiedBy", + ) + system_data.last_modified_by_type = AAZStrType( + serialized_name="lastModifiedByType", + ) + + return cls._schema_on_200 + + +class _ListHelper: + """Helper class for List""" + + +__all__ = ["List"] diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/__cmd_group.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/__cmd_group.py new file mode 100644 index 00000000000..790679678d3 --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/__cmd_group.py @@ -0,0 +1,24 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command_group( + "horizondb cluster authentication password", + is_preview=True, +) +class __CMDGroup(AAZCommandGroup): + """Manage password authentication settings for a HorizonDB cluster. + """ + pass + + +__all__ = ["__CMDGroup"] diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/__init__.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/__init__.py new file mode 100644 index 00000000000..57f3778e840 --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/__init__.py @@ -0,0 +1,15 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from .__cmd_group import * +from ._create import * +from ._show import * +from ._update import * +from ._wait import * diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_create.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_create.py new file mode 100644 index 00000000000..3a5a3365ec5 --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_create.py @@ -0,0 +1,284 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "horizondb cluster authentication password create", + is_preview=True, +) +class Create(AAZCommand): + """Create or replace password authentication settings for a HorizonDB cluster. + + :example: Set up an administrator using a securely prompted password + az horizondb cluster authentication password create --resource-group example-resource-group --cluster-name example-cluster --state Enabled --administrator-login exampleadmin --administrator-login-password + """ + + _aaz_info = { + "version": "2026-10-01-preview", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.horizondb/clusters/{}/authentications/passwordmethod", "2026-10-01-preview"], + ] + } + + AZ_SUPPORT_NO_WAIT = True + + def _handler(self, command_args): + super()._handler(command_args) + return self.build_lro_poller(self._execute_operations, self._output) + + _args_schema = None + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + if cls._args_schema is not None: + return cls._args_schema + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.cluster_name = AAZStrArg( + options=["--cluster-name"], + help="The name of the HorizonDB cluster.", + required=True, + fmt=AAZStrArgFormat( + pattern="^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?$", + max_length=63, + min_length=1, + ), + ) + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + + # define Arg Group "Properties" + + _args_schema = cls._args_schema + _args_schema.administrator_login = AAZStrArg( + options=["--administrator-login"], + arg_group="Properties", + help="The PostgreSQL administrator login name. This value is returned in responses after it is set. After it is set, renaming is not supported. Setting the login requires password authentication state to be Enabled in the same request.", + fmt=AAZStrArgFormat( + max_length=63, + min_length=1, + ), + ) + _args_schema.administrator_login_password = AAZPasswordArg( + options=["--admin-password", "--administrator-login-password"], + arg_group="Properties", + help="The PostgreSQL administrator password. Setting the password requires password authentication state to be Enabled in the same request.", + fmt=AAZStrArgFormat( + max_length=128, + min_length=8, + ), + blank=AAZPromptPasswordInput( + msg="Administrator password: ", + confirm=True, + ), + ) + _args_schema.state = AAZStrArg( + options=["--state"], + arg_group="Properties", + help="The state of PostgreSQL username-and-password authentication.", + enum={"Disabled": "Disabled", "Enabled": "Enabled"}, + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + yield self.PasswordAuthenticationsCreateOrReplace(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) + return result + + class PasswordAuthenticationsCreateOrReplace(AAZHttpOperation): + CLIENT_TYPE = "MgmtClient" + + def __call__(self, *args, **kwargs): + request = self.make_request() + session = self.client.send_request(request=request, stream=False, **kwargs) + if session.http_response.status_code in [202]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200_201, + self.on_error, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=self.url_parameters, + ) + if session.http_response.status_code in [200, 201]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200_201, + self.on_error, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=self.url_parameters, + ) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HorizonDb/clusters/{clusterName}/authentications/passwordMethod", + **self.url_parameters + ) + + @property + def method(self): + return "PUT" + + @property + def error_format(self): + return "MgmtErrorFormat" + + @property + def url_parameters(self): + parameters = { + **self.serialize_url_param( + "clusterName", self.ctx.args.cluster_name, + required=True, + ), + **self.serialize_url_param( + "resourceGroupName", self.ctx.args.resource_group, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2026-10-01-preview", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Content-Type", "application/json", + ), + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + @property + def content(self): + _content_value, _builder = self.new_content_builder( + self.ctx.args, + typ=AAZObjectType, + typ_kwargs={"flags": {"required": True, "client_flatten": True}} + ) + _builder.set_prop("properties", AAZObjectType) + + properties = _builder.get(".properties") + if properties is not None: + properties.set_prop("administratorLogin", AAZStrType, ".administrator_login") + properties.set_prop("administratorLoginPassword", AAZStrType, ".administrator_login_password", typ_kwargs={"flags": {"secret": True}}) + properties.set_prop("state", AAZStrType, ".state", typ_kwargs={"flags": {"required": True}}) + + return self.serialize_content(_content_value) + + def on_200_201(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200_201 + ) + + _schema_on_200_201 = None + + @classmethod + def _build_schema_on_200_201(cls): + if cls._schema_on_200_201 is not None: + return cls._schema_on_200_201 + + cls._schema_on_200_201 = AAZObjectType() + + _schema_on_200_201 = cls._schema_on_200_201 + _schema_on_200_201.id = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200_201.name = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200_201.properties = AAZObjectType() + _schema_on_200_201.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _schema_on_200_201.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200_201.properties + properties.administrator_login = AAZStrType( + serialized_name="administratorLogin", + ) + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.state = AAZStrType( + flags={"required": True}, + ) + + system_data = cls._schema_on_200_201.system_data + system_data.created_at = AAZStrType( + serialized_name="createdAt", + ) + system_data.created_by = AAZStrType( + serialized_name="createdBy", + ) + system_data.created_by_type = AAZStrType( + serialized_name="createdByType", + ) + system_data.last_modified_at = AAZStrType( + serialized_name="lastModifiedAt", + ) + system_data.last_modified_by = AAZStrType( + serialized_name="lastModifiedBy", + ) + system_data.last_modified_by_type = AAZStrType( + serialized_name="lastModifiedByType", + ) + + return cls._schema_on_200_201 + + +class _CreateHelper: + """Helper class for Create""" + + +__all__ = ["Create"] diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_show.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_show.py new file mode 100644 index 00000000000..4f8a7ccd772 --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_show.py @@ -0,0 +1,216 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "horizondb cluster authentication password show", + is_preview=True, +) +class Show(AAZCommand): + """Show password authentication settings for a HorizonDB cluster. + + :example: Show password authentication settings + az horizondb cluster authentication password show --resource-group example-resource-group --cluster-name example-cluster + """ + + _aaz_info = { + "version": "2026-10-01-preview", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.horizondb/clusters/{}/authentications/passwordmethod", "2026-10-01-preview"], + ] + } + + def _handler(self, command_args): + super()._handler(command_args) + self._execute_operations() + return self._output() + + _args_schema = None + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + if cls._args_schema is not None: + return cls._args_schema + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.cluster_name = AAZStrArg( + options=["--cluster-name"], + help="The name of the HorizonDB cluster.", + required=True, + id_part="name", + fmt=AAZStrArgFormat( + pattern="^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?$", + max_length=63, + min_length=1, + ), + ) + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + self.PasswordAuthenticationsGet(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) + return result + + class PasswordAuthenticationsGet(AAZHttpOperation): + CLIENT_TYPE = "MgmtClient" + + def __call__(self, *args, **kwargs): + request = self.make_request() + session = self.client.send_request(request=request, stream=False, **kwargs) + if session.http_response.status_code in [200]: + return self.on_200(session) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HorizonDb/clusters/{clusterName}/authentications/passwordMethod", + **self.url_parameters + ) + + @property + def method(self): + return "GET" + + @property + def error_format(self): + return "MgmtErrorFormat" + + @property + def url_parameters(self): + parameters = { + **self.serialize_url_param( + "clusterName", self.ctx.args.cluster_name, + required=True, + ), + **self.serialize_url_param( + "resourceGroupName", self.ctx.args.resource_group, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2026-10-01-preview", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + def on_200(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200 + ) + + _schema_on_200 = None + + @classmethod + def _build_schema_on_200(cls): + if cls._schema_on_200 is not None: + return cls._schema_on_200 + + cls._schema_on_200 = AAZObjectType() + + _schema_on_200 = cls._schema_on_200 + _schema_on_200.id = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.name = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.properties = AAZObjectType() + _schema_on_200.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _schema_on_200.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200.properties + properties.administrator_login = AAZStrType( + serialized_name="administratorLogin", + ) + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.state = AAZStrType( + flags={"required": True}, + ) + + system_data = cls._schema_on_200.system_data + system_data.created_at = AAZStrType( + serialized_name="createdAt", + ) + system_data.created_by = AAZStrType( + serialized_name="createdBy", + ) + system_data.created_by_type = AAZStrType( + serialized_name="createdByType", + ) + system_data.last_modified_at = AAZStrType( + serialized_name="lastModifiedAt", + ) + system_data.last_modified_by = AAZStrType( + serialized_name="lastModifiedBy", + ) + system_data.last_modified_by_type = AAZStrType( + serialized_name="lastModifiedByType", + ) + + return cls._schema_on_200 + + +class _ShowHelper: + """Helper class for Show""" + + +__all__ = ["Show"] diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_update.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_update.py new file mode 100644 index 00000000000..d738ef29c76 --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_update.py @@ -0,0 +1,275 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "horizondb cluster authentication password update", + is_preview=True, +) +class Update(AAZCommand): + """Update password authentication settings for a HorizonDB cluster. + + :example: Reset the administrator password using a secure prompt + az horizondb cluster authentication password update --resource-group example-resource-group --cluster-name example-cluster --administrator-login-password + """ + + _aaz_info = { + "version": "2026-10-01-preview", + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.horizondb/clusters/{}/authentications/passwordmethod", "2026-10-01-preview"], + ] + } + + AZ_SUPPORT_NO_WAIT = True + + def _handler(self, command_args): + super()._handler(command_args) + return self.build_lro_poller(self._execute_operations, self._output) + + _args_schema = None + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + if cls._args_schema is not None: + return cls._args_schema + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.cluster_name = AAZStrArg( + options=["--cluster-name"], + help="The name of the HorizonDB cluster.", + required=True, + id_part="name", + fmt=AAZStrArgFormat( + pattern="^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?$", + max_length=63, + min_length=1, + ), + ) + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + + # define Arg Group "Properties" + + _args_schema = cls._args_schema + _args_schema.administrator_login_password = AAZPasswordArg( + options=["--admin-password", "--administrator-login-password"], + arg_group="Properties", + help="The PostgreSQL administrator password. Supplying this property resets the configured administrator's password. When password authentication is currently disabled for a cluster that already has an administrator, this property can be combined with state Enabled to re-enable password authentication and reset the password.", + fmt=AAZStrArgFormat( + max_length=128, + min_length=8, + ), + blank=AAZPromptPasswordInput( + msg="Administrator password: ", + confirm=True, + ), + ) + _args_schema.state = AAZStrArg( + options=["--state"], + arg_group="Properties", + help="The target password-authentication state. Enabled can be combined with administratorLoginPassword to re-enable password authentication and reset the password for a cluster that already has an administrator. Disabling password authentication does not remove or modify existing database users or roles. Disabled cannot be combined with administratorLoginPassword.", + enum={"Disabled": "Disabled", "Enabled": "Enabled"}, + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + yield self.PasswordAuthenticationsUpdate(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) + return result + + class PasswordAuthenticationsUpdate(AAZHttpOperation): + CLIENT_TYPE = "MgmtClient" + + def __call__(self, *args, **kwargs): + request = self.make_request() + session = self.client.send_request(request=request, stream=False, **kwargs) + if session.http_response.status_code in [202]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200, + self.on_error, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=self.url_parameters, + ) + if session.http_response.status_code in [200]: + return self.client.build_lro_polling( + self.ctx.args.no_wait, + session, + self.on_200, + self.on_error, + lro_options={"final-state-via": "azure-async-operation"}, + path_format_arguments=self.url_parameters, + ) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HorizonDb/clusters/{clusterName}/authentications/passwordMethod", + **self.url_parameters + ) + + @property + def method(self): + return "PATCH" + + @property + def error_format(self): + return "MgmtErrorFormat" + + @property + def url_parameters(self): + parameters = { + **self.serialize_url_param( + "clusterName", self.ctx.args.cluster_name, + required=True, + ), + **self.serialize_url_param( + "resourceGroupName", self.ctx.args.resource_group, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2026-10-01-preview", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Content-Type", "application/json", + ), + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + @property + def content(self): + _content_value, _builder = self.new_content_builder( + self.ctx.args, + typ=AAZObjectType, + typ_kwargs={"flags": {"required": True, "client_flatten": True}} + ) + _builder.set_prop("properties", AAZObjectType) + + properties = _builder.get(".properties") + if properties is not None: + properties.set_prop("administratorLoginPassword", AAZStrType, ".administrator_login_password", typ_kwargs={"flags": {"secret": True}}) + properties.set_prop("state", AAZStrType, ".state") + + return self.serialize_content(_content_value) + + def on_200(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200 + ) + + _schema_on_200 = None + + @classmethod + def _build_schema_on_200(cls): + if cls._schema_on_200 is not None: + return cls._schema_on_200 + + cls._schema_on_200 = AAZObjectType() + + _schema_on_200 = cls._schema_on_200 + _schema_on_200.id = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.name = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.properties = AAZObjectType() + _schema_on_200.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _schema_on_200.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200.properties + properties.administrator_login = AAZStrType( + serialized_name="administratorLogin", + ) + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.state = AAZStrType( + flags={"required": True}, + ) + + system_data = cls._schema_on_200.system_data + system_data.created_at = AAZStrType( + serialized_name="createdAt", + ) + system_data.created_by = AAZStrType( + serialized_name="createdBy", + ) + system_data.created_by_type = AAZStrType( + serialized_name="createdByType", + ) + system_data.last_modified_at = AAZStrType( + serialized_name="lastModifiedAt", + ) + system_data.last_modified_by = AAZStrType( + serialized_name="lastModifiedBy", + ) + system_data.last_modified_by_type = AAZStrType( + serialized_name="lastModifiedByType", + ) + + return cls._schema_on_200 + + +class _UpdateHelper: + """Helper class for Update""" + + +__all__ = ["Update"] diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_wait.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_wait.py new file mode 100644 index 00000000000..3da65816ed8 --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/_wait.py @@ -0,0 +1,211 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# +# Code generated by aaz-dev-tools +# -------------------------------------------------------------------------------------------- + +# pylint: skip-file +# flake8: noqa + +from azure.cli.core.aaz import * + + +@register_command( + "horizondb cluster authentication password wait", +) +class Wait(AAZWaitCommand): + """Place the CLI in a waiting state until a condition is met. + """ + + _aaz_info = { + "resources": [ + ["mgmt-plane", "/subscriptions/{}/resourcegroups/{}/providers/microsoft.horizondb/clusters/{}/authentications/passwordmethod", "2026-10-01-preview"], + ] + } + + def _handler(self, command_args): + super()._handler(command_args) + self._execute_operations() + return self._output() + + _args_schema = None + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + if cls._args_schema is not None: + return cls._args_schema + cls._args_schema = super()._build_arguments_schema(*args, **kwargs) + + # define Arg Group "" + + _args_schema = cls._args_schema + _args_schema.cluster_name = AAZStrArg( + options=["--cluster-name"], + help="The name of the HorizonDB cluster.", + required=True, + id_part="name", + fmt=AAZStrArgFormat( + pattern="^[a-z0-9](?:[-a-z0-9]*[a-z0-9])?$", + max_length=63, + min_length=1, + ), + ) + _args_schema.resource_group = AAZResourceGroupNameArg( + required=True, + ) + return cls._args_schema + + def _execute_operations(self): + self.pre_operations() + self.PasswordAuthenticationsGet(ctx=self.ctx)() + self.post_operations() + + @register_callback + def pre_operations(self): + pass + + @register_callback + def post_operations(self): + pass + + def _output(self, *args, **kwargs): + result = self.deserialize_output(self.ctx.vars.instance, client_flatten=False) + return result + + class PasswordAuthenticationsGet(AAZHttpOperation): + CLIENT_TYPE = "MgmtClient" + + def __call__(self, *args, **kwargs): + request = self.make_request() + session = self.client.send_request(request=request, stream=False, **kwargs) + if session.http_response.status_code in [200]: + return self.on_200(session) + + return self.on_error(session.http_response) + + @property + def url(self): + return self.client.format_url( + "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HorizonDb/clusters/{clusterName}/authentications/passwordMethod", + **self.url_parameters + ) + + @property + def method(self): + return "GET" + + @property + def error_format(self): + return "MgmtErrorFormat" + + @property + def url_parameters(self): + parameters = { + **self.serialize_url_param( + "clusterName", self.ctx.args.cluster_name, + required=True, + ), + **self.serialize_url_param( + "resourceGroupName", self.ctx.args.resource_group, + required=True, + ), + **self.serialize_url_param( + "subscriptionId", self.ctx.subscription_id, + required=True, + ), + } + return parameters + + @property + def query_parameters(self): + parameters = { + **self.serialize_query_param( + "api-version", "2026-10-01-preview", + required=True, + ), + } + return parameters + + @property + def header_parameters(self): + parameters = { + **self.serialize_header_param( + "Accept", "application/json", + ), + } + return parameters + + def on_200(self, session): + data = self.deserialize_http_content(session) + self.ctx.set_var( + "instance", + data, + schema_builder=self._build_schema_on_200 + ) + + _schema_on_200 = None + + @classmethod + def _build_schema_on_200(cls): + if cls._schema_on_200 is not None: + return cls._schema_on_200 + + cls._schema_on_200 = AAZObjectType() + + _schema_on_200 = cls._schema_on_200 + _schema_on_200.id = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.name = AAZStrType( + flags={"read_only": True}, + ) + _schema_on_200.properties = AAZObjectType() + _schema_on_200.system_data = AAZObjectType( + serialized_name="systemData", + flags={"read_only": True}, + ) + _schema_on_200.type = AAZStrType( + flags={"read_only": True}, + ) + + properties = cls._schema_on_200.properties + properties.administrator_login = AAZStrType( + serialized_name="administratorLogin", + ) + properties.provisioning_state = AAZStrType( + serialized_name="provisioningState", + flags={"read_only": True}, + ) + properties.state = AAZStrType( + flags={"required": True}, + ) + + system_data = cls._schema_on_200.system_data + system_data.created_at = AAZStrType( + serialized_name="createdAt", + ) + system_data.created_by = AAZStrType( + serialized_name="createdBy", + ) + system_data.created_by_type = AAZStrType( + serialized_name="createdByType", + ) + system_data.last_modified_at = AAZStrType( + serialized_name="lastModifiedAt", + ) + system_data.last_modified_by = AAZStrType( + serialized_name="lastModifiedBy", + ) + system_data.last_modified_by_type = AAZStrType( + serialized_name="lastModifiedByType", + ) + + return cls._schema_on_200 + + +class _WaitHelper: + """Helper class for Wait""" + + +__all__ = ["Wait"] diff --git a/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/custom.py b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/custom.py new file mode 100644 index 00000000000..022e7ccb0c4 --- /dev/null +++ b/src/horizondb/azext_horizondb/aaz/latest/horizondb/cluster/authentication/password/custom.py @@ -0,0 +1,85 @@ +# -------------------------------------------------------------------------------------------- +# 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.aaz import has_value +from azure.cli.core.aaz.exceptions import AAZInvalidArgValueError +from azure.cli.core.azclierror import InvalidArgumentValueError + +from ._create import Create +from ._show import Show +from ._update import Update + + +class _PasswordWrite: + _arguments_schema = None + _args_schema = None + + @classmethod + def _build_arguments_schema(cls, *args, **kwargs): + schema = super()._build_arguments_schema(*args, **kwargs) + password = schema.administrator_login_password + validate = password._fmt # pylint: disable=protected-access + + def validate_without_echo(ctx, value): + try: + return validate(ctx, value) + except AAZInvalidArgValueError: + # The default AAZ string-length error includes the supplied value. + raise AAZInvalidArgValueError("Password must contain 8 to 128 characters.") from None + + password._fmt = validate_without_echo # pylint: disable=protected-access + return schema + + def _cli_arguments_loader(self): + arguments = super()._cli_arguments_loader() + password = dict(arguments)['administrator_login_password'] + + class LiteralPasswordAction(password.type.settings['action']): + # Do not interpret punctuation or AAZ shorthand in a password. + decode_str = staticmethod(str) + + password.action = LiteralPasswordAction + return arguments + + def _output(self, *args, **kwargs): + if hasattr(self.ctx.vars, 'instance'): + return super()._output(*args, **kwargs) + # A successful async operation can finish without a resource body. + return Show(cli_ctx=self.cli_ctx)(command_args={ + 'subscription': self.ctx.subscription_id, + 'resource_group': self.ctx.args.resource_group.to_serialized_data(), + 'cluster_name': self.ctx.args.cluster_name.to_serialized_data(), + }) + + +class _NoBodyLogging: + def __call__(self, *args, **kwargs): + # CLI's network trace policy otherwise logs the entire request body under --debug. + kwargs['logging_enable'] = False + return super().__call__(*args, **kwargs) + + +class PasswordCreate(_PasswordWrite, Create): + def pre_operations(self): + args = self.ctx.args + credentials_supplied = has_value(args.administrator_login) or has_value(args.administrator_login_password) + if credentials_supplied and args.state != 'Enabled': + raise InvalidArgumentValueError("Setting administrator credentials requires --state Enabled.") + + class PasswordAuthenticationsCreateOrReplace(_NoBodyLogging, Create.PasswordAuthenticationsCreateOrReplace): + pass + + +class PasswordUpdate(_PasswordWrite, Update): + def pre_operations(self): + args = self.ctx.args + if has_value(args.administrator_login_password): + if args.state == 'Disabled': + raise InvalidArgumentValueError("A password reset cannot be combined with --state Disabled.") + elif not has_value(args.state): + raise InvalidArgumentValueError("Specify --state or --administrator-login-password.") + + class PasswordAuthenticationsUpdate(_NoBodyLogging, Update.PasswordAuthenticationsUpdate): + pass diff --git a/src/horizondb/azext_horizondb/tests/latest/unittest_authentication.py b/src/horizondb/azext_horizondb/tests/latest/unittest_authentication.py new file mode 100644 index 00000000000..73d40aae34f --- /dev/null +++ b/src/horizondb/azext_horizondb/tests/latest/unittest_authentication.py @@ -0,0 +1,154 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import json +from argparse import ArgumentParser +from unittest import TestCase +from unittest.mock import Mock, patch +from uuid import uuid4 + +from azure.cli.core import get_default_cli +from azure.cli.core.azclierror import InvalidArgumentValueError +from azure.core import PipelineClient +from azure.core.pipeline.policies import ContentDecodePolicy +from knack.prompting import NoTTYException + +from azext_horizondb import HorizonDBCommandsLoader + + +class AuthenticationTests(TestCase): + def setUp(self): + prefix = 'horizondb cluster authentication ' + table = HorizonDBCommandsLoader(cli_ctx=get_default_cli()).load_command_table(None) + self.commands = {name[len(prefix):]: cmd for name, cmd in table.items() if name.startswith(prefix)} + self.args = dict(subscription='00000000-0000-0000-0000-000000000001', resource_group='rg', cluster_name='db') + self.client = Mock(wraps=PipelineClient('https://management.azure.com')) + self.client.build_lro_polling = Mock() + client_patch = patch('azure.cli.core.aaz._command_ctx.AAZCommandCtx.get_http_client', return_value=self.client) + client_patch.start() + self.addCleanup(client_patch.stop) + self.url = ('https://management.azure.com/subscriptions/' + self.args['subscription'] + + '/resourceGroups/rg/providers/Microsoft.HorizonDb/clusters/db/authentications') + self.query = '?api-version=2026-10-01-preview' + self.secret = '[' + uuid4().hex + ']' # Include punctuation meaningful to AAZ shorthand. + self.method = {'name': 'passwordMethod', 'properties': { + 'state': 'Enabled', 'provisioningState': 'Succeeded', 'administratorLogin': 'dbadmin', + 'administratorLoginPassword': self.secret, + }} + + @staticmethod + def response(status, data): + response = Mock(context={ContentDecodePolicy.CONTEXT_NAME: data}) + response.http_response.status_code = status + return response + + def run_command(self, name, **kwargs): + return self.commands[name](command_args=dict(self.args, **kwargs)) + + def test_collection_and_password_get(self): + self.assertEqual(set(self.commands), {'list', 'password show', 'password create', 'password update', + 'password wait'}) + entra = {'name': 'microsoftEntra', 'properties': {'state': 'Disabled'}} + next_page = self.url + '?page=2' + self.client.send_request.side_effect = [ + self.response(200, {'value': [self.method], 'nextLink': next_page}), + self.response(200, {'value': [entra]}), + self.response(200, self.method), + ] + methods = list(self.run_command('list')) + self.assertEqual([item['name'] for item in methods], ['passwordMethod', 'microsoftEntra']) + shown = self.run_command('password show') + self.assertEqual(shown['properties'], { + 'administratorLogin': 'dbadmin', 'state': 'Enabled', 'provisioningState': 'Succeeded'}) + self.assertNotIn(self.secret, str(methods)) + requests = [call.kwargs['request'] for call in self.client.send_request.call_args_list] + self.assertEqual([(r.method, r.url) for r in requests], [ + ('GET', self.url + self.query), ('GET', next_page), ('GET', self.url + '/passwordMethod' + self.query)]) + + def password_argument(self, command, *values, option='--admin-password'): + command.load_arguments() + settings = command.arguments['administrator_login_password'].type.settings + self.assertCountEqual(settings['options_list'], ['--admin-password', '--administrator-login-password']) + parser = ArgumentParser() + parser.add_argument(*settings['options_list'], dest='administrator_login_password', + nargs=settings['nargs'], action=settings['action']) + return vars(parser.parse_args([option, *values])) + + def test_no_wait_put_and_sparse_patch(self): + self.client.send_request.return_value = self.response(202, None) + for verb, options, expected in [ + ('create', {'state': 'Enabled', 'administrator_login': 'dbadmin'}, + {'state': 'Enabled', 'administratorLogin': 'dbadmin', 'administratorLoginPassword': self.secret}), + ('update', {}, {'administratorLoginPassword': self.secret}), + ('update', {'state': 'Enabled'}, {'state': 'Enabled', 'administratorLoginPassword': self.secret}), + ('update', {'state': 'Disabled'}, {'state': 'Disabled'})]: + with self.subTest(verb=verb, state=options.get('state')): + name = 'password ' + verb + if 'administratorLoginPassword' in expected: + option = '--administrator-login-password' if verb == 'create' else '--admin-password' + options.update(self.password_argument(self.commands[name], self.secret, option=option)) + self.assertIsNone(self.run_command(name, no_wait=True, **options)) + request = self.client.send_request.call_args.kwargs['request'] + self.assertEqual((request.method, request.url), ( + 'PUT' if verb == 'create' else 'PATCH', self.url + '/passwordMethod' + self.query)) + self.assertEqual(json.loads(request.body), {'properties': expected}) + self.assertFalse(self.client.send_request.call_args.kwargs['logging_enable']) + self.assertTrue(self.client.build_lro_polling.call_args.args[0]) + self.client.build_lro_polling.return_value.run.assert_not_called() + + def test_wait_polls_password_method(self): + pending = {'properties': {'provisioningState': 'Updating'}} + self.client.send_request.side_effect = [self.response(200, pending), self.response(200, self.method)] + with patch('time.sleep') as sleep: + result = self.run_command('password wait', updated=True, created=False, exists=False, deleted=False, + custom=None, interval=1, timeout=2) + self.assertIsNone(result) + sleep.assert_called_once_with(1) + for call in self.client.send_request.call_args_list: + self.assertEqual(call.kwargs['request'].url, self.url + '/passwordMethod' + self.query) + + def test_prompt_is_confirmed_and_optional(self): + self.client.send_request.return_value = self.response(202, None) + with patch('azure.cli.core.aaz._prompt.prompt_pass', return_value=self.secret) as prompt: + self.run_command('password update', state='Disabled', no_wait=True) + prompt.assert_not_called() + options = self.password_argument(self.commands['password update']) + self.run_command('password update', no_wait=True, **options) + self.assertTrue(prompt.call_args.kwargs['confirm']) + request = self.client.send_request.call_args.kwargs['request'] + self.assertEqual(json.loads(request.body)['properties']['administratorLoginPassword'], self.secret) + prompt.side_effect = NoTTYException + with self.assertRaisesRegex(ValueError, 'non-interactive'): + self.run_command('password update', no_wait=True, **options) + + def test_validation_does_not_echo_password_or_contact_service(self): + for verb in ['create', 'update']: + with self.subTest(verb=verb): + for invalid in [self.secret[:7], self.secret * 4]: + with self.assertRaises(InvalidArgumentValueError) as error: + self.run_command('password ' + verb, state='Enabled', administrator_login_password=invalid) + self.assertNotIn(invalid, str(error.exception)) + with self.assertRaisesRegex(InvalidArgumentValueError, '--state'): + self.run_command('password ' + verb, state='Disabled', administrator_login_password=self.secret, + no_wait=True) + self.client.send_request.assert_not_called() + + def test_completed_write_returns_safe_resource_with_or_without_final_body(self): + for verb, body in [('create', self.method), ('update', None)]: + with self.subTest(verb=verb): + self.client.send_request.side_effect = [self.response(202, None), self.response(200, self.method)] + + def build_polling(_no_wait, _session, callback, *_args, final_body=body, **_kwargs): + poller = Mock() + if final_body: + poller.resource.side_effect = lambda: callback(self.response(200, final_body)) + return poller + + self.client.build_lro_polling.side_effect = build_polling + result = self.run_command('password ' + verb, state='Enabled').result() + self.assertEqual(result['properties']['provisioningState'], 'Succeeded') + self.assertNotIn(self.secret, str(result)) + self.assertEqual(self.client.send_request.call_count, 1 if body else 2) + self.client.send_request.reset_mock() diff --git a/src/horizondb/setup.py b/src/horizondb/setup.py index f9a6225eb3e..879f3bf6ce8 100644 --- a/src/horizondb/setup.py +++ b/src/horizondb/setup.py @@ -14,7 +14,7 @@ from distutils import log as logger logger.warn("Wheel is not available, disabling bdist_wheel hook") -VERSION = '1.0.0b9' +VERSION = '1.0.0b10' CLASSIFIERS = [ 'Development Status :: 4 - Beta', From 913f204ba7e7909599fc1f97db9792e6b9438488 Mon Sep 17 00:00:00 2001 From: Rafael Mendizabal Date: Fri, 20 Nov 2026 14:08:21 -0600 Subject: [PATCH 2/2] [HorizonDB] Add recordable password authentication lifecycle scenario Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 623396a5-dd46-4d21-9278-63b6e564f9b3 --- .../latest/test_horizondb_authentication.py | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/horizondb/azext_horizondb/tests/latest/test_horizondb_authentication.py diff --git a/src/horizondb/azext_horizondb/tests/latest/test_horizondb_authentication.py b/src/horizondb/azext_horizondb/tests/latest/test_horizondb_authentication.py new file mode 100644 index 00000000000..280a5ebfc13 --- /dev/null +++ b/src/horizondb/azext_horizondb/tests/latest/test_horizondb_authentication.py @@ -0,0 +1,51 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +import secrets +from unittest.mock import patch + +from azure.cli.testsdk import ResourceGroupPreparer, ScenarioTest +from azure.cli.testsdk.scenario_tests import AllowLargeResponse + +from .constants import CLUSTER_NAME_MAX_LENGTH, CLUSTER_NAME_PREFIX, JAPANEAST + + +class HorizonDBAuthenticationScenarioTest(ScenarioTest): + + def setUp(self): + # Without a cassette the test SDK otherwise records even in playback mode. + if self.in_recording and not self.is_live: + self.skipTest('Authentication cassette missing; record explicitly in a disposable subscription.') + super().setUp() + + @AllowLargeResponse() + @ResourceGroupPreparer(name_prefix='cli_test_horizondb_auth_', location=JAPANEAST) + def test_horizondb_authentication(self, resource_group): + self.kwargs.update(rg=resource_group, location=JAPANEAST, + cluster=self.create_random_name(CLUSTER_NAME_PREFIX, CLUSTER_NAME_MAX_LENGTH)) + self.cmd('horizondb cluster create -g {rg} -n {cluster} --location {location} ' + '--version 17 --geo-redundancy Disabled --public-access Disabled') + scope = ' -g {rg} --cluster-name {cluster}' + auth = 'horizondb cluster authentication ' + password = auth + 'password ' + self.cmd(auth + 'list' + scope, checks=[ + self.check("[?name=='passwordMethod'] | length(@)", 1), + self.check("[?name=='microsoftEntra'] | length(@)", 1), + ]) + + # Keep the live credential out of command lines and replace it in the VCR traffic. + placeholder = 'REDACTED-password-1!' + secret = 'Aa1!' + secrets.token_hex(24) if self.in_recording else placeholder + self.name_replacer.register_name_pair(secret, placeholder) + with patch('azure.cli.core.aaz._prompt.prompt_pass', return_value=secret): + self.cmd(password + 'create' + scope + ' --state Enabled --administrator-login scenarioadmin ' + '--admin-password --no-wait') + self.cmd(password + 'wait' + scope + ' --created') + self.cmd(password + 'show' + scope, checks=[ + self.check('properties.state', 'Enabled'), + self.check('properties.administratorLogin', 'scenarioadmin'), + self.check('contains(keys(properties), `\"administratorLoginPassword\"`)', False), + ]) + self.cmd(password + 'update' + scope + ' --state Disabled', checks=self.check('properties.state', 'Disabled'))