Skip to content

Commit

Permalink
feat: allow rate limit bypass with token (#12)
Browse files Browse the repository at this point in the history
* add error handling for api rate limit

* feat: allow rate limit bypass with token
  • Loading branch information
CaptainCarpensir authored Jul 20, 2022
1 parent ab58d58 commit b65fc7d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ Now when editing a Copilot manifest, the __Copilot Manifest Schema__ will assist

---

### __If you encounter this exception:__
```
Exception: API rate limit exceeded for 54.240.196.168. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
```

This means that you've reached the [GitHub API rate limit](https://docs.github.com/en/rest/rate-limit). To get around this, all you need to do is to generate a [GitHub Personal Access Token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token), and pass your GitHub username and token as arguments like this:

> ```python3 main.py [username] [ghp-access-token]```
Doing so will allow you to make the API request under your personal account, increasing the [GitHub API Rate Limit](https://docs.github.com/en/rest/rate-limit).

---

## __Note__

A known limitation of the __Copilot Manifest Schema__ tool is that we generate the schema from the Copilot docs. As the docs are built and sustained to be a human readable source of information, they are not always consistent, and as such the schema that this tool generates may be inconsistent. Regardless, we've provided a useful tool for Copilot users, which allows you to maintain manifests without constantly moving between the Copilot docs and your IDE.
A known limitation of the __Copilot Manifest Schema__ tool is that we generate the schema from the Copilot docs. As the docs are built and sustained to be a human readable source of information, they are not always consistent, and as such the schema that this tool generates may not always be helpful. Regardless, we've provided a useful tool for Copilot users, which allows you to maintain manifests without constantly moving between the Copilot docs and your IDE.
18 changes: 15 additions & 3 deletions doc_retriever.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import requests
import os

def retrieve_docs():
def retrieve_docs(username="", token=""):
base_gh_url = "https://api.github.com/repos/aws/copilot-cli/contents/site/content/docs"
main_resp = requests.get(os.path.join(base_gh_url, "manifest"))
if username != "" and token != "":
main_resp = requests.get(os.path.join(base_gh_url, "manifest"), auth=(username,token))
else:
main_resp = requests.get(os.path.join(base_gh_url, "manifest"))

if "message" in main_resp.json():
raise Exception(main_resp.json()["message"])

main_docs = {}
for resp in main_resp.json():
if not resp["name"].endswith(".en.md"):
continue
r = requests.get(resp["download_url"])
main_docs[resp["name"].rstrip(".md")] = r.text
partial_resp = requests.get(os.path.join(base_gh_url, "include"))
if username != "" and token != "":
partial_resp = requests.get(os.path.join(base_gh_url, "include"), auth=(username,token))
else:
partial_resp = requests.get(os.path.join(base_gh_url, "include"))
if "message" in partial_resp.json():
raise Exception(partial_resp.json()["message"])
partial_docs = {}
for resp in partial_resp.json():
if not resp["name"].endswith(".en.md"):
Expand Down
10 changes: 8 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import json
from doc_parser import doc_parser
from doc_retriever import retrieve_docs
from generator import generate_schema
import sys

def main():
docs = retrieve_docs()
args = sys.argv[1:]
username = ""
token = ""
if len(args) == 2:
username = args[0]
token = args[1]
docs = retrieve_docs(username, token)
parser = doc_parser()
for k, v in sorted(docs["main"].items()):
parser.appendToMain(k, v)
Expand Down

0 comments on commit b65fc7d

Please sign in to comment.