taskcluster-client
Advanced tools
Comparing version 0.4.1 to 0.4.2
@@ -5,2 +5,5 @@ /* This Source Code Form is subject to the terms of the Mozilla Public | ||
// Load superagent-hawk | ||
require('superagent-hawk')(require('superagent')); | ||
var request = require('superagent-promise'); | ||
@@ -11,5 +14,18 @@ var debug = require('debug')('taskcluster-client'); | ||
/** Construct a client given a base URL and JSON API reference. */ | ||
var Client = function(baseUrl, reference) { | ||
// Default credentials | ||
var _defaultCredentials = null; | ||
/** | ||
* Construct a client given a base URL, JSON API reference and credentials. | ||
* If no credentials are provided default credentials will be used. | ||
*/ | ||
var Client = function(baseUrl, reference, credentials) { | ||
this._baseUrl = baseUrl; | ||
if (credentials) { | ||
this._credentials = { | ||
id: credentials.clientId, | ||
key: credentials.accessToken, | ||
algorithm: 'sha256' | ||
}; | ||
} | ||
var that = this; | ||
@@ -46,2 +62,6 @@ // For each API entry in the reference | ||
} | ||
// Authenticate, if credentials are provided | ||
if (that._credentials || _defaultCredentials) { | ||
req.hawk(that._credentials || _defaultCredentials); | ||
} | ||
// Send request and handle response | ||
@@ -61,6 +81,7 @@ return req.end().then(function(res) { | ||
/** | ||
* Create client given a baseUrl and version (defaults to 1) | ||
* Create client given a baseUrl, version (defaults to 1) and credentials. | ||
* Defaults to default credentials (or no credentials), if none is provided. | ||
* Return a promise for the client instance. | ||
*/ | ||
Client.load = function(baseUrl, version) { | ||
Client.load = function(baseUrl, version, credentials) { | ||
if (version === undefined) { | ||
@@ -110,3 +131,21 @@ version = 1; | ||
/** | ||
* Provide default credentials for authentication. | ||
* | ||
* Example: `Client.auth({clientId: '...', accessToken: '...'});` | ||
*/ | ||
Client.auth = function(credentials) { | ||
if (credentials) { | ||
_defaultCredentials = { | ||
id: credentials.clientId, | ||
key: credentials.accessToken, | ||
algorithm: 'sha256' | ||
}; | ||
} else { | ||
_defaultCredentials = null; | ||
} | ||
}; | ||
// Export client | ||
module.exports = Client; |
{ | ||
"name": "taskcluster-client", | ||
"version": "0.4.1", | ||
"version": "0.4.2", | ||
"author": "Jonas Finnemann Jensen <jopsen@gmail.com>", | ||
@@ -20,3 +20,4 @@ "description": "Client for interfacing taskcluster components", | ||
"superagent": "~0.16.0", | ||
"superagent-promise": "0.1.0" | ||
"superagent-promise": "0.1.0", | ||
"superagent-hawk": "0.0.3" | ||
}, | ||
@@ -23,0 +24,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41511
358
7
+ Addedsuperagent-hawk@0.0.3
+ Addedboom@0.4.2(transitive)
+ Addedcryptiles@0.2.2(transitive)
+ Addedhawk@1.0.0(transitive)
+ Addedhoek@0.9.1(transitive)
+ Addedsntp@0.2.4(transitive)
+ Addedsuperagent-hawk@0.0.3(transitive)