Skip to content

Commit

Permalink
Merge pull request #102 from cloudblue/LITE-28266-add-files-to-eaas-p…
Browse files Browse the repository at this point in the history
…roxy

LITE-28266 Add files to eaas proxy
  • Loading branch information
ffaraone authored Aug 2, 2023
2 parents 4680f2d + c7eba62 commit c9b89fa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions connect/eaas/core/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@

PROXIED_CONNECT_API_ENDPOINTS_MAX_ALLOWED_NUMBER = 100
PROXIED_CONNECT_API_ENDPOINTS_PUBLIC_PREFIX = '/public/'
PROXIED_CONNECT_API_ENDPOINTS_FILES_PREFIX = '/files'
PROXIED_CONNECT_API_ALLOWED_PREFIXES = (
PROXIED_CONNECT_API_ENDPOINTS_PUBLIC_PREFIX,
PROXIED_CONNECT_API_ENDPOINTS_FILES_PREFIX,
)
8 changes: 4 additions & 4 deletions connect/eaas/core/validation/validators/webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from fastapi_utils.cbv import CBV_CLASS_KEY

from connect.eaas.core.constants import (
PROXIED_CONNECT_API_ALLOWED_PREFIXES,
PROXIED_CONNECT_API_ENDPOINTS_MAX_ALLOWED_NUMBER,
PROXIED_CONNECT_API_ENDPOINTS_PUBLIC_PREFIX,
)
from connect.eaas.core.extension import WebApplicationBase
from connect.eaas.core.validation.helpers import get_code_context
Expand Down Expand Up @@ -193,12 +193,12 @@ def _validate_webapp_proxied_connect_api(context):
)
return errors

public_prefix = PROXIED_CONNECT_API_ENDPOINTS_PUBLIC_PREFIX
if not all(v.startswith(public_prefix) for v in api_paths):
allowed_prefixes = PROXIED_CONNECT_API_ALLOWED_PREFIXES
if not all(v.startswith(allowed_prefixes) for v in api_paths):
errors.append(
ValidationItem(
level='ERROR',
message='Only Public API can be referenced in `@proxied_connect_api`.',
message='Only Public or Files API can be referenced in `@proxied_connect_api`.',
**get_code_context(extension_class, code_pattern),
),
)
Expand Down
5 changes: 3 additions & 2 deletions tests/connect/eaas/core/validation/validators/test_webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,18 +1203,19 @@ def example(self):
(set(), 'The argument of the `@proxied_connect_api` must be a list of strings or a dict.'),
(['str', 1], 'The argument of the `@proxied_connect_api` must be a list of strings or a dict.'),
(['/public/v1/auth'] * 101, 'Max allowed length of the `@proxied_connect_api` argument: 100.'),
(['/media'], 'Only Public API can be referenced in `@proxied_connect_api`.'),
(['/media'], 'Only Public or Files API can be referenced in `@proxied_connect_api`.'),
(
{f'/public/v1/ep{i}': 'view' for i in range(200)},
'Max allowed length of the `@proxied_connect_api` argument: 100.',
),
(
{
'/files': 'view',
'/public/v1/marketplaces': 'view',
'/public/v1/products': 'edit',
'/private/api': 'view',
},
'Only Public API can be referenced in `@proxied_connect_api`.',
'Only Public or Files API can be referenced in `@proxied_connect_api`.',
),
(
{
Expand Down

0 comments on commit c9b89fa

Please sign in to comment.