Skip to content

Commit

Permalink
global: remove username and password usage
Browse files Browse the repository at this point in the history
* with new pure api the files will be downloaded over a link and the
  token is used to authorize the action
  • Loading branch information
utnapischtim committed Jan 7, 2025
1 parent fad3019 commit 4e0ca9e
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 54 deletions.
12 changes: 1 addition & 11 deletions invenio_pure/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ def pure() -> None:
@with_appcontext
@option("--endpoint", type=URL, required=True)
@option("--token", type=STRING, required=True)
@option("--username", type=STRING, required=True)
@option("--password", type=STRING, required=True)
@option("--user-email", type=STRING, required=True)
@option("--pure-id", type=STRING, required=True)
@option("--no-color", is_flag=True, default=False)
Expand Down Expand Up @@ -74,17 +72,9 @@ def list_all_available_records(pure_service: PureRESTService, user_email: str) -
@with_appcontext
@option("--endpoint", type=URL, required=True)
@option("--token", type=STRING, required=True)
@option("--username", type=STRING, required=True)
@option("--password", type=STRING, required=True)
@option("--user-email", type=STRING, required=True)
@option("--no-color", is_flag=True, default=False)
@build_service
def sync(
pure_service: PureRESTService,
user_email: str,
*,
no_color: bool,
):
def sync(pure_service: PureRESTService, user_email: str) -> None:
"""Sync Pure with the repo."""
import_func = current_app.config["PURE_IMPORT_FUNC"]
filter_records = current_app.config["PURE_FILTER_RECORDS"]
Expand Down
10 changes: 2 additions & 8 deletions invenio_pure/config.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021-2024 Graz University of Technology.
# Copyright (C) 2021-2025 Graz University of Technology.
#
# invenio-pure is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Invenio module that adds pure."""


from .types import URL, EmailAddress, PurePassword, PureToken, PureUsername
from .types import URL, EmailAddress, PureToken

PURE_CELERY_BEAT_SCHEDULE: dict[str, dict] = {}
"""The celery beat schedule is used to configure the import schedule.
Expand All @@ -31,11 +31,5 @@
PURE_PURE_TOKEN: PureToken = ""
"""This is the token to be allowed to use the API."""

PURE_PURE_USERNAME: PureUsername = ""
"""This is the pure username which is necessary to download files."""

PURE_PURE_PASSWORD: PurePassword = ""
"""This is the pure password which is necessary to download files."""

PURE_USER_EMAIL: EmailAddress = ""
"""This is the user email of the pure user within the InvenioRDM instance."""
6 changes: 2 additions & 4 deletions invenio_pure/ext.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2021-2024 Graz University of Technology.
# Copyright (C) 2021-2025 Graz University of Technology.
#
# invenio-pure is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -29,7 +29,5 @@ def init_services(self, app: Flask) -> None:
"""Initialize services."""
endpoint = app.config.get("PURE_ENDPOINT", "")
token = app.config.get("PURE_TOKEN", "")
username = app.config.get("PURE_USERNAME", "")
password = app.config.get("PURE_PASSWORD", "")
config = PureRESTServiceConfig(endpoint, token, username, password)
config = PureRESTServiceConfig(endpoint, token)
self.pure_rest_service = PureRESTService(config)
6 changes: 2 additions & 4 deletions invenio_pure/records/config.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 Graz University of Technology.
# Copyright (C) 2024-2025 Graz University of Technology.
#
# invenio-pure is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -10,7 +10,7 @@

from dataclasses import dataclass

from ..types import URL, PurePassword, PureToken, PureUsername
from ..types import URL, PureToken


@dataclass
Expand All @@ -19,5 +19,3 @@ class PureRESTConfig:

endpoint: URL = ""
token: PureToken = ""
username: PureUsername = ""
password: PurePassword = ""
8 changes: 3 additions & 5 deletions invenio_pure/records/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 Graz University of Technology.
# Copyright (C) 2024-2025 Graz University of Technology.
#
# invenio-pure is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -13,7 +13,6 @@
from typing import cast

from requests import ReadTimeout, get, post, put
from requests.auth import HTTPBasicAuth
from requests.exceptions import JSONDecodeError

from ..types import URL, Filter, PureAPIKey, PureID
Expand Down Expand Up @@ -112,9 +111,8 @@ def store_file_temporarily(
Return path to the downloaded file upon success, empty string upon failure.
"""
auth = HTTPBasicAuth(self.config.username, self.config.password)

with get(file_url, stream=True, auth=auth, timeout=10) as response:
headers = {"api-key": self.config.token}
with get(file_url, stream=True, headers=headers, timeout=10) as response:
copyfileobj(response.raw, file_pointer)

def mark_as_exported(self, pure_id: PureID, record: dict) -> bool:
Expand Down
10 changes: 4 additions & 6 deletions invenio_pure/services/decorators.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 Graz University of Technology.
# Copyright (C) 2024-2025 Graz University of Technology.
#
# invenio-pure is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -17,10 +17,10 @@


class KwargsDict(TypedDict, total=False):
"""Kwargs dict."""

endpoint: str
token: str
username: str
password: str
user_email: str
pure_id: str
no_color: bool
Expand All @@ -34,10 +34,8 @@ def build_service[T](func: Callable[..., T]) -> Callable:
def build(*_: dict, **kwargs: Unpack[KwargsDict]) -> T:
endpoint = kwargs.pop("endpoint")
token = kwargs.pop("token")
username = kwargs.pop("username")
password = kwargs.pop("password")

config = PureRESTServiceConfig(endpoint, token, username, password)
config = PureRESTServiceConfig(endpoint, token)

kwargs["pure_service"] = PureRESTService(config=config)

Expand Down
5 changes: 2 additions & 3 deletions invenio_pure/services/services.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2024 Graz University of Technology.
# Copyright (C) 2024-2025 Graz University of Technology.
#
# invenio-pure is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Services."""

from pathlib import Path

from flask_principal import Identity

from ..records import PureAPI
from ..types import URL, Filter, PureID
from ..types import Filter, PureID
from .config import PureRESTServiceConfig


Expand Down
14 changes: 1 addition & 13 deletions invenio_pure/types.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022-2024 Graz University of Technology.
# Copyright (C) 2022-2025 Graz University of Technology.
#
# invenio-pure is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -38,18 +38,6 @@
The address does not have to have a special format, but it has to be an email.
"""

PureUsername = str
"""The pure username which will be used to download files.
It will not have special schema. It is the name which will be created in PURE.
"""

PurePassword = str
"""The pure password which will be used to download files.
It will not have special schema. It is the password which will be created in PURE.
"""

PureAPIKey = str
"""Pure api token."""

Expand Down

0 comments on commit 4e0ca9e

Please sign in to comment.