Skip to content

Commit be94edf

Browse files
Updated as per comments.
1 parent f4cd1af commit be94edf

File tree

14 files changed

+52
-29
lines changed

14 files changed

+52
-29
lines changed

sparkmagic/example_config.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22
"kernel_python_credentials" : {
33
"username": "",
44
"password": "",
5-
"url": "http://localhost:8998"
5+
"url": "http://localhost:8998",
6+
"auth": "None"
67
},
78

89
"kernel_scala_credentials" : {
910
"username": "",
1011
"password": "",
11-
"url": "http://localhost:8998"
12+
"url": "http://localhost:8998",
13+
"auth": "None"
1214
},
1315

1416
"logging_config": {

sparkmagic/requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ requests
99
ipykernel>=4.2.2,<5
1010
ipywidgets>5.0.0,<7.0
1111
notebook>=4.2,<5.0
12-
tornado>=4
12+
tornado>=4
13+
requests_kerberos>=0.8.0

sparkmagic/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,6 @@ def version(path):
8989
'ipywidgets>5.0.0,<7.0',
9090
'notebook>=4.2,<5.0',
9191
'tornado>=4',
92-
'requests_kerberos'
92+
'requests_kerberos>=0.8.0'
9393
])
9494

sparkmagic/sparkmagic/kernels/kernelmagics.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,14 +349,14 @@ def _do_not_call_change_language(self, line, cell="", local_ns=None):
349349
@argument("-u", "--username", type=str, help="Username to use.")
350350
@argument("-p", "--password", type=str, help="Password to use.")
351351
@argument("-s", "--server", type=str, help="Url of server to use.")
352-
@argument("-t", "--auth_type", type=str, help="Auth type for authentication")
352+
@argument("-t", "--auth", type=str, help="Auth type for authentication")
353353
@_event
354354
def _do_not_call_change_endpoint(self, line, cell="", local_ns=None):
355355
args = parse_argstring_or_throw(self._do_not_call_change_endpoint, line)
356356
username = args.username
357357
password = args.password
358358
server = args.server
359-
auth_type = args.auth_type
359+
auth_type = args.auth
360360

361361
if self.session_started:
362362
error = u"Cannot change the endpoint if a session has been started."

sparkmagic/sparkmagic/livyclientlib/endpoint.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from .exceptions import BadUserDataException
2-
import sparkmagic.utils.configuration as conf
32

43

54
class Endpoint(object):
6-
def __init__(self, url, auth_type=conf.default_livy_endpoint_auth_type(), username="", password=""):
5+
def __init__(self, url, auth_type, username="", password=""):
76
if not url:
87
raise BadUserDataException(u"URL must not be empty")
98
self.url = url.rstrip(u"/")

sparkmagic/sparkmagic/livyclientlib/reliablehttpclient.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def __init__(self, endpoint, headers, retry_policy):
2424
self._auth = HTTPKerberosAuth(mutual_authentication=REQUIRED)
2525
elif self._endpoint.auth_type == constants.AUTH_BASIC:
2626
self._auth = (self._endpoint.username, self._endpoint.password)
27+
elif self._endpoint.auth_type != constants.NO_AUTH:
28+
raise ValueError("Unsupported auth_type.")
2729

2830
self.logger = SparkLog(u"ReliableHttpClient")
2931

sparkmagic/sparkmagic/magics/remotesparkmagics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ def spark(self, line, cell="", local_ns=None):
7979
add
8080
Add a Livy session given a session name (-s), language (-l), and endpoint credentials.
8181
The -k argument, if present, will skip adding this session if it already exists.
82-
e.g. `%spark add -s test -l python -u https://sparkcluster.net/livy -a u -p -k`
82+
e.g. `%spark add -s test -l python -u https://sparkcluster.net/livy -t Kerberos -a u -p -k`
8383
config
8484
Override the livy session properties sent to Livy on session creation. All session creations will
8585
contain these config settings from then on.

sparkmagic/sparkmagic/serverextension/handlers.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
from sparkmagic.kernels.kernelmagics import KernelMagics
1010
import sparkmagic.utils.configuration as conf
11+
from sparkmagic.utils import constants
1112
from sparkmagic.utils.sparkevents import SparkEvents
1213
from sparkmagic.utils.sparklogger import SparkLog
1314

