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

refactor(env-vars): use envalid in user-mgnt #7651

Merged
merged 7 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions packages/user-mgnt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"@hapi/hapi": "^20.0.1",
"@opencrvs/commons": "^1.3.0",
"app-module-path": "^2.2.0",
"bcryptjs": "^2.4.3",
"crypto": "^1.0.1",
"envalid": "^8.0.0",
"hapi-auth-jwt2": "10.6.0",
"hapi-pino": "^9.0.0",
"hapi-sentry": "^3.1.0",
Expand All @@ -33,16 +36,15 @@
"node-fetch": "^2.6.7",
"pino": "^7.0.0",
"tsconfig-paths": "^3.13.0",
"uuid": "^3.3.2",
"bcryptjs": "^2.4.3",
"crypto": "^1.0.1"
"uuid": "^3.3.2"
},
"devDependencies": {
"@types/bcryptjs": "^2.4.2",
"@types/fhir": "^0.0.30",
"@types/hapi__boom": "^9.0.1",
"@types/jsonwebtoken": "^9.0.0",
"@types/hapi__hapi": "^20.0.0",
"@types/jest": "^26.0.14",
"@types/jsonwebtoken": "^9.0.0",
"@types/jwt-decode": "^2.2.1",
"@types/lodash": "^4.14.135",
"@types/node-fetch": "^2.5.12",
Expand All @@ -54,8 +56,7 @@
"prettier": "2.8.8",
"ts-jest": "27.1.4",
"ts-node": "^6.1.1",
"typescript": "4.9.5",
"@types/bcryptjs": "^2.4.2"
"typescript": "4.9.5"
},
"lint-staged": {
"src/**/*.{ts,graphql}": [
Expand Down
46 changes: 18 additions & 28 deletions packages/user-mgnt/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,38 +8,28 @@
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/
export const HOST = process.env.HOST || 'localhost'
export const PORT = process.env.PORT || 3030
export const MONGO_URL =
process.env.MONGO_URL || 'mongodb://localhost/user-mgnt'
export const NOTIFICATION_SERVICE_URL =
process.env.NOTIFICATION_SERVICE_URL || 'http://localhost:2020/'
export const APPLICATION_CONFIG_URL =
process.env.APPLICATION_CONFIG_URL || 'http://localhost:2021/'
export const DOCUMENTS_URL =
process.env.DOCUMENTS_URL || 'http://localhost:9050'
export const CERT_PUBLIC_KEY_PATH =
(process.env.CERT_PUBLIC_KEY_PATH as string) ||
'../../.secrets/public-key.pem'
export const SENTRY_DSN = process.env.SENTRY_DSN
export const QA_ENV = process.env.QA_ENV || false
export const RECORD_SEARCH_QUOTA =
Number(process.env.RECORD_SEARCH_QUOTA) || 2000

export const FHIR_URL = process.env.FHIR_URL || 'http://localhost:3447/fhir'
import { env } from './environment'

export const DEFAULT_TIMEOUT = 600000
export const METRICS_URL = process.env.METRICS_URL || 'http://localhost:1050'

export const NATIONAL_ID_OIDP_BASE_URL =
process.env.NATIONAL_ID_OIDP_BASE_URL || null // e.g. https://api.esignet.io/v1/idp
export const HOST = env.HOST
export const PORT = env.PORT
export const MONGO_URL = env.MONGO_URL
export const NOTIFICATION_SERVICE_URL = env.NOTIFICATION_SERVICE_URL
export const APPLICATION_CONFIG_URL = env.APPLICATION_CONFIG_URL
export const DOCUMENTS_URL = env.DOCUMENTS_URL
export const CERT_PUBLIC_KEY_PATH = env.CERT_PUBLIC_KEY_PATH
export const SENTRY_DSN = env.SENTRY_DSN
export const QA_ENV = env.QA_ENV
export const RECORD_SEARCH_QUOTA = env.RECORD_SEARCH_QUOTA

export const NATIONAL_ID_OIDP_CLIENT_ID =
process.env.NATIONAL_ID_OIDP_CLIENT_ID || null
export const FHIR_URL = env.FHIR_URL
export const METRICS_URL = env.METRICS_URL

export const NATIONAL_ID_OIDP_BASE_URL = env.NATIONAL_ID_OIDP_BASE_URL
export const NATIONAL_ID_OIDP_CLIENT_ID = env.NATIONAL_ID_OIDP_CLIENT_ID
export const NATIONAL_ID_OIDP_ESSENTIAL_CLAIMS =
process.env.NATIONAL_ID_OIDP_ESSENTIAL_CLAIMS || null // e.g. given_name,family_name

env.NATIONAL_ID_OIDP_ESSENTIAL_CLAIMS
export const NATIONAL_ID_OIDP_VOLUNTARY_CLAIMS =
process.env.NATIONAL_ID_OIDP_VOLUNTARY_CLAIMS || null

export const MINIO_BUCKET = process.env.MINIO_BUCKET || 'ocrvs'
env.NATIONAL_ID_OIDP_VOLUNTARY_CLAIMS
33 changes: 33 additions & 0 deletions packages/user-mgnt/src/environment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* OpenCRVS is also distributed under the terms of the Civil Registration
* & Healthcare Disclaimer located at http://opencrvs.org/license.
*
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
*/

import { cleanEnv, str, port, url, bool, num } from 'envalid'

export const env = cleanEnv(process.env, {
HOST: str({ devDefault: 'localhost' }),
PORT: port({ default: 3030 }),
MONGO_URL: url({ devDefault: 'mongodb://localhost/user-mgnt' }),
NOTIFICATION_SERVICE_URL: url({ devDefault: 'http://localhost:2020/' }),
APPLICATION_CONFIG_URL: url({ devDefault: 'http://localhost:2021/' }),
DOCUMENTS_URL: url({ devDefault: 'http://localhost:9050' }),
CERT_PUBLIC_KEY_PATH: str({ devDefault: '../../.secrets/public-key.pem' }),
SENTRY_DSN: str({ default: undefined }),
QA_ENV: bool({ default: false }),
RECORD_SEARCH_QUOTA: num({ default: 2000 }),

FHIR_URL: url({ devDefault: 'http://localhost:3447/fhir' }),
METRICS_URL: url({ devDefault: 'http://localhost:1050' }),

NATIONAL_ID_OIDP_BASE_URL: str({ default: undefined }),
NATIONAL_ID_OIDP_CLIENT_ID: str({ default: undefined }),
NATIONAL_ID_OIDP_ESSENTIAL_CLAIMS: str({ default: undefined }),
NATIONAL_ID_OIDP_VOLUNTARY_CLAIMS: str({ default: undefined })
})
5 changes: 0 additions & 5 deletions packages/user-mgnt/src/features/createUser/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import {
DOCUMENTS_URL,
FHIR_URL,
MINIO_BUCKET,
NOTIFICATION_SERVICE_URL
} from '@user-mgnt/constants'
import User, {
Expand Down Expand Up @@ -85,10 +84,6 @@ export const uploadSignatureToMinio = async (
return res.refUrl
}

export const isMinioUrl = (uri: string | undefined) => {
return uri?.split('/')[3] === MINIO_BUCKET
}

export const getSignatureExtension = (extensions: Extension[] | undefined) => {
return findExtension(
`${OPENCRVS_SPECIFICATION_URL}extension/employee-signature`,
Expand Down
4 changes: 2 additions & 2 deletions packages/user-mgnt/src/utils/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ const convertClaimsToUserInfoClaims = ({
openIdProviderEssentialClaims,
openIdProviderVoluntaryClaims
}: {
openIdProviderEssentialClaims: string | null
openIdProviderVoluntaryClaims: string | null
openIdProviderEssentialClaims?: string
openIdProviderVoluntaryClaims?: string
}) => {
const userinfo: Record<string, { essential: boolean }> = {}

Expand Down
Loading