Example usage for com.amazonaws.services.identitymanagement.model GetGroupRequest GetGroupRequest

List of usage examples for com.amazonaws.services.identitymanagement.model GetGroupRequest GetGroupRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.identitymanagement.model GetGroupRequest GetGroupRequest.

Prototype

public GetGroupRequest(String groupName) 

Source Link

Document

Constructs a new GetGroupRequest object.

Usage

From source file:fr.xebia.cloud.amazon.aws.iam.AmazonAwsIamAccountCreator.java

License:Apache License

public void createUsers(String groupName, String keyPairName) {

    GetGroupResult groupDescriptor = iam.getGroup(new GetGroupRequest(groupName));

    URL emailsToVerifyURL = Thread.currentThread().getContextClassLoader()
            .getResource("accounts-to-create.txt");
    Preconditions.checkNotNull(emailsToVerifyURL, "File 'accounts-to-create.txt' NOT found in the classpath");
    Collection<String> userNames;
    try {//from  w w w. ja va  2 s  . c  om
        userNames = Sets.newTreeSet(Resources.readLines(emailsToVerifyURL, Charsets.ISO_8859_1));
    } catch (Exception e) {
        throw Throwables.propagate(e);
    }
    userNames = Collections2.filter(userNames, new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String s) {
            return !Strings.isNullOrEmpty(s);
        }
    });
    for (String userName : userNames) {
        try {
            createUser(userName, groupDescriptor, keyPairName);
        } catch (Exception e) {
            logger.error("Failure to create user '{}'", userName, e);
        }

        // sleep 10 seconds to prevent "Throttling exception"
        try {
            Thread.sleep(10 * 1000);
        } catch (InterruptedException e) {
            throw Throwables.propagate(e);
        }
    }
}

From source file:org.dasein.prototype.iamc.AWS.java

License:Apache License

public boolean grantAccessToUser(String username, Service service) {
    String entityName;/*from  ww w .  j  av a  2s .  co  m*/
    Action action;
    switch (service) {
    case ElasticBeanstalk:
        entityName = "iamc-eb";
        action = ElasticBeanstalkActions.AllElasticBeanstalkActions;
        break;
    case EC2:
        entityName = "iamc-ec2";
        action = EC2Actions.AllEC2Actions;
        break;
    default:
        return false;
    }
    try {
        iamClient.getGroup(new GetGroupRequest(entityName));
    } catch (NoSuchEntityException e) {
        iamClient.createGroup(new CreateGroupRequest(entityName));
    }
    Policy policy = new Policy(entityName).withStatements(
            new Statement(Statement.Effect.Allow).withActions(action).withResources(new Resource("*")));
    iamClient.putGroupPolicy(new PutGroupPolicyRequest(entityName, entityName, policy.toJson()));
    iamClient.addUserToGroup(new AddUserToGroupRequest(entityName, username));
    return true;
}

From source file:org.dasein.prototype.iamc.AWS.java

License:Apache License

public boolean revokeAccessFromUser(String username, Service service) {
    String entityName;//from  ww w  .ja va 2  s.co  m
    switch (service) {
    case ElasticBeanstalk:
        entityName = "iamc-eb";
        break;
    case EC2:
        entityName = "iamc-ec2";
        break;
    default:
        return false;
    }
    try {
        iamClient.getGroup(new GetGroupRequest(entityName));
    } catch (NoSuchEntityException e) {
        // no group, no access to revoke
    }
    try {
        iamClient.removeUserFromGroup(new RemoveUserFromGroupRequest(entityName, username));
    } catch (Exception ignore) {
    }
    return true;
}