Skip to content

Commit

Permalink
Added support for Consumption roles and IAM role options
Browse files Browse the repository at this point in the history
  • Loading branch information
dlpzx committed Nov 24, 2023
1 parent e7af19b commit 0d9563d
Show file tree
Hide file tree
Showing 7 changed files with 133 additions and 22 deletions.
2 changes: 1 addition & 1 deletion backend/dataall/core/environment/api/input_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,6 @@ class EnvironmentSortField(GraphQLEnumMapper):
gql.Argument('term', gql.String),
gql.Argument(name='page', type=gql.Integer),
gql.Argument(name='pageSize', type=gql.Integer),
gql.Argument('groupUri', gql.NonNullableType(gql.String)),
gql.Argument(name='groupUri', type=gql.String),
],
)
9 changes: 9 additions & 0 deletions backend/dataall/core/environment/api/queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@
resolver=list_groups,
)

listAllConsumptionRoles = gql.QueryField(
name='listAllConsumptionRoles',
type=gql.Ref('ConsumptionRoleSearchResult'),
args=[
gql.Argument(name='filter', type=gql.Ref('ConsumptionRoleFilter')),
],
resolver=list_consumption_roles,
)

listEnvironmentConsumptionRoles = gql.QueryField(
name='listEnvironmentConsumptionRoles',
type=gql.Ref('ConsumptionRoleSearchResult'),
Expand Down
10 changes: 10 additions & 0 deletions backend/dataall/core/environment/api/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ def list_groups(context: Context, source, filter=None):
with context.engine.scoped_session() as session:
return EnvironmentService.paginated_user_groups(session, filter)

def list_consumption_roles(
context: Context, source, environmentUri=None, filter=None
):
if filter is None:
filter = {}
with context.engine.scoped_session() as session:
return EnvironmentService.paginated_user_consumption_roles(
session=session,
data=filter,
)

def list_environment_networks(
context: Context, source, environmentUri=None, filter=None
Expand Down
33 changes: 33 additions & 0 deletions backend/dataall/core/environment/services/environment_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,39 @@ def paginated_user_groups(session, data=None) -> dict:
page_size=data.get('pageSize', 5),
).to_dict()

@staticmethod
def query_user_consumption_roles(session, username, groups, filter) -> Query:
query = (
session.query(ConsumptionRole)
.filter(ConsumptionRole.groupUri.in_(groups))
.distinct(ConsumptionRole.consumptionRoleName)
)
if filter and filter.get('term'):
term = filter['term']
query = query.filter(
or_(
ConsumptionRole.consumptionRoleName.ilike('%' + term + '%'),
)
)
if filter and filter.get('groupUri'):
print("filter group")
group = filter['groupUri']
query = query.filter(
or_(
ConsumptionRole.groupUri == group,
)
)
return query

@staticmethod
def paginated_user_consumption_roles(session, data=None) -> dict:
context = get_context()
return paginate(
query=EnvironmentService.query_user_consumption_roles(session, context.username, context.groups, data),
page=data.get('page', 1),
page_size=data.get('pageSize', 5),
).to_dict()

@staticmethod
def query_user_environment_groups(session, groups, uri, filter) -> Query:
query = (
Expand Down
74 changes: 53 additions & 21 deletions frontend/src/modules/Shares/components/ShareBoxList.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Defaults, Pager, ShareStatus, useSettings } from 'design';
import { SET_ERROR, useDispatch } from 'globalErrors';
import {
listAllGroups,
listAllConsumptionRoles,
listDatasetShareObjects,
getShareRequestsToMe,
useClient
Expand All @@ -38,6 +39,7 @@ export const ShareBoxList = (props) => {
const [items, setItems] = useState(Defaults.pagedResponse);
const [filter, setFilter] = useState(Defaults.filter);
const [requestGroupOptions, setRequestGroupOptions] = useState([]);
const [roleOptions, setRoleOptions] = useState([]);
const [datasetGroupOptions, setDatasetGroupOptions] = useState([]);
const [datasets, setDatasets] = useState([]);
const statusOptions = ShareStatusList;
Expand Down Expand Up @@ -132,27 +134,47 @@ export const ShareBoxList = (props) => {
}

const fetchMyGroupsOptions = useCallback(async () => {
await client
.query(
listAllGroups({
filter: Defaults.selectListFilter
})
)
.then((response) => {
if (tab === 'inbox') {
setDatasetGroupOptions(
response.data.listAllGroups.nodes.map((node) => node.groupUri)
const response = await client.query(
listAllGroups({
filter: Defaults.selectListFilter
})
);
if (!response.errors) {
if (tab === 'inbox') {
setDatasetGroupOptions(
response.data.listAllGroups.nodes.map((node) => node.groupUri)
);
} else {
setRequestGroupOptions(
response.data.listAllGroups.nodes.map((node) => node.groupUri)
);
const groupRoleOptions = response.data.listAllGroups.nodes.map(
(node) => node.environmentIAMRoleName
);
const response2 = await client.query(
listAllConsumptionRoles({
filter: Defaults.selectListFilter
})
);
if (!response2.errors) {
/* eslint-disable no-console */
console.log('good');
console.log(groupRoleOptions);
setRoleOptions(
groupRoleOptions.concat(
response2.data.listAllConsumptionRoles.nodes.map(
(node) => node.IAMRoleName
)
)
);
} else {
setRequestGroupOptions(
response.data.listAllGroups.nodes.map((node) => node.groupUri)
);
dispatch({ type: SET_ERROR, error: response2.errors[0].message });
}
})
.catch((error) => {
dispatch({ type: SET_ERROR, error: error.Error });
})
.finally(() => setLoading(false));
}
} else {
dispatch({ type: SET_ERROR, error: response.errors[0].message });
}
setLoading(false);
}, [client, dispatch, tab]);

const fetchInboxGroupOptions = useCallback(async () => {
Expand All @@ -172,6 +194,15 @@ export const ShareBoxList = (props) => {
)
)
);
setRoleOptions(
Array.from(
new Set(
response.data.getShareRequestsToMe.nodes.map(
(node) => node.principal.principalIAMRoleName
)
)
)
);
})
.catch((error) => {
dispatch({ type: SET_ERROR, error: error.Error });
Expand All @@ -186,7 +217,7 @@ export const ShareBoxList = (props) => {
);
if (!response.errors) {
setDatasets(
response.data.listDatasets.nodes.map((node) => ({
response.data.listOwnedDatasets.nodes.map((node) => ({
label: node.label,
value: node.datasetUri
}))
Expand Down Expand Up @@ -247,6 +278,7 @@ export const ShareBoxList = (props) => {
dispatch({ type: SET_ERROR, error: error.message });
});
} else {
setRoleOptions([]);
fetchOutboxGroupAndDatasetOptions().catch((error) => {
dispatch({ type: SET_ERROR, error: error.message });
});
Expand Down Expand Up @@ -385,7 +417,7 @@ export const ShareBoxList = (props) => {
multiple
fullWidth
loading={loading}
options={requestGroupOptions}
options={roleOptions}
onChange={(event, value) =>
handleFilterChange('RequestIAMRole', value)
}
Expand Down Expand Up @@ -419,7 +451,7 @@ export const ShareBoxList = (props) => {
disableCloseOnSelect
loading={loading}
options={datasets}
getOptionLabel={(option) => option.label}
getOptionLabel={(option) => option.label || ''}
onChange={(event, value) =>
handleFilterChange('Datasets', value)
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/services/graphql/Environment/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export * from './getTrustAccount';
export * from './listAllGroups';
export * from './listAllConsumptionRoles';
export * from './listDatasetsOwnedByEnvGroup';
export * from './listEnvironmentConsumptionRoles';
export * from './listEnvironmentGroups';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { gql } from 'apollo-boost';

export const listAllConsumptionRoles = ({ filter }) => ({
variables: {
filter
},
query: gql`
query listAllConsumptionRoles($filter: ConsumptionRoleFilter) {
listAllConsumptionRoles(filter: $filter) {
count
page
pages
hasNext
hasPrevious
nodes {
consumptionRoleUri
consumptionRoleName
environmentUri
groupUri
IAMRoleArn
IAMRoleName
}
}
}
`
});

0 comments on commit 0d9563d

Please sign in to comment.