Search in sources :

Example 1 with AttributesManagerApi

use of cz.metacentrum.perun.openapi.AttributesManagerApi in project perun by CESNET.

the class ListOfVoMembersWithCertificate method executeCommand.

@Override
public void executeCommand(PerunCLI.CommandContext ctx) {
    Integer voId = this.getVoId(ctx, true);
    AttributesManagerApi attributesManager = ctx.getPerunRPC().getAttributesManager();
    int prefDNid = attributesManager.getAttributeDefinitionByName("urn:perun:user:attribute-def:def:userPreferredCertDN").getId();
    for (Member member : ctx.getPerunRPC().getMembersManager().getMembers(voId, null)) {
        String pdn = (String) attributesManager.getUserAttributeById(member.getUserId(), prefDNid).getValue();
        if (pdn != null) {
            User user = ctx.getPerunRPC().getUsersManager().getUserById(member.getUserId());
            System.out.println(user.getFirstName() + " " + user.getLastName() + " (" + member.getStatus() + ") " + pdn);
        }
    }
}
Also used : AttributesManagerApi(cz.metacentrum.perun.openapi.AttributesManagerApi) User(cz.metacentrum.perun.openapi.model.User) Member(cz.metacentrum.perun.openapi.model.Member)

Example 2 with AttributesManagerApi

use of cz.metacentrum.perun.openapi.AttributesManagerApi in project perun by CESNET.

the class SetFacilityHostsAttributeValue method executeCommand.

@Override
public void executeCommand(PerunCLI.CommandContext ctx) {
    int facilityId = this.getFacilityId(ctx, true);
    int attributeDefinitionId = this.getAttributeDefinitionId(ctx, true);
    String value = ctx.getCommandLine().getOptionValue("w");
    Object attributeValue;
    if (value.matches("\\d+")) {
        attributeValue = Integer.valueOf(value);
    } else {
        attributeValue = value;
    }
    PerunRPC perunRPC = ctx.getPerunRPC();
    AttributesManagerApi attributesManager = perunRPC.getAttributesManager();
    List<Host> hosts = perunRPC.getFacilitiesManager().getHosts(facilityId);
    for (Host host : hosts) {
        Attribute attribute = attributesManager.getHostAttributeById(host.getId(), attributeDefinitionId);
        attribute.setValue(attributeValue);
        System.out.println("setting attribute on host " + host.getHostname() + " to " + attributeValue + " ...");
        attributesManager.setHostAttribute(new InputSetHostAttribute().host(host.getId()).attribute(attribute));
    }
    System.out.println("OK");
}
Also used : PerunRPC(cz.metacentrum.perun.openapi.PerunRPC) AttributesManagerApi(cz.metacentrum.perun.openapi.AttributesManagerApi) Attribute(cz.metacentrum.perun.openapi.model.Attribute) InputSetHostAttribute(cz.metacentrum.perun.openapi.model.InputSetHostAttribute) Host(cz.metacentrum.perun.openapi.model.Host) InputSetHostAttribute(cz.metacentrum.perun.openapi.model.InputSetHostAttribute)

Aggregations

AttributesManagerApi (cz.metacentrum.perun.openapi.AttributesManagerApi)2 PerunRPC (cz.metacentrum.perun.openapi.PerunRPC)1 Attribute (cz.metacentrum.perun.openapi.model.Attribute)1 Host (cz.metacentrum.perun.openapi.model.Host)1 InputSetHostAttribute (cz.metacentrum.perun.openapi.model.InputSetHostAttribute)1 Member (cz.metacentrum.perun.openapi.model.Member)1 User (cz.metacentrum.perun.openapi.model.User)1