예제 #1
0
def update(id, _org_label, _prj_label, _payload):
    _org_label = utils.get_organization_label(_org_label)
    _prj_label = utils.get_project_label(_prj_label)
    nxs = utils.get_nexus_client()
    try:
        data = nxs.resources.fetch(org_label=_org_label, project_label=_prj_label, schema_id='_', resource_id=id)
        data_md5_before = utils.generate_nexus_payload_checksum(data)
        current_revision = data["_rev"]

        if _payload is not None:
            data = json.loads(_payload)
        else:
            # If no payload given, load up the entry in a text file and open default editor
            new_file, filename = tempfile.mkstemp()
            print("Opening an editor: %s" % filename)
            f = open(filename, "w")
            f.write(json.dumps(data, indent=2))
            f.close()
            click.edit(filename=filename)
            f = open(filename, "r")
            data = json.loads(f.read())
            f.close()
            os.remove(filename)

        data_md5_after = utils.generate_nexus_payload_checksum(data)
        if data_md5_before == data_md5_after:
            print("No change in resource, aborting update.")
        else:
            nxs.resources.update(resource=data, rev=current_revision)
            print("Resource updated.")
    except nxs.HTTPError as e:
        utils.print_json(e.response.json(), colorize=True)
        utils.error(str(e))
예제 #2
0
def _import_schema(url, schema, _org_label, _prj_label,_strategy ):
    nxs = utils.get_nexus_client()
    if "@id" in schema:
        schema_uri = schema["@id"]
        try:
            schema_in_nexus = nxs.schemas.fetch(org_label=_org_label, project_label=_prj_label, schema_id=schema_uri)
            schema_in_nexus = json.loads(json.dumps(schema_in_nexus))
            current_revision = 0
            if "_rev" in schema_in_nexus:
                current_revision = schema_in_nexus["_rev"]
            # The schema exists

            if "_self" in schema_in_nexus:
                schema["_self"] =schema_in_nexus["_self"]
            else:
                raise SchemaBadFrameException("The schema {} as retrieved from Nexus is not correctly shaped: missing the _self key".format(schema_uri))
            if _strategy == UPDATE_IF_DIFFERENT:
                schema_md5_before = utils.generate_nexus_payload_checksum(schema_in_nexus)
                schema_md5_after = utils.generate_nexus_payload_checksum(schema)

                if schema_md5_before != schema_md5_after:
                    nxs.schemas.update(schema=schema, rev=current_revision)
            if _strategy == UPDATE_IF_EXISTS:
                nxs.schemas.update(schema=schema, rev=current_revision)
        except nxs.HTTPError as e:

            if e.response.status_code == 404: # the schema does not exist
                return nxs.schemas.create(org_label=_org_label, project_label=_prj_label, schema_obj=schema,
                                          schema_id=None)
예제 #3
0
def update(id, _org_label, _prj_label, _payload):
    _org_label = utils.get_organization_label(_org_label)
    _prj_label = utils.get_project_label(_prj_label)
    nxs = utils.get_nexus_client()
    try:
        view = nxs.views.fetch(org_label=_org_label, project_label=_prj_label, view_id=id)
        view_md5_before = utils.generate_nexus_payload_checksum(view, debug=True)
        current_revision = view["_rev"]

        if _payload is not None:
            view = json.loads(_payload)
        else:
            # If no payload given, load up the entry in a text file and open default editor
            new_file, filename = tempfile.mkstemp()
            print("Opening an editor: %s" % filename)
            f = open(filename, "w")
            f.write(json.dumps(view, indent=2))
            f.close()
            click.edit(filename=filename)
            f = open(filename, "r")
            view = json.loads(f.read())
            f.close()
            os.remove(filename)

        view_md5_after = utils.generate_nexus_payload_checksum(view, debug=True)
        if view_md5_before == view_md5_after:
            print("No change in view, aborting update.")
        else:
            nxs.views.update_es(esview=view, rev=current_revision)
            print("View updated.")
    except nxs.HTTPError as e:
        utils.error(str(e))
        utils.print_json(e.response.json(), colorize=True)
예제 #4
0
def update(id, _org_label, _prj_label, _projects, _identities, _priority,
           _resources_types, _type, _payload):
    _org_label = utils.get_organization_label(_org_label)
    _prj_label = utils.get_project_label(_prj_label)
    nxs = utils.get_nexus_client()
    try:
        data = nxs.resolvers.fetch(org_label=_org_label,
                                   project_label=_prj_label,
                                   id=id)
        current_revision = data["_rev"]
        data_md5_before = utils.generate_nexus_payload_checksum(data)
        if _priority is not None and _identities is not None and _projects is not None:
            response = nxs.resolvers.update(org_label=_org_label,
                                            project_label=_prj_label,
                                            projects=_projects,
                                            identities=_identities,
                                            _priority=_priority,
                                            id=id,
                                            rev=current_revision,
                                            resources_types=_resources_types)
        else:
            if _payload is not None:
                data = json.loads(_payload)
            else:
                # If no payload given, load up the entry in a text file and open default editor
                new_file, filename = tempfile.mkstemp()
                print("Opening an editor: %s" % filename)
                f = open(filename, "w")
                f.write(json.dumps(data, indent=2))
                f.close()
                click.edit(filename=filename)
                f = open(filename, "r")
                data = json.loads(f.read())
                f.close()
                os.remove(filename)

            data_md5_after = utils.generate_nexus_payload_checksum(data)
            if data_md5_before == data_md5_after:
                print("No change in resolver, aborting update.")
            else:
                encoded_id = encode_url(id)
                nxs.resolvers.update_(path=[
                    nxs.resolvers.SEGMENT, _org_label, _prj_label, encoded_id
                ],
                                      payload=data,
                                      rev=current_revision)
                print("Resolver updated.")

    except nxs.HTTPError as e:
        utils.error(str(e))
        utils.print_json(e.response.json(), colorize=True)
예제 #5
0
def update(label, _payload, name, description):
    nxs = utils.get_nexus_client()
    try:
        data = nxs.organizations.fetch(org_label=label)
        current_revision = data["_rev"]
        data_md5_before = utils.generate_nexus_payload_checksum(data)

        if _payload is None and (name is not None or description is not None):
            if name is not None:
                data["name"] = name
            if description is not None:
                data["description"] = description
        elif _payload is not None:
            data = json.loads(_payload)
        else:
            # If nothing given, load up the entry in a text file and open default editor
            new_file, filename = tempfile.mkstemp()
            print("Opening an editor: %s" % filename)
            f = open(filename, "w")
            f.write(json.dumps(data, indent=2))
            f.close()
            click.edit(filename=filename)
            f = open(filename, "r")
            data = json.loads(f.read())
            f.close()
            os.remove(filename)

        data_md5_after = utils.generate_nexus_payload_checksum(data)
        if data_md5_before == data_md5_after:
            print("No change in organization, aborting update.")
        else:
            nxs.organizations.update(org=data, rev=current_revision)
            print("Organization updated.")
    except nxs.HTTPError as e:
        utils.print_json(e.response.json(), colorize=True)
        utils.error(str(e))