Skip to content

Commit

Permalink
Merge pull request #137 from bcgov/meta-tag-filter
Browse files Browse the repository at this point in the history
Filter S3 Metadata in COMS data
  • Loading branch information
jujaga authored Oct 24, 2023
2 parents 73410eb + 569ebe8 commit 21609ec
Show file tree
Hide file tree
Showing 15 changed files with 72 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/environments/values.dev.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config:
configMap:
FRONTEND_APIPATH: api/v1
FRONTEND_COMS_APIPATH: https://coms-dev.api.gov.bc.ca/api/v1
FRONTEND_EXCLUDE_METADATA: geodrive.common.encoding,geodrive.windows.attr,geodrive.windows.secdesc,s3b-last-modified
FRONTEND_NOTIFICATION_BANNER : This is the DEV environment of BCBox. Uploaded files may not persist and may be deleted from the COMS database as we continue development. Please do not upload personal or private information. Thank you for your understanding as we work to improve BCBox
FRONTEND_OIDC_AUTHORITY: https://dev.loginproxy.gov.bc.ca/auth/realms/standard
FRONTEND_OIDC_CLIENTID: bc-box-4555
Expand Down
1 change: 1 addition & 0 deletions .github/environments/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config:
configMap:
FRONTEND_APIPATH: api/v1
FRONTEND_COMS_APIPATH: https://coms.api.gov.bc.ca/api/v1
FRONTEND_EXCLUDE_METADATA: geodrive.common.encoding,geodrive.windows.attr,geodrive.windows.secdesc,s3b-last-modified
FRONTEND_OIDC_AUTHORITY: https://loginproxy.gov.bc.ca/auth/realms/standard
FRONTEND_OIDC_CLIENTID: bc-box-4555
SERVER_APIPATH: /api/v1
Expand Down
1 change: 1 addition & 0 deletions .github/environments/values.test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ config:
configMap:
FRONTEND_APIPATH: api/v1
FRONTEND_COMS_APIPATH: https://coms-test.api.gov.bc.ca/api/v1
FRONTEND_EXCLUDE_METADATA: geodrive.common.encoding,geodrive.windows.attr,geodrive.windows.secdesc,s3b-last-modified
FRONTEND_NOTIFICATION_BANNER: This is the TEST environment of BCBox. Uploaded files may not persist and may be deleted from the COMS database as we continue development. Please do not upload personal or private information. Thank you for your understanding as we work to improve BCBox
FRONTEND_OIDC_AUTHORITY: https://test.loginproxy.gov.bc.ca/auth/realms/standard
FRONTEND_OIDC_CLIENTID: bc-box-4555
Expand Down
4 changes: 4 additions & 0 deletions app/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"coms": {
"apiPath": "FRONTEND_COMS_APIPATH"
},
"exclude": {
"metadata": "FRONTEND_EXCLUDE_METADATA",
"tagset": "FRONTEND_EXCLUDE_TAGSET"
},
"notificationBanner": "FRONTEND_NOTIFICATION_BANNER",
"oidc": {
"authority": "FRONTEND_OIDC_AUTHORITY",
Expand Down
5 changes: 4 additions & 1 deletion app/config/default.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"frontend": {
"apiPath": "api/v1"
"apiPath": "api/v1",
"exclude": {
"tagset": "coms-id"
}
},
"server": {
"apiPath": "/api/v1",
Expand Down
2 changes: 1 addition & 1 deletion charts/bcbox/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: bcbox
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.0.9
version: 0.0.10
kubeVersion: ">= 1.13.0"
description: A frontend UI for managing access control to S3 Objects
# A chart can be either an 'application' or a 'library' chart.
Expand Down
2 changes: 2 additions & 0 deletions charts/bcbox/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ config:
configMap:
FRONTEND_APIPATH: "api/v1"
FRONTEND_COMS_APIPATH: ~
# FRONTEND_EXCLUDE_METADATA: ~
# FRONTEND_EXCLUDE_TAGSET: ~
# FRONTEND_NOTIFICATION_BANNER: ~
FRONTEND_OIDC_AUTHORITY: ~
FRONTEND_OIDC_CLIENTID: ~
Expand Down
4 changes: 1 addition & 3 deletions frontend/src/components/object/ObjectFilters.vue
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ const tagsetValues = computed(() => {
.flatMap((obj) => obj.tagset)
// Add a display property to each tag to be used by the multiselect
.map((val) => ({ ...val, display: `${val.key}=${val.value}` }))
// coms-id not allowed as a tag to filter on by COMS
.filter((val) => val.key !== 'coms-id')
// Unique by display property
.filter(
(val, index, self) =>
Expand Down Expand Up @@ -116,7 +114,7 @@ const selectedMetadataChanged = (event: MultiSelectChangeEvent) => {
};
const selectedTagsChanged = (event: MultiSelectChangeEvent) => {
// Unselect any other tags that have the same tag key
// e.g. if 'coms-id=1234' is selected, unselect any other tags that have 'coms-id' as the key
// e.g. if 'colour=red' is selected, unselect any other tags that have 'colour' as the key
uncheckOther(event, selectedTags);
selectedFilterValuesChanged();
};
Expand Down
3 changes: 1 addition & 2 deletions frontend/src/components/object/ObjectMetadataTagForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ onBeforeMount(() => {
// Empty arrays can be given which won't trigger default prop values so check to see if blank rows need to be added
initialValues.metadata = initialValues.metadata?.length ? initialValues.metadata : [{ key: '', value: '' }];
// Filter coms-id first before determining initial set
initialValues.tagset = initialValues.tagset?.filter( (x: {key: string, value: string}) => x.key !== 'coms-id' );
// Determine initial set
initialValues.tagset = initialValues.tagset?.length ? initialValues.tagset : [{ key: '', value: '' }];
});
</script>
Expand Down
3 changes: 0 additions & 3 deletions frontend/src/components/object/ObjectSidebar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ const closeObjectInfo = async () => {
};
const obj = objectStore.findObjectById(props.objectId);
const bucketId = obj?.bucketId;
watch( props, () => {
if( obj &&
Expand Down Expand Up @@ -70,12 +69,10 @@ watch( props, () => {
:full-view="false"
/>
<ObjectMetadata
:bucket-id="bucketId"
:editable="false"
:object-id="props.objectId"
/>
<ObjectTag
:bucket-id="bucketId"
:editable="false"
:object-id="props.objectId"
/>
Expand Down
5 changes: 1 addition & 4 deletions frontend/src/components/object/ObjectTag.vue
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ watch( [props, tsGetTagging, vsGetTagging], () => {
</script>

<template>
<div
v-if="objectTagging?.tagset.length"
class="grid details-grid grid-nogutter mb-2"
>
<div class="grid details-grid grid-nogutter mb-2">
<div class="col-12">
<h2>
Tags
Expand Down
21 changes: 15 additions & 6 deletions frontend/src/services/objectService.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { comsAxios } from './interceptors';
import { setDispositionHeader } from '@/utils/utils';
import ConfigService from './configService';
import { comsAxios } from './interceptors';
import { excludeMetaTag, setDispositionHeader } from '@/utils/utils';

import type { AxiosRequestConfig } from 'axios';
import type { GetMetadataOptions, GetObjectTaggingOptions, MetadataPair, SearchObjectsOptions, Tag } from '@/types';
import { ExcludeTypes } from '@/utils/enums';

const PATH = '/object';

Expand Down Expand Up @@ -102,7 +103,9 @@ export default {
getMetadata(headers: any = {}, params: GetMetadataOptions = {}) {
// remove objectId array if its first element is undefined
if (params.objectId && params.objectId[0] === undefined) delete params.objectId;
return comsAxios().get(`${PATH}/metadata`, { headers: headers, params: params });
return comsAxios().get(`${PATH}/metadata`, { headers: headers, params: params })
// filter out a configured list of select metadata
.then((response) => ({ data: excludeMetaTag(ExcludeTypes.METADATA, response.data) }));
},

/**
Expand All @@ -112,7 +115,9 @@ export default {
* @returns {Promise} An axios response
*/
getObjectTagging(params: GetObjectTaggingOptions = {}) {
return comsAxios().get(`${PATH}/tagging`, { params: params });
return comsAxios().get(`${PATH}/tagging`, { params: params })
// filter out a configured list of select tags
.then((response) => ({ data: excludeMetaTag(ExcludeTypes.TAGSET, response.data) }));
},

/**
Expand Down Expand Up @@ -215,7 +220,9 @@ export default {
...Object.fromEntries((headers.metadata.map((x: { key: string; value: string }) => ([x.key, x.value]))))
};
}
return comsAxios().get(`${PATH}/metadata`, config);
return comsAxios().get(`${PATH}/metadata`, config)
// filter out a configured list of select metadata
.then((response) => ({ data: excludeMetaTag(ExcludeTypes.METADATA, response.data)}));
},

/**
Expand Down Expand Up @@ -287,7 +294,9 @@ export default {
params: {
tagset: Object.fromEntries((tagset.map((x: { key: string; value: string }) => ([x.key, x.value]))))
}
});
})
// filter out a configured list of select tags
.then((response) => ({ data: excludeMetaTag(ExcludeTypes.TAGSET, response.data)}));
},

/**
Expand Down
10 changes: 8 additions & 2 deletions frontend/src/services/versionService.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { comsAxios } from './interceptors';
import { excludeMetaTag } from '@/utils/utils';

import type { GetVersionMetadataOptions, GetVersionTaggingOptions } from '@/types';
import { ExcludeTypes } from '@/utils/enums';

const PATH = '/version';

Expand All @@ -11,7 +13,9 @@ export default {
* @returns {Promise} An axios response
*/
getMetadata(headers: any = {}, params: GetVersionMetadataOptions) {
return comsAxios().get(`${PATH}/metadata`, { headers: headers, params: params });
return comsAxios().get(`${PATH}/metadata`, { headers: headers, params: params })
// filter out a configured list of select metadata
.then((response) => ({ data: excludeMetaTag(ExcludeTypes.METADATA, response.data) }));
},

/**
Expand All @@ -20,6 +24,8 @@ export default {
* @returns {Promise} An axios response
*/
getObjectTagging(params: GetVersionTaggingOptions) {
return comsAxios().get(`${PATH}/tagging`, { params: params });
return comsAxios().get(`${PATH}/tagging`, { params: params })
// filter out a configured list of select tags
.then((response) => ({ data: excludeMetaTag(ExcludeTypes.TAGSET, response.data) }));
},
};
5 changes: 5 additions & 0 deletions frontend/src/utils/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ export enum ButtonMode {
BUTTON = 'BUTTON',
ICON = 'ICON',
}

export enum ExcludeTypes {
METADATA = 'metadata',
TAGSET = 'tagset',
}
27 changes: 27 additions & 0 deletions frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { DELIMITER } from '@/utils/constants';
import ConfigService from '@/services/configService';
import { ExcludeTypes } from '@/utils/enums';

/**
* @function differential
Expand Down Expand Up @@ -63,6 +65,31 @@ export function partition<T>(
);
}

/**
* @function excludeMetaTag
* Filter out a configured list of select metadata or tags from a COMS response
* @param {string} type either 'metadata' or 'tagset'
* @param {object} data An object with metadata/tags from COMS
* @returns {object} The response data with select metadata/tags from a configured list removed
*/
export function excludeMetaTag(type: ExcludeTypes, data: [{
objectId: string,
metadata?: Array<{ key: string; value: string }>,
tagset?: Array<{ key: string; value: string }>
}]){
// TODO: consider unit testing this function
// array of selected tags/metadata (keys) to hide from UI
const excludeArray = new ConfigService()
.getConfig().exclude?.[type]?.split(',').map((s: string) => s.trim()) ?? [];
// filter COMS data
return data.map((obj: any) => {
return {
...obj,
[type]: obj[type]?.filter((el: any) => !excludeArray.includes(el.key))
};
});
}

/**
* @function setDispositionHeader
* Constructs a valid RFC 6266 'Content-Disposition' header
Expand Down

0 comments on commit 21609ec

Please sign in to comment.