Search in sources :

Example 1 with Attribute

use of cz.metacentrum.perun.openapi.model.Attribute in project perun by CESNET.

the class GetRichUser method executeCommand.

@Override
public void executeCommand(PerunCLI.CommandContext ctx) {
    int id = Integer.parseInt(ctx.getCommandLine().getOptionValue("id"));
    RichUser richUser = ctx.getPerunRPC().getUsersManager().getRichUserWithAttributes(id);
    System.out.println("         id: " + richUser.getId());
    System.out.println("titleBefore: " + richUser.getTitleBefore());
    System.out.println("  firstName: " + richUser.getFirstName());
    System.out.println(" middleName: " + richUser.getMiddleName());
    System.out.println("   lastName: " + richUser.getLastName());
    System.out.println(" titleAfter: " + richUser.getTitleAfter());
    System.out.println("  createdAt: " + richUser.getCreatedAt());
    System.out.println("  createdBy: " + richUser.getCreatedBy());
    System.out.println(" modifiedAt: " + richUser.getModifiedAt());
    System.out.println(" modifiedBy: " + richUser.getModifiedBy());
    System.out.println();
    System.out.println(" UserExtSources:");
    System.out.println();
    List<UserExtSource> userExtSources = richUser.getUserExtSources();
    userExtSources.sort(Comparator.comparing(UserExtSource::getLastAccess));
    for (UserExtSource ues : userExtSources) {
        System.out.println("(" + ues.getLastAccess() + ") " + ues.getLogin() + " " + ues.getExtSource().getName());
    }
    System.out.println();
    System.out.println(" user attributes:");
    System.out.println();
    List<Attribute> userAttributes = richUser.getUserAttributes();
    for (Attribute a : userAttributes) {
        System.out.println("attribute " + a.getNamespace() + ":" + a.getFriendlyName() + " = " + a.getValue());
    }
}
Also used : UserExtSource(cz.metacentrum.perun.openapi.model.UserExtSource) Attribute(cz.metacentrum.perun.openapi.model.Attribute) RichUser(cz.metacentrum.perun.openapi.model.RichUser)

Example 2 with Attribute

use of cz.metacentrum.perun.openapi.model.Attribute in project perun by CESNET.

the class GetExpirationByExtLogin method executeCommand.

@Override
public void executeCommand(PerunCLI.CommandContext ctx) {
    String extSourceName = ctx.getCommandLine().getOptionValue("E");
    Integer voId = getVoId(ctx, true);
    String filename = ctx.getCommandLine().getOptionValue("f");
    try {
        PerunRPC perunRPC = ctx.getPerunRPC();
        for (String login : Files.readAllLines(Paths.get(filename))) {
            Member member = perunRPC.getMembersManager().getMemberByExtSourceNameAndExtLogin(voId, login, extSourceName);
            Attribute attr = perunRPC.getAttributesManager().getMemberAttributeByName(member.getId(), "urn:perun:member:attribute-def:def:membershipExpiration");
            String expiration = (String) attr.getValue();
            System.out.println(login + ";" + expiration);
        }
    } catch (IOException e) {
        System.err.println("file " + filename + " cannot be read");
        System.exit(1);
    }
}
Also used : PerunRPC(cz.metacentrum.perun.openapi.PerunRPC) Attribute(cz.metacentrum.perun.openapi.model.Attribute) IOException(java.io.IOException) Member(cz.metacentrum.perun.openapi.model.Member)

Example 3 with Attribute

use of cz.metacentrum.perun.openapi.model.Attribute in project perun by CESNET.

the class ListOfFacilityGroups method executeCommand.

@Override
public void executeCommand(PerunCLI.CommandContext ctx) {
    int facilityId = this.getFacilityId(ctx, true);
    Integer voId = this.getVoId(ctx, false);
    Integer serviceId = this.getServiceId(ctx, false);
    String[] optionA = ctx.getCommandLine().getOptionValues("a");
    if (optionA == null) {
        List<Group> groups = ctx.getPerunRPC().getFacilitiesManager().getAllowedGroups(facilityId, voId, serviceId);
        this.sort(ctx, groups, Comparator.comparing(Group::getName));
        for (Group group : groups) {
            System.out.println(group.getId() + "\t" + group.getName() + "\t" + "\"" + group.getDescription() + "\"\t voId: " + group.getVoId());
        }
    } else {
        List<String> attrNames = Arrays.asList(optionA);
        List<RichGroup> groups = ctx.getPerunRPC().getFacilitiesManager().getAllowedRichGroupsWithAttributes(facilityId, attrNames, voId, serviceId);
        this.sort(ctx, groups, Comparator.comparing(RichGroup::getName));
        for (RichGroup group : groups) {
            System.out.println(group.getId() + "\t" + group.getName() + "\t" + "\"" + group.getDescription() + "\"\t voId: " + group.getVoId());
            List<Attribute> groupAttributes = group.getAttributes();
            if (groupAttributes != null) {
                for (Attribute a : groupAttributes) {
                    System.out.println("  " + a.getNamespace() + ":" + a.getFriendlyName() + " = " + a.getValue());
                }
            }
        }
    }
}
Also used : RichGroup(cz.metacentrum.perun.openapi.model.RichGroup) Group(cz.metacentrum.perun.openapi.model.Group) Attribute(cz.metacentrum.perun.openapi.model.Attribute) RichGroup(cz.metacentrum.perun.openapi.model.RichGroup)

Example 4 with Attribute

use of cz.metacentrum.perun.openapi.model.Attribute 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

Attribute (cz.metacentrum.perun.openapi.model.Attribute)4 PerunRPC (cz.metacentrum.perun.openapi.PerunRPC)2 AttributesManagerApi (cz.metacentrum.perun.openapi.AttributesManagerApi)1 Group (cz.metacentrum.perun.openapi.model.Group)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 RichGroup (cz.metacentrum.perun.openapi.model.RichGroup)1 RichUser (cz.metacentrum.perun.openapi.model.RichUser)1 UserExtSource (cz.metacentrum.perun.openapi.model.UserExtSource)1 IOException (java.io.IOException)1