Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial setup (db, email, admin, etc) #681

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
5 changes: 5 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"Sortable": "~0.4.1",
"bootbox": "3.3.0",
"codemirror": "3.18.0",
"angular-wizard": "~0.4.2",
"jquery-timeago": "1.3.0"
},
"install" : {
Expand All @@ -25,6 +26,10 @@
"sources": {
"bootbox": "bower_components/bootbox/bootbox.js",
"jquery-timeago": "bower_components/jquery-timeago/jquery.timeago.js",
"angular-wizard": [
"bower_components/angular-wizard/dist/angular-wizard.js",
"bower_components/angular-wizard/dist/angular-wizard.less"
],
"bootstrap": [
"bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css",
"bower_components/bootstrap/docs/assets/css/bootstrap.css",
Expand Down
4 changes: 3 additions & 1 deletion client/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require('./plugin-manager');
require('./job-status');
require('./dashboard');
require('./projects');
require('./setup');

// Shared?
require('./alerts');
Expand All @@ -37,7 +38,8 @@ var app = angular.module('app', [
'plugin-manager',
'job-status',
'dashboard',
'projects'
'projects',
'setup'
]);

// For access from plugins, need a better way
Expand Down
20 changes: 20 additions & 0 deletions client/setup/controllers/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

module.exports = function ($scope, $http) {
$scope.config = {
general: {},
smtp: {},
admin: {}
};

$scope.finishedWizard = function () {
console.log('finished', $scope.config);
$http.post('/api/setup', $scope.config)
.success(function (data) {
global.location.reload();
})
.error(function (error) {
console.error('Setup error: ', error);
});
};
};
13 changes: 13 additions & 0 deletions client/setup/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

var angular = require('angular');
var interpolate = require('../utils/interpolate');
var SetupController = require('./controllers/setup');

require('angular-wizard');

var app = angular.module('setup', ['mgo-angular-wizard'])
.config(['$interpolateProvider', interpolate])
.controller('Setup', ['$scope', '$http', SetupController]);

module.exports = app;
3 changes: 3 additions & 0 deletions client/styles/libs.less
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
@import (less) "vendor/CodeMirror/css/codemirror.css";
@import (less) "vendor/CodeMirror/css/twilight.css";

// Angular Wizard
@import "vendor/angular-wizard/less/angular-wizard.less";

// Fontawesome
@import "vendor/font-awesome/less/font-awesome.less";
@fa-font-path: "../vendor/font-awesome/fonts";
1 change: 1 addition & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ var init = exports.init = function (config) {

app.get('/api/session', api_session.get);
app.post('/api/session', api_session.create);
app.use('/api/setup', require('./routes/api/setup'));


app.use(function(req, res, next) {
Expand Down
78 changes: 50 additions & 28 deletions lib/libconfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ module.exports = {
addPlugins: addPlugins,
camel: camel,
getConfig: getConfig
}
};

// main function. Get the config, using rc
function getConfig() {
process.env = filterEnv(deprecated(process.env), envDefaults);

var rc = require('rc')('strider', defaults);

if (!rc.smtp) rc.smtp = smtp(rc);
Expand All @@ -87,65 +88,86 @@ function camel(words) {
}

function addPlugins(rc, env) {
var parts
if (!rc.plugins) rc.plugins = {}
var parts;

if (!rc.plugins) rc.plugins = {};

for (var key in env) {
if (!key.match(/^plugin_/i)) continue;

parts = key.toLowerCase().split('_')

if (parts.length === 2) {
try {
rc.plugins[parts[1]] = JSON.parse(env[key])
rc.plugins[parts[1]] = JSON.parse(env[key]);
} catch (e) {
console.warn("Ignoring config because it's not valid JSON: ", key, env[key])
console.warn('Ignoring config because it\'s not valid JSON: ', key, env[key]);
}

continue;
}
if (!rc.plugins[parts[1]]) rc.plugins[parts[1]] = {}
rc.plugins[parts[1]][camel(parts.slice(2))] = env[key]
if (!rc.plugins[parts[1]]) {
rc.plugins[parts[1]] = {};
}

rc.plugins[parts[1]][camel(parts.slice(2))] = env[key];
}
}

// Filter process.env.FOO to process.env.strider_foo for rc's benefit
function filterEnv(env, defaults) {
var res = {}
var res = {};

for (var k in env) {
if (defaults[k.toLowerCase()] !== undefined) {
res["strider_" + k.toLowerCase()] = env[k]
res['strider_' + k.toLowerCase()] = env[k];
} else {
res[k] = env[k]
res[k] = env[k];
}
}
return res

return res;
}

function deprecated(env) {
var nenv = _.extend({}, env)
var nenv = _.extend({}, env);

if (env.APP_ID) {
console.warn("WARNING: You are using APP_ID to configure Github OAuth application id.")
console.warn("This name has been deprecated. Please use PLUGIN_GITHUB_APP_ID instead.\n")
nenv.PLUGIN_GITHUB_APP_ID = env.APP_ID
console.warn('WARNING: You are using APP_ID to configure Github OAuth application id.');
console.warn('This name has been deprecated. Please use PLUGIN_GITHUB_APP_ID instead.\n');

nenv.PLUGIN_GITHUB_APP_ID = env.APP_ID;
}

if (env.APP_SECRET) {
console.warn("WARNING: You are using APP_SECRET to configure Github OAuth application secret.")
console.warn("This name has been deprecated. Please use PLUGIN_GITHUB_APP_SECRET instead.\n")
nenv.PLUGIN_GITHUB_APP_SECRET = env.APP_SECRET
console.warn('WARNING: You are using APP_SECRET to configure Github OAuth application secret.');
console.warn('This name has been deprecated. Please use PLUGIN_GITHUB_APP_SECRET instead.\n');

nenv.PLUGIN_GITHUB_APP_SECRET = env.APP_SECRET;
}

if (env.GITHUB_APP_ID) {
console.warn("WARNING: You are using GITHUB_APP_ID to configure Github OAuth application id.")
console.warn("This name has been deprecated. Please use PLUGIN_GITHUB_APP_ID instead.\n")
nenv.PLUGIN_GITHUB_APP_ID = env.GITHUB_APP_ID
console.warn('WARNING: You are using GITHUB_APP_ID to configure Github OAuth application id.');
console.warn('This name has been deprecated. Please use PLUGIN_GITHUB_APP_ID instead.\n');

nenv.PLUGIN_GITHUB_APP_ID = env.GITHUB_APP_ID;
}

if (env.GITHUB_SECRET) {
console.warn("WARNING: You are using GITHUB_SECRET to configure Github OAuth application secret.")
console.warn("This name has been deprecated. Please use PLUGIN_GITHUB_APP_SECRET instead.\n")
nenv.PLUGIN_GITHUB_APP_SECRET = env.GITHUB_SECRET
console.warn('WARNING: You are using GITHUB_SECRET to configure Github OAuth application secret.');
console.warn('This name has been deprecated. Please use PLUGIN_GITHUB_APP_SECRET instead.\n');

nenv.PLUGIN_GITHUB_APP_SECRET = env.GITHUB_SECRET;
}

if (env.GITHUB_API_ENDPOINT) {
console.warn("WARNING: You are using GITHUB_API_ENDPOINT to configure Github API base URL.")
console.warn("This name has been deprecated. Please use PLUGIN_GITHUB_API_BASE instead.\n")
nenv.PLUGIN_GITHUB_API_BASE = env.GITHUB_API_ENDPOINT
console.warn('WARNING: You are using GITHUB_API_ENDPOINT to configure Github API base URL.');
console.warn('This name has been deprecated. Please use PLUGIN_GITHUB_API_BASE instead.\n');

nenv.PLUGIN_GITHUB_API_BASE = env.GITHUB_API_ENDPOINT;
}
return nenv

return nenv;
}

function smtp(rc) {
Expand Down
22 changes: 16 additions & 6 deletions lib/models/config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
'use strict';

var mongoose = require('mongoose')
, Schema = mongoose.Schema
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var Config = new Schema({
version: Number,
// is there any other configuration we want?
})
serverName: String,
proxyUrl: String,

module.exports = mongoose.model('Config', Config)
smtp: {
host: String,
port: Number,
user: String,
password: String,
fromAddress: String
}
});

module.exports.SCHEMA_VERSION = 2
module.exports = mongoose.model('Config', Config);

module.exports.SCHEMA_VERSION = 2;
Loading