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 840c926
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 45 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
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 = ""
7 changes: 3 additions & 4 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 Down Expand Up @@ -112,9 +112,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 840c926

Please sign in to comment.