Skip to content

Commit 6c9a989

Browse files
Merge branch 'master' into apikey-username
2 parents 6bf7bc0 + 038c955 commit 6c9a989

File tree

6 files changed

+47
-13
lines changed

6 files changed

+47
-13
lines changed

.travis.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ sudo: false
33
node_js:
44
- 4
55
- 6
6-
- stable
6+
- 8
77
before_install:
88
- '[ "${TRAVIS_PULL_REQUEST}" = "false" ] && openssl aes-256-cbc -K $encrypted_320e4a7e27b3_key
99
-iv $encrypted_320e4a7e27b3_iv -in auth.js.enc -out test/resources/auth.js -d ||
@@ -21,5 +21,3 @@ deploy:
2121
- provider: script
2222
skip_cleanup: true
2323
script: npx travis-deploy-once "npx semantic-release"
24-
on:
25-
node: stable

authorization/v1.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,31 @@ class AuthorizationV1 extends BaseService {
4444
}
4545

4646
/**
47-
* Get a percent-encoded authorization token based on resource query string param
47+
* If using an RC service, get an IAM access token. If using a CF service,
48+
* get a percent-encoded authorization token based on resource query string param
4849
*
4950
* @param {Object} [options]
5051
* @param {String} [options.url] defaults to url supplied to constructor (if any)
51-
* @param {Function(err, token)} callback - called with a %-encoded token
52+
* @param {Function(err, token)} callback - called with a %-encoded token if CF
5253
*/
5354
getToken(params, callback) {
5455
if (typeof params === 'function') {
5556
callback = params;
5657
params = { url: this['target_url'] };
5758
}
59+
60+
// if the service is an RC instance, return an IAM access token
61+
if (this.tokenManager) {
62+
// callback should expect (err, token) format,
63+
// which is what the token manager will pass in
64+
return this.tokenManager.getToken(callback);
65+
}
66+
67+
// otherwise, return a CF Watson token
5868
if (!params.url) {
5969
callback(new Error('Missing required parameters: url'));
6070
return;
6171
}
62-
6372
const parameters = {
6473
options: {
6574
method: 'GET',

lib/recognize-stream.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ class RecognizeStream extends Duplex {
112112
* @param {Boolean} [options.smart_formatting=false] - formats numeric values such as dates, times, currency, etc.
113113
* @param {String} [options.customization_id] - Customization ID
114114
* @param {IamTokenManagerV1} [options.token_manager] - Token manager for authenticating with IAM
115+
* @param {string} [options.base_model_version] - The version of the specified base model that is to be used with recognition request or, for the **Create a session** method, with the new session.
116+
* Multiple versions of a base model can exist when a model is updated for internal improvements. The parameter is intended primarily for use with custom models that have been upgraded for a new base model.
117+
* The default value depends on whether the parameter is used with or without a custom model. For more information, see [Base model version](https://console.bluemix.net/docs/services/speech-to-text/input.html#version).
115118
*
116119
* @constructor
117120
*/

speech-to-text/v1.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ const protocols = {
1616
};
1717

1818
const PARAMS_ALLOWED = [
19-
'continuous',
2019
'max_alternatives',
2120
'timestamps',
2221
'word_confidence',
@@ -32,7 +31,8 @@ const PARAMS_ALLOWED = [
3231
'customization_id',
3332
'speaker_labels',
3433
'customization_weight',
35-
'acoustic_customization_id'
34+
'acoustic_customization_id',
35+
'base_model_version'
3636
];
3737

3838
/**
@@ -474,7 +474,7 @@ class SpeechToTextV1 extends GeneratedSpeechToTextV1 {
474474
* @param {Object} params The parameters
475475
* @param {Stream} params.audio - Audio to be recognized
476476
* @param {String} params.content_type - Content-type
477-
* @param {Boolean} [params.continuous]
477+
* @param {String} [params.base_model_version]
478478
* @param {Number} [params.max_alternatives]
479479
* @param {Boolean} [params.timestamps]
480480
* @param {Boolean} [params.word_confidence]

test/unit/test.authorization.v1.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ const assert = require('assert');
44
const watson = require('../../index');
55
const nock = require('nock');
66

7+
const sinon = require('sinon');
8+
const IamTokenManagerV1 = require('../../iam-token-manager/v1').IamTokenManagerV1;
9+
710
describe('authorization', function() {
811
// Test params
912
const service_request = {
@@ -16,6 +19,11 @@ describe('authorization', function() {
1619
version: 'v1',
1720
};
1821

22+
const rc_service = {
23+
iam_apikey: 'abc123',
24+
version: 'v1',
25+
};
26+
1927
// tokens are URL-encoded when recieved from the service
2028
const mock_token = 'token';
2129

@@ -67,5 +75,21 @@ describe('authorization', function() {
6775
it('should default to url from credentials', function(done) {
6876
authorization.getToken(checkToken(done));
6977
});
78+
79+
it('should return an iam access token if given iam_api_key', function(done) {
80+
const rc_authorization = watson.authorization(rc_service);
81+
assert.notEqual(rc_authorization.tokenManager, null);
82+
83+
// mock the token manager
84+
const tokenManager = new IamTokenManagerV1({ iamApikey: rc_service.iam_apikey });
85+
const requestStub = sinon.stub(tokenManager, 'requestToken');
86+
requestStub.yields(null, { access_token: mock_token });
87+
88+
// use the mocked token manager - we have already asserted that the
89+
// authorization object created a token manager for itself
90+
rc_authorization.tokenManager = tokenManager;
91+
92+
rc_authorization.getToken(checkToken(done));
93+
});
7094
});
7195
});

test/unit/test.iam_token_manager.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('iam_token_manager_v1', function() {
2020
});
2121

2222
it('should turn an iam apikey into an access token', function(done) {
23-
const instance = new IamTokenManagerV1({ iam_api_key: 'abcd-1234' });
23+
const instance = new IamTokenManagerV1({ iamApikey: 'abcd-1234' });
2424
const requestStub = sinon.stub(instance, 'requestToken');
2525
const refreshSpy = sinon.spy(instance, 'refreshToken');
2626

@@ -43,7 +43,7 @@ describe('iam_token_manager_v1', function() {
4343
});
4444

4545
it('should refresh an expired access token', function(done) {
46-
const instance = new IamTokenManagerV1({ iam_api_key: 'abcd-1234' });
46+
const instance = new IamTokenManagerV1({ iamApikey: 'abcd-1234' });
4747
const requestSpy = sinon.spy(instance, 'requestToken');
4848
const refreshStub = sinon.stub(instance, 'refreshToken');
4949

@@ -76,7 +76,7 @@ describe('iam_token_manager_v1', function() {
7676
});
7777

7878
it('should use a valid access token if one is stored', function(done) {
79-
const instance = new IamTokenManagerV1({ iam_api_key: 'abcd-1234' });
79+
const instance = new IamTokenManagerV1({ iamApikey: 'abcd-1234' });
8080
const requestSpy = sinon.spy(instance, 'requestToken');
8181
const refreshSpy = sinon.spy(instance, 'refreshToken');
8282

@@ -100,7 +100,7 @@ describe('iam_token_manager_v1', function() {
100100
});
101101

102102
it('should return a user-managed access token if one is set post-construction', function(done) {
103-
const instance = new IamTokenManagerV1({ iam_api_key: 'abcd-1234' });
103+
const instance = new IamTokenManagerV1({ iamApikey: 'abcd-1234' });
104104
const requestSpy = sinon.spy(instance, 'requestToken');
105105
const refreshSpy = sinon.spy(instance, 'refreshToken');
106106

0 commit comments

Comments
 (0)