This repository has been archived by the owner on Jun 5, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathawssum-amazon-route53.js
107 lines (82 loc) · 3.43 KB
/
awssum-amazon-route53.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
// --------------------------------------------------------------------------------------------------------------------
//
// route53.js - class for AWS Route 53
//
// Copyright (c) 2011 AppsAttic Ltd - http://www.appsattic.com/
// Written by Andrew Chilton <chilts@appsattic.com>
//
// License: http://opensource.org/licenses/MIT
//
// --------------------------------------------------------------------------------------------------------------------
// requires
// built-ins
var util = require('util');
var crypto = require('crypto');
// dependencies
var _ = require('underscore');
var dateFormat = require('dateformat');
// our own
var awssum = require('awssum');
var amazon = require('awssum-amazon');
var operations = require('./config.js');
// --------------------------------------------------------------------------------------------------------------------
// package variables
var MARK = 'route53: ';
var version = '2011-05-05';
// --------------------------------------------------------------------------------------------------------------------
// constructor
var Route53 = function(opts) {
var self = this;
// we only have one region for this service, so default it here
opts.region = amazon.US_EAST_1;
// call the superclass for initialisation
Route53.super_.call(this, opts);
return self;
};
// inherit from Amazon
util.inherits(Route53, amazon.AmazonSignatureV2);
// --------------------------------------------------------------------------------------------------------------------
// methods we need to implement from amazon.js
Route53.prototype.host = function(args) {
return 'route53.amazonaws.com';
};
Route53.prototype.version = function() {
return version;
};
// From: http://docs.amazonwebservices.com/Route53/latest/DeveloperGuide/RESTAuthentication.html#StringToSign
//
// Returns a strToSign for this request.
Route53.prototype.strToSign = function(options) {
var self = this;
return options.headers.Date;
};
// From: http://docs.amazonwebservices.com/Route53/latest/DeveloperGuide/RESTAuthentication.html#AuthorizationHeader
//
// Adds the signature to the request.
Route53.prototype.addSignature = function(options, signature) {
var self = this;
options.headers['X-Amzn-Authorization'] = 'AWS3-HTTPS AWSAccessKeyId=' + self.accessKeyId()
+ ',Algorithm=' + self.signatureMethod()
+ ',Signature=' + signature;
};
// From: http://docs.amazonwebservices.com/Route53/latest/APIReference/Headers.html
//
// Adds the common headers to this request.
Route53.prototype.addCommonOptions = function(options) {
var self = this;
// add in the date
options.headers.Date = dateFormat(new Date(), "UTC:ddd, dd mmm yyyy HH:MM:ss Z");
// make the strToSign, create the signature and sign it
var strToSign = self.strToSign(options);
var signature = self.signature(strToSign);
self.addSignature(options, signature);
};
// --------------------------------------------------------------------------------------------------------------------
// operations on the service
_.each(operations, function(operation, operationName) {
Route53.prototype[operationName] = awssum.makeOperation(operation);
});
// --------------------------------------------------------------------------------------------------------------------
// exports
exports.Route53 = Route53;
// --------------------------------------------------------------------------------------------------------------------