Skip to content

Commit 66c4bbe

Browse files
committed
feat: allow reading of token from env
1 parent b121cca commit 66c4bbe

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

lighthouse/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
class Config:
55
"""Config class for lighthouse"""
66

7-
lighthouse_api = "https://api.lighthouse.storage"
7+
lighthouse_api = "http://13.234.35.183:5050" # "https://api.lighthouse.storage"
88
lighthouse_node = "https://node.lighthouse.storage"
99
lighthouse_bls_node = "https://encryption.lighthouse.storage"

main.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
#!/usr/bin/env python3
22

3+
import os
34
import lighthouse.deploy as d
45
from lighthouse import types as t
56

67

78
class Lighthouse:
8-
def __init__(self, token: str):
9-
self.token = token
9+
def __init__(self, token: str = ""):
10+
self.token = token or os.environ.get("LIGHTHOUSE_TOKEN", "")
11+
if not self.token:
12+
raise Exception(
13+
"No token provided: Please provide a token or set the LIGHTHOUSE_TOKEN environment variable"
14+
)
1015

1116
def deploy(self, source: str) -> t.Deploy:
1217
"""

tests/test_deploy.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ def setUp(self) -> None:
1313

1414
def test_deploy_file(self):
1515
"""test deploy function"""
16-
l = Lighthouse(os.environ.get("LH_TOKEN", ""))
16+
l = Lighthouse() # will use env var
1717
res = l.deploy("tests/testdir/testfile.txt")
1818
self.assertNotEqual(res.get("data"), None, "data is None")
1919
self.assertNotEqual(res.get("data").get("Hash"), None, "data is None")
2020

2121
def test_deploy_dir(self):
2222
"""test deploy function"""
23-
l = Lighthouse(os.environ["LH_TOKEN"])
23+
l = Lighthouse(os.environ["LIGHTHOUSE_TOKEN"])
2424
res = l.deploy("tests/testdir/")
2525
self.assertNotEqual(res.get("data"), None, "data is None")
2626
self.assertIsInstance(res.get("data"), dict, "data is a dict")

0 commit comments

Comments
 (0)