Skip to content

Commit a529dd5

Browse files
Merge pull request #229 from watson-developer-cloud/chore/dep-up
fix: Update dependencies
2 parents 8c20cda + 16371b3 commit a529dd5

File tree

11 files changed

+1364
-1573
lines changed

11 files changed

+1364
-1573
lines changed

.env.example

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
11
# Environment variables
2-
# You need to provide either username and password
3-
SPEECH_TO_TEXT_USERNAME=
4-
SPEECH_TO_TEXT_PASSWORD=
5-
# OR IAM API key and URL
62
SPEECH_TO_TEXT_IAM_APIKEY=
7-
SPEECH_TO_TEXT_IAM_URL=
8-
# Service URL
9-
SPEECH_TO_TEXT_URL=https://stream.watsonplatform.net/speech-to-text/api
3+
SPEECH_TO_TEXT_URL=https://stream.watsonplatform.net/speech-to-text/api

.travis.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
language: node_js
2-
dist: trusty
32
sudo: required
4-
node_js: '8'
3+
node_js: 12
54
script:
65
- npm run test
76

@@ -25,5 +24,3 @@ deploy:
2524
- provider: script
2625
skip_cleanup: true
2726
script: npx semantic-release
28-
on:
29-
node: 8

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
FROM centos:centos6
3-
RUN curl -sL https://rpm.nodesource.com/setup_8.x | bash -
3+
RUN curl -sL https://rpm.nodesource.com/setup_12.x | bash -
44
RUN yum install -y nodejs #
55
# Define working directory.
66
COPY . /src

README.md

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ You can view a [demo][demo_url] of this app.
2323
- Log in to your IBM Cloud account.
2424
- Click **Create**.
2525
- Click **Show** to view the service credentials.
26-
- Copy the `apikey` value, or copy the `username` and `password` values if your service instance doesn't provide an `apikey`.
26+
- Copy the `apikey` value.
2727
- Copy the `url` value.
2828

2929
## Configuring the application
@@ -43,16 +43,6 @@ You can view a [demo][demo_url] of this app.
4343
SPEECH_TO_TEXT_URL=https://gateway-wdc.watsonplatform.net/speech-to-text/api
4444
```
4545
46-
- If your service instance uses `username` and `password` credentials, add the `SPEECH_TO_TEXT_USERNAME` and `SPEECH_TO_TEXT_PASSWORD` variables to the *.env* file.
47-
48-
Example *.env* file that configures the `username`, `password`, and `url` for a Speech to Text service instance hosted in the Sydney region:
49-
50-
```
51-
SPEECH_TO_TEXT_USERNAME=522be-7b41-ab44-dec3-g1eab2ha73c6
52-
SPEECH_TO_TEXT_PASSWORD=A4Z5BdGENrwu8
53-
SPEECH_TO_TEXT_URL=https://gateway-syd.watsonplatform.net/speech-to-text/api
54-
```
55-
5646
## Running locally
5747
5848
1. Install the dependencies
@@ -105,7 +95,7 @@ You can view a [demo][demo_url] of this app.
10595
Find more open source projects on the [IBM Github Page](http://ibm.github.io/)
10696
10797
108-
[service_url]: https://www.ibm.com/watson/services/speech-to-text/
98+
[service_url]: https://www.ibm.com/cloud/watson-speech-to-text
10999
[docs]: https://cloud.ibm.com/apidocs/speech-to-text
110100
[sign_up]: https://cloud.ibm.com/registration/?target=/catalog/services/speech-to-text/
111101
[demo_url]: https://speech-to-text-demo.ng.bluemix.net

app.js

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,57 +17,31 @@
1717
const express = require('express');
1818

1919
const app = express();
20-
const SpeechToTextV1 = require('ibm-watson/speech-to-text/v1');
21-
const AuthorizationV1 = require('ibm-watson/authorization/v1');
22-
const IamTokenManagerV1 = require('ibm-watson/iam-token-manager/v1');
20+
const { IamTokenManager } = require('ibm-watson/auth');
2321

2422
// Bootstrap application settings
2523
require('./config/express')(app);
2624

27-
// Create the token manager
28-
let tokenManager;
29-
let instanceType;
30-
const serviceUrl = process.env.SPEECH_TO_TEXT_URL || 'https://stream.watsonplatform.net/speech-to-text/api';
25+
const serviceUrl = process.env.SPEECH_TO_TEXT_URL;
26+
27+
const tokenManager = new IamTokenManager({
28+
apikey: process.env.SPEECH_TO_TEXT_IAM_APIKEY || '<iam_apikey>',
29+
});
3130

32-
if (process.env.SPEECH_TO_TEXT_IAM_APIKEY && process.env.SPEECH_TO_TEXT_IAM_APIKEY !== '') {
33-
instanceType = 'iam';
34-
tokenManager = new IamTokenManagerV1({
35-
iamApikey: process.env.SPEECH_TO_TEXT_IAM_APIKEY || '<iam_apikey>',
36-
iamUrl: process.env.SPEECH_TO_TEXT_IAM_URL || 'https://iam.bluemix.net/identity/token',
37-
});
38-
} else {
39-
instanceType = 'cf';
40-
const speechService = new SpeechToTextV1({
41-
username: process.env.SPEECH_TO_TEXT_USERNAME || '<username>',
42-
password: process.env.SPEECH_TO_TEXT_PASSWORD || '<password>',
43-
url: serviceUrl,
44-
});
45-
tokenManager = new AuthorizationV1(speechService.getServiceCredentials());
46-
}
4731

4832
app.get('/', (req, res) => res.render('index'));
4933

5034
// Get credentials using your credentials
51-
app.get('/api/v1/credentials', (req, res, next) => {
52-
tokenManager.getToken((err, token) => {
53-
if (err) {
54-
next(err);
55-
} else {
56-
let credentials;
57-
if (instanceType === 'iam') {
58-
credentials = {
59-
accessToken: token,
60-
serviceUrl,
61-
};
62-
} else {
63-
credentials = {
64-
token: token.token,
65-
serviceUrl,
66-
};
67-
}
68-
res.json(credentials);
69-
}
70-
});
35+
app.get('/api/v1/credentials', async (req, res, next) => {
36+
try {
37+
const accessToken = await tokenManager.getToken();
38+
res.json({
39+
accessToken,
40+
serviceUrl,
41+
});
42+
} catch (err) {
43+
next(err);
44+
}
7145
});
7246

7347
module.exports = app;

casper-runner.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
require('dotenv').config({ silent: true });
1717

18-
if (!process.env.SPEECH_TO_TEXT_IAM_APIKEY && !process.env.SPEECH_TO_TEXT_USERNAME) {
18+
if (!process.env.SPEECH_TO_TEXT_IAM_APIKEY) {
1919
console.log(
20-
'Skipping integration tests because SPEECH_TO_TEXT_IAM_APIKEY and SPEECH_TO_TEXT_USERNAME are null',
20+
'Skipping integration tests because SPEECH_TO_TEXT_IAM_APIKEY is null',
2121
);
2222
process.exit(0);
2323
}

manifest.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
---
2-
declared-services:
3-
my-stt-service:
4-
label: speech_to_text
5-
plan: standard
62
applications:
73
- name: speech-to-text-demo
84
path: .
95
command: npm start
106
memory: 512M
11-
services:
12-
- my-stt-service

0 commit comments

Comments
 (0)