Skip to content

Commit 880dd96

Browse files
committed
Support attaching to an existing session
This commit adds support for attaching to an existing session. To do so, use the '-a' or '--attach' flag with the session identifier printed out in the gssapi-console banner (for example, the identifier for the krb5 mech is the tmp directory path).
1 parent 9b7a9bd commit 880dd96

File tree

3 files changed

+38
-4
lines changed

3 files changed

+38
-4
lines changed

gssapi-console.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# interactive console with easy access to krb5 test harness stuff
44

5+
from __future__ import print_function
6+
57
import argparse
68
import os
79
import sys
@@ -25,6 +27,11 @@
2527
parser.add_argument('--mech', default='krb5',
2628
help='Which environment to setup up '
2729
'(supports krb5 [default])')
30+
parser.add_argument('-a', '--attach', metavar='IDENTIFIER', nargs='?',
31+
default=None, dest='attach',
32+
help='Attach to an existing gssapi-console environment, '
33+
'indicated by IDENTIFIER.')
34+
2835

2936
PARSED_ARGS = parser.parse_args()
3037

@@ -48,7 +55,7 @@
4855
try:
4956
# import the env
5057
SAVED_ENV = copy.deepcopy(os.environ)
51-
console = GSSAPIConsole(mech_cls, realm_args=realm_args)
58+
console = GSSAPIConsole(mech_cls, realm_args=realm_args, attach=PARSED_ARGS.attach)
5259
for k, v in console.realm.env.items():
5360
os.environ[k] = v
5461

@@ -58,6 +65,8 @@
5865
if not PARSED_ARGS.force_interactive:
5966
INTER = False
6067

68+
print('Session: {0}'.format(console.session))
69+
6170
with open(PARSED_ARGS.file) as src:
6271
console.runsource(src.read(), src.name, 'exec')
6372

gssapi_console/core.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,21 @@
3131
Type "help", "copyright", "credits" or "license" for more information about Python.
3232
3333
Functions for controlling the realm are available in `REALM`.
34+
Session: {session}
3435
Mechansim: {mech} ({driver}), Realm: {realm}, User: {user}, Host: {host}"""
3536

3637

3738
class GSSAPIConsole(code.InteractiveConsole):
38-
def __init__(self, driver_cls, use_readline=True, realm_args={}, *args, **kwargs):
39+
def __init__(self, driver_cls, use_readline=True, realm_args={},
40+
attach=None, *args, **kwargs):
3941
code.InteractiveConsole.__init__(self, *args, **kwargs)
4042

4143
self._driver = driver_cls()
42-
self.realm = self._driver.create_realm(realm_args)
44+
if attach is None:
45+
self.realm = self._driver.create_realm(realm_args)
46+
else:
47+
self.realm = self._driver.attach_to_realm(attach, realm_args)
48+
4349
self.locals['REALM'] = self.realm
4450

4551
self.runsource('import gssapi')
@@ -57,9 +63,14 @@ def stop(self):
5763
def _add_readline(self):
5864
self.runsource(READLINE_SRC, '<readline setup>', 'exec')
5965

66+
@property
67+
def session(self):
68+
return self._driver.identifier(self.realm)
69+
6070
@property
6171
def banner_text(self):
6272
return BANNER.format(ver=sys.version, platform=sys.platform,
73+
session=self.session,
6374
mech=self._driver.MECH_NAME,
6475
driver=self._driver.PROVIDER_NAME,
6576
realm=self.realm.realm,
@@ -70,4 +81,5 @@ def interact(self, banner=None):
7081
if banner is None:
7182
banner = self.banner_text
7283

73-
super(GSSAPIConsole, self).interact(banner)
84+
# Python 2.7 uses old-style classes :-(
85+
code.InteractiveConsole.interact(self, banner)

gssapi_console/drivers.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import sys
23

34

@@ -9,6 +10,12 @@ def create_realm(self, realm_args):
910
return None
1011

1112
def destroy_realm(self, realm):
13+
pass
14+
15+
def attach_to_realm(self, identifier, realm_args={}):
16+
pass
17+
18+
def identifier(self, realm):
1219
return None
1320

1421

@@ -25,3 +32,9 @@ def create_realm(self, realm_args):
2532

2633
def destroy_realm(self, realm):
2734
realm.stop()
35+
36+
def attach_to_realm(self, identifier, realm_args={}):
37+
return self._k5test.K5Realm(existing=identifier, **realm_args)
38+
39+
def identifier(self, realm):
40+
return realm.tmpdir

0 commit comments

Comments
 (0)