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());
}
}
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);
}
}
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());
}
}
}
}
}
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");
}
Aggregations