Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pragerdom/be-366: OpenAIRE authority provider #199

Open
wants to merge 20 commits into
base: main
Choose a base branch
from

Conversation

pragerdom
Copy link
Contributor

No description provided.

@pragerdom pragerdom requested a review from mesemus December 1, 2024 16:07
response.raise_for_status()
return response.json().get("access_token")
except requests.exceptions.HTTPError as http_err:
print(f"HTTP error occurred: {http_err}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use logger.error() instead of print


response = requests.get(url, headers=headers, params=params)
if response.status_code != 200:
print(f"Error response: {response.status_code}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dtto

client_id = current_app.config["OPENAIRE_CLIENT_ID"]
client_secret = current_app.config["OPENAIRE_CLIENT_SECRET"]
except RuntimeError:
client_id = os.environ["INVENIO_OPENAIRE_CLIENT_ID"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assume you always have current_app and remove the os.environ code (if needed in tests, add "app" fixture to test arguments

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed I should keep this since we also have it at orcid_provider.py. Will change it there too in that case.


def search(self, identity, params, **kwargs):
params = params or {}
access_token = self.openaire_client.get_token()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we cache the token for some time?


try:
relations = project.get("rels", {}).get("rel", [])
except KeyError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Key & Attribute error should not be thrown here, as you use .get(...)

"id": OpenAIREProvider.dict_get(funding, "funder", "id", "$"),
"name": OpenAIREProvider.dict_get(funding, "funder", "name", "$"),
}
except IndexError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these errors thrown? dict_get seems to check for path existence before x[...]

"id": relation_to.get("$", ""),
"organization": relation.get("legalname", {}).get("$", "")
})
except AttributeError:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the attribute error come from?

Copy link

sonarqubecloud bot commented Dec 5, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants