@ibm-gpn/platform-config
v1.1.39
Published
Library with shared configuration
Readme
GPN shared configuration library
Configuration could be performed by creation of the environment specific configuration files with specific app configuration in it or/and by defining environment variables.
Getting started
Login to the private artifactory (ask maintainers for credentials):
npm login
Install dependencies:
npm i
To turn on debug messages display set NODE_DEBUG=gpn-config* environment variable in your project.
When developing, it's useful to use npm's link feature to link local copy of the library to your project.
In gpn-config library:
npm run relink
In your project:
npm link @ibm-gpn/gpn-config
Add new configs
To add new app specific configurations you need to add it to the environment specific config file in the /configs folder or to the /configs/default.ts.
Your config must be placed under application name key and should consist props that later will be merged with default ones.
Ex.:
{
...
APP_NAME: {
db: {
database: 'APP_SPECIFIC_DB'
},
server: {
port: 8888 // APP specific port
}
}
}Usage
Instantiate in your project with application name from EApplication enum:
import { EApplication } from '@ibm-gpn/gpn-common';
const config = new Configuration(EApplication.DP);
// Get database configuration for DP app.
console.log('DB configuration', config.db());
// Get api configuration for DP app.
console.log('API configuration', config.api());
// Get specific key from configuration.
console.log('DB SSL option', config.instance.get('db.ssl'));
Also, you can get configuration of specific app by passing app name from the EApplication enum:
import { EApplication } from '@ibm-gpn/gpn-common';
const config = new Configuration(EApplication.DP);
// Get database configuration for DP app.
console.log('DB configuration', config.db());
// Get api configuration for DP app.
console.log('API configuration', config.api());
// Get specific key from configuration.
console.log('DB SSL option', config.instance.get('db.ssl'));
Under the hood, node-config library used, so you can use its api throw instance property:
import { EApplication } from '@ibm-gpn/gpn-common';
const config = new Configuration(EApplication.DP);
// Get specific key from configuration.
console.log('DB SSL option', config.instance.get('db.ssl'));
// Get specific key existence in configuration.
console.log('Is DB SSL option exists?', config.instance.has('db.ssl'));
You can pass specific configuration and it will be used with highest priority:
import { EApplication } from '@ibm-gpn/gpn-common';
const config = new Configuration(EApplication.DP, { db: { username: 'master' } });
console.log('DB SSL option', config.instance.get('db.username'));
// master
NestJS module
This library provides you with global NestJS configuration module, so you can load it once in your NestJS app and use it everywhere within your app.
import { EApplication } from '@ibm-gpn/gpn-common';
...
@Module({
imports: [ConfigModule.register(EApplication.SECURITY)],
})
export class AppModule { }
Then you can use app specific ConfigService in your code.
@Module({
imports: [
JwtModule.registerAsync(
{
inject: [ConfigService],
useFactory: (config: ConfigService) => config.auth(),
}),
],
})
export class AuthModule {}
Also, you can use decorator to inject ConfigService into your class.
@Injectable()
export class SomeService {
constructor(@InjectConfig() private readonly config: ConfigService) {
}
}
Environment variables
Also, you can define env variables listed below (higher priority) with app prefix.
For example, to define database name for the SECURITY app, you need to pass SECURITY_DB_NAME env variable.
Database:
DB_NAME - Name.
DB_HOST - Host. Default: localhost.
DB_PASSWORD - Password. Default: 1qazse4rfv.
DB_PORT - Port. Default: 30933.
DB_SCHEMA - Schema. Default: dev.
DB_USER - User. Default: admin.Host:
HOST - host url.Server:
HTTP_PORT - Server port.Microservice:
MS_PORT - Microservice port.Authentication and authorization:
AUTH_SECRET - Secret key. Default: 2c54a418-3563-4af9-849b-36b6ff6a5429.
AUTH_TOKEN_EXPIRATION_TIME - Authentication token expiration time. Default: 1h.API:
API_PREFIX - Api prefix.Swagger:
SWAGGER_PREFIX - Swagger portal prefix. Default: api-doc.Logger:
LOGGER_LEVEL - Level of logging.
LOGGER_NAME - Logger name. CAPEX:
CAPEX_BASE_URL - Capex base url.Primavera:
PRIMAVERA_HOST - Primavera host.
PRIMAVERA_PORT - Primavera port.Deployment
NPM registry
To publish library you should be member of the ibm-gpn organization in NPM. If you are not - contact with organization admins.
List of the team admins:
- Roman Samokhin ([email protected])
New version tag
Run one of the following commands:
npm run release-patch - to increment and push patch version
npm run release-minor - to increment and push minor version
npm run release-major - to increment and push major version
After it, new git tag will be pushed to the master branch.
Publish
For publishing to the private NPM registry you need to login:
npm login --registry=https://ibm-platform-repo.club/repository/npm-private/
After that run:
npm publish
