Skip to content

Commit

Permalink
Filter S3 Metadata or Tags from COMS data
Browse files Browse the repository at this point in the history
  • Loading branch information
TimCsaky committed Oct 19, 2023
1 parent ff0a213 commit 3fccaf5
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 19 deletions.
9 changes: 9 additions & 0 deletions .github/environments/values.prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ config:
FRONTEND_COMS_APIPATH: https://coms.api.gov.bc.ca/api/v1
FRONTEND_OIDC_AUTHORITY: https://loginproxy.gov.bc.ca/auth/realms/standard
FRONTEND_OIDC_CLIENTID: bc-box-4555
FRONTEND_S3METATAG_EXCLUDE:
metadata:
- geodrive.common.encoding
- geodrive.windows.attr
- geodrive.windows.secdesc
- s3b-last-modified
- sha256
tagset:
- coms-id
SERVER_APIPATH: /api/v1
SERVER_BODYLIMIT: 30mb
# SERVER_LOGFILE: ~
Expand Down
3 changes: 2 additions & 1 deletion app/config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"oidc": {
"authority": "FRONTEND_OIDC_AUTHORITY",
"clientId": "FRONTEND_OIDC_CLIENTID"
}
},
"s3MetaTagExclude": "FRONTEND_S3METATAG_EXCLUDE"
},
"server": {
"apiPath": "SERVER_APIPATH",
Expand Down
4 changes: 2 additions & 2 deletions 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 Expand Up @@ -37,6 +37,6 @@ maintainers:
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.4.0"
appVersion: "0.5.0"
deprecated: false
annotations: {}
1 change: 1 addition & 0 deletions charts/bcbox/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ config:
# SERVER_LOGFILE: ~
SERVER_LOGLEVEL: "http"
SERVER_PORT: "8080"
# FRONTEND_S3METATAG_EXCLUDE: ~
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
5 changes: 4 additions & 1 deletion frontend/src/components/object/ObjectMetadata.vue
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ watch([props, tsGetMetadata,vsGetMetadata] , () => {
</script>

<template>
<div class="grid details-grid grid-nogutter mb-2">
<div
v-if="objectMetadata?.metadata.length"
class="grid details-grid grid-nogutter mb-2"
>
<div class="col-12">
<h2 class="font-bold">
Metadata
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
26 changes: 21 additions & 5 deletions frontend/src/services/objectService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { comsAxios } from './interceptors';
import { setDispositionHeader } from '@/utils/utils';
import { s3MetaTagExclude, setDispositionHeader } from '@/utils/utils';
import ConfigService from './configService';

import type { AxiosRequestConfig } from 'axios';
Expand Down Expand Up @@ -102,7 +102,11 @@ 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 metadata and return as a promise again
.then((response) => {
return s3MetaTagExclude('metadata', response);
});
},

/**
Expand All @@ -112,7 +116,11 @@ 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) => {
return s3MetaTagExclude('tagset', response);
});
},

/**
Expand Down Expand Up @@ -215,7 +223,11 @@ 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) => {
return s3MetaTagExclude('metadata', response);
});
},

/**
Expand Down Expand Up @@ -287,7 +299,11 @@ 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) => {
return s3MetaTagExclude('tagset', response);
});
},

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

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

Expand All @@ -11,7 +12,11 @@ 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) => {
return s3MetaTagExclude('metadata', response);
});
},

/**
Expand All @@ -20,6 +25,10 @@ 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) => {
return s3MetaTagExclude('tagset', response);
});
},
};
23 changes: 23 additions & 0 deletions frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DELIMITER } from '@/utils/constants';
import ConfigService from '@/services/configService';

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

/**
* @function s3MetaTagExclude
* Filter out a configured list of select metadata or tags from a COMS response
* @param {object} type either 'metadata' or 'tagset'
* @param {object} axiosResponse A resolved axios response from COMS
* @returns {object} The response data with select metadata/tags from a configured list removed
*/
export function s3MetaTagExclude(type: string, axiosResponse: { data: any }){
// array of selected tags/metadata (keys) to hide from UI
const excludeArray = new ConfigService().getConfig().s3MetaTagExclude?.[type] ?? [];
// filter COMS data
const filtered = axiosResponse.data.map((obj:any) => {
return {
...obj,
[type]: obj[type]?.filter((el:any) => {
return !excludeArray.includes(el.key);
})
};
});
return { data: filtered };
}

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

0 comments on commit 3fccaf5

Please sign in to comment.