Created
December 8, 2017 23:19
-
-
Save vudngo/68e2fece28e786d80b4deda93cedf14b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Token (SENTRY_AUTH_TOKEN) must have appropriate priveleges (i.e. project:write, etc.) | |
# You will get 401 Unauthorized (RestClient::Unauthorized) if auth token does not appropriate permissions. | |
# Usage: SENTRY_AUTH_TOKEN=<YOUR_SENTRY_AUTH_TOKEN> SENTRY_ORG_SLUG=<YOUR_SENTRY_ORG_SLUG> | |
# SENTRY API DOCS https://docs.sentry.io/api/ | |
import requests | |
import json | |
import os | |
base_url="https://sentry.io" | |
org_slug = "<YOUR_ORG_SLUG>" # | |
team_slug = "<YOUR_TEAM_SLUG" # | |
project_name = "SAMPLE PROJECT NAME" | |
project_slug = "<YOUR_PROJECT_SLUG>" | |
rate_limit_count = "666" | |
rate_limit_window = "900" | |
auth_token = os.environ["SENTRY_AUTH_TOKEN"] | |
headers = { | |
'Content-Type': "application/json", | |
'Authorization': "Bearer " + auth_token | |
} | |
######Create Project####### API DOC: https://docs.sentry.io/api/teams/post-team-project-index/ | |
create_project_url = base_url + "/api/0/teams/" + org_slug + "/" + team_slug + "/projects/" | |
payload = "{\"name\": \"" + project_name + "\", \"slug\": \"" + project_slug + "\"}" | |
response = requests.post(create_project_url, headers=headers, data=payload) | |
print(response.status_code, response.reason) | |
######Get Client Key####### API DOC: https://docs.sentry.io/api/projects/get-project-keys/ | |
get_client_key_url = base_url + "/api/0/projects/" + org_slug + "/" + project_slug + "/keys/" | |
response = requests.get(get_client_key_url, headers=headers) | |
print(response.status_code, response.reason) | |
######Update Client Key With Rate Limit####### API DOC: https://docs.sentry.io/api/projects/put-project-key-details/ | |
response_body = json.loads(response.content) | |
update_client_key_url = base_url + "/api/0/projects/" + org_slug + "/" + project_slug + "/keys/" + response_body[0]['public'] + "/" | |
payload = "{\"rateLimit\": {\"count\": " + rate_limit_count + ", \"window\":" + rate_limit_window + "}}" | |
response = requests.request("PUT", update_client_key_url, data=payload, headers=headers) | |
print(response.status_code, response.reason) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment