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-5430] ENABLE_GV feature flipping for get_addon #10610

Draft
wants to merge 16 commits into
base: develop
Choose a base branch
from

Conversation

Johnetordoff
Copy link
Contributor

@Johnetordoff Johnetordoff commented May 9, 2024

Purpose

Allows us to feature flip between our current system and the new GravyValet addon service. Should change files related routes to use new set up.

Changes

QA Notes

Please make verification statements inspired by your code and what your code touches.

  • Verify
  • Verify

What are the areas of risk?

Any concerns/considerations/questions that development raised?

Documentation

Side Effects

Ticket

https://openscience.atlassian.net/browse/ENG-5430

@Johnetordoff Johnetordoff force-pushed the gv-files-provider-waffle branch 3 times, most recently from 0b9d7f6 to 934ea23 Compare May 9, 2024 15:37
Copy link
Collaborator

@jwalz jwalz left a comment

Choose a reason for hiding this comment

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

Next steps:

  1. AddonModelMixin._settings_model won't currently work. We actually need to make the request beforehand using the name as the ID for the AuthorizedStorageAccount (user.get_addon) or the ConfiguredStorageAddon (node.get_addon). If those serializers don't currently return the name of the connected service, they should. That can then be used as a lookup to get the correct SettingsModel.

  2. MockUserSettings and MockNodeSettings should populate based on data from the AuthorizedStorageAccount and ConfiguredStorageAddon (UserReference and ResourceReference just exist to link things and contain no configuration data).

  3. (future ticket) get_addons should request all of the authorized storage accounts for a user or connected_storage_addons for a node instead of iterating through a list of provider names (and then pack a list whatever the appropriate serializer is based on the returned values).

Comment on lines 2145 to 2146
GV_RESOURCE_DOMAIN = 'http://192.168.168.167:8004/v1/resource-references/?filter[resource_uri]={owner_uri}'
GV_USER_DOMAIN = 'http://192.168.168.167:8004/v1/user-references/?filter[user_uri]={owner_uri}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
GV_RESOURCE_DOMAIN = 'http://192.168.168.167:8004/v1/resource-references/?filter[resource_uri]={owner_uri}'
GV_USER_DOMAIN = 'http://192.168.168.167:8004/v1/user-references/?filter[user_uri]={owner_uri}'
GV_API_ROOT = 'http://192.168.168.167:8004/v1
GV_RESOURCE_ENDPOINT = GV_DOMAIN + 'resource-references/?filter[resource_uri]={resource_uri}'
GV_USER_ENDPOINT = GV_DOMAIN + 'user-references/?filter[user_uri]={owner_uri}'
# These two are for `get_addon` vs `get_addons`
GV_USER_ADDON_ENDPOINT = GV_DOMAIN + 'v1/authorized-storage-accounts/{account_id}'
GV_NODE_ADDON_ENDPOINT = GV_DOMAIN + 'v1/configured-storage-addons/{addon_id}'

Copy link
Collaborator

Choose a reason for hiding this comment

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

Could optionally append &include=authorized_storage_accounts|configured_storage_addons to the user/resource endpoints

addons/box/apps.py Outdated Show resolved Hide resolved
@Johnetordoff Johnetordoff force-pushed the gv-files-provider-waffle branch 8 times, most recently from 293e89a to 221248b Compare May 13, 2024 13:26
 into gv-files-provider-waffle

* 'develop' of https://github.com/CenterForOpenScience/osf.io:
  [ENG-5140] #2 Update get_auth for GV and readability  (CenterForOpenScience#10613)
@Johnetordoff Johnetordoff force-pushed the gv-files-provider-waffle branch 2 times, most recently from 375673b to 074878f Compare May 13, 2024 18:07
api_tests/providers/test_files_with_gv.py Outdated Show resolved Hide resolved
attributes = res.json['data']['attributes']
assert attributes['provider'] == str(provider_gv_id)
assert attributes['name'] == str(provider_gv_id)
assert res.json['data']['id'] == f'{file.target._id}:{str(provider_gv_id)}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we want this to just be the provider_gv_id. @brianjgeiger?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, for everything but (I believe) osfstorage, if there's a gv provider id, then that should be the whole id. Yay for unique provider ids.

Comment on lines +79 to +80
assert attributes['provider'] == str(provider_gv_id)
assert attributes['name'] == str(provider_gv_id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@brianjgeiger would we like either of these (probably name?) to be the display_name of the addon?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think I'm using primarily gv information for this on the front end, but yeaaaahhh, let's try name to be the display_name.

api_tests/providers/test_files_with_gv.py Outdated Show resolved Hide resolved
@@ -2430,6 +2433,29 @@ def _remove_from_associated_collections(self, auth=None, force=False):
force=True
)

def get_addon(self, name, is_deleted=False):
Copy link
Collaborator

Choose a reason for hiding this comment

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

