Skip to content

Instantly share code, notes, and snippets.

@mcepl
Created November 16, 2017 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcepl/e4a6f7aea55f9cca0f603873dc5a7d1b to your computer and use it in GitHub Desktop.
Save mcepl/e4a6f7aea55f9cca0f603873dc5a7d1b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
from __future__ import print_function
import logging
import sys
import time
from ctypes import CDLL, c_char_p
import gi
gi.require_version('Goa', '1.0')
from gi.repository import Goa
logging.basicConfig(format='%(levelname)s:%(funcName)s:%(message)s',
stream=sys.stdout, level=logging.DEBUG)
log = logging.getLogger('t_kinit')
goa_blib = CDLL('libgoa-backend-1.0.so.1')
GFALSE = 0
GTRUE = 1
class GoaProvider(object):
"""Python bindings over GoaProvider class"""
def __init__(self, provider_type):
# This is UNMUTEABLE sack of bytes
self.provider_type = goa_blib.goa_provider_get_for_provider_type(
c_char_p(provider_type))
log.debug('self.provider_type = %s (%s)', self.provider_type,
type(self.provider_type))
def refresh_account(self, client, obj):
cl = client # XXX how to get C version of GoaClient
o = obj # XXX how to get C version of GoaObject
res = goa_blib.goa_provider_refresh_account(self.provider_type,
cl, o, None, None)
if res == GFALSE:
raise IOError("Account %s has not been refreshed!" % obj)
def get_krb_accounts():
out = []
c = Goa.Client.new_sync(None)
acc_list = c.get_accounts()
for obj in acc_list:
test_a = obj.get_account()
if test_a.props.provider_type == 'kerberos':
out.append(obj)
return c, out
cl, accounts = get_krb_accounts()
for a in accounts:
acc = a.get_account()
# print(dir(acc))
# exp_secs = acc.call_ensure_credentials_sync(None)
# expires = time.localtime(time.time() + exp_secs)
# print(time.strftime("%d.%m.%Y %H:%M:%S", expires))
acc_prov = GoaProvider(acc.props.provider_type)
acc_prov.refresh_account(cl, a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment