-
Notifications
You must be signed in to change notification settings - Fork 0
[DPE-7322] Support predefined roles #34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dpe
Are you sure you want to change the base?
Conversation
c0ce903
to
9a40854
Compare
2e0bd19
to
7e4758b
Compare
f"{app_name} app requested an invalid database name on " | ||
f"{endpoint_name} endpoint: {exception_msg}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
super().__init__(ops.BlockedStatus(exception_msg)) | |
super().__init__(ops.BlockedStatus(message)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Answered in this comment.
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 | ||
) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
________ = self._create_application_database(database=database, rolename=rolename) | |
self._create_application_database(database=database, rolename=rolename) |
nit
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" |
There was a problem hiding this comment.
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
line-length = 99 |
There was a problem hiding this comment.
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).
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.