From b8b8d23e6acc483a535b8bb0a4d50cbc2f8f0225 Mon Sep 17 00:00:00 2001 From: Sofia Sazonova Date: Tue, 23 Jan 2024 16:21:11 +0000 Subject: [PATCH] 377 version param (#991) ### Feature or Bugfix - Feature ### Detail version.json in repo root contains information about version. This json-string is uploaded to SSM parameter /dataall/{env}/versin. Also this file is copied to frontend folder and version number is displayed near "dataall" header ### Relates https://github.com/data-dot-all/dataall/issues/377 ### Security Please answer the questions below briefly where applicable, or write `N/A`. Based on [OWASP 10](https://owasp.org/Top10/en/). - Does this PR introduce or modify any input fields or queries - this includes fetching data from storage outside the application (e.g. a database, an S3 bucket)? NA - Is the input sanitized? - What precautions are you taking before deserializing the data you consume? - Is injection prevented by parametrizing queries? - Have you ensured no `eval` or similar functions are used? - Does this PR introduce any functionality or component that requires authorization? NA - How have you ensured it respects the existing AuthN/AuthZ mechanisms? - Are you logging failed auth attempts? - Are you using or adding any cryptographic features? NA - Do you use a standard proven implementations? - Are the used keys controlled by the customer? Where are they stored? - Are you introducing any new policies/roles/users?NA - Have you used the least-privilege principle? How? By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Sofia Sazonova --- deploy/stacks/deploy_config.py | 16 ++++++++++++---- deploy/stacks/param_store_stack.py | 10 ++++++++++ deploy/stacks/pipeline.py | 1 + frontend/docker/dev/Dockerfile | 2 ++ frontend/docker/prod/Dockerfile | 2 ++ frontend/package.json | 7 ++++--- frontend/src/design/components/Logo.js | 11 +++++++---- version.json | 4 ++++ 8 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 version.json diff --git a/deploy/stacks/deploy_config.py b/deploy/stacks/deploy_config.py index 4d87d754a..48bcf07a7 100644 --- a/deploy/stacks/deploy_config.py +++ b/deploy/stacks/deploy_config.py @@ -12,6 +12,10 @@ class _DeployConfig: def __init__(self): self._config = self._read_config_file() + self._version = self._read_version_file() + + def get_dataall_version(self) -> str: + return json.dumps(self._version) def get_property(self, key: str, default=None) -> Any: """ @@ -52,20 +56,24 @@ def set_property(self, key: str, value: Any) -> None: @classmethod def _read_config_file(cls) -> Dict[str, Any]: - with open(cls._path_to_file()) as config_file: + with open(cls._path_to_file("config.json")) as config_file: return json.load(config_file) + @classmethod + def _read_version_file(cls) -> Dict[str, Any]: + with open(cls._path_to_file("version.json")) as version_file: + return json.load(version_file) + @staticmethod - def _path_to_file() -> str: + def _path_to_file(filename) -> str: """Tries to get a property. If not defined it tries to resolve the config from the current file's directory""" path = os.getenv("config_location") if path: return path - return os.path.join(Path(__file__).parents[2], "config.json") + return os.path.join(Path(__file__).parents[2], filename) def __repr__(self): return str(self._config) deploy_config = _DeployConfig() - diff --git a/deploy/stacks/param_store_stack.py b/deploy/stacks/param_store_stack.py index 7be190538..fa6505338 100644 --- a/deploy/stacks/param_store_stack.py +++ b/deploy/stacks/param_store_stack.py @@ -1,3 +1,4 @@ +import json import random import string @@ -8,6 +9,7 @@ ) from .pyNestedStack import pyNestedClass +from .deploy_config import deploy_config class ParamStoreStack(pyNestedClass): @@ -122,6 +124,14 @@ def __init__( description=f"Stores dataall external id for environment {envname}", ) + aws_ssm.StringParameter( + self, + f'dataall_{envname}_version', + parameter_name=f'/dataall/{envname}/version', + string_value=str(json.dumps(deploy_config.get_dataall_version())), + description='Deployed data all version' + ) + def _get_external_id_value(envname, account_id, region): """ For first deployments and upgrades from <=V1.5.6 to >=v1.6 - returns False and a new ssm parameter created, diff --git a/deploy/stacks/pipeline.py b/deploy/stacks/pipeline.py index 51d9703db..9af4de40e 100644 --- a/deploy/stacks/pipeline.py +++ b/deploy/stacks/pipeline.py @@ -508,6 +508,7 @@ def set_quality_gate_stage(self): f'aws codeartifact login --tool npm --repository {self.codeartifact.codeartifact_npm_repo_name} --domain {self.codeartifact.codeartifact_domain_name} --domain-owner {self.codeartifact.domain.attr_owner}', 'npm install', 'npm run copy-config', + 'npm run copy-version', 'npm run lint -- --quiet', ], role=self.baseline_codebuild_role.without_policy_updates(), diff --git a/frontend/docker/dev/Dockerfile b/frontend/docker/dev/Dockerfile index 960233341..f746b0e16 100644 --- a/frontend/docker/dev/Dockerfile +++ b/frontend/docker/dev/Dockerfile @@ -22,6 +22,8 @@ COPY --chown=${CONTAINER_USER}:root ./frontend . # Copy config.json to docker root, because app scripts read it from ".." COPY --chown=${CONTAINER_USER}:root ./config.json / +# Copy vesion.json to docker root, because app scripts read it from ".." +COPY --chown=${CONTAINER_USER}:root ./version.json / # Disable linting before starting the server ENV DISABLE_ESLINT_PLUGIN=true diff --git a/frontend/docker/prod/Dockerfile b/frontend/docker/prod/Dockerfile index 8fa71ebd2..35098667b 100644 --- a/frontend/docker/prod/Dockerfile +++ b/frontend/docker/prod/Dockerfile @@ -55,6 +55,8 @@ RUN . ~/.nvm/nvm.sh && npm install -g npm@9 yarn COPY --chown=${CONTAINER_USER}:root ./frontend/package.json ./frontend/yarn.lock ./ COPY --chown=${CONTAINER_USER}:root ./config.json / +# Copy vesion.json to docker root, because app scripts read it from ".." +COPY --chown=${CONTAINER_USER}:root ./version.json / RUN . ~/.nvm/nvm.sh && yarn install diff --git a/frontend/package.json b/frontend/package.json index 095983d2f..bd736be08 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -7,9 +7,10 @@ "start": "react-scripts start", "build": "react-scripts build", "copy-config": "mkdir -p ./src/generated; cp ../config.json ./src/generated/", - "postinstall": "yarn copy-config", - "prestart": "yarn copy-config", - "prebuild": "yarn copy-config", + "copy-version": "mkdir -p ./src/generated; cp ../version.json ./src/generated/", + "postinstall": "yarn copy-config; yarn copy-version", + "prestart": "yarn copy-config; yarn copy-version", + "prebuild": "yarn copy-config; yarn copy-version", "test": "react-scripts test", "eject": "react-scripts eject", "lint": "eslint --ext js src", diff --git a/frontend/src/design/components/Logo.js b/frontend/src/design/components/Logo.js index e72082b97..8d967f8da 100644 --- a/frontend/src/design/components/Logo.js +++ b/frontend/src/design/components/Logo.js @@ -1,4 +1,5 @@ -import { Box, CardMedia, Grid, Typography } from '@mui/material'; +import { Box, CardMedia, Grid, Tooltip, Typography } from '@mui/material'; +import version from '../../generated/version.json'; export const Logo = () => ( <> @@ -16,9 +17,11 @@ export const Logo = () => ( - -  data.all - + + +  data.all + + diff --git a/version.json b/version.json new file mode 100644 index 000000000..d3ae31d28 --- /dev/null +++ b/version.json @@ -0,0 +1,4 @@ +{ + "version": "2.2.0", + "release-date": "14.12.2023" +} \ No newline at end of file