Skip to content

Commit

Permalink
chore: Grant enableSharding permission to admin and default
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu1nness committed Oct 4, 2024
1 parent 7d6d095 commit 86069e3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 8 additions & 2 deletions lib/charms/mongodb/v0/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class NotReadyError(PyMongoError):

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 1
LIBPATCH = 2

ADMIN_AUTH_SOURCE = "authSource=admin"
SYSTEM_DBS = ("admin", "local", "config")
Expand All @@ -40,6 +40,7 @@ class NotReadyError(PyMongoError):
{"role": "userAdminAnyDatabase", "db": "admin"},
{"role": "readWriteAnyDatabase", "db": "admin"},
{"role": "userAdmin", "db": "admin"},
{"role": "enableSharding", "db": "admin"},
],
"monitor": [
{"role": "explainRole", "db": "admin"},
Expand Down Expand Up @@ -127,7 +128,12 @@ def uri(self):

def supported_roles(config: MongoConfiguration):
"""Return the supported roles for the given configuration."""
return REGULAR_ROLES | {"default": [{"db": config.database, "role": "readWrite"}]}
return REGULAR_ROLES | {
"default": [
{"db": config.database, "role": "readWrite"},
{"db": config.database, "role": "enableSharding"},
]
}


class MongoConnection:
Expand Down
3 changes: 2 additions & 1 deletion lib/charms/mongodb/v1/mongodb_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version
LIBPATCH = 13
LIBPATCH = 14

logger = logging.getLogger(__name__)
REL_NAME = "database"
Expand Down Expand Up @@ -506,6 +506,7 @@ def _get_database_from_relation(relation: Relation) -> Optional[str]:
def _get_roles_from_relation(relation: Relation) -> Set[str]:
"""Return additional user roles from relation if specified or return None."""
roles = relation.data[relation.app].get("extra-user-roles", None)
logger.error(f"ROLES = {roles}")
if roles is not None:
return set(roles.split(","))
return {"default"}

0 comments on commit 86069e3

Please sign in to comment.