Skip to content

Commit 356527f

Browse files
authored
Merge branch 'archivist-auth' of 'https://github.com/jjmerchante/grimoirelab-core'
Merges #43 Closes #43
2 parents 2b1c935 + 8964f08 commit 356527f

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

src/grimoirelab/core/config/settings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,8 @@
334334
'WORKERS': int(os.environ.get('GRIMOIRELAB_ARCHIVIST_WORKERS', 10)),
335335
'STORAGE_TYPE': os.environ.get('GRIMOIRELAB_ARCHIVIST_STORAGE_TYPE', 'opensearch'),
336336
'STORAGE_URL': os.environ.get('GRIMOIRELAB_ARCHIVIST_STORAGE_URL', 'https://admin:admin@localhost:9200'),
337+
'STORAGE_USERNAME': os.environ.get('GRIMOIRELAB_ARCHIVIST_STORAGE_USERNAME', ''),
338+
'STORAGE_PASSWORD': os.environ.get('GRIMOIRELAB_ARCHIVIST_STORAGE_PASSWORD', ''),
337339
'STORAGE_INDEX': os.environ.get('GRIMOIRELAB_ARCHIVIST_STORAGE_INDEX', 'events'),
338340
'STORAGE_VERIFY_CERT': os.environ.get('GRIMOIRELAB_ARCHIVIST_STORAGE_VERIFY_CERT', 'False').lower() in ('true', '1'),
339341
'EVENTS_PER_JOB': int(os.environ.get('GRIMOIRELAB_ARCHIVIST_EVENTS_PER_JOB', 10000)),

src/grimoirelab/core/runner/commands/run.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ def create_background_tasks(clear_tasks: bool):
155155

156156
workers = settings.GRIMOIRELAB_ARCHIVIST['WORKERS']
157157
storage_url = settings.GRIMOIRELAB_ARCHIVIST['STORAGE_URL']
158+
storage_username = settings.GRIMOIRELAB_ARCHIVIST['STORAGE_USERNAME']
159+
storage_password = settings.GRIMOIRELAB_ARCHIVIST['STORAGE_PASSWORD']
158160
storage_db_name = settings.GRIMOIRELAB_ARCHIVIST['STORAGE_INDEX']
159161
storage_type = settings.GRIMOIRELAB_ARCHIVIST['STORAGE_TYPE']
160162
verify_certs = settings.GRIMOIRELAB_ARCHIVIST['STORAGE_VERIFY_CERT']
@@ -172,6 +174,8 @@ def create_background_tasks(clear_tasks: bool):
172174

173175
task_args = {
174176
'storage_url': storage_url,
177+
'storage_username': storage_username,
178+
'storage_password': storage_password,
175179
'storage_db_name': storage_db_name,
176180
'storage_verify_certs': verify_certs,
177181
'redis_group': 'archivist',

src/grimoirelab/core/scheduler/tasks/archivist.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
def archivist_job(
4242
storage_type: str,
4343
storage_url: str,
44+
storage_username: str,
45+
storage_password: str,
4446
storage_db_name: str,
4547
storage_verify_certs: bool,
4648
redis_group: str,
@@ -56,6 +58,8 @@ def archivist_job(
5658
5759
:param storage_type: type of the storage system (e.g., 'opensearch')
5860
:param storage_url: URL of the storage system
61+
:param storage_username: Username to use when authentication is required
62+
:param storage_password: Password to use when authentication is required
5963
:param storage_db_name: Name of the database to use
6064
:param storage_verify_certs: Verify certificates when connecting to the storage system
6165
:param redis_group: Redis group name to use for fetching events
@@ -77,6 +81,8 @@ def archivist_job(
7781

7882
Storage = get_storage_backend(storage_type)
7983
storage = Storage(url=storage_url,
84+
user=storage_username,
85+
password=storage_password,
8086
db_name=storage_db_name,
8187
verify_certs=storage_verify_certs)
8288
events = events_consumer(rq_job.connection,
@@ -272,8 +278,17 @@ class StorageBackend:
272278
273279
:param url: URL of the storage backend
274280
"""
275-
def __init__(self, url: str, db_name: str, verify_certs: bool = False) -> None:
281+
def __init__(
282+
self,
283+
url: str,
284+
db_name: str,
285+
user: str | None = None,
286+
password: str | None = None,
287+
verify_certs: bool = False
288+
) -> None:
276289
self.url = url
290+
self.user = user
291+
self.password = password
277292
self.db_name = db_name
278293
self.verify_certs = verify_certs
279294

@@ -361,13 +376,24 @@ class OpenSearchStorage(StorageBackend):
361376
}
362377
}
363378

364-
def __init__(self, url: str, db_name: str, verify_certs: bool = False) -> None:
365-
super().__init__(url, db_name, verify_certs)
379+
def __init__(
380+
self,
381+
url: str,
382+
db_name: str,
383+
user: str | None = None,
384+
password: str | None = None,
385+
verify_certs: bool = False
386+
) -> None:
387+
super().__init__(url=url, db_name=db_name, user=user, password=password, verify_certs=verify_certs)
366388

367389
if not verify_certs:
368390
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
369391

370-
self.client = OpenSearch([url], verify_certs=self.verify_certs)
392+
auth = None
393+
if user and password:
394+
auth = (user, password)
395+
396+
self.client = OpenSearch([url], http_auth=auth, verify_certs=self.verify_certs)
371397
self._create_index(db_name)
372398
self.max_items_bulk = 100
373399

src/grimoirelab/core/scheduler/tasks/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,8 @@ def prepare_job_parameters(self):
231231
task_args = {
232232
'storage_type': self.storage_type,
233233
'storage_url': self.task_args.get('storage_url'),
234+
'storage_username': self.task_args.get('storage_username'),
235+
'storage_password': self.task_args.get('storage_password'),
234236
'storage_db_name': self.task_args.get('storage_db_name'),
235237
'storage_verify_certs': self.task_args.get('storage_verify_certs'),
236238
'redis_group': self.task_args.get('redis_group'),

tests/scheduler/test_task_archivist.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def test_job(self):
8888
job_args = {
8989
'storage_type': 'mock_storage',
9090
'storage_url': 'example.com',
91+
'storage_username': 'user',
92+
'storage_password': 'password',
9193
'storage_db_name': 'mock_db',
9294
'storage_verify_certs': True,
9395
'redis_group': 'archivist',
@@ -127,6 +129,8 @@ def test_job_no_result(self):
127129
job_args = {
128130
'storage_type': 'mock_storage',
129131
'storage_url': 'example.com',
132+
'storage_username': 'user',
133+
'storage_password': 'password',
130134
'storage_db_name': 'mock_db',
131135
'storage_verify_certs': True,
132136
'redis_group': 'archivist',
@@ -167,6 +171,8 @@ def test_backend_not_found(self):
167171
job_args = {
168172
'storage_type': 'nobackend',
169173
'storage_url': 'example.com',
174+
'storage_username': 'user',
175+
'storage_password': 'password',
170176
'storage_db_name': 'mock_db',
171177
'storage_verify_certs': True,
172178
'redis_group': 'archivist',

0 commit comments

Comments
 (0)