Skip to content

Commit

Permalink
Adding small refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
TejasRGitHub authored and trajopadhye committed Sep 24, 2024
1 parent cc1c5e7 commit 2b1b2f1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
5 changes: 1 addition & 4 deletions backend/dataall/core/stacks/api/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ def resolve_events(context, source: Stack, **kwargs):
def resolve_stack_visibility(context, source: Stack, **kwargs):
if not source:
return False
log_config = config.get_property(map_target_type_to_log_config_path(target_type=source.stack), 'enabled')
try:
return StackService.check_if_user_allowed_view_logs(
target_type=source.stack, target_uri=source.targetUri, config=log_config
)
return StackService.check_if_user_allowed_view_logs(target_type=source.stack, target_uri=source.targetUri)
except Exception as e:
log.error(f'Failed to check if the user is allowed to view stack logs due to: {e}')
return False
Expand Down
10 changes: 5 additions & 5 deletions backend/dataall/core/stacks/services/stack_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,7 @@ def update_stack_tags(input):
@staticmethod
def get_stack_logs(target_uri, target_type):
context = get_context()
log_config = config.get_property(map_target_type_to_log_config_path(target_type=target_type), 'enabled')
StackService.check_if_user_allowed_view_logs(target_type=target_type, target_uri=target_uri, config=log_config)
StackService.check_if_user_allowed_view_logs(target_type=target_type, target_uri=target_uri)
StackRequestVerifier.verify_target_type_and_uri(target_uri, target_type)

with context.db_engine.scoped_session() as session:
Expand Down Expand Up @@ -242,12 +241,13 @@ def get_stack_logs(target_uri, target_type):
default_value='enabled',
resolve_property=map_target_type_to_log_config_path,
)
def check_if_user_allowed_view_logs(target_type: str, target_uri: str, config: str):
def check_if_user_allowed_view_logs(target_type: str, target_uri: str):
context = get_context()
if config == 'admin-only' and 'DAAdministrators' not in context.groups:
config_value = config.get_property(map_target_type_to_log_config_path(target_type=target_type), 'enabled')
if config_value == 'admin-only' and 'DAAdministrators' not in context.groups:
raise exceptions.ResourceUnauthorized(
username=context.username,
action='View Stack logs',
resource_uri=f'{target_uri} ( Resource type: {target_type})',
resource_uri=f'{target_uri} ( Resource type: {target_type} )',
)
return True

0 comments on commit 2b1b2f1

Please sign in to comment.