Skip to content
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

ASK_CLI_PROXY is not used by the DefaultApiClient #434

Closed
cillfore opened this issue Jun 28, 2022 · 3 comments
Closed

ASK_CLI_PROXY is not used by the DefaultApiClient #434

cillfore opened this issue Jun 28, 2022 · 3 comments

Comments

@cillfore
Copy link

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request 
[ ] Other... Please describe: 

Expected Behavior

The ASK_CLI_PROXY environment variable should work for every SMAPI call made through ASK-CLI.

Current Behavior

The environment variable is completely ignored for most calls, as they go through the DefaultApiClient (ask-sdk-model-runtime\dist\index.js). A call that works with this variable is 'export-package,' which goes through clients\http-client.js.

This issue causes our corporate proxy to block the following calls:

   1. ask smapi create-upload-url
   2. ask smapi import-skill-package
   3. ask smapi submit-skill-for-certification

Steps to Reproduce (for bugs)

Run 'ask smapi create-upload-url' as an example of a call that uses the DefaultApiClient.

Possible Solution

The following change to index.js allows the calls above to be made successfully in our environment[s]. If this approach could be made more robust, and was implemented into ask-cli, it'd be very helpful.

DefaultApiClient.prototype.invoke = function (request) {
    var _this = this;
    var urlObj = url.parse(request.url);
    var urlPath = urlObj.protocol + '//' + urlObj.hostname + urlObj.path;
    const proxyUrl = process.env.ASK_CLI_PROXY;
    if (!!proxyUrl.trim()) {
        var proxyHost = proxyUrl.substring(proxyUrl.indexOf('//') + 2, proxyUrl.lastIndexOf(':'));
        var proxyPort = proxyUrl.substring(proxyUrl.lastIndexOf(':') + 1);
    }
    var headers = this.arrayToObjectHeader(request.headers);
    if (!!proxyHost && !!proxyPort) {
        headers['host'] = urlObj.hostname;
    }
    var clientRequestOptions = {
        hostname: !!proxyHost ? proxyHost : urlObj.hostname,
        port: !!proxyPort ? proxyPort : urlObj.port,
        path: (!!proxyHost && !!proxyPort) ? urlPath : urlObj.path,            
        protocol: proxyHost === 'companyProxy (proxyHost)' ? 'http:' : urlObj.protocol, //an issue with localhost
        auth: urlObj.auth,
        headers: headers,
        method: request.method,
    };        
    var client = clientRequestOptions.protocol === 'https:' ? require('https') : require('http');

Your Environment and Context

  • ask-cli version: 2.27.0
  • Operating System and version: Windows 10 & Windows Server 2016, x64
  • Node.js version used for development: 16.15.1
  • NPM version used for development: 8.5.5
@CamdenFoucht
Copy link
Contributor

Thanks for the bug report Jamie!

@doiron
Copy link
Contributor

doiron commented May 22, 2023

jamiecill Could you try installing the latest ask-cli release 2.30.0 and re-open this issue if the issue is not resolved.

thanks again for reporting.

@doiron doiron closed this as completed May 22, 2023
@cillfore
Copy link
Author

This looks to be working as expected now! I really appreciate you getting this installed @doiron 😀

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

No branches or pull requests

3 participants