Skip to content

Commit e26380e

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 622f4fd commit e26380e

File tree

6 files changed

+582
-5
lines changed

6 files changed

+582
-5
lines changed

gssapi-console.py

Lines changed: 12 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

@@ -43,7 +50,9 @@
4350
'GSSAPI console' % PARSED_ARGS.mech)
4451

4552
mech_cls = mech_cls_loader.load()
46-
console = GSSAPIConsole(mech_cls, realm_args=realm_args)
53+
54+
console = GSSAPIConsole(mech_cls, realm_args=realm_args,
55+
attach=PARSED_ARGS.attach)
4756

4857
SAVED_ENV = None
4958

@@ -59,6 +68,8 @@
5968
if not PARSED_ARGS.force_interactive:
6069
INTER = False
6170

71+
print('Session: {0}'.format(console.session))
72+
6273
with open(PARSED_ARGS.file) as src:
6374
console.runsource(src.read(), src.name, 'exec')
6475

gssapi_console/core.py

Lines changed: 13 additions & 2 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')
@@ -54,9 +60,14 @@ def __init__(self, driver_cls, use_readline=True, realm_args={}, *args, **kwargs
5460
def _add_readline(self):
5561
self.runsource(READLINE_SRC, '<readline setup>', 'exec')
5662

63+
@property
64+
def session(self):
65+
return self._driver.identifier(self.realm)
66+
5767
@property
5868
def banner_text(self):
5969
return BANNER.format(ver=sys.version, platform=sys.platform,
70+
session=self.session,
6071
mech=self._driver.MECH_NAME,
6172
driver=self._driver.PROVIDER_NAME,
6273
realm=self.realm.realm,

gssapi_console/drivers.py

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

34

@@ -8,14 +9,26 @@ class GSSAPIConsoleDriver(object):
89
def create_realm(self, realm_args):
910
return None
1011

12+
def attach_to_realm(self, identifier, realm_args={}):
13+
pass
14+
15+
def identifier(self, realm):
16+
return None
17+
1118

1219
class Krb5Console(GSSAPIConsoleDriver):
1320
MECH_NAME = 'krb5'
1421
PROVIDER_NAME = 'MIT Kerberos 5'
1522

1623
def __init__(self):
17-
__import__('gssapi.tests.k5test')
18-
self._k5test = sys.modules['gssapi.tests.k5test']
24+
__import__('gssapi_console.k5test')
25+
self._k5test = sys.modules['gssapi_console.k5test']
1926

2027
def create_realm(self, realm_args):
2128
return self._k5test.K5Realm(**realm_args)
29+
30+
def attach_to_realm(self, identifier, realm_args={}):
31+
return self._k5test.K5Realm(existing=identifier, **realm_args)
32+
33+
def identifier(self, realm):
34+
return realm.tmpdir

gssapi_console/k5test/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from gssapi_console.k5test.core import K5Realm, KerberosTestCase # noqa

0 commit comments

Comments
 (0)