Skip to content
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

Fix config for mysql 8 #650

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions config/add_dj_collaborator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,24 @@
import sys
import tempfile

# shared_modules = [
# "common\_%",
# "spikesorting\_%",
# "decoding\_%",
# "position\_%",
# "lfp\_%",
# ]


def add_collab_user(user_name):
# create a tempoary file for the command
# create a temporary file for the command
file = tempfile.NamedTemporaryFile(mode="w")

# Create the user (if not already created) and set the password
file.write(
f"CREATE USER IF NOT EXISTS '{user_name}'@'%' IDENTIFIED BY 'temppass';\n"
)

# Grant privileges to databases matching the user_name pattern
file.write(
f"GRANT ALL PRIVILEGES ON `{user_name}\_%`.* TO `{user_name}`@'%' IDENTIFIED BY 'temppass';\n"
f"GRANT ALL PRIVILEGES ON `{user_name}\_%`.* TO '{user_name}'@'%';\n"
)
# for module in shared_modules:
# file.write(f"GRANT ALL PRIVILEGES ON `{module}`.* TO `{user_name}`@'%';\n")
file.write(f"GRANT SELECT ON `%`.* TO `{user_name}`@'%';\n")

# Grant SELECT privileges on all databases
file.write(f"GRANT SELECT ON `%`.* TO '{user_name}'@'%';\n")

file.flush()

# run those commands in sql
Expand Down
13 changes: 10 additions & 3 deletions config/add_dj_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,27 @@
"spikesorting\_%",
"decoding\_%",
"position\_%",
"position_linearization\_%",
"ripple\_%",
"lfp\_%",
]


def add_user(user_name):
# create a tempoary file for the command
# create a temporary file for the command
file = tempfile.NamedTemporaryFile(mode="w")

# Create the user (if not already created) and set password
file.write(
f"GRANT SELECT ON `%`.* TO `{user_name}`@'%' IDENTIFIED BY 'Data_$haring';\n"
f"CREATE USER IF NOT EXISTS '{user_name}'@'%' IDENTIFIED BY 'Data_$haring';\n"
)

# Grant privileges
file.write(f"GRANT SELECT ON `%`.* TO '{user_name}'@'%';\n")

file.flush()

# run that commands in sql
# run those commands in sql
os.system(f"mysql -p -h lmf-db.cin.ucsf.edu < {file.name}")


Expand Down
10 changes: 8 additions & 2 deletions config/add_dj_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import tempfile

target_group = "kachery-users"
TARGET_GROUP = "kachery-users"


def add_module(module_name):
Expand All @@ -15,10 +15,16 @@ def add_module(module_name):

# find the kachery-users group
groups = grp.getgrall()
group_found = False # initialize the flag as False
for group in groups:
if group.gr_name == target_group:
if group.gr_name == TARGET_GROUP:
group_found = True # set the flag to True when the group is found
break

# Check if the group was found
if not group_found:
sys.exit(f"Error: The target group {TARGET_GROUP} was not found.")

# get a list of usernames
for user in group.gr_mem:
file.write(
Expand Down
23 changes: 17 additions & 6 deletions config/add_dj_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import sys
import tempfile

shared_modules = ["common\_%", "spikesorting\_%", "decoding\_%"]
shared_modules = [
"common\_%",
"spikesorting\_%",
"decoding\_%",
"position\_%",
"position_linearization\_%",
"ripple\_%",
"lfp\_%",
]


def add_user(user_name):
Expand All @@ -14,15 +22,18 @@ def add_user(user_name):

# create a tempoary file for the command
file = tempfile.NamedTemporaryFile(mode="w")

file.write(
f"GRANT ALL PRIVILEGES ON `{user_name}\_%`.* TO `{user_name}`@'%' IDENTIFIED BY 'temppass';\n"
create_user_query = f"CREATE USER IF NOT EXISTS '{user_name}'@'%' IDENTIFIED BY 'temppass';\n"
grant_privileges_query = (
f"GRANT ALL PRIVILEGES ON `{user_name}\_%`.* TO '{user_name}'@'%';"
)

file.write(create_user_query + "\n")
file.write(grant_privileges_query + "\n")
for module in shared_modules:
file.write(
f"GRANT ALL PRIVILEGES ON `{module}`.* TO `{user_name}`@'%';\n"
f"GRANT ALL PRIVILEGES ON `{module}`.* TO '{user_name}'@'%';\n"
)
file.write(f"GRANT SELECT ON `%`.* TO `{user_name}`@'%';\n")
file.write(f"GRANT SELECT ON `%`.* TO '{user_name}'@'%';\n")
file.flush()

# run those commands in sql
Expand Down
Loading