Skip to content

Commit

Permalink
Add env "LOGGER_SILLY"
Browse files Browse the repository at this point in the history
  • Loading branch information
SecondDim committed Dec 16, 2021
1 parent df89e82 commit 9b32424
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
5 changes: 2 additions & 3 deletions cicd/test_script/ca-gen.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash -ve
#! /bin/bash -ve

export NODE_ENV=development # testing development production
export NODE_ENV=production # testing development production
export BDK_NETWORK_NAME=shell-network-ca
export DOCKER_LOGGING=true
export BDK_ORG_TYPE=peer

ICA_DOMAIN_BEN='ica.ben.cathaybc.com'
Expand Down
5 changes: 2 additions & 3 deletions cicd/test_script/crypto-gen.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/bin/bash -ve
#! /bin/bash -ve

export NODE_ENV=development # testing development production
export NODE_ENV=production # testing development production
export BDK_NETWORK_NAME=shell-network-cryptogen
export DOCKER_LOGGING=true
export BDK_ORG_TYPE=peer

ORDERER_ORG_DOMAIN_BEN=$(jq --raw-output '.ordererOrgs[0].domain' ./cicd/test_script/network-create.json)
Expand Down
4 changes: 2 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export interface Config {
environment: EnvironmentEnum
isDevMode: boolean
isTestMode: boolean
dockerLogging: boolean
isSillyMode: boolean
infraConfig: InfraConfig
networkName: string
orgName: string
Expand Down Expand Up @@ -82,7 +82,7 @@ const config: Config = {
environment: environment,
isDevMode: isDevMode,
isTestMode: isTestMode,
dockerLogging: (process.env.DOCKER_LOGGING?.toLowerCase() === 'true') || false,
isSillyMode: (process.env.LOGGER_SILLY?.toLowerCase() === 'true') || false,
infraConfig: {
bdkPath: bdkPath,
dockerHostPath: process.env.BDK_DOCKER_HOST_PATH || bdkPath,
Expand Down
4 changes: 2 additions & 2 deletions src/model/type/config.type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { EnvironmentEnum } from '../../config'
* @requires BDK_ORG_NAME - [string] org 的名稱
* @requires BDK_ORG_DOMAIN - [string] org 的 domain 名稱
* @requires BDK_HOSTNAME - [string] hostname 的名稱
* @requires DOCKER_LOGGING - [boolean] 是否要顯示 docker log 資訊
* @requires LOGGER_SILLY - [boolean] 是否要顯示 silly log 資訊
*/
export interface ConfigEnvType {
NODE_ENV: EnvironmentEnum
Expand All @@ -16,7 +16,7 @@ export interface ConfigEnvType {
BDK_ORG_NAME: string
BDK_ORG_DOMAIN: string
BDK_HOSTNAME: string
DOCKER_LOGGING: boolean
LOGGER_SILLY: boolean
BDK_DOCKER_HOST_PATH?: string
}

Expand Down
2 changes: 1 addition & 1 deletion src/service/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const defaultEnv: ConfigEnvType = {
BDK_ORG_NAME: 'Org1',
BDK_ORG_DOMAIN: 'org1.example.com',
BDK_HOSTNAME: 'peer0',
DOCKER_LOGGING: false,
LOGGER_SILLY: false,
}

export default class Config extends AbstractService {
Expand Down
2 changes: 1 addition & 1 deletion src/util/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { transports, format, createLogger } from 'winston'
import { LEVEL } from 'triple-beam'

const defaultLoggerConfig = {
level: 'debug',
level: config.isSillyMode ? 'silly' : 'debug',
silent: config.isTestMode,
format: format.combine(
format.splat(),
Expand Down
10 changes: 5 additions & 5 deletions test/service/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ describe('Config service: ', () => {
BDK_ORG_NAME: 'TestOrg',
BDK_ORG_DOMAIN: 'test.domain.com',
BDK_HOSTNAME: 'peer0',
DOCKER_LOGGING: true,
LOGGER_SILLY: true,
}

const configSetEnv: ConfigSetType = {
Expand All @@ -37,7 +37,7 @@ describe('Config service: ', () => {
it('.env content and inputs should be the same', () => {
(new Config(config)).init()

const checkConfig = 'NODE_ENV=production\nBDK_NETWORK_NAME=bdk-network\nBDK_ORG_TYPE=peer\nBDK_ORG_NAME=Org1\nBDK_ORG_DOMAIN=org1.example.com\nBDK_HOSTNAME=peer0\nDOCKER_LOGGING=false\n'
const checkConfig = 'NODE_ENV=production\nBDK_NETWORK_NAME=bdk-network\nBDK_ORG_TYPE=peer\nBDK_ORG_NAME=Org1\nBDK_ORG_DOMAIN=org1.example.com\nBDK_HOSTNAME=peer0\nLOGGER_SILLY=false\n'

assert.strictEqual(fs.readFileSync(`${config.infraConfig.bdkPath}/.env`).toString(), checkConfig)
})
Expand All @@ -57,7 +57,7 @@ describe('Config service: ', () => {
it('.env content and inputs should be the same', () => {
(new Config(config)).init(configEnv)

const checkConfig = 'NODE_ENV=testing\nBDK_NETWORK_NAME=test-network\nBDK_ORG_TYPE=peer\nBDK_ORG_NAME=TestOrg\nBDK_ORG_DOMAIN=test.domain.com\nBDK_HOSTNAME=peer0\nDOCKER_LOGGING=true\n'
const checkConfig = 'NODE_ENV=testing\nBDK_NETWORK_NAME=test-network\nBDK_ORG_TYPE=peer\nBDK_ORG_NAME=TestOrg\nBDK_ORG_DOMAIN=test.domain.com\nBDK_HOSTNAME=peer0\nLOGGER_SILLY=true\n'

assert.strictEqual(fs.readFileSync(`${config.infraConfig.bdkPath}/.env`).toString(), checkConfig)
})
Expand All @@ -78,7 +78,7 @@ describe('Config service: ', () => {
(new Config(config)).init();
(new Config(config)).set(configSetEnv)

const checkConfig = 'NODE_ENV=production\nBDK_NETWORK_NAME=bdk-network\nBDK_ORG_TYPE=peer\nBDK_ORG_NAME=Org1\nBDK_ORG_DOMAIN=test.set.domain.com\nBDK_HOSTNAME=peer0\nDOCKER_LOGGING=false\n'
const checkConfig = 'NODE_ENV=production\nBDK_NETWORK_NAME=bdk-network\nBDK_ORG_TYPE=peer\nBDK_ORG_NAME=Org1\nBDK_ORG_DOMAIN=test.set.domain.com\nBDK_HOSTNAME=peer0\nLOGGER_SILLY=false\n'

assert.strictEqual(fs.readFileSync(`${config.infraConfig.bdkPath}/.env`).toString(), checkConfig)
})
Expand All @@ -98,7 +98,7 @@ describe('Config service: ', () => {
(new Config(config)).init();
(new Config(config)).ls()

const checkConfig = 'NODE_ENV=production\nBDK_NETWORK_NAME=bdk-network\nBDK_ORG_TYPE=peer\nBDK_ORG_NAME=Org1\nBDK_ORG_DOMAIN=org1.example.com\nBDK_HOSTNAME=peer0\nDOCKER_LOGGING=false\n'
const checkConfig = 'NODE_ENV=production\nBDK_NETWORK_NAME=bdk-network\nBDK_ORG_TYPE=peer\nBDK_ORG_NAME=Org1\nBDK_ORG_DOMAIN=org1.example.com\nBDK_HOSTNAME=peer0\nLOGGER_SILLY=false\n'

assert.strictEqual(fs.readFileSync(`${config.infraConfig.bdkPath}/.env`).toString(), checkConfig)
})
Expand Down

0 comments on commit 9b32424

Please sign in to comment.