This repository has been archived by the owner on Jun 5, 2018. It is now read-only.
/
awssum-amazon-glacier.js
131 lines (101 loc) · 4.31 KB
/
awssum-amazon-glacier.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
// --------------------------------------------------------------------------------------------------------------------
//
// glacier.js - class for AWS Glacier
//
// Copyright (c) 2011, 2012 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');
// dependencies
var _ = require('underscore');
// our own
var awssum = require('awssum');
var amazon = require('awssum-amazon');
var operations = require('./config.js');
var awsSignatureV4 = require('awssum-amazon/lib/aws-signature-v4');
// --------------------------------------------------------------------------------------------------------------------
// package variables
var MARK = 'glacier: ';
// From: http://docs.amazonwebservices.com/general/latest/gr/rande.html
var endPoint = {};
endPoint[amazon.US_EAST_1] = "glacier.us-east-1.amazonaws.com";
endPoint[amazon.US_WEST_1] = "glacier.us-west-1.amazonaws.com";
endPoint[amazon.US_WEST_2] = "glacier.us-west-2.amazonaws.com";
endPoint[amazon.EU_WEST_1] = "glacier.eu-west-1.amazonaws.com";
// endPoint[amazon.AP_SOUTHEAST_1] = "";
endPoint[amazon.AP_NORTHEAST_1] = "glacier.ap-northeast-1.amazonaws.com";
// endPoint[amazon.SA_EAST_1] = "";
// endPoint[amazon.US_GOV_WEST_1] = "";
var version = '2012-06-01';
// --------------------------------------------------------------------------------------------------------------------
// constructor
var Glacier = function(opts) {
var self = this;
// call the superclass for initialisation
Glacier.super_.call(this, opts);
// check the region is valid
if ( ! endPoint[opts.region] ) {
throw MARK + "invalid region '" + opts.region + "'";
}
return self;
};
// inherit from Amazon
util.inherits(Glacier, amazon.AmazonSignatureV2);
// --------------------------------------------------------------------------------------------------------------------
// methods we need to implement from awssum.js/amazon.js
Glacier.prototype.scope = function() {
return 'glacier';
};
Glacier.prototype.serviceName = function() {
return 'Glacier';
};
Glacier.prototype.needsTarget = function() {
return false;
};
Glacier.prototype.host = function() {
return endPoint[this.region()];
};
Glacier.prototype.version = function() {
return version;
};
Glacier.prototype.extractBody = function() {
return 'json';
};
// this service uses the AWS Signature v4
Glacier.prototype.strToSign = awsSignatureV4.strToSign;
Glacier.prototype.signature = awsSignatureV4.signature;
Glacier.prototype.addSignature = awsSignatureV4.addSignature;
// Glacier.prototype.addCommonOptions = awsSignatureV4.addCommonOptions;
Glacier.prototype.contentType = awsSignatureV4.contentType;
Glacier.prototype.addCommonOptions = function(options, args) {
var self = this;
// yes, Signature v4, but we also need this
options.headers['x-amz-glacier-version'] = self.version();
// now call the signature addCommonOptions
awsSignatureV4.addCommonOptions.apply(self, [ options, args ]);
};
// --------------------------------------------------------------------------------------------------------------------
// operations on the service
_.each(operations, function(operation, operationName) {
Glacier.prototype[operationName] = awssum.makeOperation(operation);
});
// --------------------------------------------------------------------------------------------------------------------
// exports
// endpoints
exports.US_EAST_1 = amazon.US_EAST_1;
exports.US_WEST_1 = amazon.US_WEST_1;
exports.US_WEST_2 = amazon.US_WEST_2;
exports.EU_WEST_1 = amazon.EU_WEST_1;
// exports.AP_SOUTHEAST_1 = amazon.AP_SOUTHEAST_1;
// exports.AP_SOUTHEAST_2 = amazon.AP_SOUTHEAST_2;
exports.AP_NORTHEAST_1 = amazon.AP_NORTHEAST_1;
// exports.SA_EAST_1 = amazon.SA_EAST_1;
// exports.US_GOV_WEST = amazon.US_GOV_WEST;
exports.Glacier = Glacier;
// --------------------------------------------------------------------------------------------------------------------