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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best Practise Proxy Support 馃榾馃憦馃徏 #54

Closed
NickLiffen opened this issue Mar 11, 2020 · 2 comments
Closed

Best Practise Proxy Support 馃榾馃憦馃徏 #54

NickLiffen opened this issue Mar 11, 2020 · 2 comments
Projects

Comments

@NickLiffen
Copy link
Contributor

Hey 馃憢馃徎,

I have a question, we are looking to use this module alongside the @octokit/graphql.js.

We work behind a corporate proxy, so we need to be able to pass a proxy to any egress request from within our network.

I see that both this and the @octokit/graphql.js modules use the @octokit/request.js) module to make its requests to the GitHub API.

By taking a look at your code, you seem to be using node-fetch for actually making the HTTP Requests behind the scenes.

Taking a look at node-fetch it does support passing in an agent. When taking a look at your request library, there doesn't seem to be any options, which I would have expected to see here? (maybe?)

We would love to be able to pass in a httpsAgent somewhere?

const { createAppAuth } = require("@octokit/auth-app");
const httpAgent = new http.Agent({ keepAlive: true });
const httpsAgent = new https.Agent({ keepAlive: true });

const auth = createAppAuth({
  id: 1,
  privateKey: "-----BEGIN PRIVATE KEY-----\n...",
  installationId: 123,
  clientId: "1234567890abcdef1234",
  clientSecret: "1234567890abcdef12341234567890abcdef1234"
});

const installationAuthentication = await auth({ 
  type: "installation" ,
  agent: url => url.protocol === 'https:' ? httpsAgent : httpAgent
});

const graphqlWithAuth = graphql.defaults({
  request: {
    hook: auth.hook
    agent: url => url.protocol === 'https:' ? httpsAgent : httpAgent
  }
});

Something like that? It would be great if we could do this in a single place when looking through the octokit modules, it would be great to have a single experience across the @octokit ecosystem 馃?

Just wanted to put it here and get some of your thoughts on best practice 馃憤

Thanks for all your help.

@gr2m
Copy link
Contributor

gr2m commented Mar 11, 2020

What I would suggest you do is to use https://github.com/octokit/core.js where you can pass { request: { agent } } to setup a proxy. The full code would look like this

const { Octokit } = require('@octokit/core')
const { createAppAuth } = require("@octokit/auth-app");
const httpsAgent = new https.Agent({ keepAlive: true });

const MyEnterpriseOctokit = Octokit.defaults({
  authStrategy: createAppAuth,
  baseUrl: YOUR_ENTERPRISE_BASE_URL,
  request: { agent: httpsAgent }
})

const octokit = new Octokit({
  auth: {
    id: 1,
    privateKey: "-----BEGIN PRIVATE KEY-----\n...",
    installationId: 123,
    clientId: "1234567890abcdef1234",
    clientSecret: "1234567890abcdef12341234567890abcdef1234"
  }
})

octokit.graphql(query, variables)

If you don't want to use @octokit/core, you can create a custom @octokit/request instance and pass that to both, @octokit/graphql (see docs and @octokit/auth-app (via request option)

Does either work for you?

@gr2m gr2m added the support label Mar 11, 2020
@gr2m gr2m added this to Support in JS May 5, 2020
@gr2m
Copy link
Contributor

gr2m commented Oct 21, 2020

let me know if you have further questions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
JS
  
Done
Development

No branches or pull requests

2 participants