Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add environment identification tag in the header #483

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d00a2b8
Add environment identification tag in the header
davidjamesstone Sep 20, 2024
e0af209
Sonarcloud changes
davidjamesstone Sep 20, 2024
1e0ebba
change prod to pink
KiranVarma02 Oct 28, 2024
d3252eb
minor refactor
KiranVarma02 Oct 28, 2024
903ecc7
add unit tests
KiranVarma02 Oct 28, 2024
98ad37d
fix lint issue
KiranVarma02 Oct 28, 2024
3f9b108
fix lodash import
KiranVarma02 Oct 28, 2024
78bdb5a
file rename
KiranVarma02 Oct 28, 2024
6f1d3d0
change import path
KiranVarma02 Oct 28, 2024
784cbdf
fix import path
KiranVarma02 Oct 28, 2024
9a9767c
move logic to njk macro
KiranVarma02 Oct 30, 2024
d8b2ee2
add eol
KiranVarma02 Oct 30, 2024
f8f7a75
move env inside config prop
KiranVarma02 Oct 30, 2024
a1506a9
take appTagEnv out of service header
KiranVarma02 Oct 30, 2024
b227314
fix lint issue
KiranVarma02 Oct 30, 2024
8f7690b
fix unit tests
KiranVarma02 Oct 30, 2024
97c71e6
make first letter upper
KiranVarma02 Oct 30, 2024
3983e29
config changes
KiranVarma02 Oct 31, 2024
3d79afc
config changes
KiranVarma02 Oct 31, 2024
65ebffb
config changes
KiranVarma02 Oct 31, 2024
ab8e7f0
use node env config for test
KiranVarma02 Oct 31, 2024
6a74d86
fix tests after config changes
KiranVarma02 Oct 31, 2024
1fae189
change nodeEnv to env
KiranVarma02 Oct 31, 2024
6eb3b14
revert isDevelopment env var
KiranVarma02 Oct 31, 2024
feeff41
review comments
KiranVarma02 Nov 1, 2024
01e308d
Merge remote-tracking branch 'origin/main' into feature/290089-form-o…
KiranVarma02 Nov 1, 2024
ad90acd
Update designer/server/src/common/components/tag-env/template.njk
KiranVarma02 Nov 1, 2024
1579c60
change macro to use dev friendly env names
KiranVarma02 Nov 1, 2024
bb1e773
change loglevel envs
KiranVarma02 Nov 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% from "tag-env/macro.njk" import appTagEnv %}

