Skip to content

Commit d85bb68

Browse files
authored
Add oss support (#12)
* Omit Authorization header when no api key is provided * Update README to reflect updated usage * Update test setup to make it more configuration more clear * Add api endpoint configuration section to README
1 parent 2d22c27 commit d85bb68

File tree

3 files changed

+26
-8
lines changed

3 files changed

+26
-8
lines changed

README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,21 @@ pip install warrant-python
1616
```python
1717
import warrant
1818

19-
warrant = Warrant("api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E=")
20-
warrant.create_user()
19+
warrant.api_key = "api_test_f5dsKVeYnVSLHGje44zAygqgqXiLJBICbFzCiAg1E="
20+
21+
warrant.User.create()
22+
warrant.Tenant.create(id="dunder_mifflin")
23+
```
24+
25+
## Configuring the API Endpoint
26+
---
27+
The API endpoint the SDK makes requests to is configurable via the `warrant.api_endpoint` attribute:
28+
29+
```python
30+
import warrant
31+
32+
# Set api endpoint to http://localhost:8000
33+
warrant.api_endpoint = 'http://localhost:8000'
2134
```
2235

2336
We’ve used a random API key in these code examples. Replace it with your
@@ -31,4 +44,4 @@ Note that we may release new [minor and patch](https://semver.org/) versions of
3144

3245
## Warrant Documentation
3346

34-
- [Warrant Docs](https://docs.warrant.dev/)
47+
- [Warrant Docs](https://docs.warrant.dev/)

examples/example.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"""
1010

1111
# Replace with your own API key to run example
12-
warrant.api_key = "YOUR_KEY"
12+
warrant.api_key = ""
13+
warrant.api_endpoint = "https://api.warrant.dev"
1314

1415
"""
1516
Users & Tenants

warrant/api_resource.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ class APIResource(object):
1616
@classmethod
1717
def _get(cls, uri, params={}, object_hook=None):
1818
headers = {
19-
"Authorization": "ApiKey " + warrant.api_key,
2019
"User-Agent": warrant.user_agent
2120
}
21+
if warrant.api_key != "":
22+
headers["Authorization"] = "ApiKey " + warrant.api_key
2223
resp = requests.get(url=warrant.api_endpoint+uri, headers=headers, params=params)
2324
if resp.status_code == 200:
2425
return resp.json(object_hook=object_hook)
@@ -28,9 +29,10 @@ def _get(cls, uri, params={}, object_hook=None):
2829
@classmethod
2930
def _post(cls, uri, json={}, object_hook=None):
3031
headers = {
31-
"Authorization": "ApiKey " + warrant.api_key,
3232
"User-Agent": warrant.user_agent
3333
}
34+
if warrant.api_key != "":
35+
headers["Authorization"] = "ApiKey " + warrant.api_key
3436
resp = requests.post(url=warrant.api_endpoint+uri, headers=headers, json=json)
3537
if resp.status_code == 200:
3638
return resp.json(object_hook=object_hook)
@@ -40,9 +42,10 @@ def _post(cls, uri, json={}, object_hook=None):
4042
@classmethod
4143
def _put(cls, uri, json={}, object_hook=None):
4244
headers = {
43-
"Authorization": "ApiKey " + warrant.api_key,
4445
"User-Agent": warrant.user_agent
4546
}
47+
if warrant.api_key != "":
48+
headers["Authorization"] = "ApiKey " + warrant.api_key
4649
resp = requests.put(url=warrant.api_endpoint+uri, headers=headers, json=json)
4750
if resp.status_code == 200:
4851
resp.json(object_hook=object_hook)
@@ -52,9 +55,10 @@ def _put(cls, uri, json={}, object_hook=None):
5255
@classmethod
5356
def _delete(cls, uri, params={}, json={}):
5457
headers = {
55-
"Authorization": "ApiKey " + warrant.api_key,
5658
"User-Agent": warrant.user_agent
5759
}
60+
if warrant.api_key != "":
61+
headers["Authorization"] = "ApiKey " + warrant.api_key
5862
resp = requests.delete(url=warrant.api_endpoint+uri, headers=headers, params=params, json=json)
5963
if resp.status_code != 200:
6064
raise WarrantException(msg=resp.text, status_code=resp.status_code)

0 commit comments

Comments
 (0)