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

Gv files provider waffle #212

Draft
wants to merge 32 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
82b8469
Merge branch 'hotfix/24.01.5'
mfraezz Mar 26, 2024
ea8578b
Remove spurious Glacier helper function
mfraezz Apr 17, 2024
60935db
Merge branch 'hotfix/24.01.6'
mfraezz Apr 18, 2024
f27a698
Merge branch 'hotfix/24.01.6' into develop
mfraezz Apr 18, 2024
04aa1e8
adjust serialization to include embargo end date (#10596)
uditijmehta Apr 18, 2024
7511b03
Deactivate "Welcome to OSF" email
mfraezz Apr 22, 2024
a990cf2
Merge branch 'hotfix/24.01.7' into develop
mfraezz Apr 22, 2024
3b0ebcb
Update CHANGELOG, bump version
mfraezz Apr 30, 2024
fb266c6
Merge branch 'release/24.02.0' into develop
mfraezz Apr 30, 2024
b6ea6c2
ENG-4839 Add advertiseOnDiscoverPage Flag to Provider Model and Admin…
uditijmehta May 9, 2024
cf4ab0d
[ENG-5140] Update get_auth for GV and readability (#10584)
Johnetordoff May 10, 2024
d194c91
waffle get_addon code for gravyvalet
May 10, 2024
2d8e4c1
[ENG-5140] #2 Update get_auth for GV and readability (#10613)
Johnetordoff May 13, 2024
671f188
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
May 13, 2024
c60bd66
improve gravyvalet integration
May 13, 2024
8483e57
Fix get auth number two (#10614)
jwalz May 13, 2024
230be4d
debug commit
May 16, 2024
4425024
mock WB and add mocking resolution for generic FileNode
May 16, 2024
bc3fd85
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
May 16, 2024
e888e87
improve tests for gravyvalet feature flagging
May 21, 2024
9d1bbe5
mock user_setting and node_settings with the addon gracy valet addon …
May 21, 2024
a23cf78
pass basic auth and cookie for v1 route tests
May 21, 2024
41c0e85
make CR improvements
May 22, 2024
cdaafec
clean-up waffling code logic
May 22, 2024
9bd6ad5
clean-up node_setting user_setting mocking for GraveyValet
May 23, 2024
01430c7
add DraftRegistration file permission test (#10622)
Johnetordoff May 23, 2024
8181da6
add DraftRegistration file permission test (#10626)
Johnetordoff May 24, 2024
82d54ae
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
May 24, 2024
491ecab
Configurable GV Mock + HMAC Auth (#10623)
jwalz May 24, 2024
a73a069
Merge branch 'develop' of https://github.com/CenterForOpenScience/osf…
May 24, 2024
d358809
add provider id caching
May 28, 2024
3b164ff
update tests to work with GV mock and refactor
May 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

We follow the CalVer (https://calver.org/) versioning scheme: YY.MINOR.MICRO.

24.01.0 (2024-04-30)
====================
- Initial Addons Service work, Waffled
- Improve default `description` for Google Dataset Discovery
- Improve Embargo visibility for moderators
- Bug fix: PreprintProvider highlighted subjects
- Bug fix: PreprintProvider `advisory_board` styling

24.01.0 (2024-02-26)
====================
- Support CEDAR Embeddable Editor
Expand Down
2 changes: 2 additions & 0 deletions addons/base/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@

signals = blinker.Namespace()
file_updated = signals.signal('file_updated')
file_viewed = signals.signal('file_viewed')
file_downloaded = signals.signal('file_downloaded')
79 changes: 79 additions & 0 deletions addons/base/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import requests
import markupsafe
from os.path import basename
from website.settings import MFR_SERVER_URL


from api.caching import settings as cache_settings
from api.caching.utils import legacy_addon_cache

from website import settings


Expand Down Expand Up @@ -54,3 +59,77 @@ def format_last_known_metadata(auth, node, file, error_type):
]
return ''.join(parts)
return msg


class GravyValetAddonAppConfig:

@staticmethod
def get_configured_storage_addons_data(config_id, user):
from osf.external.gravy_valet import auth_helpers as gv_auth
url = settings.GV_NODE_ADDON_ENDPOINT.format(config_id=config_id)

auth_headers = gv_auth.make_gravy_valet_hmac_headers(
request_url=url,
request_method='GET',
requesting_user=user,
)

resp = requests.get(url, headers=auth_headers)
resp.raise_for_status()
return resp.json()

@staticmethod
def get_authorized_storage_account(config_id, user):
from osf.external.gravy_valet import auth_helpers as gv_auth
url = settings.GV_USER_ADDON_ENDPOINT.format(config_id=config_id)
auth_headers = gv_auth.make_gravy_valet_hmac_headers(
request_url=url,
request_method='GET',
requesting_user=user,
)

resp = requests.get(url, headers=auth_headers)
resp.raise_for_status()
return resp.json()

def cache_config_id_translation(self):
"""
Cache what legacy addon name corresponds to which config ids.
"""

key = cache_settings.LEGACY_ADDON_KEY.format(target_id=self.config_id)
legacy_addon_cache.set(key, self.addon_name, settings.STORAGE_USAGE_CACHE_TIMEOUT)

def __init__(self, resource, config_id, user):
self.resource = resource
self.user = user
self.FOLDER_SELECTED = self.legacy_app_config.FOLDER_SELECTED
self.NODE_AUTHORIZED = self.legacy_app_config.NODE_DEAUTHORIZED
self.NODE_DEAUTHORIZED = self.legacy_app_config.NODE_DEAUTHORIZED
self.actions = self.legacy_app_config.actions

from osf.models import OSFUser, AbstractNode
if isinstance(resource, AbstractNode):
self.gv_data = self.get_configured_storage_addons_data(config_id, user)
elif isinstance(resource, OSFUser):
self.gv_data = self.get_authorized_storage_account(config_id, user)
else:
raise NotImplementedError()

# TODO: Names in GV must be exact matches?
self.addon_name = self.gv_data['data']['embeds']['external_storage_service']['attributes']['name']
self.cache_config_id_translation()
self.legacy_app_config = settings.ADDONS_AVAILABLE_DICT[self.addon_name]


@property
def config(self):
return self.legacy_app_config

@property
def configured(self):
return True

@property
def config_id(self):
return self.gv_data.config_id
Loading
Loading