Skip to content
Snippets Groups Projects
Unverified Commit 8b150c72 authored by Joe Beda's avatar Joe Beda
Browse files

Implement github token to work around rate limits


Signed-off-by: default avatarJoe Beda <joe.github@bedafamily.com>
parent 664ac1a5
No related branches found
No related tags found
No related merge requests found
......@@ -7,3 +7,4 @@ If you prefer to view content in Github, you can check out the links below:
* [Manually build and install](/docs/build-install.md)
* [CLI reference](/docs/cli-reference#command-line-reference)
* [Concept reference](/docs/concepts.md)
* [Troubleshooting](/docs/troubleshooting.md)
\ No newline at end of file
# Troubleshooting
## Github rate limiting errors
If you get an error saying something to the effect of `403 API rate limit of 60 still exceeded` you can work around that by getting a Github personal access token and setting it up so that `ks` can use it. Github has higher rate limits for authenticated users than unauthenticated users.
1. Go to https://github.com/settings/tokens and generate a new token. You don't have to give it any access at all as you are simply authenticating.
2. Make sure you save that token someplace because you can't see it again. If you lose it you'll have to delete and create a new one.
3. Set an environment variable in your shell: `export GITHUB_TOKEN=<token>`. You may want to do this as part of your shell startup scripts (i.e. `.profile`).
\ No newline at end of file
......@@ -3,7 +3,9 @@ package metadata
import (
"context"
"fmt"
"net/http"
"net/url"
"os"
"path"
"strings"
......@@ -12,6 +14,7 @@ import (
"github.com/ksonnet/ksonnet/metadata/app"
"github.com/ksonnet/ksonnet/metadata/parts"
"github.com/ksonnet/ksonnet/metadata/registry"
"golang.org/x/oauth2"
)
const (
......@@ -36,6 +39,21 @@ type gitHubRegistryManager struct {
registrySpecRepoPath string
}
func makeGithubClient() *github.Client {
var hc *http.Client
ght := os.Getenv("GITHUB_TOKEN")
if len(ght) > 0 {
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: ght},
)
hc = oauth2.NewClient(ctx, ts)
}
return github.NewClient(hc)
}
func makeGitHubRegistryManager(registryRef *app.RegistryRefSpec) (*gitHubRegistryManager, error) {
gh := gitHubRegistryManager{RegistryRefSpec: registryRef}
......@@ -52,7 +70,7 @@ func makeGitHubRegistryManager(registryRef *app.RegistryRefSpec) (*gitHubRegistr
}
// Resolve the refspec to a commit SHA.
client := github.NewClient(nil)
client := makeGithubClient()
ctx := context.Background()
sha, _, err := client.Repositories.GetCommitSHA1(ctx, gh.org, gh.repo, refspec, "")
......@@ -80,7 +98,7 @@ func (gh *gitHubRegistryManager) RegistrySpecFilePath() string {
func (gh *gitHubRegistryManager) FetchRegistrySpec() (*registry.Spec, error) {
// Fetch app spec at specific commit.
client := github.NewClient(nil)
client := makeGithubClient()
ctx := context.Background()
// Get contents.
......@@ -117,7 +135,7 @@ func (gh *gitHubRegistryManager) MakeRegistryRefSpec() *app.RegistryRefSpec {
}
func (gh *gitHubRegistryManager) ResolveLibrarySpec(libID, libRefSpec string) (*parts.Spec, error) {
client := github.NewClient(nil)
client := makeGithubClient()
// Resolve `version` (a git refspec) to a specific SHA.
ctx := context.Background()
......@@ -156,7 +174,7 @@ func (gh *gitHubRegistryManager) ResolveLibrary(libID, libAlias, libRefSpec stri
defaultRefSpec = "master"
)
client := github.NewClient(nil)
client := makeGithubClient()
// Resolve `version` (a git refspec) to a specific SHA.
ctx := context.Background()
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment