Closed lsgrep closed 6 years ago
I have the same problem with github.repos.getArchiveLink
var GitHubApi = require("github");
var github = new GitHubApi({
// optional
debug: true,
protocol: "https",
// host: 'api.github.com', // "github.my-GHE-enabled-company.com", // should be api.github.com for GitHub
pathPrefix: "/api/v3", // for some GHEs; none for GitHub
headers: {
"user-agent": "My-Cool-GitHub-App" // GitHub is happy with a unique user agent
},
Promise: require('bluebird'),
followRedirects: false, // default: true; there's currently an issue with non-get redirects, so allow ability to disable follow-redirects
timeout: 5000
});
var x = github.repos.getArchiveLink({
owner: 'mikedeboer',
repo: 'node-github',
archive_format: 'tarball',
ref: 'master'
}, (x) => {
console.log(x);
});
// console.log(x);
@lsgrep did you find the error?
Can you share the output you're seeing when the debug
option is true
?
@zeke this is the output in debug mode
REQUEST: { host: 'api.github.com',
port: 443,
path: '/api/v3/repos/mikedeboer/node-github/tarball/master',
method: 'get',
headers:
{ host: 'api.github.com',
'content-length': '0',
'user-agent': 'My-Cool-GitHub-App',
accept: 'application/vnd.github.v3+json' },
ca: undefined }
STATUS: 404
HEADERS: {"server":"GitHub.com","date":"Mon, 31 Jul 2017 08:43:14 GMT","content-type":"application/json; charset=utf-8","content-length":"77","connection":"close","status":"404 Not Found","x-ratelimit-limit":"60","x-ratelimit-remaining":"55","x-ratelimit-reset":"1501491387","x-github-media-type":"github.v3; format=json","access-control-expose-headers":"ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval","access-control-allow-origin":"*","content-security-policy":"default-src 'none'","strict-transport-security":"max-age=31536000; includeSubdomains; preload","x-content-type-options":"nosniff","x-frame-options":"deny","x-xss-protection":"1; mode=block","x-runtime-rack":"0.005969","x-github-request-id":"F990:0CFB:1280B5A:25F5CA5:597EEDA2"}
[error] { [Error: {"message":"Not Found","documentation_url":"https://developer.github.com/v3"}]
[error] message: '{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}',
[error] code: 404,
[error] status: 'Not Found',
[error] headers:
[error] { server: 'GitHub.com',
[error] date: 'Mon, 31 Jul 2017 08:43:14 GMT',
[error] 'content-type': 'application/json; charset=utf-8',
[error] 'content-length': '77',
[error] connection: 'close',
[error] status: '404 Not Found',
[error] 'x-ratelimit-limit': '60',
[error] 'x-ratelimit-remaining': '55',
[error] 'x-ratelimit-reset': '1501491387',
[error] 'x-github-media-type': 'github.v3; format=json',
[error] 'access-control-expose-headers': 'ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
[error] 'access-control-allow-origin': '*',
[error] 'content-security-policy': 'default-src \'none\'',
[error] 'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
[error] 'x-content-type-options': 'nosniff',
[error] 'x-frame-options': 'deny',
[error] 'x-xss-protection': '1; mode=block',
[error] 'x-runtime-rack': '0.005969',
[error] 'x-github-request-id': 'F990:0CFB:1280B5A:25F5CA5:597EEDA2' } } { owner: 'mikedeboer',
[error] repo: 'node-github',
[error] archive_format: 'tarball',
[error] ref: 'master' } null
{ [Error: {"message":"Not Found","documentation_url":"https://developer.github.com/v3"}]
message: '{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}',
code: 404,
status: 'Not Found',
headers:
{ server: 'GitHub.com',
date: 'Mon, 31 Jul 2017 08:43:14 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '77',
connection: 'close',
status: '404 Not Found',
'x-ratelimit-limit': '60',
'x-ratelimit-remaining': '55',
'x-ratelimit-reset': '1501491387',
'x-github-media-type': 'github.v3; format=json',
'access-control-expose-headers': 'ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
'access-control-allow-origin': '*',
'content-security-policy': 'default-src \'none\'',
'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
'x-content-type-options': 'nosniff',
'x-frame-options': 'deny',
'x-xss-protection': '1; mode=block',
'x-runtime-rack': '0.005969',
'x-github-request-id': 'F990:0CFB:1280B5A:25F5CA5:597EEDA2' } }
@florent1933 and @lsgrep I had a similar issue. Realized that my 2nd call to github api wasn't getting authenticated. Once I passed in the right authentication keys and values in the headers, all went well.
Not sure how your app is setup but reading through my issue and solution might help.
Yeah it shows 404 but it's most likely an authentication issue. I'd go through the examples folder and try running some of the really simple ones that require authentication.
@florent1933 note that the 404 in your case is because you set pathPrefix
which you shouldn’t unless you use GitHub Enterprise. It tries to get https://api.github.com/api/v3...
and that doesn’t exist. I’ll get back to the original issue once I work more on tests
I'm experiencing the same problem as @florent1933 with getArchiveLink
.
I'm requesting this (public) tarball:
https://api.github.com/repos/badges/shields/tarball/20c29db7a645609defffdb576f51d3156d70d04
Which 302 redirects to:
https://codeload.github.com/badges/shields/legacy.tar.gz/20c29db7a645609defffdb576f51d3156d70d04a
There are two issues:
getArchiveLink
, I expect a URL string. Plus a string is what I want, so I can stream it to disk or to tar.extract
. Buffering the whole tarball in memory is not what I want.Possible solutions:
getArchiveLink
definition as resulting in a 302. Only when that flag is set, attempt to differentiate the end result from the API-to-API redirects.I don't see much advantage in 2, since it still requires solving the problem from 1.
Thoughts? Does it make sense that this method should return a URL string?
@gr2m Any thoughts on how you'd like to approach this? Would it be helpful if I opened an issue specific to getArchiveLink
?
Sorry I missed your comment from two days ago. No need to open another issue, I’ll have a look tomorrow
I try to stay as close as possible to the REST API, with all its arguable design flaws and leave better higher-level abstractions to higher level libraries like https://github.com/gr2m/octokit-release-asset-upload
But I agree that in this case the implementation is not ideal. Using the API with sth like curl at least returns a stream https://developer.github.com/v3/repos/contents/#get-archive-link. Plus the current implementation wouldn’t even allow to a higher level library that would use that internally.
So yeah, I think your 1st suggestion is the way to go: resolving with the link. Not yet sure if it should just resolve as string or as a JSON object like {"link": "https://codeload.github.com/badges/shields/legacy.tar.gz/20c29db7a645609defffdb576f51d3156d70d04a"}
.
I’ll also check in with my fellow octokit maintainers on this one
here is some context why we don’t change hostnames right now: https://github.com/octokit/node-github/issues/658. I think we are safe to allow for that though as long as it’s just a read request
Plus the current implementation wouldn’t even allow to a higher level library that would use that internally.
Yea, this is the crux of it. It keeps me from using the library at all.
The redirect code only updates the path, although the hostname is changing too.
this should no longer be the case with @octokit/rest
, the full URL is updated now:
https://github.com/octokit/rest.js/blob/9003db1701979493dd2130a01a93c1d928b3d023/lib/request/request.js#L65
When I fix the redirect, the code downloads the redirect code downloads the entire tarball and returns it in a string
I’m still thinking about that, also considering how things should behave in the browser as it is the next milestone. But probably resolving with the link is the right thing to do.
i dont know if its the same problem or not, but this is the code that works
passport.use(
new GithHubStrategy(
{
clientID: keys.githubClientId,
clientSecret: keys.githubClientSecret,
callbackURL: routes.AUTH_GITHUB_CALLBACK,
proxy: true
},
async (accessToken, refreshToken, { _json: profile }, done) => {
octokit.authenticate({
type: "oauth",
token: accessToken
});
octokit.users.get(
{},
(err, res) => {
console.log(res?res:err);
}
);
let user = await User.findOne({githubId: profile.id});
if (!user) {
user = await new User({githubId: profile.id}).save();
}
done(null, user);
}
)
);
i use passport to login with clientId
and clientSecret
, and it successfully returns accessToken
.
But, when i change fetching user method from callback to async/await
try {
const user1 = await octokit.users.get({});
} catch (err) {
console.log(err);
process.exit();
}
console.log(user1);
i get 404
{ [Error: {"message":"Not Found","documentation_url":"https://developer.github.com/v3"}]
[0] message: '{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}',
[0] code: 404,
[0] status: 'Not Found',
[0] headers:
[0] { server: 'GitHub.com',
[0] date: 'Tue, 06 Feb 2018 13:24:36 GMT',
[0] 'content-type': 'application/json; charset=utf-8',
[0] 'content-length': '77',
[0] connection: 'close',
[0] status: '404 Not Found',
[0] 'x-github-media-type': 'github.v3; format=json',
[0] 'x-ratelimit-limit': '60',
[0] 'x-ratelimit-remaining': '44',
[0] 'x-ratelimit-reset': '1517923970',
[0] 'access-control-expose-headers': 'ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval',
[0] 'access-control-allow-origin': '*',
[0] 'content-security-policy': 'default-src \'none\'',
[0] 'strict-transport-security': 'max-age=31536000; includeSubdomains; preload',
[0] 'x-content-type-options': 'nosniff',
[0] 'x-frame-options': 'deny',
[0] 'x-xss-protection': '1; mode=block',
[0] 'x-runtime-rack': '0.013886',
[0] 'x-github-request-id': 'DA5C:11ED:34C2E4:A0D6D1:5A79AC94' } }
also, authorization check i cant get to work in any form i try, always 404
octokit.authorization.check(
{access_token: accessToken},
(err, res) => {
console.log(res?res:err);
}
);
// or
try {
const result = await octokit.authorization.check({
access_token: accessToken
});
} catch (err) {
console.log(err);
process.exit();
}
console.log(result);
I cant see that im doing anything wrong here
@paulmelnikow
Any thoughts on how you'd like to approach this? Would it be helpful if I opened an issue specific to getArchiveLink?
I think that would be great. I’ll close this issue as the the original question has been addressed.
The redirect code only updates the path, although the hostname is changing too.
I think that should be fixed now
When I fix the redirect, the code downloads the redirect code downloads the entire tarball and returns it in a string. Since the method is called getArchiveLink, I expect a URL string. Plus a string is what I want, so I can stream it to disk or to tar.extract. Buffering the whole tarball in memory is not what I want.
I agree, I’m not yet sure how to make that work (including in browsers). As a workaround, could you try passing method: 'HEAD'
this?
const {meta: {location: archiveLink}} = github.repos.getArchiveLink({
owner: 'mikedeboer',
repo: 'node-github',
archive_format: 'tarball',
ref: 'master'
})
console.log(archiveLink)
yup, in github logic, 404 can mean anything, not found, unauthorized, etc, etc if only there were different status codes for each.
It's a security issue. If you gave another status when you try to access a private repository that you don't have access to, the API would expose the fact that the private repository indeed exists. And that by itself can be a problem in some cases
github authentication code,
my-token
is an user access token with all necessary privileges.the code above is working perfectly.
these 2 above are giving me this errors