-
Notifications
You must be signed in to change notification settings - Fork 81
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
Refactoring env stack part4 #1181
Refactoring env stack part4 #1181
Conversation
remove unused param target_lable from create_stack
remove unused param target_lable from create_stack
def get_stack_by_uri(stack_uri): | ||
with get_context().db_engine.scoped_session() as session: | ||
return StackRepository.get_stack_by_uri(session, stack_uri) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think get_environmental_stack_by_uri
is not needed. We can call get_stack_by_uri
directly from get_and_describe_stack_in_env
because the environment permissions check was done previously in the resolver get_stack
when we call find_environment_by_uri
, the decorator is already checking the GET_ENVIRONMENT permissions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's still needed for get_stack_logs
, but here I replaced it with get_stack_by_uri
5ddf7b3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But if we think about it, checking GET_ENVIRONMENT permissions when we get ANY type of stack does not make much sense. We should check GET_ENVIRONMENT when we get the Environment stack, GET_DATASET for the Dataset stack and so on. But instead we check GET_ENVIRONMENT when we get the dataset, which means that a user could execute an API call to get other teams' infrastructure stack details if they are in the same environment.
To fix this we could use something similar to what is implemented in update_stack_by_target_uri
or in list_key_value_tags
ResourcePolicyService.check_user_resource_permission(
session=session,
username=context.username,
groups=context.groups,
resource_uri=target_uri,
permission_name=TargetType.get_resource_read_permission_name(target_type),
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 - can we remove get_environmental_stack_by_uri
since it is no longer used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 - Can we add targetUri and targetType as additional inputs in getStack
and then add a permission check block similar to the one @dlpzx added above for get_and_describe_stack_in_env
-
pass through
targetUri
andtargetType
togetStack
API -
in
get_and_describe_stack_in_env
add:
ResourcePolicyService.check_user_resource_permission(
session=session,
username=context.username,
groups=context.groups,
resource_uri=stack.targetUri,
permission_name=TargetType.get_resource_read_permission_name(stack.targetType),
)
- Update
get_stack_by_uri
to pass alongsession
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This #2 above is a bigger change than originally anticipated - I have been looking into a bit and can open an enhancement PR after this one and can push this through if we clean up get_environmental_stack_by_uri
and address type hints comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to draft PR addressing permission checks described above - #1182
stack = StackRepository.update_stack(session=session, uri=targetUri, target_type=targetType) | ||
StackService.deploy_stack(stack.targetUri) | ||
return stack | ||
return StackService.update_stack_by_target_uri(targetUri, targetType) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
General comment about the refactoring...
- doesn't the existence of the
resolvers.py
become redundant? They are now just proxy calls so can't we just point the resolver (where the GraphQL query is defined) directly to the service? - by creating the session within the business logic it's going to be more difficult to unit-test those methods because it will by harder to mock the results from the db. Right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, it's open question yet. At least it gives us asyncronous calls (like in get_logs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The principle was that in resolvers we check the api input and in service we just execute business logic. In the PRs for refactoring we are adding validation in the service layer but not in the resolvers. I did not add any comment in these PRs, because we already talked about implementing a better validation mechanism. I opened an issue so that we do not forget about it
uri param should set by name
Tested creating Environments, describing env stacks, describing dataset stacks, etc. All looks good!! (have one related PR regarding some additional stack clean up parts here but I think is not of immediate priority and to come after this PR) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
approving!
Feature or Bugfix
Detail
Relates
Security
Please answer the questions below briefly where applicable, or write
N/A
. Based onOWASP 10.
fetching data from storage outside the application (e.g. a database, an S3 bucket)?
eval
or similar functions are used?By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.