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

[ENG-6036] Implement DataverseStorageAddonImp #125

Merged
merged 6 commits into from
Oct 24, 2024

Conversation

opaduchak
Copy link
Collaborator

No description provided.

Copy link
Collaborator

@aaxelb aaxelb left a comment

Choose a reason for hiding this comment

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

comment on the "header transformation", but haven't dug into dataverse specifics

Comment on lines 30 to 36
@staticmethod
def make_headers(raw_headers: dict):
header_value = raw_headers.get("Authorization")
return {"X-Dataverse-key": header_value.split(" ")[-1]}

def __post_init__(self):
self.network.add_header_transformation_callback(self.make_headers)
Copy link
Collaborator

Choose a reason for hiding this comment

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

there was the idea to keep request auth an entirely separate concern from addon imps (so multiple services could implement a common/standard api while using distinct auth methods) -- this is why ExternalService has both credentials_format and addon_imp, and why auth headers were not exposed to imp code

...unfortunately, we did so imperfectly, as you found.

to support dataverse's custom auth header while maintaining that separation of concerns, could:

  1. remove iter_headers from addon_toolkit.credentials.Credentials and its subclasses
  2. instead, generate headers in (or at least based on) addon_service.common.credentials_formats -- could be a method on CredentialsFormats, so instead of self.account.credentials.iter_headers(), would do something like:
    self.account.external_service.credentials_format.make_headers(self.account.credentials)
  3. add CredentialsFormats.DATAVERSE_TOKEN member that uses the existing AccessTokenCredentials dataclass but generates a X-Dataverse-key: ... header instead of Authorization: Bearer ...

...alternately, could destroy that separation of concerns altogether -- delete CredentialsFormats and ExternalService.int_credentials_format, make the addon-imp fully in charge of authenticating requests and whether to use oauth1/oauth2/etc...

i think there's value in maintaining the separation and keeping the imp oblivious to auth headers (this would allow for dataverse installations configured to use bearer tokens, for example), but i acknowledge this is a bit of a mess; apologies

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed credentials handling, please look once more and tell me whether this is suffiecient

Copy link
Collaborator

Choose a reason for hiding this comment

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

looks great!

Comment on lines +38 to +39
async def get_external_account_id(self, _: dict[str, str]) -> str:
return ""
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: this should be unnecessary, it's already implemented by the base class

@opaduchak opaduchak requested a review from aaxelb October 16, 2024 12:00
Copy link
Collaborator

@aaxelb aaxelb left a comment

Choose a reason for hiding this comment

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

the credentials changes seem a good improvement! i don't know the dataverse api well, but the code looks reasonable 👍

"mydata/retrieve",
query=[
["page", page_cursor],
*[("role_ids", role) for role in range(1, 9)],
Copy link
Collaborator

Choose a reason for hiding this comment

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

dataverse docs say roles are configurable per instance... do we have a sense whether they actually vary in practice, or is it safe to hard-code this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

these are all of the standart roles which are present in all dataverses

Copy link
Collaborator

@aaxelb aaxelb left a comment

Choose a reason for hiding this comment

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

just a bit of dead code, otherwise seems good

Comment on lines 66 to 69
def add_header_transformation_callback(
self, callback: Callable[[dict], dict]
) -> None: ...

Copy link
Collaborator

Choose a reason for hiding this comment

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

this is no longer used, can be removed

Copy link
Collaborator

@brianjgeiger brianjgeiger left a comment

Choose a reason for hiding this comment

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

Just one small change to make CI happy.

Comment on lines 92 to 93


Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like this is causing problems with pre-commit; you should probably delete these two lines.

@brianjgeiger brianjgeiger merged commit bd3b51d into CenterForOpenScience:develop Oct 24, 2024
1 check passed
Vlad0n20 pushed a commit to Vlad0n20/gravyvalet that referenced this pull request Oct 24, 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.

3 participants