2017-05-03 22:48:15 +03:00
|
|
|
'use strict';
|
|
|
|
|
2017-06-05 23:54:44 +03:00
|
|
|
const Data = require('portal-data');
|
2017-05-03 22:48:15 +03:00
|
|
|
|
|
|
|
|
2017-06-05 23:54:44 +03:00
|
|
|
const ifError = function (err) {
|
|
|
|
if (err) {
|
|
|
|
console.error(err);
|
|
|
|
process.exit(1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-09 21:13:22 +03:00
|
|
|
const bootstrap = function () {
|
2017-06-21 19:15:17 +03:00
|
|
|
const data = new Data({
|
|
|
|
db: {
|
|
|
|
host: process.env.RETHINK_HOST || 'localhost'
|
|
|
|
}
|
|
|
|
});
|
2017-06-05 23:54:44 +03:00
|
|
|
|
2017-06-22 04:05:45 +03:00
|
|
|
const region = process.env.TRITON_DC || 'us-sw-1';
|
|
|
|
const login = process.env.TRITON_USER || 'nikola';
|
|
|
|
|
2017-06-09 21:13:22 +03:00
|
|
|
data.connect(() => {
|
2017-06-22 04:05:45 +03:00
|
|
|
data.createDatacenter({ region, name: region }, (err, datacenter) => {
|
2017-06-05 23:54:44 +03:00
|
|
|
ifError(err);
|
|
|
|
|
2017-06-22 04:05:45 +03:00
|
|
|
data.createUser({ firstName: 'Nikola', lastName: 'Tesla', email: 'nikola@tesla.com', login }, (err, user) => {
|
2017-06-05 23:54:44 +03:00
|
|
|
ifError(err);
|
|
|
|
|
2017-06-09 21:13:22 +03:00
|
|
|
data.createPortal({
|
|
|
|
user,
|
|
|
|
datacenter
|
|
|
|
}, (err, portal) => {
|
2017-06-05 23:54:44 +03:00
|
|
|
ifError(err);
|
|
|
|
console.log('data bootstrapped');
|
|
|
|
process.exit(0);
|
|
|
|
});
|
|
|
|
});
|
2017-05-03 22:48:15 +03:00
|
|
|
});
|
|
|
|
});
|
2017-06-09 21:13:22 +03:00
|
|
|
};
|
2017-06-22 04:05:45 +03:00
|
|
|
/*
|
2017-06-09 21:13:22 +03:00
|
|
|
const main = function () {
|
2017-06-21 19:15:17 +03:00
|
|
|
const dropData = new Data({
|
|
|
|
db: {
|
|
|
|
host: process.env.RETHINK_HOST || 'localhost'
|
|
|
|
}
|
|
|
|
});
|
2017-06-09 21:13:22 +03:00
|
|
|
|
|
|
|
dropData.connect(() => {
|
|
|
|
dropData._db.r.dbDrop('portal').run(dropData._db._connection, () => {
|
|
|
|
bootstrap();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2017-06-22 04:05:45 +03:00
|
|
|
*/
|
|
|
|
bootstrap();
|