Skip to content

Commit d2341e0

Browse files
committed
Normalize away from 'desired_' argument names
All argument names of the form `desired_foo` have been converted to simply `foo`, with the exception of `desired_output_size` for clarity.
1 parent 6281fe1 commit d2341e0

File tree

4 files changed

+59
-63
lines changed

4 files changed

+59
-63
lines changed

gssapi/creds.py

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,8 @@ class Credentials(rcreds.Creds):
2525

2626
__slots__ = ()
2727

28-
def __new__(cls, base=None, token=None,
29-
desired_name=None, lifetime=None,
30-
desired_mechs=None, usage='both',
31-
store=None):
28+
def __new__(cls, base=None, token=None, name=None, lifetime=None,
29+
mechs=None, usage='both', store=None):
3230
"""Acquire or import a set of credentials.
3331
3432
The constructor either acquires or imports a set of GSSAPI
@@ -58,7 +56,7 @@ def __new__(cls, base=None, token=None,
5856

5957
base_creds = rcred_imp_exp.import_cred(token)
6058
else:
61-
res = cls.acquire(desired_name, lifetime, desired_mechs, usage,
59+
res = cls.acquire(name, lifetime, mechs, usage,
6260
store=store)
6361
base_creds = res.creds
6462

@@ -89,8 +87,8 @@ def usage(self):
8987
usage=True, mechs=False).usage
9088

9189
@classmethod
92-
def acquire(cls, desired_name=None, lifetime=None,
93-
desired_mechs=None, usage='both', store=None):
90+
def acquire(cls, name=None, lifetime=None, mechs=None, usage='both',
91+
store=None):
9492
"""Acquire GSSAPI credentials
9593
9694
This method acquires credentials. If the `store` argument is
@@ -106,11 +104,11 @@ def acquire(cls, desired_name=None, lifetime=None,
106104
extension.
107105
108106
Args:
109-
desired_name (Name): the name associated with the credentials,
107+
name (Name): the name associated with the credentials,
110108
or None for the default name
111109
lifetime (int): the desired lifetime of the credentials, or None
112110
for indefinite
113-
desired_mechs (list): the desired mechanisms to be used with these
111+
mechs (list): the desired mechanisms to be used with these
114112
credentials, or None for the default set
115113
usage (str): the usage for these credentials -- either 'both',
116114
'initiate', or 'accept'
@@ -124,8 +122,8 @@ def acquire(cls, desired_name=None, lifetime=None,
124122
"""
125123

126124
if store is None:
127-
res = rcreds.acquire_cred(desired_name, lifetime,
128-
desired_mechs, usage)
125+
res = rcreds.acquire_cred(name, lifetime,
126+
mechs, usage)
129127
else:
130128
if rcred_cred_store is None:
131129
raise NotImplementedError("Your GSSAPI implementation does "
@@ -134,8 +132,8 @@ def acquire(cls, desired_name=None, lifetime=None,
134132

135133
store = _encode_dict(store)
136134

137-
res = rcred_cred_store.acquire_cred_from(store, desired_name,
138-
lifetime, desired_mechs,
135+
res = rcred_cred_store.acquire_cred_from(store, name,
136+
lifetime, mechs,
139137
usage)
140138

141139
return tuples.AcquireCredResult(cls(base=res.creds), res.mechs,
@@ -183,19 +181,19 @@ def store(self, store=None, usage='both', mech=None,
183181
return rcred_cred_store.store_cred_into(store, self, usage, mech,
184182
overwrite, set_default)
185183

186-
def impersonate(self, desired_name=None, lifetime=None,
187-
desired_mechs=None, usage='initiate'):
184+
def impersonate(self, name=None, lifetime=None, mechs=None,
185+
usage='initiate'):
188186
"""Impersonate a name using the current credentials
189187
190188
This method acquires credentials by impersonating another
191189
name using the current credentials. This requires the
192190
Services4User extension.
193191
194192
Args:
195-
desired_name (Name): the name to impersonate
193+
name (Name): the name to impersonate
196194
lifetime (int): the desired lifetime of the new credentials,
197195
or None for indefinite
198-
desired_mechs (list): the desired mechanisms for the new
196+
mechs (list): the desired mechanisms for the new
199197
credentials
200198
usage (str): the desired usage for the new credentials -- either
201199
'both', 'initiate', or 'accept'. Note that some mechanisms
@@ -209,8 +207,8 @@ def impersonate(self, desired_name=None, lifetime=None,
209207
raise NotImplementedError("Your GSSAPI implementation does not "
210208
"have support for S4U")
211209

212-
res = rcred_s4u.acquire_cred_impersonate_name(self, desired_name,
213-
lifetime, desired_mechs,
210+
res = rcred_s4u.acquire_cred_impersonate_name(self, name,
211+
lifetime, mechs,
214212
usage)
215213

216214
return type(self)(base=res.creds)
@@ -275,7 +273,7 @@ def inquire_by_mech(self, mech, name=True, init_lifetime=True,
275273
res.accept_lifetime,
276274
res.usage)
277275

278-
def add(self, desired_name, desired_mech, usage='both',
276+
def add(self, name, mech, usage='both',
279277
init_lifetime=None, accept_lifetime=None, impersonator=None,
280278
store=None):
281279
"""Acquire more credentials to add to the current set
@@ -302,9 +300,9 @@ def add(self, desired_name, desired_mech, usage='both',
302300
`impersonator` argument.
303301
304302
Args:
305-
desired_name (Name): the name associated with the
303+
name (Name): the name associated with the
306304
credentials
307-
desired_mech (OID): the desired mechanism to be used with these
305+
mech (OID): the desired mechanism to be used with these
308306
credentials
309307
usage (str): the usage for these credentials -- either 'both',
310308
'initiate', or 'accept'
@@ -334,22 +332,20 @@ def add(self, desired_name, desired_mech, usage='both',
334332
"credential stores")
335333
store = _encode_dict(store)
336334

337-
res = rcred_cred_store.add_cred_from(store, self, desired_name,
338-
desired_mech, usage,
339-
init_lifetime,
335+
res = rcred_cred_store.add_cred_from(store, self, name, mech,
336+
usage, init_lifetime,
340337
accept_lifetime)
341338
elif impersonator is not None:
342339
if rcred_s4u is None:
343340
raise NotImplementedError("Your GSSAPI implementation does "
344341
"not have support for S4U")
345342
res = rcred_s4u.add_cred_impersonate_name(self, impersonator,
346-
desired_name,
347-
desired_mech,
348-
usage, init_lifetime,
343+
name, mech, usage,
344+
init_lifetime,
349345
accept_lifetime)
350346
else:
351-
res = rcreds.add_cred(self, desired_name, desired_mech, usage,
352-
init_lifetime, accept_lifetime)
347+
res = rcreds.add_cred(self, name, mech, usage, init_lifetime,
348+
accept_lifetime)
353349

354350
return Credentials(res.creds)
355351

gssapi/sec_contexts.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class SecurityContext(rsec_contexts.SecurityContext):
2626
"""
2727

2828
def __new__(cls, base=None, token=None,
29-
name=None, creds=None, desired_lifetime=None, flags=None,
29+
name=None, creds=None, lifetime=None, flags=None,
3030
mech_type=None, channel_bindings=None, usage=None):
3131

3232
if token is not None:
@@ -35,7 +35,7 @@ def __new__(cls, base=None, token=None,
3535
return super(SecurityContext, cls).__new__(cls, base)
3636

3737
def __init__(self, base=None, token=None,
38-
name=None, creds=None, desired_lifetime=None, flags=None,
38+
name=None, creds=None, lifetime=None, flags=None,
3939
mech_type=None, channel_bindings=None, usage=None):
4040
"""
4141
The constructor creates a new security context, but does not begin
@@ -56,7 +56,7 @@ def __init__(self, base=None, token=None,
5656
5757
For a security context of the `initiate` usage, the `name` argument
5858
must be used, and the `creds`, `mech_type`, `flags`,
59-
`desired_lifetime`, and `channel_bindings` arguments may be
59+
`lifetime`, and `channel_bindings` arguments may be
6060
used as well.
6161
6262
For a security context of the `accept` usage, the `creds` and
@@ -94,11 +94,11 @@ def __init__(self, base=None, token=None,
9494
self._target_name = name
9595
self._mech_type = mech_type
9696
self._desired_flags = IntEnumFlagSet(RequirementFlag, flags)
97-
self._desired_lifetime = desired_lifetime
97+
self._desired_lifetime = lifetime
9898
else:
9999
# takes creds?
100100
if (name is not None or flags is not None or
101-
mech_type is not None or desired_lifetime is not None):
101+
mech_type is not None or lifetime is not None):
102102
raise TypeError("You must pass at most the 'creds' "
103103
"argument when creating an accepting "
104104
"security context")

gssapi/tests/test_high_level.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -121,19 +121,19 @@ def setUp(self):
121121
self.name = gssnames.Name(SERVICE_PRINCIPAL,
122122
gb.NameType.kerberos_principal)
123123

124-
@exist_perms(lifetime=30, desired_mechs=[gb.MechType.kerberos],
124+
@exist_perms(lifetime=30, mechs=[gb.MechType.kerberos],
125125
usage='both')
126126
def test_acquire_by_init(self, str_name, kwargs):
127-
creds = gsscreds.Credentials(desired_name=self.name, **kwargs)
127+
creds = gsscreds.Credentials(name=self.name, **kwargs)
128128

129129
creds.lifetime.should_be_an_integer()
130130

131131
del creds
132132

133-
@exist_perms(lifetime=30, desired_mechs=[gb.MechType.kerberos],
133+
@exist_perms(lifetime=30, mechs=[gb.MechType.kerberos],
134134
usage='both')
135135
def test_acquire_by_method(self, str_name, kwargs):
136-
cred_resp = gsscreds.Credentials.acquire(desired_name=self.name,
136+
cred_resp = gsscreds.Credentials.acquire(name=self.name,
137137
**kwargs)
138138

139139
cred_resp.shouldnt_be_none()
@@ -177,7 +177,7 @@ def test_store_acquire(self):
177177
store_res.usage.should_be('initiate')
178178
store_res.mech_types.should_include(gb.MechType.kerberos)
179179

180-
reacquired_creds = gsscreds.Credentials(desired_name=deleg_creds.name,
180+
reacquired_creds = gsscreds.Credentials(name=deleg_creds.name,
181181
usage='initiate')
182182
reacquired_creds.shouldnt_be_none()
183183

@@ -192,7 +192,7 @@ def test_store_into_acquire_from(self):
192192
self.realm.extract_keytab(princ_name, KT)
193193
self.realm.kinit(princ_name, None, ['-k', '-t', KT])
194194

195-
initial_creds = gsscreds.Credentials(desired_name=None,
195+
initial_creds = gsscreds.Credentials(name=None,
196196
usage='initiate')
197197

198198
store_res = initial_creds.store(store, overwrite=True)
@@ -202,19 +202,19 @@ def test_store_into_acquire_from(self):
202202
store_res.usage.should_be('initiate')
203203

204204
name = gssnames.Name(princ_name)
205-
retrieved_creds = gsscreds.Credentials(desired_name=name, store=store)
205+
retrieved_creds = gsscreds.Credentials(name=name, store=store)
206206

207207
retrieved_creds.shouldnt_be_none()
208208

209209
def test_create_from_other(self):
210-
raw_creds = gb.acquire_cred(None, cred_usage='accept').creds
210+
raw_creds = gb.acquire_cred(None, usage='accept').creds
211211

212212
high_level_creds = gsscreds.Credentials(raw_creds)
213213
high_level_creds.usage.should_be('accept')
214214

215215
@true_false_perms('name', 'lifetime', 'usage', 'mechs')
216216
def test_inquire(self, str_name, kwargs):
217-
creds = gsscreds.Credentials(desired_name=self.name)
217+
creds = gsscreds.Credentials(name=self.name)
218218
resp = creds.inquire(**kwargs)
219219

220220
if kwargs['name']:
@@ -240,7 +240,7 @@ def test_inquire(self, str_name, kwargs):
240240

241241
@true_false_perms('name', 'init_lifetime', 'accept_lifetime', 'usage')
242242
def test_inquire_by_mech(self, str_name, kwargs):
243-
creds = gsscreds.Credentials(desired_name=self.name)
243+
creds = gsscreds.Credentials(name=self.name)
244244
resp = creds.inquire_by_mech(mech=gb.MechType.kerberos, **kwargs)
245245

246246
if kwargs['name']:
@@ -283,7 +283,7 @@ def test_store_into_add_from(self):
283283
self.realm.extract_keytab(princ_name, KT)
284284
self.realm.kinit(princ_name, None, ['-k', '-t', KT])
285285

286-
initial_creds = gsscreds.Credentials(desired_name=None,
286+
initial_creds = gsscreds.Credentials(name=None,
287287
usage='initiate')
288288

289289
store_res = initial_creds.store(store, overwrite=True)
@@ -302,13 +302,13 @@ def test_store_into_add_from(self):
302302

303303
@_extension_test('cred_imp_ext', 'credentials import-export')
304304
def test_export(self):
305-
creds = gsscreds.Credentials(desired_name=self.name)
305+
creds = gsscreds.Credentials(name=self.name)
306306
token = creds.export()
307307
token.should_be(bytes)
308308

309309
@_extension_test('cred_imp_ext', 'credentials import-export')
310310
def test_import_by_init(self):
311-
creds = gsscreds.Credentials(desired_name=self.name)
311+
creds = gsscreds.Credentials(name=self.name)
312312
token = creds.export()
313313
imported_creds = gsscreds.Credentials(token=token)
314314

@@ -317,14 +317,14 @@ def test_import_by_init(self):
317317

318318
@_extension_test('cred_imp_ext', 'credentials import-export')
319319
def test_pickle_unpickle(self):
320-
creds = gsscreds.Credentials(desired_name=self.name)
320+
creds = gsscreds.Credentials(name=self.name)
321321
pickled_creds = pickle.dumps(creds)
322322
unpickled_creds = pickle.loads(pickled_creds)
323323

324324
unpickled_creds.lifetime.should_be(creds.lifetime)
325325
unpickled_creds.name.should_be(creds.name)
326326

327-
@exist_perms(lifetime=30, desired_mechs=[gb.MechType.kerberos],
327+
@exist_perms(lifetime=30, mechs=[gb.MechType.kerberos],
328328
usage='initiate')
329329
@_extension_test('s4u', 'S4U')
330330
def test_impersonate(self, str_name, kwargs):
@@ -336,7 +336,7 @@ def test_impersonate(self, str_name, kwargs):
336336
del client_ctx_resp # free everything but the token
337337

338338
server_name = self.name
339-
server_creds = gsscreds.Credentials(desired_name=server_name,
339+
server_creds = gsscreds.Credentials(name=server_name,
340340
usage='both')
341341
server_ctx_resp = gb.accept_sec_context(client_token,
342342
acceptor_cred=server_creds)
@@ -461,14 +461,14 @@ def setUp(self):
461461
super(SecurityContextTestCase, self).setUp()
462462
gssctx.SecurityContext.__DEFER_STEP_ERRORS__ = False
463463
self.client_name = gssnames.Name(self.USER_PRINC)
464-
self.client_creds = gsscreds.Credentials(desired_name=None,
464+
self.client_creds = gsscreds.Credentials(name=None,
465465
usage='initiate')
466466

467467
self.target_name = gssnames.Name(TARGET_SERVICE_NAME,
468468
gb.NameType.hostbased_service)
469469

470470
self.server_name = gssnames.Name(SERVICE_PRINCIPAL)
471-
self.server_creds = gsscreds.Credentials(desired_name=self.server_name,
471+
self.server_creds = gsscreds.Credentials(name=self.server_name,
472472
usage='accept')
473473

474474
def _create_client_ctx(self, **kwargs):
@@ -483,7 +483,7 @@ def test_create_from_other(self):
483483
high_level_ctx = gssctx.SecurityContext(raw_client_ctx)
484484
high_level_ctx.target_name.should_be(self.target_name)
485485

486-
@exist_perms(desired_lifetime=30, flags=[],
486+
@exist_perms(lifetime=30, flags=[],
487487
mech_type=gb.MechType.kerberos,
488488
channel_bindings=None)
489489
def test_create_new_init(self, str_name, kwargs):
@@ -506,7 +506,7 @@ def create_sec_context():
506506
create_sec_context.should_raise(TypeError)
507507

508508
def _create_completed_contexts(self):
509-
client_ctx = self._create_client_ctx(desired_lifetime=400)
509+
client_ctx = self._create_client_ctx(lifetime=400)
510510

511511
client_token = client_ctx.step()
512512
client_token.should_be_a(bytes)
@@ -542,7 +542,7 @@ def test_channel_bindings(self):
542542
initiator_address=b'127.0.0.1',
543543
acceptor_address_type=gb.AddressType.ip,
544544
acceptor_address=b'127.0.0.1')
545-
client_ctx = self._create_client_ctx(desired_lifetime=400,
545+
client_ctx = self._create_client_ctx(lifetime=400,
546546
channel_bindings=bdgs)
547547

548548
client_token = client_ctx.step()
@@ -561,7 +561,7 @@ def test_bad_channel_bindings_raises_error(self):
561561
initiator_address=b'127.0.0.1',
562562
acceptor_address_type=gb.AddressType.ip,
563563
acceptor_address=b'127.0.0.1')
564-
client_ctx = self._create_client_ctx(desired_lifetime=400,
564+
client_ctx = self._create_client_ctx(lifetime=400,
565565
channel_bindings=bdgs)
566566

567567
client_token = client_ctx.step()
@@ -659,7 +659,7 @@ def test_verify_signature_raise(self):
659659
def test_defer_step_error_on_method(self):
660660
gssctx.SecurityContext.__DEFER_STEP_ERRORS__ = True
661661
bdgs = gb.ChannelBindings(application_data=b'abcxyz')
662-
client_ctx = self._create_client_ctx(desired_lifetime=400,
662+
client_ctx = self._create_client_ctx(lifetime=400,
663663
channel_bindings=bdgs)
664664

665665
client_token = client_ctx.step()
@@ -674,7 +674,7 @@ def test_defer_step_error_on_method(self):
674674
def test_defer_step_error_on_complete_property_access(self):
675675
gssctx.SecurityContext.__DEFER_STEP_ERRORS__ = True
676676
bdgs = gb.ChannelBindings(application_data=b'abcxyz')
677-
client_ctx = self._create_client_ctx(desired_lifetime=400,
677+
client_ctx = self._create_client_ctx(lifetime=400,
678678
channel_bindings=bdgs)
679679

680680
client_token = client_ctx.step()

0 commit comments

Comments
 (0)