Skip to content

Commit

Permalink
adding update consumption role capability
Browse files Browse the repository at this point in the history
  • Loading branch information
petrkalos committed Jan 31, 2024
1 parent 3e33479 commit 9df37da
Show file tree
Hide file tree
Showing 8 changed files with 271 additions and 56 deletions.
8 changes: 8 additions & 0 deletions backend/dataall/core/environment/api/input_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,11 @@ class EnvironmentSortField(GraphQLEnumMapper):
gql.Argument(name='groupUri', type=gql.String),
],
)

UpdateConsumptionRoleInput = gql.InputType(
name='UpdateConsumptionRoleInput',
arguments=[
gql.Argument('consumptionRoleName', gql.String),
gql.Argument('groupUri', gql.String),
],
)
14 changes: 13 additions & 1 deletion backend/dataall/core/environment/api/mutations.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
NewEnvironmentInput,
EnableDataSubscriptionsInput,
InviteGroupOnEnvironmentInput,
AddConsumptionRoleToEnvironmentInput
AddConsumptionRoleToEnvironmentInput,
UpdateConsumptionRoleInput,
)
from dataall.core.environment.api.resolvers import *

Expand Down Expand Up @@ -110,3 +111,14 @@
resolver=disable_subscriptions,
type=gql.Boolean,
)

updateConsumptionRole = gql.MutationField(
name='updateConsumptionRole',
args=[
gql.Argument('environmentUri', type=gql.NonNullableType(gql.String)),
gql.Argument('consumptionRoleUri', type=gql.NonNullableType(gql.String)),
gql.Argument('input', type=UpdateConsumptionRoleInput),
],
type=gql.Ref('ConsumptionRole'),
resolver=update_consumption_role,
)
11 changes: 11 additions & 0 deletions backend/dataall/core/environment/api/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,17 @@ def remove_consumption_role(context: Context, source, environmentUri=None, consu
return status


def update_consumption_role(context: Context, source, environmentUri=None, consumptionRoleUri=None, input={}):
with context.engine.scoped_session() as session:
status = EnvironmentService.update_consumption_role(
session=session,
uri=consumptionRoleUri,
env_uri=environmentUri,
input=input,
)
return status


def list_environment_invited_groups(
context: Context, source, environmentUri=None, filter=None
):
Expand Down
25 changes: 23 additions & 2 deletions backend/dataall/core/environment/services/environment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,27 @@ def remove_consumption_role(session, uri, env_uri):
)
return True

@staticmethod
@has_tenant_permission(permissions.MANAGE_ENVIRONMENTS)
@has_resource_permission(permissions.REMOVE_ENVIRONMENT_CONSUMPTION_ROLE)
def update_consumption_role(session, uri, env_uri, input):
role_query = session.query(ConsumptionRole).filter(
(
and_(
ConsumptionRole.consumptionRoleUri == uri,
ConsumptionRole.environmentUri == env_uri,
)
)
)
role_query.update(input)
ResourcePolicy.update_resource_policy(
session=session,
group_uri=input['groupUri'],
resource_uri=uri,
)
session.commit()
return role_query.first()

@staticmethod
def query_user_environments(session, username, groups, filter) -> Query:
query = (
Expand Down Expand Up @@ -699,7 +720,7 @@ def query_user_environment_consumption_roles(session, groups, uri, filter) -> Qu
ConsumptionRole.groupUri == group,
)
)
return query
return query.order_by(ConsumptionRole.consumptionRoleUri)

@staticmethod
@has_resource_permission(permissions.LIST_ENVIRONMENT_CONSUMPTION_ROLES)
Expand Down Expand Up @@ -731,7 +752,7 @@ def query_all_environment_consumption_roles(session, uri, filter) -> Query:
ConsumptionRole.groupUri == group,
)
)
return query
return query.order_by(ConsumptionRole.consumptionRoleUri)

@staticmethod
@has_resource_permission(permissions.LIST_ENVIRONMENT_CONSUMPTION_ROLES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,25 @@ def find_resource_policy(
)
return resource_policy

@staticmethod
def update_resource_policy(
session, group_uri: str, resource_uri: str
) -> models.ResourcePolicy:
if not group_uri:
raise exceptions.RequiredParameter(param_name='group')
if not resource_uri:
raise exceptions.RequiredParameter(param_name='resource_uri')
resource_policy = (
session.query(models.ResourcePolicy)
.filter(
and_(
models.ResourcePolicy.resourceUri == resource_uri,
)
)
.update({models.ResourcePolicy.principalId: group_uri})
)
return resource_policy

@staticmethod
def attach_resource_policy(
session,
Expand Down
Loading

0 comments on commit 9df37da

Please sign in to comment.