Skip to content
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
19 changes: 6 additions & 13 deletions onboarding-enabler-nodejs/src/EurekaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,14 @@ export default class Eureka extends EventEmitter {
const cwd = config.cwd || process.cwd();
const env = process.env.EUREKA_ENV || process.env.NODE_ENV || 'development';

// Config can either be passed via config file or as json
// Check if config file and cwd was provided
if (cwd) {
const filename = config.filename || 'eureka-client';
const filename = config.filename || 'eureka-client';

// Load in the configuration files:
const defaultYml = getYaml(path.join(cwd, `${filename}.yml`));
const envYml = getYaml(path.join(cwd, `${filename}-${env}.yml`));
// Load in the configuration files:
const defaultYml = getYaml(path.join(cwd, `${filename}.yml`));
const envYml = getYaml(path.join(cwd, `${filename}-${env}.yml`));

// apply config overrides in appropriate order
this.config = merge({}, defaultConfig, defaultYml, envYml, config);
} else {
// config was provided as JSON
this.config = config;
}
// apply config overrides in appropriate order
this.config = merge({}, defaultConfig, defaultYml, envYml, config);

// Validate the provided the values we need:
this.validateConfig(this.config);
Expand Down
38 changes: 24 additions & 14 deletions onboarding-enabler-nodejs/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ let certFile = null;
let keyFile = null;
let caFile = null;
let passPhrase = null;
let client = null;
let tlsOpts = null;

/**
* Read ssl service configuration
Expand All @@ -31,22 +33,30 @@ function readTlsProps() {
console.log(e);
}
}
readTlsProps();

export const tlsOptions = {
cert: fs.readFileSync(certFile),
key: fs.readFileSync(keyFile),
passphrase: passPhrase,
ca: fs.readFileSync(caFile),
};
export const tlsOptions = tlsOpts;

const client = new Eureka({
filename: 'service-configuration',
cwd: 'config/',
requestMiddleware: (requestOpts, done) => {
done(Object.assign(requestOpts, tlsOptions));
},
});
function init () {
const defaultFile = fs.existsSync('config/service-configuration.yml', 'utf8');
if (defaultFile) {
readTlsProps();
tlsOpts = {
cert: fs.readFileSync(certFile),
key: fs.readFileSync(keyFile),
passphrase: passPhrase,
ca: fs.readFileSync(caFile),
};
client = new Eureka({
filename: 'service-configuration',
cwd: 'config/',
requestMiddleware: (requestOpts, done) => {
done(Object.assign(requestOpts, tlsOpts));
},
});
}
}

init();

/**
* Function that uses the eureka-js-client library to register the application to Eureka
Expand Down
Loading