My instinct is that, instead of having the subclasses completely override get_addon, the superclass should start with a check for the GravyValet flag and then invoke a _get_addon_from_gravyvalet or similar method that is defined on the subclass. That gets rid of the need to call super() and better delegates responsibility to the subclass

def get_addon(self, name, is_deleted=False):
request, user_id = get_request_and_user_id()

if hasattr(request, 'user') and not isinstance(request.user, AnonymousUser) and waffle.flag_is_active(request, features.ENABLE_GV) and name not in ['osfstorage', 'wiki']:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we need to guard this against the AnonymousUser. Unauthenticated users should still be able to see the addons for a public node.

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 still true (this is also a delta between node and user behavior)

osf/models/node.py Outdated Show resolved Hide resolved
@Johnetordoff Johnetordoff force-pushed the gv-files-provider-waffle branch 5 times, most recently from c7606c9 to dc4cda4 Compare May 16, 2024 19:35
api_tests/utils.py Outdated Show resolved Hide resolved
website/settings/defaults.py Outdated Show resolved Hide resolved
Comment on lines 2151 to 2153
GV_USER_ADDON_ENDPOINT = 'http://192.168.168.167:8004/v1/authorized-storage-accounts/{account_id}'
GV_NODE_ADDON_ENDPOINT = 'http://192.168.168.167:8004/v1/configured-storage-addons/{config_id}/base_account/'
GV_EXTERNAL_STORAGE_ENDPOINT = 'http://192.168.168.167:8004/v1/external-storage-services/{service_id}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
GV_USER_ADDON_ENDPOINT = 'http://192.168.168.167:8004/v1/authorized-storage-accounts/{account_id}'
GV_NODE_ADDON_ENDPOINT = 'http://192.168.168.167:8004/v1/configured-storage-addons/{config_id}/base_account/'
GV_EXTERNAL_STORAGE_ENDPOINT = 'http://192.168.168.167:8004/v1/external-storage-services/{service_id}'
GV_USER_ADDON_ENDPOINT = GV_API_ROOT + 'authorized-storage-accounts/{account_id}'
GV_NODE_ADDON_ENDPOINT = GV_API_ROOT + 'configured-storage-addons/{config_id}/base_account/'
GV_EXTERNAL_STORAGE_ENDPOINT = GV_API_ROOT + 'external-storage-services/{service_id}'

Comment on lines 2145 to 2146
GV_RESOURCE_DOMAIN = 'http://192.168.168.167:8004/v1/resource-references/?filter[resource_uri]={owner_uri}'
GV_USER_DOMAIN = 'http://192.168.168.167:8004/v1/user-references/?filter[user_uri]={owner_uri}'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
GV_RESOURCE_DOMAIN = 'http://192.168.168.167:8004/v1/resource-references/?filter[resource_uri]={owner_uri}'
GV_USER_DOMAIN = 'http://192.168.168.167:8004/v1/user-references/?filter[user_uri]={owner_uri}'

api/nodes/utils.py Outdated Show resolved Hide resolved
def get_addon(self, name, is_deleted=False):
request, user_id = get_request_and_user_id()

if hasattr(request, 'user') and not isinstance(request.user, AnonymousUser) and waffle.flag_is_active(request, features.ENABLE_GV) and name not in ['osfstorage', 'wiki']:
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 still true (this is also a delta between node and user behavior)

addons/base/utils.py Outdated Show resolved Hide resolved
addons/base/utils.py Outdated Show resolved Hide resolved
Comment on lines 61 to 73
class MockNodeSetting:
def __init__(self, resource, auth, legacy_config, gv_data):
self.gv_data = gv_data

@property
def configured(self):
return True

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

class MockUserSetting:
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the benefit of making these internal classes? They don't seem to be using the enclosing scope in any way. Also, the majority of the init args are going unused.


class GravyValetAddonAppConfig:
class MockNodeSetting:
def __init__(self, resource, auth, legacy_config, gv_data):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Something like:

        def __init__(self, configured_storage_addon_id):
           self.gv_data = requests.get(configured-storage-addons/configured-storage-addon-id/?include=external_storage_service)
           self.legacy_app_config = _get_legacy_config_for_gv_service(gv_data.name)
           self.magically_mirror_legacy_node_settings(legacy_app_config.node_settings_module)
           
       @property
       def config:
          return self.legacy_app_config

"magically_mirror_legacy_node_settings" could come from a per-provider translator class/module that is surfaced with a standardized name on the legacy_config

@Johnetordoff Johnetordoff force-pushed the gv-files-provider-waffle branch 2 times, most recently from 7a55c02 to 9f0d6e4 Compare May 22, 2024 21:05
@Johnetordoff Johnetordoff force-pushed the gv-files-provider-waffle branch 7 times, most recently from 647f35c to 06cf8fe Compare May 23, 2024 15:43
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.

None yet

3 participants