Skip to content

[natural-language-understanding] undefined auth parameters throws error contrary to the docs #605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
villasv opened this issue Jan 9, 2018 · 6 comments
Assignees
Labels

Comments

@villasv
Copy link

villasv commented Jan 9, 2018

Code:

const WatsonDeveloperCloudNLUV1 = require('watson-developer-cloud/natural-language-understanding/v1.js');

const NaturalLanguageUnderstanding = new WatsonDeveloperCloudNLUV1({
  version_date: WatsonDeveloperCloudNLUV1.VERSION_DATE_2017_02_27,
});

Expected behavior:

As specified in the docs and in the examples, it should pick up auth credentials from the environment.

Actual behavior:

...\node_modules\watson-developer-cloud\lib\base_service.js:92
                throw new Error("Argument error: username and password are required for " + this.name

Error: Argument error: username and password are required for NATURAL-LANGUAGE-UNDERSTANDING V1 unless use_unauthenticated is set

Setup:

  • npm: 5.6.0
  • watson-developer-cloud: 3.0.3
@villasv
Copy link
Author

villasv commented Jan 9, 2018

Investigating the section of the code responsible from fetching the credentials from the environment:

  /**
   * Pulls credentials from env properties
   *
   * Property checked is uppercase service.name suffixed by _USERNAME and _PASSWORD
   *
   * For example, if service.name is speech_to_text, 
   * env properties are SPEECH_TO_TEXT_USERNAME and SPEECH_TO_TEXT_PASSWORD
   *
   * @private
   * @param {string} name - the service snake case name
   * @returns {Credentials}
   */
  private getCredentialsFromEnvironment(name: string): Credentials {
    const _name: string = name.toUpperCase();
    const _username: string = process.env[`${_name}_USERNAME`];
    const _password: string = process.env[`${_name}_PASSWORD`];
    const _api_key: string = process.env[`${_name}_API_KEY`];
    const _url: string = process.env[`${_name}_URL`];

But as the error message hinted before, the ${_name} of the service is being resolved to NATURAL-LANGUAGE-UNDERSTANDING and not NATURAL_LANGUAGE_UNDERSTANDING. That is, docs suggests that underscores are used are separators but at least for the NLU service hyphens are instead.

I renamed the environment variables to NATURAL-LANGUAGE-UNDERSTANDING_USERNAME and
NATURAL-LANGUAGE-UNDERSTANDING_PASSWORD and it worked as expected.

@anweshan anweshan self-assigned this Jan 9, 2018
@anweshan anweshan added the bug label Jan 9, 2018
@villasv
Copy link
Author

villasv commented Jan 11, 2018

I'm not sure if this is the place to discuss a higher level change, but it would be very good if the environment variables were prefixed with IBM or WATSON or whatever vendor specific token you prefer.

This convention is respected by all major providers and makes configuring production environments much easier.

@yulianovdey
Copy link

+1 to use underscores, as the docs suggest, and not dashes.

@anweshan
Copy link
Contributor

Thanks for pointing out this bug, I'll put out a patch soon to change the variable to be underscores

@germanattanasio
Copy link
Contributor

@anweshan what's the status of this?. We probably want to fix this in the generator.

@germanattanasio
Copy link
Contributor

I talked to @anweshan, we are going to fix it manually and update the sdk generation wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

4 participants