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

If a user provides bad credentials, throw an error. #75

Merged
merged 8 commits into from
Oct 25, 2016

Conversation

parkr
Copy link
Member

@parkr parkr commented Oct 4, 2016

This fixes #67. If you give me ACCESS_TOKEN=1234, you'll receive a loud error when you run jekyll serve that it's invalid. Providing either no token or a valid token will solve the error.

/cc @jekyll/gh-pages for review.

Copy link
Contributor

@benbalter benbalter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Why not just raise a descriptive error from https://github.com/jekyll/github-metadata/blob/master/lib/jekyll-github-metadata/client.rb#L65 if the user provides a token? Why not provide if even if they don't (to let them know they need to provide a token).

@@ -71,13 +72,25 @@ def inspect
"#<#{self.class.name} @client=#{client_inspect}>"
end

def authenticated?
!@client.access_token.nil? && !@client.access_token.empty?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this better as to_s.empty??

# Raise an error if credentials are provided and they cause a 401.
def check_credentials!
return unless authenticated?
@client.user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why make an extra call to check credentials, when we can just rescue if the call we need fails due to bad auth?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are not an owner of jekyll/github-metadata and you fetch the /repos/jekyll/github-metadata/pages endpoint, will you get a 404 or a 401? If 401 always means bad credentials and not "this resource isn't available to you" then I think we can fail more loudly on those calls, too.

@@ -8,6 +8,9 @@ class GHPMetadataGenerator < Jekyll::Generator
def generate(site)
Jekyll::GitHubMetadata.log :debug, "Initializing..."

# Fail loudly if credentials are provided but aren't valid.
Jekyll::GitHubMetadata.client.check_credentials!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this be a change in behavior? Right now, I can have an invalid credential, but if I don't use any site.github metadata, the drop isn't called, and thus it's okay, right? I don't know that we need to go out of our way to fail a user's build if they're not relying on the plugin for their site to build.

@parkr
Copy link
Member Author

parkr commented Oct 5, 2016

@benbalter Ready for another round of review!

@@ -15,6 +16,7 @@ class Client
releases
list_repos
organization_public_members
user
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this still?

@benbalter
Copy link
Contributor

@parkr my bad. One question, which I think is left over from the previous iteration.

Can this go in a point release, or does it need its own minor release?

@parkr
Copy link
Member Author

parkr commented Oct 6, 2016

@benbalter OK. Ready for another review.

@parkr
Copy link
Member Author

parkr commented Oct 25, 2016

@jekyllbot: merge +minor

@jekyllbot jekyllbot merged commit 8bda039 into master Oct 25, 2016
@jekyllbot jekyllbot deleted the fail-with-invalid-token branch October 25, 2016 17:25
jekyllbot added a commit that referenced this pull request Oct 25, 2016
@jekyll jekyll locked and limited conversation to collaborators Apr 26, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fail loudly with an invalid token
3 participants