@@ -38,6 +39,12 @@ def post(self):
3839
username = self._get_argument_or_raise(data, 'username')
3940
password = self._get_argument_or_raise(data, 'password')
4041
endpoint = self._get_argument_or_raise(data, 'endpoint')
42+
auth_type = self._get_argument_if_exists(data, 'auth_type')
43+
if auth_type is None:
44+
if username == '' and password == '':
45+
auth_type = constants.NO_AUTH
46+
else:
47+
auth_type = constants.AUTH_BASIC
4148
except MissingArgumentError as e:
4249
self.set_status(400)
4350
self.finish(str(e))
@@ -52,7 +59,7 @@ def post(self):
5259

5360
# Execute code
5461
client = kernel_manager.client()
55-
code = '%{} -s {} -u {} -p {}'.format(KernelMagics._do_not_call_change_endpoint.__name__, endpoint, username, password)
62+
code = '%{} -s {} -u {} -p {} -t {}'.format(KernelMagics._do_not_call_change_endpoint.__name__, endpoint, username, password, auth_type)
5663
response_id = client.execute(code, silent=False, store_history=False)
5764
msg = client.get_shell_msg(response_id)
5865

sparkmagic/sparkmagic/tests/test_configuration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,6 @@ def test_configuration_raise_error_for_bad_base64_password():
5959

6060
@with_setup(_setup)
6161
def test_share_config_between_pyspark_and_pyspark3():
62-
kpc = { 'username': 'U', 'password': 'P', 'base64_password': 'cGFzc3dvcmQ=', 'url': 'L' }
62+
kpc = { 'username': 'U', 'password': 'P', 'base64_password': 'cGFzc3dvcmQ=', 'url': 'L', 'auth_type': AUTH_BASIC }
6363
overrides = { conf.kernel_python_credentials.__name__: kpc }
6464
assert_equals(conf.base64_kernel_python3_credentials(), conf.base64_kernel_python_credentials())

sparkmagic/sparkmagic/tests/test_handlers.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from sparkmagic.serverextension.handlers import ReconnectHandler
1010
from sparkmagic.kernels.kernelmagics import KernelMagics
1111
import sparkmagic.utils.configuration as conf
12+
from sparkmagic.utils import constants
1213

1314

1415
class SimpleObject(object):
@@ -30,6 +31,7 @@ class TestSparkMagicHandler(AsyncTestCase):
3031
username = 'username'
3132
password = 'password'
3233
endpoint = 'http://endpoint.com'
34+
auth_type = constants.AUTH_BASIC
3335
response_id = '0'
3436
good_msg = dict(content=dict(status='ok'))
3537
bad_msg = dict(content=dict(status='error', ename='SyntaxError', evalue='oh no!'))
@@ -62,7 +64,7 @@ def setUp(self):
6264

6365
# Mock request
6466
self.request = MagicMock()
65-
self.request.body = json.dumps({"path": self.path, "username": self.username, "password": self.password, "endpoint": self.endpoint})
67+
self.request.body = json.dumps({"path": self.path, "username": self.username, "password": self.password, "endpoint": self.endpoint, "auth_type": self.auth_type})
6668

6769
# Create mocked reconnect_handler
6870
ReconnectHandler.__bases__ = (SimpleObject,)
@@ -124,7 +126,7 @@ def test_post_existing_kernel(self, _get_kernel_manager):
124126
res = yield self.reconnect_handler.post()
125127
assert_equals(res, None)
126128

127-
code = '%{} -s {} -u {} -p {}'.format(KernelMagics._do_not_call_change_endpoint.__name__, self.endpoint, self.username, self.password)
129+
code = '%{} -s {} -u {} -p {} -t {}'.format(KernelMagics._do_not_call_change_endpoint.__name__, self.endpoint, self.username, self.password, self.auth_type)
128130
self.client.execute.assert_called_once_with(code, silent=False, store_history=False)
129131
self.reconnect_handler.set_status.assert_called_once_with(200)
130132
self.reconnect_handler.finish.assert_called_once_with('{"error": null, "success": true}')
@@ -141,7 +143,7 @@ def test_post_existing_kernel_failed(self, _get_kernel_manager):
141143
res = yield self.reconnect_handler.post()
142144
assert_equals(res, None)
143145

144-
code = '%{} -s {} -u {} -p {}'.format(KernelMagics._do_not_call_change_endpoint.__name__, self.endpoint, self.username, self.password)
146+
code = '%{} -s {} -u {} -p {} -t {}'.format(KernelMagics._do_not_call_change_endpoint.__name__, self.endpoint, self.username, self.password, self.auth_type)
145147
self.client.execute.assert_called_once_with(code, silent=False, store_history=False)
146148
self.reconnect_handler.set_status.assert_called_once_with(500)
147149
self.reconnect_handler.finish.assert_called_once_with('{"error": "SyntaxError:\\noh no!", "success": false}')

0 commit comments

Comments
 (0)