Example #1
0
def authenticate_oidc():
    """ Authentication to OIDC Service
    """
    # TODO: decorator authentication
    global user
    user = raw_input("Username of Gaspar's account ")
    services = get_services()
    env = get_environments()
    oauth_url = services['oidc_service'][env[0]]['url']
    # print oauth_url
    # TODO: try ... catch exception
    BBPOIDCClient.implicit_auth(user, oauth_url=oauth_url)
    # root token can get expired, need to login again with Gaspar-pass

    # create Client-instance
    cl = Client.new()
    return cl
 def new(cls, environment='prod', user=None, password=None, token=None):
     '''create new documentservice client'''
     services = get_services()
     oauth_url = services['oidc_service'][environment]['url']
     ds_url = services['document_service'][environment]['url']
     if token:
         oauth_client = BBPOIDCClient.bearer_auth(oauth_url, token)
     else:
         oauth_client = BBPOIDCClient.implicit_auth(user, password, oauth_url)
     return cls(ds_url, oauth_client)
Example #3
0
 def new(cls, environment='prod', user=None, password=None, token=None):
     '''create new collab service client'''
     services = get_services()
     oauth_url = services['oidc_service'][environment]['url']
     service_url = services['stream_service'][environment]['url']
     if token:
         oauth_client = BBPOIDCClient.bearer_auth(oauth_url, token)
     else:
         oauth_client = BBPOIDCClient.implicit_auth(user, password, oauth_url)
     return cls(service_url, oauth_client, environment)
Example #4
0
def main(args=None):
    '''Main function'''
    args = args or sys.argv[1:]
    args = get_parser().parse_args(args)

    if hasattr(args, 'ex_yaml') and args.ex_yaml:
        print EXAMPLE_YAML
        return

    L.debug('Environment: %s Username: %s', args.env, args.user)

    logging.basicConfig(level=VERBOSITY_LEVELS[min(args.verbose,
                                                   len(VERBOSITY_LEVELS) - 1)],
                        format=DEFAULT_LOG_FORMAT)

    if args.subcommand == 'path':
        if os.path.isfile(args.src):
            if args.type is not None or args.ignore_type:
                all_info = [
                    collect_single_file(args.src, args.dst, args.type,
                                        args.upload)
                ]
            else:
                raise SystemExit(
                    _get_missing_contenttype_msg(args.src, args.type))
        else:
            all_info = collect_from_local_fs(args.src, args.dst, args.upload)

    else:
        assert args.subcommand == 'yaml'
        if not args.src:
            raise SystemExit('Must supply at least one yaml file to import')
        all_info = collect_from_registry(args.src)

    oidc_client = BBPOIDCClient.implicit_auth(user=args.user,
                                              password=args.password,
                                              oauth_url=args.env)
    ds_server = args.server or args.env
    ds_client = DSClient(ds_server, oidc_client)

    services = get_services()
    hbp_portal_url = services['hbp_portal'][args.env]['url']

    new_imports, _ = do_import(ds_client, all_info, args.fail_hard)

    if not args.return_imports:
        for i in new_imports:
            print 'Link:', viewer_url(hbp_portal_url, i.dst)
        print 'imported', len(new_imports), 'items'
    else:
        return new_imports
def main(args=None):
    '''Main function'''
    args = args or sys.argv[1:]
    args = get_parser().parse_args(args)

    if hasattr(args, 'ex_yaml') and args.ex_yaml:
        print EXAMPLE_YAML
        return

    L.debug('Environment: %s Username: %s', args.env, args.user)

    logging.basicConfig(level=VERBOSITY_LEVELS[min(args.verbose, len(VERBOSITY_LEVELS) - 1)],
                        format=DEFAULT_LOG_FORMAT)

    if args.subcommand == 'path':
        if os.path.isfile(args.src):
            if args.type is not None or args.ignore_type:
                all_info = [collect_single_file(args.src, args.dst, args.type, args.upload)]
            else:
                raise SystemExit(_get_missing_contenttype_msg(args.src, args.type))
        else:
            all_info = collect_from_local_fs(args.src, args.dst, args.upload)

    else:
        assert args.subcommand == 'yaml'
        if not args.src:
            raise SystemExit('Must supply at least one yaml file to import')
        all_info = collect_from_registry(args.src)

    oidc_client = BBPOIDCClient.implicit_auth(user=args.user, password=args.password,
                                              oauth_url=args.env)
    ds_server = args.server or args.env
    ds_client = DSClient(ds_server, oidc_client)

    services = get_services()
    hbp_portal_url = services['hbp_portal'][args.env]['url']

    new_imports, _ = do_import(ds_client, all_info, args.fail_hard)

    if not args.return_imports:
        for i in new_imports:
            print 'Link:', viewer_url(hbp_portal_url, i.dst)
        print 'imported', len(new_imports), 'items'
    else:
        return new_imports