-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
200 lines (177 loc) · 4.43 KB
/
server.js
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
var express = require('express');
var redis = require('redis');
var db = redis.createClient();
var app = express();
var expressHbs = require('express3-handlebars');
app.engine('hbs', expressHbs({extname:'hbs', defaultLayout:'main.hbs'}));
app.set('view engine', 'hbs');
var AWS = require('aws-sdk');
var uuid = require('node-uuid');
AWS.config.loadFromPath('./config.json');
var s3 = new AWS.S3();
var elb = new AWS.ELB();
var route53 = new AWS.Route53();
var support = new AWS.Support();
s3.listBuckets(function(err, data) {
if (err)
console.log(err, err.stack); // experienced error
else
bucket_list = data
});
app.use(function(req, res, next){
var ua = req.headers['user-agent'];
db.zadd('online', Date.now(), ua, next);
});
app.use(function(req, res, next){
var min = 60 * 1000;
var ago = Date.now() - min;
db.zrevrangebyscore('online', '+inf', ago, function(err, users){
if (err) return next(err);
req.online = users;
next();
});
});
app.get('/', function(req, res){
res.render('index');
});
app.get('/buckets', function(req, res, next){
var ua = req.headers['user-agent'];
db.zadd('online_list_buckets', Date.now(), ua, next);
res.json(bucket_list);
});
app.get('/bucket/:name/location', function(req, res) {
s3.getBucketLocation(params={Bucket: req.params.name}, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/bucket/:name/objects', function(req, res) {
var params = {
Bucket: req.params.name, // required
// Delimiter: 'STRING_VALUE',
// EncodingType: 'url',
// Marker: 'STRING_VALUE',
// MaxKeys: 0,
// Prefix: 'STRING_VALUE'
};
s3.listObjects(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/bucket/:name/policy', function(req, res) {
var params = {
Bucket: req.params.name // required
};
s3.getBucketPolicy(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/elbs', function(req, res) {
elb.describeLoadBalancers(function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/elb/:name', function(req, res) {
var params = {
LoadBalancerNames: [ req.params.name ]
}
elb.describeLoadBalancers(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/elb/:name/health', function(req, res) {
var params = {
LoadBalancerName: req.params.name
};
elb.describeInstanceHealth(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/route53/zones', function(req, res) {
route53.listHostedZones(function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/route53/:id/zone', function(req, res) {
var params = {
Id: req.params.id
};
route53.getHostedZone(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/route53/:id/records', function(req, res) {
var params = {
HostedZoneId: req.params.id // required
};
route53.listResourceRecordSets(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/support/cases', function(req,res) {
var params = {
caseId: 'STRING_VALUE' // required
};
support.describeCommunications(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
app.get('/support/cases/all', function(req, res){
var params = {
};
support.describeCases(params, function(err, data) {
if (err) console.log(err, err.stack);
else {
res.json(data);
}
});
});
// app.get('/bucket/:name/lifecycle', function(req, res) {
// s3.getBucketLifecycle(params={Bucket: req.params.name}, function(err, data) {
// if (err) console.log(err, err.stack); // an error occurred
// else res.json(data); // successful response
// });
// });
// app.get('/test', function(req, res){
//
// s3.listBuckets(function(err, data) {
// if (err)
// console.log(err, err.stack); // experienced error
// else
// bucket_list = data
// });
//
// res.render('test', bucket_list);
// });
var server = app.listen(5000, function() {
console.log('Listening on port %d', server.address().port);
});