-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.js
102 lines (84 loc) · 2.69 KB
/
client.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
/*
* client.js: Base client from which all AWS clients inherit from
*
* (C) 2012 Charlie Robbins, Ken Perkins, Ross Kukulinski & the Contributors.
*
*/
var util = require('util'),
AWS = require('ibm-cos-sdk'),
base = require('./core/base');
var userAgent = AWS.util.userAgent();
var Client = exports.Client = function(options) {
var self = this;
base.Client.call(this, options);
options = options || {};
// Allow overriding serversUrl in child classes
this.provider = 'ibm';
this.endpoint = options.endpoint;
this.securityGroup = options.securityGroup;
this.securityGroupId = options.securityGroupId;
this.version = options.version || '2014-06-15';
this.protocol = options.protocol || 'https://';
// support either key/accessKey syntax
this.config.key = this.config.key || options.accessKey;
this.config.keyId = this.config.keyId || options.accessKeyId;
this._awsConfig = {
accessKeyId: this.config.keyId,
secretAccessKey: this.config.key,
region: options.region,
s3ForcePathStyle: options.forcePathBucket,
endpoint: this.config.endpoint,
apiKeyId: this.config.apiKeyId,
ibmAuthEndpoint: this.config.ibmAuthEndpoint,
serviceInstanceId: this.config.serviceInstanceId
};
//srova
this.ovConfig = {
ovBucket: this.config.ovBucket,
ovLocationConstraint: this.config.ovLocationConstraint,
};
// TODO think about a proxy option for pkgcloud
// enable forwarding to mock test server
if (options.serversUrl) {
this._awsConfig.httpOptions = {
proxy: this.protocol + options.serversUrl
};
}
if (options.endpoint) {
this._awsConfig.endpoint = new AWS.Endpoint(options.endpoint);
}
this.userAgent = util.format('%s %s', self.getUserAgent(), userAgent);
// Setup a custom user agent for pkgcloud
AWS.util.userAgent = function() {
return self.userAgent;
};
if (!this.before) {
this.before = [];
}
};
util.inherits(Client, base.Client);
//util.inherits(Client, require('./storage').Client);
Client.prototype._toArray = function toArray(obj) {
if (typeof obj === 'undefined') {
return [];
}
return Array.isArray(obj) ? obj : [obj];
};
Client.prototype.failCodes = {
400: 'Bad Request',
401: 'Unauthorized',
403: 'Resize not allowed',
404: 'Item not found',
409: 'Build in progress',
413: 'Over Limit',
415: 'Bad Media Type',
500: 'Fault',
503: 'Service Unavailable'
};
Client.prototype.successCodes = {
200: 'OK',
201: 'Created',
202: 'Accepted',
203: 'Non-authoritative information',
204: 'No content'
};