Beispiel #1
0
 protected CloudTrailEvent getMockedEvent() {
   CloudTrailEvent event = Mockito.mock(CloudTrailEvent.class);
   CloudTrailEventData eventData = Mockito.mock(CloudTrailEventData.class);
   Mockito.when(event.getEventData()).thenReturn(eventData);
   Mockito.when(eventData.getEventSource()).thenReturn("ec2.amazonaws.com");
   Mockito.when(eventData.getEventName()).thenReturn("RunInstances");
   return event;
 }
Beispiel #2
0
  /** We use this as a filter for events. */
  @Override
  public boolean supports(final CloudTrailEvent event) {
    CloudTrailEventData eventData = event.getEventData();

    String eventSource = eventData.getEventSource();
    String eventName = eventData.getEventName();

    return eventSource.equals(EC2_EVENTS) && eventName.startsWith(DELETE);
  }
Beispiel #3
0
  @Override
  // @HystrixCommand(fallback = my coole exception)
  // command for account id and client type -> generate new credentials
  public void processEvent(final CloudTrailEvent event) {

    String parameters = event.getEventData().getRequestParameters();
    String instanceId = getFromParameters(parameters);

    AmazonEC2Client client =
        getClientForAccount(
            event.getEventData().getUserIdentity().getAccountId(),
            Region.getRegion(Regions.fromName(event.getEventData().getAwsRegion())));

    DescribeInstancesRequest request = new DescribeInstancesRequest();
    request.setInstanceIds(Collections.singleton(instanceId));

    // try
    DescribeInstancesResult result = client.describeInstances(request);
    // catch credentials are old
    // throw new my coole exception ( account id, CLIENTTYPE.EC2, exception) -> this will trigger
    // hystrix

    LOG.info("SAVING RESULT INTO MAGIC DB", result);
  }