Example usage for com.amazonaws.auth.policy Policy Policy

List of usage examples for com.amazonaws.auth.policy Policy Policy

Introduction

In this page you can find the example usage for com.amazonaws.auth.policy Policy Policy.

Prototype

public Policy(String id, Collection<Statement> statements) 

Source Link

Document

Constructs a new AWS access control policy with the specified policy ID and collection of statements.

Usage

From source file:com.netflix.spinnaker.clouddriver.aws.lifecycle.InstanceTerminationLifecycleAgent.java

License:Apache License

private static Policy buildSNSPolicy(ARN topicARN, List<String> allAccountIds) {
    Statement statement = new Statement(Statement.Effect.Allow).withActions(SNSActions.Publish);
    statement.setPrincipals(allAccountIds.stream().map(Principal::new).collect(Collectors.toList()));
    statement.setResources(Collections.singletonList(new Resource(topicARN.arn)));

    return new Policy("allow-remote-account-send", Collections.singletonList(statement));
}

From source file:com.netflix.spinnaker.clouddriver.aws.lifecycle.InstanceTerminationLifecycleAgent.java

License:Apache License

private static Policy buildSQSPolicy(ARN queue, ARN topic) {
    Statement statement = new Statement(Statement.Effect.Allow).withActions(SQSActions.SendMessage);
    statement.setPrincipals(Principal.All);
    statement.setResources(Collections.singletonList(new Resource(queue.arn)));
    statement.setConditions(Collections.singletonList(
            new Condition().withType("ArnEquals").withConditionKey("aws:SourceArn").withValues(topic.arn)));

    return new Policy("allow-sns-topic-send", Collections.singletonList(statement));
}

From source file:com.netflix.spinnaker.clouddriver.aws.lifecycle.InstanceTerminationLifecycleWorker.java

License:Apache License

/**
 * This policy allows operators to choose whether or not to have lifecycle hooks to be sent via SNS for fanout, or
 * be sent directly to an SQS queue from the autoscaling group.
 *///from   w w w  . j ava  2  s  .  c om
private static Policy buildSQSPolicy(ARN queue, ARN topic, Set<String> terminatingRoleArns) {
    Statement snsStatement = new Statement(Effect.Allow).withActions(SQSActions.SendMessage);
    snsStatement.setPrincipals(Principal.All);
    snsStatement.setResources(Collections.singletonList(new Resource(queue.arn)));
    snsStatement.setConditions(Collections.singletonList(
            new Condition().withType("ArnEquals").withConditionKey("aws:SourceArn").withValues(topic.arn)));

    Statement sqsStatement = new Statement(Effect.Allow).withActions(SQSActions.SendMessage,
            SQSActions.GetQueueUrl);
    sqsStatement.setPrincipals(terminatingRoleArns.stream().map(Principal::new).collect(Collectors.toList()));
    sqsStatement.setResources(Collections.singletonList(new Resource(queue.arn)));

    return new Policy("allow-sns-or-sqs-send", Arrays.asList(snsStatement, sqsStatement));
}

From source file:com.netflix.spinnaker.echo.pubsub.amazon.SQSSubscriber.java

License:Apache License

/**
 * This policy allows operators to choose whether or not to have pubsub messages to be sent via SNS for fanout, or
 * be sent directly to an SQS queue from the autoscaling group.
 *//*  w  w w.  j a va2 s.co  m*/
private static Policy buildSQSPolicy(ARN queue, ARN topic) {
    Statement snsStatement = new Statement(Statement.Effect.Allow).withActions(SQSActions.SendMessage);
    snsStatement.setPrincipals(Principal.All);
    snsStatement.setResources(Collections.singletonList(new Resource(queue.getArn())));
    snsStatement.setConditions(Collections.singletonList(new Condition().withType("ArnEquals")
            .withConditionKey("aws:SourceArn").withValues(topic.getArn())));

    Statement sqsStatement = new Statement(Statement.Effect.Allow).withActions(SQSActions.SendMessage,
            SQSActions.GetQueueUrl);
    sqsStatement.setPrincipals(Principal.All);
    sqsStatement.setResources(Collections.singletonList(new Resource(queue.getArn())));

    return new Policy("allow-sns-or-sqs-send", Arrays.asList(snsStatement, sqsStatement));
}

From source file:com.netflix.spinnaker.front50.model.TemporarySQSQueue.java

License:Apache License

private TemporaryQueue createQueue(String snsTopicArn, String sqsQueueArn, String sqsQueueName) {
    String sqsQueueUrl = amazonSQS.createQueue(new CreateQueueRequest().withQueueName(sqsQueueName)
            .withAttributes(Collections.singletonMap("MessageRetentionPeriod", "60")) // 60s message retention
    ).getQueueUrl();//from   www .j  ava2 s. c  o  m
    log.info("Created Temporary S3 Notification Queue: {}", value("queue", sqsQueueUrl));

    String snsTopicSubscriptionArn = amazonSNS.subscribe(snsTopicArn, "sqs", sqsQueueArn).getSubscriptionArn();

    Statement snsStatement = new Statement(Statement.Effect.Allow).withActions(SQSActions.SendMessage);
    snsStatement.setPrincipals(Principal.All);
    snsStatement.setResources(Collections.singletonList(new Resource(sqsQueueArn)));
    snsStatement.setConditions(Collections.singletonList(
            new Condition().withType("ArnEquals").withConditionKey("aws:SourceArn").withValues(snsTopicArn)));

    Policy allowSnsPolicy = new Policy("allow-sns", Collections.singletonList(snsStatement));

    HashMap<String, String> attributes = new HashMap<>();
    attributes.put("Policy", allowSnsPolicy.toJson());
    amazonSQS.setQueueAttributes(sqsQueueUrl, attributes);

    return new TemporaryQueue(snsTopicArn, sqsQueueArn, sqsQueueUrl, snsTopicSubscriptionArn);
}

From source file:com.netflix.spinnaker.kork.aws.pubsub.PubSubUtils.java

License:Apache License

/**
 * This policy allows messages to be sent from an SNS topic.
 */// www.ja v  a  2  s . co m
public static Policy buildSQSPolicy(ARN queue, ARN topic) {
    Statement snsStatement = new Statement(Statement.Effect.Allow).withActions(SQSActions.SendMessage);
    snsStatement.setPrincipals(Principal.All);
    snsStatement.setResources(Collections.singletonList(new Resource(queue.getArn())));
    snsStatement.setConditions(Collections.singletonList(new Condition().withType("ArnEquals")
            .withConditionKey("aws:SourceArn").withValues(topic.getArn())));

    return new Policy("allow-sns-send", Collections.singletonList(snsStatement));
}

From source file:org.finra.herd.service.helper.AwsPolicyBuilder.java

License:Apache License

public AwsPolicyBuilder() {
    policy = new Policy(null, new ArrayList<>());
}