Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const { Etcd3 } = require('etcd3');
let endpoints = process.env.COMPOSE_ETCD_ENDPOINTS;
let envuser = process.env.COMPOSE_ETCD_USER
let envpass = process.env.COMPOSE_ETCD_PASS
// Create auth credentials
let opts = {
hosts: endpoints.split(","),
auth: {
username: envuser,
password: envpass
}
}
var etcd = new Etcd3(opts).namespace("/grand_tour/words/");
// We want to extract the port to publish our app on
let port = process.env.PORT || 8080;
// We can now set up our web server. First up we set it to serve static pages
app.use(express.static(__dirname + '/public'));
// The user has clicked submit to add a word and definition to the database
// put them into etcd3 and respond
app.put("/words", function (request, response) {
etcd.put(request.body.word).value(request.body.definition).then(
(result) => {
response.send(result);
}
).catch((err) => {
console.log(err);
process.exit(1);
}
let envuser = process.env.COMPOSE_ETCD_USER;
let envpass = process.env.COMPOSE_ETCD_PASS;
// Create auth credentials
let opts = {
hosts: endpoints.split(","),
auth: {
username: envuser,
password: envpass
}
};
var etcd = new Etcd3(opts).namespace("/grand_tour/words/");
// We want to extract the port to publish our app on
let port = process.env.PORT || 8080;
// We can now set up our web server. First up we set it to serve static pages
app.use(express.static(__dirname + '/public'));
// Add a word to the database
function addWord(word, definition) {
return new Promise(function(resolve, reject) {
etcd.put(word).value(definition).then(() => {
resolve();
}).catch((err) => {
reject(err);
});
});
delete(clusterStatus.apiEndpoints[node.metadata!.name!]);
kubeadmCM.data![configMapKey] = yaml.safeDump(clusterStatus);
const { response: cmReplaceResp } = await coreV1Client.replaceNamespacedConfigMap(configMapName, configMapNS, kubeadmCM);
if (!purgedMasterIP) {
logger.warn(`Failed to find IP of deleted master node from kubeadm-config: skipping etcd peer removal step`);
return;
}
if (!remainingMasterIPs.length) {
logger.error(`Cannot remove etcd peer: no remaining etcd endpoints available to connect to`);
return;
}
// 2. Use the credentials from the mounted etcd client cert secret to connect to the remaining
// etcd members and tell them to forget the purged member.
const etcd = new Etcd3({
credentials: {
rootCertificate: fs.readFileSync("/etc/kubernetes/pki/etcd/ca.crt"),
privateKey: fs.readFileSync("/etc/kubernetes/pki/etcd/client.key"),
certChain: fs.readFileSync("/etc/kubernetes/pki/etcd/client.crt"),
},
hosts: _.map(remainingMasterIPs, (ip) => `https://${ip}:2379`),
});
const peerURL = `https://${purgedMasterIP}:2380`;
const { members } = await etcd.cluster.memberList();
const purgedMember = _.find(members, (member) => {
return _.includes(member.peerURLs, peerURL);
});
if (!purgedMember) {
logger.info(`Purged node was not a member of etcd cluster`);
return;
}
function etcdConnector() {
const etcd = new Etcd3({
hosts: config.etcd.url,
credentials: {
rootCertificate: Buffer.from(config.etcd.ssl.ca, 'utf8'),
privateKey: Buffer.from(config.etcd.ssl.key, 'utf8'),
certChain: Buffer.from(config.etcd.ssl.crt, 'utf8')
}
});
return etcd;
}
function etcdConnector() {
const client = new Etcd3({
hosts: config.etcd.url,
credentials: {
rootCertificate: Buffer.from(config.etcd.ssl.ca, 'utf8'),
privateKey: Buffer.from(config.etcd.ssl.key, 'utf8'),
certChain: Buffer.from(config.etcd.ssl.crt, 'utf8')
}
});
return client;
}
const time_minute = (1 * 60 * 1000);
function etcdConnector() {
const etcd = new Etcd3({
hosts: config.etcd.url,
credentials: {
rootCertificate: Buffer.from(config.etcd.ssl.ca, 'utf8'),
privateKey: Buffer.from(config.etcd.ssl.key, 'utf8'),
certChain: Buffer.from(config.etcd.ssl.crt, 'utf8')
}
});
return etcd;
}
'use strict';
const _ = require('lodash');
const assert = require('assert');
const config = require('../common/config');
const logger = require('../common/logger');
const CONST = require('../common/constants');
const EventMeshServer = require('./EventMeshServer');
const {
Etcd3
} = require('etcd3');
const etcd = new Etcd3({
hosts: config.etcd.url,
credentials: {
rootCertificate: Buffer.from(config.etcd.ssl.ca, 'utf8'),
privateKey: Buffer.from(config.etcd.ssl.key, 'utf8'),
certChain: Buffer.from(config.etcd.ssl.crt, 'utf8')
}
});
class Etcd3EventMeshServer extends EventMeshServer {
registerService(resourceType, serviceId, serviceAttributesValue, servicePlansValue) {
const serviceFolderName = this.getServiceFolderName(resourceType, serviceId);
const attributesKey = `${serviceFolderName}/${CONST.SERVICE_KEYS.ATTRIBUTES}`;
logger.debug(`Registering Service ${serviceId} for resource ${resourceType}` +
`with attributes: ${serviceAttributesValue} and plans: ${servicePlansValue}`);
return etcd.put(attributesKey).value(JSON.stringify(serviceAttributesValue))
.then(() => {