From e06ec920f7a5d784e674c4c4b4e6d1da3dc7391d Mon Sep 17 00:00:00 2001 From: Piotr Russ Date: Mon, 16 Nov 2020 00:10:28 +0100 Subject: api, login, auth --- node_modules/mongoose/tools/auth.js | 30 +++++++++++++++++++++++ node_modules/mongoose/tools/repl.js | 36 +++++++++++++++++++++++++++ node_modules/mongoose/tools/sharded.js | 45 ++++++++++++++++++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 node_modules/mongoose/tools/auth.js create mode 100644 node_modules/mongoose/tools/repl.js create mode 100644 node_modules/mongoose/tools/sharded.js (limited to 'node_modules/mongoose/tools') diff --git a/node_modules/mongoose/tools/auth.js b/node_modules/mongoose/tools/auth.js new file mode 100644 index 0000000..7cfaf86 --- /dev/null +++ b/node_modules/mongoose/tools/auth.js @@ -0,0 +1,30 @@ +'use strict'; + +const Server = require('mongodb-topology-manager').Server; +const co = require('co'); +const mongodb = require('mongodb'); + +co(function*() { + // Create new instance + const server = new Server('mongod', { + auth: null, + dbpath: '/data/db/27017' + }); + + // Purge the directory + yield server.purge(); + + // Start process + yield server.start(); + + const db = yield mongodb.MongoClient.connect('mongodb://localhost:27017/admin'); + + yield db.addUser('passwordIsTaco', 'taco', { + roles: ['dbOwner'] + }); + + console.log('done'); +}).catch(error => { + console.error(error); + process.exit(-1); +}); diff --git a/node_modules/mongoose/tools/repl.js b/node_modules/mongoose/tools/repl.js new file mode 100644 index 0000000..8139a51 --- /dev/null +++ b/node_modules/mongoose/tools/repl.js @@ -0,0 +1,36 @@ +'use strict'; + +const co = require('co'); + +co(function*() { + const ReplSet = require('mongodb-topology-manager').ReplSet; + + // Create new instance + const topology = new ReplSet('mongod', [{ + // mongod process options + options: { + bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000` + } + }, { + // mongod process options + options: { + bind_ip: 'localhost', port: 31001, dbpath: `/data/db/31001` + } + }, { + // Type of node + arbiterOnly: true, + // mongod process options + options: { + bind_ip: 'localhost', port: 31002, dbpath: `/data/db/31002` + } + }], { + replSet: 'rs' + }); + + yield topology.start(); + + console.log('done'); +}).catch(error => { + console.error(error); + process.exit(-1); +}); diff --git a/node_modules/mongoose/tools/sharded.js b/node_modules/mongoose/tools/sharded.js new file mode 100644 index 0000000..2b0cc04 --- /dev/null +++ b/node_modules/mongoose/tools/sharded.js @@ -0,0 +1,45 @@ +'use strict'; + +const co = require('co'); + +co(function*() { + const Sharded = require('mongodb-topology-manager').Sharded; + + // Create new instance + const topology = new Sharded({ + mongod: 'mongod', + mongos: 'mongos' + }); + + yield topology.addShard([{ + options: { + bind_ip: 'localhost', port: 31000, dbpath: `/data/db/31000`, shardsvr: null + } + }], { replSet: 'rs1' }); + + yield topology.addConfigurationServers([{ + options: { + bind_ip: 'localhost', port: 35000, dbpath: `/data/db/35000` + } + }], { replSet: 'rs0' }); + + yield topology.addProxies([{ + bind_ip: 'localhost', port: 51000, configdb: 'localhost:35000' + }], { + binary: 'mongos' + }); + + console.log('Start...'); + // Start up topology + yield topology.start(); + + console.log('Started'); + + // Shard db + yield topology.enableSharding('test'); + + console.log('done'); +}).catch(error => { + console.error(error); + process.exit(-1); +}); -- cgit v1.2.3