{#
Component options:
- organisationName (string): The name of the organisation
Expand Down Expand Up @@ -72,6 +74,8 @@ Component options:
{% endif %}
</span>
</a>
{# Environment identification tag -#}
{{ appTagEnv(params.env) }}
</div>
<button type="button"
aria-controls="one-login-header__nav"
Expand Down
3 changes: 3 additions & 0 deletions designer/server/src/common/components/tag-env/macro.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{% macro appTagEnv(env) %}
{%- include "./template.njk" -%}
{% endmacro %}
15 changes: 15 additions & 0 deletions designer/server/src/common/components/tag-env/template.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{%- from "govuk/components/tag/macro.njk" import govukTag -%}

{%- switch env %}
{% case "test" %}
{% set classes = "govuk-tag--yellow" %}
{% case "production" %}
{% set classes = "govuk-tag--red" %}
{% default %}
{% set classes = "govuk-tag--grey" %}
KiranVarma02 marked this conversation as resolved.
Show resolved Hide resolved
{% endswitch -%}

{{ govukTag({
text: env | capitalize,
classes: classes
}) }}
5 changes: 3 additions & 2 deletions designer/server/src/common/nunjucks/context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { buildNavigation } from '~/src/common/nunjucks/context/build-navigation.
import config from '~/src/config.js'

const logger = createLogger()
const { phase, serviceName } = config
const { phase, serviceName, env } = config

/** @type {Record<string, string> | undefined} */
let webpackManifest
Expand All @@ -34,7 +34,8 @@ export async function context(request) {
breadcrumbs: [],
config: {
phase,
serviceName
serviceName,
env
},
navigation: buildNavigation(request),
getAssetPath: (asset = '') => `/${webpackManifest?.[asset] ?? asset}`,
Expand Down
3 changes: 2 additions & 1 deletion designer/server/src/common/nunjucks/context/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ describe('Nunjucks context', () => {

expect(ctx.config).toEqual({
phase: config.phase,
serviceName: config.serviceName
serviceName: config.serviceName,
env: config.env
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
{{ appServiceHeader({
organisationName: "Defra",
productName: "Forms Designer",
env: config.env,
navigationItems: navigation if isAuthenticated and isAuthorized and isFormsUser,
accountName: authedUser.displayName if isAuthenticated,
accountLink: "/library",
Expand Down
82 changes: 56 additions & 26 deletions designer/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,33 @@ import joi from 'joi'

const configPath = fileURLToPath(import.meta.url)

const {
DEPLOYMENT_ENV,
LOG_LEVEL,
NODE_ENV,
PHASE,
SESSION_COOKIE_PASSWORD,
SESSION_TTL,
PORT,
MANAGER_URL,
SUBMISSION_URL,
PREVIEW_URL,
SESSION_COOKIE_TTL,
AZURE_CLIENT_ID,
AZURE_CLIENT_SECRET,
OIDC_WELL_KNOWN_CONFIGURATION_URL,
APP_BASE_URL,
REDIS_HOST,
REDIS_USERNAME,
REDIS_PASSWORD,
REDIS_KEY_PREFIX,
ROLE_EDITOR_GROUP_ID,
FILE_DOWNLOAD_PASSWORD_TTL
} = process.env

export interface Config {
env: 'development' | 'test' | 'production'
env: 'development' | 'test' | 'perf test' | 'production'
nodeEnv: 'development' | 'test' | 'production'
port: number
appDir: string
clientDir: string
Expand Down Expand Up @@ -38,14 +63,18 @@ export interface Config {
const schema = joi.object<Config>({
port: joi.number().default(3000),
env: joi
.string()
.valid('development', 'test', 'perf test', 'production')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm still thinking we should match these names to how they're used in URLs

We might want to use them to replace wildcards in URLs in future

Suggested change
.valid('development', 'test', 'perf test', 'production')
.valid('dev', 'test', 'perf-test', 'prod')

Copy link
Contributor

@KiranVarma02 KiranVarma02 Nov 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will let @alexluckett decide that I think!

I don't have strong opinion

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll ask on Slack

What shall we use when running locally?

Because the "dev" environment isn't local, e.g.

http://forms-designer.dev.cdp-int.defra.cloud
http://forms-runner.dev.cdp-int.defra.cloud

We'll need maybe local or localhost as the default

.default('development'),
nodeEnv: joi
.string()
.valid('development', 'test', 'production')
.default('development'),
appDir: joi.string().default(dirname(configPath)),
clientDir: joi
.string()
.default(resolve(dirname(configPath), '../../client/dist'))
.when('env', {
.when('nodeEnv', {
is: 'test',
then: joi
.string()
Expand Down Expand Up @@ -89,31 +118,32 @@ const schema = joi.object<Config>({
// Validate config
const result = schema.validate(
{
port: process.env.PORT,
env: process.env.NODE_ENV,
managerUrl: process.env.MANAGER_URL,
submissionUrl: process.env.SUBMISSION_URL,
previewUrl: process.env.PREVIEW_URL,
port: PORT,
env: DEPLOYMENT_ENV,
nodeEnv: NODE_ENV,
managerUrl: MANAGER_URL,
submissionUrl: SUBMISSION_URL,
previewUrl: PREVIEW_URL,
serviceName: 'Submit a form to Defra',
logLevel: process.env.LOG_LEVEL,
phase: process.env.PHASE,
isProduction: process.env.NODE_ENV === 'production',
isDevelopment: !['production', 'test'].includes(`${process.env.NODE_ENV}`),
isTest: process.env.NODE_ENV === 'test',
sessionTtl: process.env.SESSION_TTL,
fileDownloadPasswordTtl: process.env.FILE_DOWNLOAD_PASSWORD_TTL,
sessionCookiePassword: process.env.SESSION_COOKIE_PASSWORD,
sessionCookieTtl: process.env.SESSION_COOKIE_TTL,
azureClientId: process.env.AZURE_CLIENT_ID,
azureClientSecret: process.env.AZURE_CLIENT_SECRET,
oidcWellKnownConfigurationUrl:
process.env.OIDC_WELL_KNOWN_CONFIGURATION_URL,
appBaseUrl: process.env.APP_BASE_URL,
redisHost: process.env.REDIS_HOST,
redisUsername: process.env.REDIS_USERNAME,
redisPassword: process.env.REDIS_PASSWORD,
redisKeyPrefix: process.env.REDIS_KEY_PREFIX,
roleEditorGroupId: process.env.ROLE_EDITOR_GROUP_ID
logLevel: LOG_LEVEL,
phase: PHASE,
isProduction: DEPLOYMENT_ENV === 'production',
isDevelopment:
!DEPLOYMENT_ENV || !['production', 'test'].includes(DEPLOYMENT_ENV),
isTest: NODE_ENV === 'test',
sessionTtl: SESSION_TTL,
fileDownloadPasswordTtl: FILE_DOWNLOAD_PASSWORD_TTL,
sessionCookiePassword: SESSION_COOKIE_PASSWORD,
sessionCookieTtl: SESSION_COOKIE_TTL,
azureClientId: AZURE_CLIENT_ID,
azureClientSecret: AZURE_CLIENT_SECRET,
oidcWellKnownConfigurationUrl: OIDC_WELL_KNOWN_CONFIGURATION_URL,
appBaseUrl: APP_BASE_URL,
redisHost: REDIS_HOST,
redisUsername: REDIS_USERNAME,
redisPassword: REDIS_PASSWORD,
redisKeyPrefix: REDIS_KEY_PREFIX,
roleEditorGroupId: ROLE_EDITOR_GROUP_ID
},
{ abortEarly: false }
)
Expand Down