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

Header needed for Checks API for Enterprise Server #478

Closed
mcaulifn opened this issue Jan 19, 2021 · 13 comments
Closed

Header needed for Checks API for Enterprise Server #478

mcaulifn opened this issue Jan 19, 2021 · 13 comments

Comments

@mcaulifn
Copy link
Contributor

2021-01-19T16:58:27.528Z	784f32d9-df03-522b-86b6-6a58cee71a88	ERROR	RequestError [HttpError]: If you would like to help us test the Checks API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details. 

Likely caused by #386

@mcaulifn
Copy link
Contributor Author

Suggest we revert #386 for now.

@mcaulifn
Copy link
Contributor Author

@npalm
Copy link
Member

npalm commented Jan 20, 2021

Solved by #481

@npalm npalm closed this as completed Jan 20, 2021
@samuelb
Copy link
Contributor

samuelb commented Jan 21, 2021

I'm still getting this error. Tried to built the lambdas by my own yesterday after #481 got merged as well as the just released 0.9.0 lambda zips.

2021-01-21T18:33:14.240Z	66df9451-e423-5303-ab9e-ccd22f36bbf2	ERROR	RequestError [HttpError]: If you would like to help us test the Checks API during its preview period, you must specify a custom media type in the 'Accept' header. Please see the docs for full details.
    at /var/task/index.js:2756:23
    at processTicksAndRejections (internal/process/task_queues.js:97:5) {
  status: 415,
  headers: {
    'access-control-allow-origin': '*',
    'access-control-expose-headers': 'ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset',
    'alt-svc': 'clear',
    connection: 'close',
    'content-length': '288',
    'content-security-policy': "default-src 'none'",
    'content-type': 'application/json; charset=utf-8',
    date: 'Thu, 21 Jan 2021 18:33:14 GMT',
    'referrer-policy': 'origin-when-cross-origin, strict-origin-when-cross-origin',
    server: 'GitHub.com',
    status: '415 Unsupported Media Type',
    'strict-transport-security': 'max-age=31536000; includeSubdomains',
    via: '1.1 google',
    'x-content-type-options': 'nosniff',
    'x-frame-options': 'deny',
    'x-github-enterprise-version': '2.22.6',
    'x-github-media-type': 'github.v3; format=json',
    'x-github-request-id': '197c6068-c1d5-43d2-9ed4-bb0d409b2500',
    'x-ratelimit-limit': '12500',
    'x-ratelimit-remaining': '12036',
    'x-ratelimit-reset': '1611255703',
    'x-runtime-rack': '0.038530',
    'x-xss-protection': '1; mode=block'
  },
  request: {
    method: 'GET',
    url: 'https://github.example.com/api/v3/repos/acme/somerepo/check-runs/68859',
    headers: {
      accept: 'application/vnd.github.v3+json',
      'user-agent': 'octokit-rest.js/18.0.12 octokit-core.js/3.2.4 Node.js/12.20.1 (linux; x64)',
      authorization: 'token [REDACTED]'
    },
    request: { hook: [Function: bound bound register] }
  },
  documentation_url: 'https://docs.github.com/enterprise/2.22/rest/reference/checks#get-a-check-run'
}

@buamod
Copy link

buamod commented Jan 21, 2021

server: 'GitHub.com',

you are still using an older commit for your Lambdas ..

@samuelb
Copy link
Contributor

samuelb commented Jan 22, 2021

No. I'm very sure I'm running the lambdas v0.9.0 as downloadable here from Github. The header server: 'GitHub.com' is returned from our companies GitHub Enterprise.

What could be the reason why the header Accept: application/vnd.github.v3+json is still being send instead of application/vnd.github.antiope-preview+json? The ghesApiUrl is set at https://github.com/philips-labs/terraform-aws-github-runner/blob/v0.9.0/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts#L51-L56.

@mcaulifn
Copy link
Contributor Author

@buamod I get the same server header. Seems that is normal?

@samuelb I missed modifying the test for the fix that made it in to v0.9.0, so I modified L120 of gh-auth.test.ts locally:

request: mockedRequestInterface.defaults({ baseUrl: githubServerUrl, mediaType: { previews: ['antiope'] } }),

The test passed.

I also found that you can enable debug in octokit. log: console, was inserted to L11 of gh-auth.ts, recompiled, uploaded, and yielded this:

