Skip to content

Commit d4ba974

Browse files
author
Naor Livne
committed
adding token auth
1 parent 58c5782 commit d4ba974

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

NebulaPythonSDK/sdk.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,22 @@ class Nebula:
1010

1111
# the nebula class init module serves as the login against the nebula API as it's the only shared thing among the
1212
# class functions
13-
def __init__(self, username=None, password=None, host="127.0.0.1", port=80, protocol="http", request_timeout=60):
13+
def __init__(self, username=None, password=None, token=None, host="127.0.0.1", port=80, protocol="http",
14+
request_timeout=60):
1415
self.request_timeout = request_timeout
1516
self.username = username
1617
self.password = password
18+
self.token = token
1719
self.protocol = protocol
1820
self.port = port
1921
self.host = protocol + "://" + host + ":" + str(port)
2022
self.headers = {
2123
'content-type': "application/json",
2224
'cache-control': "no-cache"
2325
}
24-
if username is not None and password is not None:
26+
if token is not None:
27+
self.headers["authorization"] = "Bearer " + self.token
28+
elif username is not None and password is not None:
2529
user_pass_combo = username + ":" + password
2630
if six.PY3 is True:
2731
user_pass_combo = user_pass_combo.encode('utf-8')

test/test_nebula_python_sdk.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@
88
def nebula_connection():
99
nebula_user = os.getenv("NEBULA_TEST_USERNAME", "nebula")
1010
nebula_password = os.getenv("NEBULA_TEST_PASSWORD", "nebula")
11+
nebula_token = os.getenv("NEBULA_TEST_TOKEN", None)
1112
nebula_hostname = os.getenv("NEBULA_TEST_HOST", "127.0.0.1")
1213
nebula_port = int(os.getenv("NEBULA_TEST_PORT", "80"))
1314
nebula_protocol = os.getenv("NEBULA_TEST_PROTOCOL", "http")
1415
nebula_request_timeout = int(os.getenv("NEBULA_TEST_REQUEST_TIMEOUT", "60"))
1516
connection = Nebula(username=nebula_user, password=nebula_password, host=nebula_hostname, port=nebula_port,
16-
protocol=nebula_protocol, request_timeout=nebula_request_timeout)
17+
protocol=nebula_protocol, request_timeout=nebula_request_timeout, token=nebula_token)
1718
return connection
1819

1920

test/travis_ci_scripts/docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,4 @@ services:
2626
SCHEMA_NAME: nebula
2727
BASIC_AUTH_PASSWORD: nebula
2828
BASIC_AUTH_USER: nebula
29+
AUTH_TOKEN: nebula

0 commit comments

Comments
 (0)