Skip to content

Commit

Permalink
377 version param (#991)
Browse files Browse the repository at this point in the history
### Feature or Bugfix
<!-- please choose -->
- 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
#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 <sazonova@amazon.co.uk>
  • Loading branch information
SofiaSazonova and Sofia Sazonova authored Jan 23, 2024
1 parent 5e14fef commit b8b8d23
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 11 deletions.
16 changes: 12 additions & 4 deletions deploy/stacks/deploy_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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()

10 changes: 10 additions & 0 deletions deploy/stacks/param_store_stack.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import random
import string

Expand All @@ -8,6 +9,7 @@
)

from .pyNestedStack import pyNestedClass
from .deploy_config import deploy_config


class ParamStoreStack(pyNestedClass):
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions deploy/stacks/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions frontend/docker/dev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions frontend/docker/prod/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 7 additions & 4 deletions frontend/src/design/components/Logo.js
Original file line number Diff line number Diff line change
@@ -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 = () => (
<>
Expand All @@ -16,9 +17,11 @@ export const Logo = () => (
</Box>
</Grid>
<Grid item>
<Typography variant="h5" color="#fff">
&nbsp;data.all
</Typography>
<Tooltip title={'version ' + version.version} placement="top-start">
<Typography variant="h5" color="#fff">
&nbsp;data.all
</Typography>
</Tooltip>
</Grid>
</Grid>
</>
Expand Down
4 changes: 4 additions & 0 deletions version.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"version": "2.2.0",
"release-date": "14.12.2023"
}

0 comments on commit b8b8d23

Please sign in to comment.