Skip to content

Commit

Permalink
fix: make requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Danyal-Faheem committed Sep 9, 2024
1 parent d266f4b commit 24e8872
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
4 changes: 2 additions & 2 deletions docs/local.rst
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ Tutor makes it easy do so with this handy command::

tutor local do update_mysql_authentication_plugin

If you only want to update the authentication plugin of specific users, you can use the ``--users`` option. This option takes comma seperated names of users to upgrade::
The above command will update all the database users created by Tutor. If you only want to update the authentication plugin of specific users, you can use the ``--users`` option. This option takes comma seperated names of users to upgrade::

tutor local do update_mysql_authentication_plugin --users=discovery,ecommerce

Do note that if you are updating a specific user, there should be corresponding entries in the configuration for the mysql username and password for that user. For example, if you are trying to update the user ``myuser``, the following case sensitive entries need to be present in the configuration::
For this command, Tutor expects specific entries in the configuration for the mysql username and password of a database user. For example, if you are trying to update the user ``myuser``, the following case sensitive entries need to be present in the configuration::

MYUSER_MYSQL_USERNAME
MYUSER_MYSQL_PASSWORD
Expand Down
6 changes: 5 additions & 1 deletion tutor/commands/jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def update_mysql_authentication_plugin(
) -> t.Iterable[tuple[str, str]]:
"""
Update the authentication plugin of MySQL users from mysql_native_password to caching_sha2_password
Handy command used when upgrading to v8.4 of MySQL which deprecates mysql_native_password
Handy command utilized when upgrading to v8.4 of MySQL which deprecates mysql_native_password
"""

config = tutor_config.load(context.root)
Expand All @@ -348,6 +348,10 @@ def update_mysql_authentication_plugin(
config, users_to_update, not users
)

# In case there is no user to update the authentication plugin of
if not query:
return

mysql_command = (
"mysql --user={{ MYSQL_ROOT_USERNAME }} --password={{ MYSQL_ROOT_PASSWORD }} --host={{ MYSQL_HOST }} --port={{ MYSQL_PORT }} --database={{ OPENEDX_MYSQL_DATABASE }} "
+ shlex.join(["-e", query])
Expand Down
13 changes: 8 additions & 5 deletions tutor/commands/jobs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from typing import List

from tutor import exceptions
from tutor import exceptions, fmt
from tutor.types import Config, ConfigValue


Expand Down Expand Up @@ -41,6 +41,9 @@ def get_mysql_change_authentication_plugin_query(
def generate_mysql_authentication_plugin_update_query(
username: ConfigValue, password: ConfigValue, host: str
) -> str:
fmt.echo_info(
f"Authentication plugin of user {username} will be updated to caching_sha2_password"
)
return f"ALTER USER '{username}'@'{host}' IDENTIFIED with caching_sha2_password BY '{password}';"

def generate_user_queries(users: List[str]) -> str:
Expand All @@ -51,11 +54,11 @@ def generate_user_queries(users: List[str]) -> str:
f"{user_uppercase}_MYSQL_USERNAME" in config
and f"{user_uppercase}_MYSQL_PASSWORD" in config
):
raise exceptions.TutorError(
f"Username or Password for User {user} not found in config. "
f"Please make sure that the following entries are present in the configuration:\n"
f"{user_uppercase}_MYSQL_USERNAME\n{user_uppercase}_MYSQL_PASSWORD"
fmt.echo_warning(
f"Username or Password for User {user} not found in config. Skipping update process for User {user}."
)
continue

query += generate_mysql_authentication_plugin_update_query(
config[f"{user_uppercase}_MYSQL_USERNAME"],
config[f"{user_uppercase}_MYSQL_PASSWORD"],
Expand Down
8 changes: 8 additions & 0 deletions tutor/fmt.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ def alert(text: str) -> str:
return click.style("⚠️ " + text, fg="yellow", bold=True)


def warning(text: str) -> str:
return click.style(text, fg="bright_yellow")


def echo_warning(text: str) -> None:
echo(warning(text))


def echo(text: str, err: bool = False) -> None:
if os.environ.get("_TUTOR_COMPLETE"):
if os.environ.get("COMP_WORDS") or os.environ.get("COMP_CWORD"):
Expand Down
7 changes: 4 additions & 3 deletions tutor/templates/k8s/deployments.yml
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,10 @@ spec:
- "--character-set-server=utf8mb4"
- "--collation-server=utf8mb4_unicode_ci"
- "--binlog-expire-logs-seconds=259200"
# We only require this option for MySQL 8.4 and above
# Breaks MySQL for previous versions as this option does not exist on versions earlier than 8.4
{% if DOCKER_IMAGE_MYSQL.split(':')[-1] == "latest" or (DOCKER_IMAGE_MYSQL.split(':')[-1].split('.') | map('int') | list >= '8.4.0'.split('.') | map('int') | list) -%}
# We only require this option for MySQL 8.4.0 and above
# Breaks MySQL for previous versions as this option does not exist on versions earlier than 8.4.0
{% set mysql_version = DOCKER_IMAGE_MYSQL.split(':')[-1] -%}
{% if mysql_version == "latest" or (mysql_version.split('.') | map('int') | list >= '8.4.0'.split('.') | map('int') | list) -%}
- "--mysql-native-password=ON"
{%- endif %}
env:
Expand Down

0 comments on commit 24e8872

Please sign in to comment.