Exemple #1
0
def _register_minid(minid_user, minid_email, minid_title, minid_test,
                    globus_auth_token, checksum, locations):
    try:
        minid = minid_client_api.register_entity(
            settings.MINID_SERVER,
            checksum,
            minid_email,
            None,
            locations,
            minid_title,
            minid_test,
            globus_auth_token=globus_auth_token)
    except minid_client_api.MinidAPIException as minid_exc:
        if minid_exc.type == 'UserNotRegistered':
            try:
                minid_client_api.register_user(
                    settings.MINID_SERVER,
                    minid_email,
                    minid_user,
                    '',  # ORCID is not currently used
                    globus_auth_token=globus_auth_token)
                minid = minid_client_api.register_entity(
                    settings.MINID_SERVER,
                    checksum,
                    minid_email,
                    None,
                    locations,
                    minid_title,
                    minid_test,
                    globus_auth_token=globus_auth_token)
            except minid_client_api.MinidAPIException as minid_exc:
                msg = 'Failed to created minid, user not registered and ' \
                      'auto-registration failed: {}'.format(minid_exc.message)
                if minid_exc.code in [401, 403]:
                    raise ServiceAuthException(msg, code='minid_auth_error')
                else:
                    log.error('"{}": {}'.format(minid_email, msg))
                    raise ConciergeException(msg, code='minid_auth_error')
        else:
            msg = 'Could not create minid: {}'.format(minid_exc.message)
            if minid_exc.code in [401, 403]:
                raise ServiceAuthException(msg, code='minid_auth_error')
            else:
                log.error('"{}": {}'.format(minid_email, msg))
                raise ConciergeException(msg, code='minid_auth_error')
    return minid
Exemple #2
0
def main():
    args = parse_cli()
    if not args.quiet:
        mca.configure_logging()

    config = mca.parse_config(args.config)

    server = config["minid_server"]
    if args.server:
        server = args.server

    entities = None

    # register a new user
    if args.register_user:
        mca.register_user(server, args.email, args.name, args.orcid)
        return

    # if we got this far we *must* have a filename (or identifier) arg
    if not args.filename:
        print("Either a file name or an identifier must be specified.")
        return

    # see if this file or name exists
    file_exists = os.path.isfile(args.filename)
    if file_exists:
        checksum = mca.compute_checksum(args.filename)
        entities = mca.get_entities(server, checksum, args.test)
    else:
        entities = mca.get_entities(server, args.filename, False)
        if entities is None:
            print("No entity registered with identifier: %s" % args.filename)
            return

    # register file or display info about the entity
    if args.register:
        if entities and not file_exists:
            print("You must use the --update command to update a minid")
            return
        else:
            locations = args.locations
            if locations is None or len(locations) == 0:
                if "local_server" in config:
                    locations = [
                        "%s%s" % (config["local_server"],
                                  os.path.abspath(args.filename))
                    ]
            mca.register_entity(server, checksum,
                                args.email if args.email else config["email"],
                                args.code if args.code else config["code"],
                                locations, args.title, args.test,
                                args.content_key)
    elif args.update:
        if entities is None:
            print("No entity found to update. You must use a valid minid.")
            return
        elif len(entities) > 1:
            print(
                "More than one minid identified. Please use a minid identifier"
            )
        else:
            entity = entities.values()[0]
            if args.status:
                entity['status'] = args.status
            if args.obsoleted_by:
                entity['obsoleted_by'] = args.obsoleted_by
            if args.title:
                entity['titles'] = [{"title": args.title}]
            if args.locations:
                locs = []
                for l in args.locations:
                    locs.append({'uri': l})
                entity['locations'] = locs

            updated_entity = mca.update_entity(
                server, args.filename, entity,
                args.email if args.email else config["email"],
                args.code if args.code else config["code"])
            print(updated_entity)
    else:
        if entities:
            mca.print_entities(entities, args.json)
        else:
            print(
                "File is not named. Use --register to create a name for this file."
            )
def main():
    args = parse_cli()

    # Need to change this....
    args.scheme = 'https'

    if not (args.register or args.update or args.register_user or args.url
            or args.landingpage):
        args.register = True

    if not args.quiet:
        mca.configure_logging()

    config = mca.parse_config(args.config)

    email = args.email if args.email else config["email"]
    code = args.code if args.code else config["code"]
    server = args.server if args.server else config['minid_server']
    try:
        # register a new user
        if args.register_user:
            mca.register_user(server, email, config['name'], args.orcid)
            return

        if args.url:
            url = resolve_catalog_minid(args.path)
            print(url)
            return

        if args.landingpage:
            if args.path[0:len('ark:')] == 'ark:':
                entities = mca.get_entities(server, args.path, args.test)
            else:
                vc = VersionedCatalog(args.url, args.version)
                entities = lookup_catalog_minid(vc, server, test=args.test)
            if entities is not None:
                mca.print_entities(entities, args.json)
            else:
                print(
                    "Catalog is not named. Use --register to create a name for this file."
                )
            return

        if args.path is None:
            print("Catalog path must be specified")
            return

        vc = VersionedCatalog(args.path, args.version)

        # register file or display info about the entity
        if args.register:
            create_catalog_minid(vc,
                                 server,
                                 email,
                                 code,
                                 title=args.title,
                                 test=args.test)
        elif args.update:
            update_catalog_minid(vc,
                                 server,
                                 email,
                                 code,
                                 title=args.title,
                                 status=args.status,
                                 obsoleted_by=args.obsoleted_by,
                                 test=args.test)
    except MINIDError as err:
        print('ERROR: ' + err.message)
    except requests.exceptions.HTTPError as err:
        print(err)