Skip to content

Commit

Permalink
fix: Release 1.3 bug修复 (#786)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayuan929 authored Oct 24, 2023
1 parent 7e99f8e commit c4f9f49
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 7 deletions.
5 changes: 2 additions & 3 deletions apiserver/paasng/paasng/platform/applications/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from django.core.exceptions import ObjectDoesNotExist, SuspiciousOperation
from django.db import models
from django.db.models import Q, QuerySet
from django.shortcuts import get_object_or_404
from pilkit.processors import ResizeToFill

from paasng.accessories.iam.helpers import fetch_role_members
Expand Down Expand Up @@ -320,10 +319,10 @@ def get_default_module(self):
return self.modules.get(is_default=True)

def get_module(self, module_name: Optional[str]):
"""Get a module object by given module_name"""
"""Get a module object by given module_name."""
if not module_name:
return self.get_default_module()
return get_object_or_404(self.modules, name=module_name)
return self.modules.get(name=module_name)

def get_app_envs(self, environment=None):
"""获取所有环境对象(所有模块)"""
Expand Down
3 changes: 3 additions & 0 deletions apiserver/paasng/tests/publish/entrance/test_preallocated.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class TestGetExposedUrlType:
def test_non_existent(self):
assert get_exposed_url_type('foo', 'bar-module') is None

def test_non_existent_module(self, bk_app):
assert get_exposed_url_type(bk_app.code, 'bar-module') is None

def test_normal(self, bk_module):
bk_module.exposed_url_type = ExposedURLType.SUBPATH.value
bk_module.save()
Expand Down
4 changes: 3 additions & 1 deletion svc-mysql/svc_mysql/vendor/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ class MySQLAuthTypeEnum(IntEnum):
REVOKE = 2


GRANT_SQL_FMT = "grant {privileges} on `{db_name}`.* " "to `{db_user}`@`{auth_ip}` " 'identified by "{db_password}";'
CREATE_USER_FMT = "create user `{db_user}`@`{auth_ip}` identified by '{db_password}';"

GRANT_SQL_FMT = "grant {privileges} on `{db_name}`.* " "to `{db_user}`@`{auth_ip}` ;"

REVOKE_SQL_FMT = "revoke {privileges} on `{db_name}`.* from `{db_user}`@{auth_ip};"

Expand Down
15 changes: 12 additions & 3 deletions svc-mysql/svc_mysql/vendor/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,23 @@ def grant_db(

with self.db.cursor() as cursor:
for auth_ip in self.client_hosts:
sql = constants.GRANT_SQL_FMT.format(
# 在 MySQL 8.0 版本中,`identified by` 语法已被弃用,需要分 2 步来完成
create_user_sql = constants.CREATE_USER_FMT.format(
db_user=user,
auth_ip=auth_ip,
db_password=password,
)
logger.info(f"Mysql 正在执行 `{create_user_sql.replace(password, '******')}`...")
cursor.execute(create_user_sql)

grant_sql = constants.GRANT_SQL_FMT.format(
db_name=db_name,
db_user=user,
auth_ip=auth_ip,
db_password=password,
privileges=privileges,
)
logger.info(f"Mysql 正在执行 `{sql.replace(password, '******')}`...")
cursor.execute(sql)
logger.info(f"Mysql 正在执行 `{grant_sql.replace(password, '******')}`...")
cursor.execute(grant_sql)
logger.info("Mysql 正在执行 `flush privileges;`")
cursor.execute("flush privileges;")

0 comments on commit c4f9f49

Please sign in to comment.