Permalink
Browse files

Merge branch 'master' into improved_api

Conflicts:
	lib/web/handlers.js
  • Loading branch information...
2 parents c98fd9a + f966953 commit 67a27e1ba9f498d57ad423525cbf52119779e7bd Russell Haering committed Mar 19, 2012
Showing with 147 additions and 3 deletions.
  1. +1 −0 README.md
  2. +15 −1 lib/dreadnot.js
  3. +16 −1 lib/plugins/irc.js
  4. +13 −1 lib/util/knife.js
  5. +102 −0 lib/util/pagerduty.js
View
@@ -4,6 +4,7 @@ Dreadnot is a 'one click' deploy tool written in [Node.js](http://www.nodejs.org
Dreadnot was heavily inspired by [Etsy's Deployinator](https://github.com/etsy/deployinator/).
+![Deploy all the branches](http://desmond.imageshack.us/Himg442/scaled.php?server=442&filename=deployallthebranches.png&res=medium)
## Configuration
View
@@ -87,19 +87,33 @@ Dreadnot.prototype.unlock = function(names) {
};
-Dreadnot.prototype.setWarning = function(text, callback) {
+
+/**
+ * Set or clear a warning.
+ *
+ * @param {Object} user User object.
+ * @param {String} text User Warning text.
+ * @param {Function} callback Callback called with (err).
+ */
+Dreadnot.prototype.setWarning = function(user, text, callback) {
var self = this;
this.queue.push(function(callback) {
fs.writeFile(path.join(self.config.data_root, 'warning.txt'), text, function(err) {
+ var oldWarning = self.warning;
+
if (!err) {
self.warning = text;
if (text) {
log.warnf('warning set to "${text}"', {
text: text
});
+
+ self.emitter.emit('warning.set', {'text': text, 'username': user.name});
} else {
log.info('warning cleared');
+
+ self.emitter.emit('warning.removed', {'text': oldWarning, 'username': user.name});
}
}
callback(err);
View
@@ -65,8 +65,23 @@ exports.run = function(dreadnot) {
});
});
});
-};
+ dreadnot.emitter.on('warning.set', function(obj) {
+ var msg = sprintf('Warning has been set to "%s" by %s', obj.text, obj.username);
+
+ onEach(clients, joined, function(client, channel) {
+ client.notice(channel, msg);
+ });
+ });
+
+ dreadnot.emitter.on('warning.removed', function(obj) {
+ var msg = sprintf('Warning "%s" has been removed by %s', obj.text, obj.username);
+
+ onEach(clients, joined, function(client, channel) {
+ client.notice(channel, msg);
+ });
+ });
+};
function onEach(clients, joined, fn) {
View
@@ -26,6 +26,7 @@ var sprintf = require('./sprintf');
function knife(args, options) {
return function(callback) {
var env = misc.copyEnv();
+ var knife_path = '/usr/bin/knife';
options = options || {};
// Support for these must be implemented in your knife.rb
@@ -37,7 +38,18 @@ function knife(args, options) {
env['CHEF_USER'] = options.user;
}
- args = ['/usr/bin/knife'].concat(args);
+ if (env['KNIFE_PATH']) {
+ knife_path = env['KNIFE_PATH'];
+ }
+ else if (options.knife_path) {
+ knife_path = options.knife_path;
+ }
+
+ if (options.knife_config) {
+ args = args.concat(['-c', options.knife_config]);
+ }
+
+ args = [knife_path].concat(args);
misc.spawn(args, {env: env}, function(err, stdout, stderr) {
var payload;
View
@@ -0,0 +1,102 @@
+/*
+ * Copyright 2011 Rackspace
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+var url = require('url');
+var querystring = require('querystring');
+
+var logmagic = require('logmagic');
+var request = require('request');
+
+var misc = require('./misc');
+var sprintf = require('./sprintf');
+
+
+/**
+ * PagerDuty Client.
+ * @constructor
+ * @param {Object} options The options.
+ */
+function PagerDuty(options, log) {
+ var parsed = url.parse(options.url);
+
+ // Inject auth into the URL
+ delete parsed.host;
+ parsed['auth'] = sprintf('%s:%s', options.username, options.password);
+
+ this.url = options.url;
+ this.authedURL = url.format(parsed);
+ this.users = options.users;
+ this.schedules = options.schedules;
+ this.log = log || logmagic.local('pagerduty');
+}
+
+
+/**
+ * Create a schedule override.
+ */
+PagerDuty.prototype.override = function(schedule, user, startTime, endTime, callback) {
+ var self = this,
+ scheduleId = this.schedules[schedule],
+ userId = this.users[user],
+ reqOpts;
+
+ if (!scheduleId) {
+ callback(new Error('Unconfigured schedule: ' + schedule));
+ return;
+ }
+
+ if (!userId) {
+ callback(new Error('Unconfigured user: ' + user));
+ return;
+ }
+
+ reqOpts = {
+ method: 'POST',
+ uri: sprintf('%s/api/beta/schedules/%s/overrides', this.authedURL, scheduleId),
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({
+ override: {
+ start: startTime.toISOString(),
+ end: endTime.toISOString(),
+ user_id: userId
+ }
+ })
+ };
+
+ request(reqOpts, function(err, response, body) {
+ var obj;
+
+ if (err) {
+ callback(err);
+ } else if (response.statusCode !== 200) {
+ callback(new Error(sprintf('Received %s from %s', response.statusCode, self.url)));
+ } else {
+ try {
+ obj = JSON.parse(body);
+ } catch (e) {
+ err = e;
+ }
+ callback(err, err ? null : obj.override);
+ }
+ });
+};
+
+
+/** PagerDuty Class */
+exports.PagerDuty = PagerDuty;

0 comments on commit 67a27e1

Please sign in to comment.