Beispiel #1
0
def clean_context_options(context, **options):
    """Clean argument to related object

    In the case of using Key table, principal is required. keytab_file is
    optional, and default key table file ``/etc/krb5.keytab`` is used if
    keytab_file is not provided.

    In the case of initing as a regular user, principal is optional, and
    current user's effective name is used if principal is not provided.

    By default, initialize credentials cache for regular user.

    :param krbV.Context context: Kerberos context.
    :param options: keyword arguments that contains values passed from
        caller. Each one will be converted to corresponding krbV objects. Refer
        to ``krbContext.__init__`` to see each argument.
    :return: a mapping containing each converted krbV objects. It could
        contains keys principal, ccache, keytab, and using_keytab.
    :rtype: dict
    """
    cleaned_kwargs = {}

    using_keytab = options.get('using_keytab', False)
    if using_keytab:
        # Principal is required when using key table to initialize
        # credential cache.
        principal_name = options.get('principal', None)
        if principal_name is None:
            raise NameError('Principal is required when using key table.')
        else:
            principal = krbV.Principal(principal_name, context=context)
            cleaned_kwargs['principal'] = principal
        kt_name = options.get('keytab_file', None)
        if kt_name is None:
            keytab = context.default_keytab()
        else:
            keytab = krbV.Keytab(kt_name, context=context)
        cleaned_kwargs['keytab'] = keytab
    else:
        # When initialize credentials cache with a regular user, clean
        # principal has different rule. It will return a valid Principal object
        # always.
        principal_name = options.get('principal', None)
        if principal_name is None:
            principal_name = get_login()
        principal = krbV.Principal(principal_name, context=context)
        cleaned_kwargs['principal'] = principal
    cleaned_kwargs['using_keytab'] = using_keytab

    ccache_file = options.get('ccache_file', None)
    if ccache_file is None:
        ccache = get_default_ccache(context)
    else:
        ccache = krbV.CCache(ccache_file, context=context)
    cleaned_kwargs['ccache'] = ccache

    return cleaned_kwargs
def clean_kwargs(context, kwargs):
    ''' Clean argument to related object

    In the case of using Key table, principal is required. keytab_file is
    optional, and default key table file /etc/krb5.keytab is used if
    keytab_file is not provided.

    In the case of initing as a regular user, principal is optional, and
    current user's effective name is used if principal is not provided.

    By default, initialize credentials cache for regular user.
    '''
    cleaned_kwargs = {}

    using_keytab = kwargs.get('using_keytab', False)
    if using_keytab:
        # Principal is required when using key table to initialize
        # credential cache.
        principal_name = kwargs.get('principal', None)
        if principal_name is None:
            raise NameError('Principal is required when using key table.')
        else:
            principal = krbV.Principal(principal_name, context=context)
            cleaned_kwargs['principal'] = principal
        kt_name = kwargs.get('keytab_file', None)
        if kt_name is None:
            keytab = context.default_keytab()
        else:
            keytab = krbV.Keytab(kt_name, context=context)
        cleaned_kwargs['keytab'] = keytab
    else:
        # When initialize credentials cache with a regular user, clean
        # principal has different rule. It will return a valid Principal object
        # always.
        principal_name = kwargs.get('principal', None)
        if principal_name is None:
            principal_name = get_login()
        principal = krbV.Principal(principal_name, context=context)
        cleaned_kwargs['principal'] = principal
    cleaned_kwargs['using_keytab'] = using_keytab

    ccache_file = kwargs.get('ccache_file', None)
    if ccache_file is None:
        ccache = get_default_ccache(context)
    else:
        ccache = krbV.CCache(ccache_file, context=context)
    cleaned_kwargs['ccache'] = ccache

    return cleaned_kwargs
def clean_kwargs(context, kwargs):
    ''' Clean argument to related object

    In the case of using Key table, principal is required. keytab_file is
    optional, and default key table file /etc/krb5.keytab is used if
    keytab_file is not provided.

    In the case of initing as a regular user, principal is optional, and
    current user's effective name is used if principal is not provided.

    By default, initialize credentials cache for regular user.
    '''
    cleaned_kwargs = {}

    using_keytab = kwargs.get('using_keytab', False)
    if using_keytab:
        # Principal is required when using key table to initialize
        # credential cache.
        principal_name = kwargs.get('principal', None)
        if principal_name is None:
            raise NameError('Principal is required when using key table.')
        else:
            principal = krbV.Principal(principal_name, context=context)
            cleaned_kwargs['principal'] = principal
        kt_name = kwargs.get('keytab_file', None)
        if kt_name is None:
            keytab = context.default_keytab()
        else:
            keytab = krbV.Keytab(kt_name, context=context)
        cleaned_kwargs['keytab'] = keytab
    else:
        # When initialize credentials cache with a regular user, clean
        # principal has different rule. It will return a valid Principal object
        # always.
        principal_name = kwargs.get('principal', None)
        if principal_name is None:
            principal_name = get_login()
        principal = krbV.Principal(principal_name, context=context)
        cleaned_kwargs['principal'] = principal
    cleaned_kwargs['using_keytab'] = using_keytab

    ccache_file = kwargs.get('ccache_file', None)
    if ccache_file is None:
        ccache = get_default_ccache(context)
    else:
        ccache = krbV.CCache(ccache_file, context=context)
    cleaned_kwargs['ccache'] = ccache

    return cleaned_kwargs
