Skip to content

Conversation

sinclert-canonical
Copy link
Contributor

This PR supports the set of predefined roles proposed in this specification.

Contents have been ported from the MySQL Router VM and K8s approved PRs. However, clauses to create a DBA role for each created databases have been added (see code), which is something that got added late into the spec review process.

@sinclert-canonical sinclert-canonical added the enhancement New feature, UI change, or workload upgrade label Sep 4, 2025
Comment on lines +45 to +46
f"{app_name} app requested an invalid database name on "
f"{endpoint_name} endpoint: {exception_msg}"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"{app_name} app requested an invalid database name on "
f"{endpoint_name} endpoint: {exception_msg}"
f"{app_name} app requested invalid database name >20 characters on "
f"{endpoint_name} endpoint"

to keep message short (under 120 characters) so it doesn't get truncated in juju status & to give user clear actionable next step (request a shorter database name)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather have a distinction between the log message (long format), and the message displayed when doing juju status (short format). As it is proposed at the moment:

  • Log: {app} requested an invalid database name on {endpoint} endpoint: DBA role longer than 32 characters
  • Status: DBA role longer than 32 characters.

f"{endpoint_name} endpoint: {exception_msg}"
)
logger.warning(message)
super().__init__(ops.BlockedStatus(exception_msg))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
super().__init__(ops.BlockedStatus(exception_msg))
super().__init__(ops.BlockedStatus(message))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered in this comment.

Comment on lines 97 to 100
if self._databag.get("extra-user-roles"):
raise _UnsupportedExtraUserRole(
app_name=relation.app.name, endpoint_name=relation.name
app_name=self._app_name, endpoint_name=self._endpoint_name
)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you raise here if database name > 20 characters so that the _RelationThatRequestedUser object does not get instantiated?

the current pattern/design is _RelationThatRequestedUser is only successfully initialized if the request is valid

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that approach too, to have the exception being raised in the __init__ method. I am on the fence whether that is a good separation of concerns or not, as it will require the _RelationThatRequestedUser class to know implementation details about the MySQLshell.create_application_database function.

Maybe exposing a new mysql_shell's MYSQL_DBA_ROLE_PREFIX constant with the charmed_dba_ value?

logger.debug(f"Created {username=} with {attributes=}")
return password

def create_application_database(self, *, database: str, username: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def create_application_database(self, *, database: str, username: str) -> str:
def create_application_database_and_user(self, *, database: str, username: str) -> str:

logger.debug(f"MySQL roles found for {name_pattern=}: {len(rows)}")
return {row[0] for row in rows}

def _create_application_database(self, *, database: str, rolename: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def _create_application_database(self, *, database: str, rolename: str) -> str:
def _create_application_database(self, *, database: str, rolename: str):

nit; return value unused

if len(rolename) >= _ROLE_MAX_LENGTH:
raise ValueError("Database DBA role longer than 32 characters")

________ = self._create_application_database(database=database, rolename=rolename)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
________ = self._create_application_database(database=database, rolename=rolename)
self._create_application_database(database=database, rolename=rolename)

nit

Comment on lines -33 to +34
f"{app_name} app requested unsupported extra user role on {endpoint_name} endpoint"
f"{app_name} app requested unsupported extra user role on "
f"{endpoint_name} endpoint"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why wrap? line length is 99 characters

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to make both exceptions have break lines in the same exact places. Easier to see where they differ (i.e. one includes the underlying exception message, while the other do not).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature, UI change, or workload upgrade Libraries: Out of sync
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants