Repository navigation
Expand file tree
/
Copy pathconsole
More file actions
executable file
·91 lines (81 loc) · 2.71 KB
/
Copy pathconsole
File metadata and controls
executable file
·91 lines (81 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env node
/**
* Copyright 2012-2013 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"). You
* may not use this file except in compliance with the License. A copy of
* the License is located at
*
* http://aws.amazon.com/apache2.0/
*
* or in the "license" file accompanying this file. This file 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 repl = require('repl').start('aws-sdk> '),
replEval = repl.eval,
replHistory = require('repl.history'),
defaultOptions = {
region: process.env.AWS_REGION || 'us-east-1'
};
function customEval(cmd, context, filename, callback) {
replEval(cmd, context, filename, function(err, value) {
if (err) {
callback(err, null);
return;
}
if (value && value.constructor === AWS.Request) {
if (!value.__hasBeenSent__) {
value.__hasBeenSent__ = true;
try {
value.on('complete', function consoleDataExtraction(resp) {
context.data = resp.data;
context.error = resp.error;
callback(resp.error, resp.data);
});
context.request = value;
context.data = null;
context.error = null;
context.response = value.send();
} catch (err2) {
callback(err2, null);
return;
}
}
} else {
callback(null, value);
}
});
}
var AWS = repl.context.AWS = require('../lib/aws');
repl.eval = customEval;
// context variables
repl.context.data = null;
repl.context.error = null;
repl.context.request = null;
repl.context.response = null;
// custom logger
repl.context.AWS.events.on('send', function (resp) {
resp.requestStarted = new Date().getTime();
}).on('complete', function (resp) {
var time = new Date().getTime(),
status = resp.httpResponse.statusCode,
params = require('util').inspect(this.params, true, true);
console.log('\x1B[33m[AWS', this.service.serviceIdentifier, status,
(time-resp.requestStarted)/1000, resp.retryCount + ' retries]\x1B[0;1m',
this.operation + '(' + params + ')\x1B[0m');
});
// setup REPL history
replHistory(repl, process.env.HOME + '/.node_history');
// load services as defined instances
for (var key in AWS) {
if (AWS[key].serviceIdentifier) {
var svcClass = AWS[key];
var svc = new svcClass(defaultOptions);
svc.with = function(config) {
return new this.constructor.__super__(AWS.util.merge(this.config, config));
};
repl.context[svcClass.serviceIdentifier] = svc;
}
}