2021-01-22T13:33:31.960Z	a3e98909-2b21-52b0-9e5c-d18dfd7d23cf	DEBUG	request {
  method: 'GET',
  baseUrl: 'https://githubtest.internal/api/v3',
  headers: {
    accept: 'application/vnd.github.v3+json',
    'user-agent': 'octokit-rest.js/18.0.9 octokit-core.js/3.2.4 Node.js/12.19.0 (linux; x64)'
  },
  mediaType: { format: '', previews: [ 'antiope' ] },
  request: { hook: [Function: bound bound register] },
  url: '/repos/{owner}/{repo}/check-runs/{check_run_id}',
  check_run_id: 845,
  owner: 'ActionsTest',
  repo: 'repo-test'
}

The header is still passed but a new mediaType is now set.

@samuelb
Copy link
Contributor

samuelb commented Jan 22, 2021

When adding log: console,, I'm getting this:

021-01-22T15:15:21.285Z	68d40d07-e072-55a8-b924-55830e47ae02	DEBUG	request {
  method: 'GET',
  baseUrl: 'https://github.example.com/api/v3',
  headers: {
    accept: 'application/vnd.github.v3+json',
    'user-agent': 'octokit-rest.js/18.0.12 octokit-core.js/3.2.4 Node.js/12.20.1 (linux; x64)'
  },
  mediaType: { format: '', previews: [] },
  request: { hook: [Function: bound bound register] },
  url: '/repos/{owner}/{repo}/check-runs/{check_run_id}',
  check_run_id: 69556,
  owner: 'acme',
  repo: 'somerepo'
}

This mediaType is not set.
I double and tripple checked that checkout the right branch. I even checked it out fresh, removed the lambda docker image etc.

@samuelb
Copy link
Contributor

samuelb commented Jan 22, 2021

I just see from the user agent, the octokit-rest.js version differs from yours. You suggested earlier that reverting #386 would be one option to solve it. Could it be that #481 actually don't solved that problem but you accidentally considered it to be fixed as you build it using octokit-rest.js/18.0.9?

@mcaulifn
Copy link
Contributor Author

Looks like my last compile may have been using a cached library. I re-compiled and got the same result as you.

This modification worked for me:
(gh-auth.ts L8)

export async function createOctoClient(token: string, ghesApiUrl: string = ''): Promise<Octokit> {
  const ocktokitOptions: OctokitOptions = {
    auth: token,
    log: console,
  };
  if (ghesApiUrl) {
    ocktokitOptions.baseUrl = ghesApiUrl;
    ocktokitOptions.previews = ['antiope'];
  }
  return new Octokit(ocktokitOptions);
}

@npalm npalm reopened this Jan 22, 2021
@samuelb
Copy link
Contributor

samuelb commented Jan 22, 2021

I can confirm that this is working for me 👍

iff --git a/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts b/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts
index 01dc3cf..ae3720e 100644
--- a/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts
+++ b/modules/runners/lambdas/runners/src/scale-runners/gh-auth.ts
@@ -11,6 +11,7 @@ export async function createOctoClient(token: string, ghesApiUrl: string = ''):
   };
   if (ghesApiUrl) {
     ocktokitOptions.baseUrl = ghesApiUrl;
+    ocktokitOptions.previews = ['antiope'];
   }
   return new Octokit(ocktokitOptions);
 }
@@ -51,7 +52,6 @@ export async function createGithubAuth(
   if (ghesApiUrl) {
     authOptions.request = request.defaults({
       baseUrl: ghesApiUrl,
-      mediaType: { previews: ['antiope'] }
     });
   }
   return await createAppAuth(authOptions)({ type: authType });

From CloudWatch:

2021-01-22T16:34:00.464Z	750ac5d2-fd1a-52ff-a26a-9d57fdbb2281	DEBUG	request {
  method: 'GET',
  baseUrl: 'https://github.example.com/api/v3',
  headers: {
    accept: 'application/vnd.github.v3+json',
    'user-agent': 'octokit-rest.js/18.0.12 octokit-core.js/3.2.4 Node.js/12.20.1 (linux; x64)'
  },
  mediaType: { format: '', previews: [ 'antiope' ] },
  request: { hook: [Function: bound bound register] },
  url: '/repos/{owner}/{repo}/check-runs/{check_run_id}',
  check_run_id: 69599,
  owner: 'acme',
  repo: 'somerepo'
}

2021-01-22T16:34:00.841Z	750ac5d2-fd1a-52ff-a26a-9d57fdbb2281	INFO	GET /repos/acme/somerepo/check-runs/69599 - 200 in 377ms

@mcaulifn
Copy link
Contributor Author

Opened #482

@npalm
Copy link
Member

npalm commented Jan 22, 2021

Created release 0.9.1

@npalm npalm closed this as completed Jan 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants