Skip to content

Commit

Permalink
Merge pull request #50 from cloudblue/LITE-25758_support_webapp_for_hub
Browse files Browse the repository at this point in the history
LITE-25758 allow web app for hub extensions
  • Loading branch information
marcserrat authored Nov 24, 2022
2 parents d7341dc + 1b192f7 commit 0ad8984
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
2 changes: 1 addition & 1 deletion connect/eaas/core/inject/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def get_call_context(
x_connect_installation_id: str = Header(),
x_connect_installation_id: str = Header(None),
x_connect_user_id: str = Header(),
x_connect_account_id: str = Header(),
x_connect_account_role: str = Header(),
Expand Down
4 changes: 2 additions & 2 deletions connect/eaas/core/inject/models.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Literal
from typing import Literal, Optional

from pydantic import BaseModel


class Context(BaseModel):
installation_id: str
installation_id: Optional[str] = None
user_id: str
account_id: str
account_role: str
Expand Down
19 changes: 13 additions & 6 deletions connect/eaas/core/testing/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,14 @@ def _get_client_mocker(self, method, url):
return ConnectClientMocker

def _generate_call_context(self, installation):
return Context(**{
'installation_id': installation['id'] if installation else 'EIN-000',
return {
'installation_id': installation['id'] if installation else None,
'user_id': 'UR-000',
'account_id': 'VA-000',
'account_role': 'vendor',
'call_source': 'ui',
'call_type': 'user',
})
}

def _populate_internal_headers(
self,
Expand All @@ -127,12 +127,19 @@ def _populate_internal_headers(
context=None,
log_level=None,
):

if not context:
context = Context(**self._generate_call_context(installation))
elif isinstance(context, dict):
ctx_data = self._generate_call_context(installation)
ctx_data.update(context)
context = Context(**ctx_data)

headers['X-Connect-Logging-Level'] = log_level or 'INFO'
if config:
headers['X-Connect-Config'] = json.dumps(config)

context: Context = context or self._generate_call_context(installation)
headers['X-Connect-Installation-id'] = context.installation_id
if context.installation_id:
headers['X-Connect-Installation-id'] = context.installation_id
headers['X-Connect-User-Id'] = context.user_id
headers['X-Connect-Account-Id'] = context.account_id
headers['X-Connect-Account-Role'] = context.account_role
Expand Down
23 changes: 22 additions & 1 deletion tests/connect/eaas/core/testing/test_testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_get_call_context_default(webapp_mock):

assert resp.status_code == 200
assert resp.json() == {
'installation_id': 'EIN-000',
'installation_id': None,
'user_id': 'UR-000',
'account_id': 'VA-000',
'account_role': 'vendor',
Expand All @@ -109,6 +109,27 @@ def test_get_call_context_custom(webapp_mock):
assert resp.json() == ctx


def test_get_call_context_merge(webapp_mock):
client = WebAppTestClient(webapp_mock)

ctx = {
'installation_id': 'EIN-111',
'call_type': 'admin',
}

resp = client.get('/api/context', context=ctx)

assert resp.status_code == 200
assert resp.json() == {
'installation_id': 'EIN-111',
'user_id': 'UR-000',
'account_id': 'VA-000',
'account_role': 'vendor',
'call_source': 'ui',
'call_type': 'admin',
}


def test_not_found(webapp_mock):
client = WebAppTestClient(webapp_mock)
installation = {
Expand Down

0 comments on commit 0ad8984

Please sign in to comment.