Skip to content

Commit

Permalink
Remove use of unix user group. Add note for retroactive role assign
Browse files Browse the repository at this point in the history
  • Loading branch information
CBroz1 committed Feb 14, 2024
1 parent 472d59a commit 88736b4
Showing 1 changed file with 6 additions and 23 deletions.
29 changes: 6 additions & 23 deletions src/spyglass/utils/database_settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
import grp
import os
import sys
import tempfile
Expand Down Expand Up @@ -33,7 +32,6 @@ def __init__(
self,
user_name=None,
host_name=None,
target_group=None,
debug=False,
target_database=None,
):
Expand All @@ -45,14 +43,18 @@ def __init__(
- dj_user: select for all prefix, all for user prefix, all for shared
- dj_admin: all for all prefix
Note: To add dj_user role to all those with common access, run:
query = "SELECT user, host FROM mysql.db WHERE Db LIKE 'common%';"
users = dj.conn().query(query).fetchall()
for user in users:
dj.conn().query(f"GRANT dj_user TO '{user[0][0]}'@'%';")
Parameters
----------
user_name : str, optional
The name of the user to add to the database. Default from dj.config
host_name : str, optional
The name of the host to add to the database. Default from dj.config
target_group : str, optional
Group to which user belongs. Default is kachery-users
debug : bool, optional
Default False. If True, pprint sql instead of running
target_database : str, optional
Expand All @@ -63,7 +65,6 @@ def __init__(
self.host = (
host_name or dj.config["database.host"] or "lmf-db.cin.ucsf.edu"
)
self.target_group = target_group or "kachery-users"
self.debug = debug
self.target_database = target_database or "mysql"

Expand Down Expand Up @@ -130,24 +131,6 @@ def add_guest(self):
file = self.write_temp_file(self._add_guest_sql)
self.exec(file)

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

if not group_found: # Check if the group was found
if self.debug:
logger.info(f"All groups: {[g.gr_name for g in groups]}")
sys.exit(
f"Error: The target group {self.target_group} was not found."
)

return group

def add_module(self, module_name):
"""Add module to database. Grant permissions to all users in group"""
logger.info(f"Granting everyone permissions to module {module_name}")
Expand Down

0 comments on commit 88736b4

Please sign in to comment.