Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7122953
D7913.id28712.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
D7913.id28712.diff
View Options
diff --git a/swh/core/db/db_utils.py b/swh/core/db/db_utils.py
--- a/swh/core/db/db_utils.py
+++ b/swh/core/db/db_utils.py
@@ -689,3 +689,12 @@
"Asked for flavor %s, but module does not support database flavors",
flavor,
)
+
+ # Grant read-access to guest user on all tables of the schema (if possible)
+ with connect_to_conninfo(db_or_conninfo) as db:
+ try:
+ with db.cursor() as c:
+ query = "grant select on all tables in schema public to guest"
+ c.execute(query)
+ except Exception:
+ logger.warning("Grant read-only access to guest user failed. Skipping.")
diff --git a/swh/core/db/tests/conftest.py b/swh/core/db/tests/conftest.py
--- a/swh/core/db/tests/conftest.py
+++ b/swh/core/db/tests/conftest.py
@@ -7,7 +7,9 @@
from click.testing import CliRunner
from hypothesis import HealthCheck
+import psycopg2
import pytest
+from pytest_postgresql import factories
from swh.core.db.db_utils import import_swhmodule
@@ -21,6 +23,17 @@
)
+def create_role_guest(**kwargs):
+ with psycopg2.connect(**kwargs) as conn:
+ with conn.cursor() as cur:
+ cur.execute("CREATE ROLE guest LOGIN PASSWORD 'guest'")
+
+
+postgresql_proc = factories.postgresql_proc(
+ load=[create_role_guest],
+)
+
+
@pytest.fixture
def cli_runner():
return CliRunner()
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 17, 1:09 PM (3 d, 4 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3223135
Attached To
D7913: db: Grant read access to guest user on all tables of the schema
Event Timeline
Log In to Comment