Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/documentdb/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Release History
* Add ``az documentdb mongocluster`` commands to create, update, show, list, and delete
mongo clusters, list connection strings, and check name availability.
* Add ``az documentdb mongocluster firewall-rule`` commands to manage IP firewall rules.
* Add ``az documentdb mongocluster user`` commands to manage Microsoft Entra-backed
* Add ``az documentdb mongocluster entra-user`` commands to manage Microsoft Entra ID
database users.
* Add ``az documentdb mongocluster identity`` commands to manage the cluster's
user-assigned managed identity.
Expand Down
9 changes: 5 additions & 4 deletions src/documentdb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ managed identity, cross-region read replicas, and point-in-time restore.
|--|--|
| `az documentdb mongocluster` | Create and manage mongo clusters |
| `az documentdb mongocluster firewall-rule` | Manage IP firewall rules (public access) |
| `az documentdb mongocluster user` | Manage Microsoft Entra-backed database users |
| `az documentdb mongocluster entra-user` | Manage Microsoft Entra ID database users |
| `az documentdb mongocluster identity` | Manage the cluster's user-assigned managed identity |
| `az documentdb mongocluster replica` | List, create, and promote cross-region read replicas |

Expand Down Expand Up @@ -60,11 +60,12 @@ az documentdb mongocluster firewall-rule create -n AllowMyIp --cluster-name MyCl
az documentdb mongocluster firewall-rule list --cluster-name MyCluster -g MyResourceGroup
```

### Microsoft Entra-backed users
### Microsoft Entra ID users

```bash
az documentdb mongocluster user create -n alice --cluster-name MyCluster -g MyResourceGroup \
--type User --role db=admin role=root
# The user is identified by its Microsoft Entra object (client) ID, not a friendly name.
az documentdb mongocluster entra-user assign --object-id 11111111-1111-1111-1111-111111111111 \
--cluster-name MyCluster -g MyResourceGroup --type User --role db=admin role=root
```

### Managed identity (user-assigned)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def _build_arguments_schema(cls, *args, **kwargs):

_args_schema = cls._args_schema
_args_schema.admin_password = AAZPasswordArg(
options=["-p", "--admin-password"],
options=["-p", "--password", "--admin-password"],
arg_group="Administrator",
help="The administrator password.",
required=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _build_arguments_schema(cls, *args, **kwargs):

_args_schema = cls._args_schema
_args_schema.admin_password = AAZPasswordArg(
options=["-p", "--admin-password"],
options=["-p", "--password", "--admin-password"],
arg_group="Administrator",
help="The administrator password.",
nullable=True,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@


@register_command_group(
"documentdb mongocluster user",
"documentdb mongocluster entra-user",
)
class __CMDGroup(AAZCommandGroup):
"""Manage User
"""Manage Microsoft Entra ID users on a mongo cluster.
"""
pass

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
# flake8: noqa

from .__cmd_group import *
from ._create import *
from ._delete import *
from ._assign import *
from ._list import *
from ._remove import *
from ._show import *
from ._update import *
from ._wait import *
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@


@register_command(
"documentdb mongocluster user create",
"documentdb mongocluster entra-user assign",
)
class Create(AAZCommand):
"""Create a new user or updates an existing user on a mongo cluster.
class Assign(AAZCommand):
"""Grant a Microsoft Entra ID principal access to a mongo cluster by assigning it database roles.

:example: Create an Entra-backed user.
az documentdb mongocluster user create -n alice-entra --cluster-name MyCluster -g MyResourceGroup --type User --role db=admin role=root
:example: Assign admin access to an Entra ID user (or service principal) by object ID.
az documentdb mongocluster entra-user assign --object-id 11111111-1111-1111-1111-111111111111 --cluster-name MyCluster -g MyResourceGroup --type User --role db=admin role=root
"""

_aaz_info = {
Expand Down Expand Up @@ -49,6 +49,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
options=["--cluster-name"],
help="The name of the mongo cluster.",
required=True,
id_part="name",
fmt=AAZStrArgFormat(
pattern="^[a-z0-9]+(-[a-z0-9]+)*",
max_length=40,
Expand All @@ -58,10 +59,11 @@ def _build_arguments_schema(cls, *args, **kwargs):
_args_schema.resource_group = AAZResourceGroupNameArg(
required=True,
)
_args_schema.user_name = AAZStrArg(
options=["-n", "--name", "--user-name"],
help="The name of the mongo cluster user.",
_args_schema.object_id = AAZStrArg(
options=["-n", "--name", "--object-id"],
help="Object ID (client ID) of the Microsoft Entra principal. Provide the GUID of the service principal or user, not a friendly name or UPN.",
required=True,
id_part="child_name_1",
fmt=AAZStrArgFormat(
pattern="^[a-zA-Z0-9\\-]*",
max_length=63,
Expand Down Expand Up @@ -189,7 +191,7 @@ def url_parameters(self):
required=True,
),
**self.serialize_url_param(
"userName", self.ctx.args.user_name,
"userName", self.ctx.args.object_id,
required=True,
),
}
Expand Down Expand Up @@ -348,8 +350,8 @@ def _build_schema_on_200_201(cls):
return cls._schema_on_200_201


class _CreateHelper:
"""Helper class for Create"""
class _AssignHelper:
"""Helper class for Assign"""


__all__ = ["Create"]
__all__ = ["Assign"]
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@


@register_command(
"documentdb mongocluster user list",
"documentdb mongocluster entra-user list",
)
class List(AAZCommand):
"""List all the users on a mongo cluster.
"""List the Microsoft Entra ID users on a mongo cluster.

:example: List users on a cluster.
:example: List Entra ID users on a cluster.
az documentdb mongocluster user list --cluster-name MyCluster -g MyResourceGroup
"""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@


@register_command(
"documentdb mongocluster user delete",
"documentdb mongocluster entra-user remove",
confirmation="Are you sure you want to perform this operation?",
)
class Delete(AAZCommand):
"""Delete a mongo cluster user.
class Remove(AAZCommand):
"""Remove a Microsoft Entra ID principal's access from a mongo cluster.

:example: Delete a user.
az documentdb mongocluster user delete -n alice@contoso.com --cluster-name MyCluster -g MyResourceGroup
:example: Remove an Entra ID user's access by object ID.
az documentdb mongocluster entra-user remove --object-id 11111111-1111-1111-1111-111111111111 --cluster-name MyCluster -g MyResourceGroup
"""

_aaz_info = {
Expand Down Expand Up @@ -60,9 +60,9 @@ def _build_arguments_schema(cls, *args, **kwargs):
_args_schema.resource_group = AAZResourceGroupNameArg(
required=True,
)
_args_schema.user_name = AAZStrArg(
options=["-n", "--name", "--user-name"],
help="The name of the mongo cluster user.",
_args_schema.object_id = AAZStrArg(
options=["-n", "--name", "--object-id"],
help="Object ID (client ID) of the Microsoft Entra principal. Provide the GUID of the service principal or user, not a friendly name or UPN.",
required=True,
id_part="child_name_1",
fmt=AAZStrArgFormat(
Expand Down Expand Up @@ -153,7 +153,7 @@ def url_parameters(self):
required=True,
),
**self.serialize_url_param(
"userName", self.ctx.args.user_name,
"userName", self.ctx.args.object_id,
required=True,
),
}
Expand All @@ -176,8 +176,8 @@ def on_200_201(self, session):
pass


class _DeleteHelper:
"""Helper class for Delete"""
class _RemoveHelper:
"""Helper class for Remove"""


__all__ = ["Delete"]
__all__ = ["Remove"]
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@


@register_command(
"documentdb mongocluster user show",
"documentdb mongocluster entra-user show",
)
class Show(AAZCommand):
"""Get the defintion of a Mongo cluster user.
"""Get the definition of a Microsoft Entra ID user on a mongo cluster.

:example: Get a user.
az documentdb mongocluster user show -n alice@contoso.com --cluster-name MyCluster -g MyResourceGroup
:example: Get an Entra ID user by object ID.
az documentdb mongocluster user show --object-id 11111111-1111-1111-1111-111111111111 --cluster-name MyCluster -g MyResourceGroup
"""

_aaz_info = {
Expand Down Expand Up @@ -58,9 +58,9 @@ def _build_arguments_schema(cls, *args, **kwargs):
_args_schema.resource_group = AAZResourceGroupNameArg(
required=True,
)
_args_schema.user_name = AAZStrArg(
options=["-n", "--name", "--user-name"],
help="The name of the mongo cluster user.",
_args_schema.object_id = AAZStrArg(
options=["-n", "--name", "--object-id"],
help="Object ID (client ID) of the Microsoft Entra principal. Provide the GUID of the service principal or user, not a friendly name or UPN.",
required=True,
id_part="child_name_1",
fmt=AAZStrArgFormat(
Expand Down Expand Up @@ -130,7 +130,7 @@ def url_parameters(self):
required=True,
),
**self.serialize_url_param(
"userName", self.ctx.args.user_name,
"userName", self.ctx.args.object_id,
required=True,
),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@


@register_command(
"documentdb mongocluster user update",
"documentdb mongocluster entra-user update",
)
class Update(AAZCommand):
"""Update a new user or updates an existing user on a mongo cluster.
"""Update a Microsoft Entra ID user on a mongo cluster.

:example: Update a user's roles.
az documentdb mongocluster user update -n alice-entra --cluster-name MyCluster -g MyResourceGroup --role db=admin role=root
:example: Update an Entra ID user's roles.
az documentdb mongocluster user update --object-id 11111111-1111-1111-1111-111111111111 --cluster-name MyCluster -g MyResourceGroup --role db=admin role=root
"""

_aaz_info = {
Expand Down Expand Up @@ -61,9 +61,9 @@ def _build_arguments_schema(cls, *args, **kwargs):
_args_schema.resource_group = AAZResourceGroupNameArg(
required=True,
)
_args_schema.user_name = AAZStrArg(
options=["-n", "--name", "--user-name"],
help="The name of the mongo cluster user.",
_args_schema.object_id = AAZStrArg(
options=["-n", "--name", "--object-id"],
help="Object ID (client ID) of the Microsoft Entra principal. Provide the GUID of the service principal or user, not a friendly name or UPN.",
required=True,
id_part="child_name_1",
fmt=AAZStrArgFormat(
Expand Down Expand Up @@ -191,7 +191,7 @@ def url_parameters(self):
required=True,
),
**self.serialize_url_param(
"userName", self.ctx.args.user_name,
"userName", self.ctx.args.object_id,
required=True,
),
}
Expand Down Expand Up @@ -294,7 +294,7 @@ def url_parameters(self):
required=True,
),
**self.serialize_url_param(
"userName", self.ctx.args.user_name,
"userName", self.ctx.args.object_id,
required=True,
),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


@register_command(
"documentdb mongocluster user wait",
"documentdb mongocluster entra-user wait",
)
class Wait(AAZWaitCommand):
"""Place the CLI in a waiting state until a condition is met.
Expand Down Expand Up @@ -54,9 +54,9 @@ def _build_arguments_schema(cls, *args, **kwargs):
_args_schema.resource_group = AAZResourceGroupNameArg(
required=True,
)
_args_schema.user_name = AAZStrArg(
options=["-n", "--name", "--user-name"],
help="The name of the mongo cluster user.",
_args_schema.object_id = AAZStrArg(
options=["-n", "--name", "--object-id"],
help="Object ID (client ID) of the Microsoft Entra principal. Provide the GUID of the service principal or user, not a friendly name or UPN.",
required=True,
id_part="child_name_1",
fmt=AAZStrArgFormat(
Expand Down Expand Up @@ -126,7 +126,7 @@ def url_parameters(self):
required=True,
),
**self.serialize_url_param(
"userName", self.ctx.args.user_name,
"userName", self.ctx.args.object_id,
required=True,
),
}
Expand Down
7 changes: 4 additions & 3 deletions src/documentdb/azext_documentdb/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@

def load_command_table(self, _): # pylint: disable=unused-argument
from azext_documentdb.custom import (
UserCreate, UserUpdate, ResetPassword, ReplicaCreate, Restore)
self.command_table['documentdb mongocluster user create'] = UserCreate(loader=self)
self.command_table['documentdb mongocluster user update'] = UserUpdate(loader=self)
UserAssign, UserUpdate, ResetPassword, ReplicaCreate, Restore, ReplicaPromote)
self.command_table['documentdb mongocluster entra-user assign'] = UserAssign(loader=self)
self.command_table['documentdb mongocluster entra-user update'] = UserUpdate(loader=self)
self.command_table['documentdb mongocluster reset-password'] = ResetPassword(loader=self)
self.command_table['documentdb mongocluster replica create'] = ReplicaCreate(loader=self)
self.command_table['documentdb mongocluster replica promote'] = ReplicaPromote(loader=self)
self.command_table['documentdb mongocluster restore'] = Restore(loader=self)
Loading
Loading