Beispiel #4
0
def check_status(do_send=False):
    ts, ip_old = get_ts_ip()
    # logger.debug('%s %s %s %s' % (ts, ip_old, sa, cw))
    ip = router_wan_ip()
    logger.info('Current WAN ip: %s' % ip)

    if ip == ip_old:
        logger.info('No changes')
        if do_send: logger.debug('Force to send e-mail for test purpose')
        else: return
        #=======================
    rec = save_ts_ip(ip)
    logger.info('ip has changed, email msg: %s' % rec)
    send_email_v0(msg='Update %s' % rec, subject='Msg from %s' % get_login())
    add_record_to_log('%s\n' % rec)
Beispiel #5
0
def namer():
    return '.%s/.at/.%s/.%s'%\
        (get_login(), get_hostname(), sys._getframe().f_code.co_name)
Beispiel #6
0
sa, cw = get_sa_cw()


def save_ts_ip(ip):
    ts = str_tstamp(fmt='%Y-%m-%dT%H:%M:%S')
    ofname = '%s/%s' % (get_homedir(), namer())
    rec = '%s %s' % (ts, ip)
    save_textfile(rec, ofname, mode='w', verb=False)
    return rec


def add_record_to_log(rec):
    save_textfile(rec, logname(), mode='a', verb=False)


#------------------------------

if __name__ == "__main__":
    print('get_enviroment("PWD") : %s' % get_enviroment(env='PWD'))
    print('get_homedir()         : %s' % get_homedir())
    print('get_login()           : %s' % get_login())
    print('get_hostname()        : %s' % get_hostname())
    print('get_cwd()             : %s' % get_cwd())
    print('str_tstamp()          : %s' % str_tstamp(fmt='%Y-%m-%dT%H:%M'))
    print('namer()               : %s' % namer())
    print('cwname()              : %s' % cwname())
    sys.exit('END OF TEST')

#------------------------------
Beispiel #7
0
    """Runs tests for given app."""
    uprint('Testing %s... ' % app_name)
    with mkcd(app_name):
        try:
            fetch_code(app['FETCH'], login)
            build_code(app['BUILD'])
            print('OK')
        except CodeFetchError as e:
            print(e)
        except CodeBuildError as e:
            print(e)


def run_tests(apps, scratch, login):
    """Kinda main. Runs the whole thing."""
    with mkcd(scratch):
        # TODO: multiprocessing?
        for app_name in apps:
            app = apps[app_name]
            run_app_test(app_name, app, login)


if __name__ == '__main__':
    args = docopt(_doc_, version=VERSION)
    print('$MAXCOMPILERDIR=' + os.environ['MAXCOMPILERDIR'])
    print('$MAXELEROSDIR=' + os.environ['MAXELEROSDIR'])
    ins = load_inst(args['<instructions_file>'])
    scratch = os.path.abspath(args['<scratch_directory>'])
    run_tests(ins['APPS'], scratch, get_login())

Beispiel #8
0
def run_app_test(app_name, app, login):
    """Runs tests for given app."""
    uprint('Testing %s... ' % app_name)
    with mkcd(app_name):
        try:
            fetch_code(app['FETCH'], login)
            build_code(app['BUILD'])
            print('OK')
        except CodeFetchError as e:
            print(e)
        except CodeBuildError as e:
            print(e)


def run_tests(apps, scratch, login):
    """Kinda main. Runs the whole thing."""
    with mkcd(scratch):
        # TODO: multiprocessing?
        for app_name in apps:
            app = apps[app_name]
            run_app_test(app_name, app, login)


if __name__ == '__main__':
    args = docopt(_doc_, version=VERSION)
    print('$MAXCOMPILERDIR=' + os.environ['MAXCOMPILERDIR'])
    print('$MAXELEROSDIR=' + os.environ['MAXELEROSDIR'])
    ins = load_inst(args['<instructions_file>'])
    scratch = os.path.abspath(args['<scratch_directory>'])
    run_tests(ins['APPS'], scratch, get_login())