use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.
the class AuditEventToGrpcAuditEventConverterTest method convertUnknownActorThrows.
@Test
void convertUnknownActorThrows() {
class Unknown extends ActorBase {
}
AuditEvent source = makeAuditEvent(new Unknown(), null);
assertThatThrownBy(() -> underTest.convert(source)).isInstanceOf(IllegalArgumentException.class);
}
use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.
the class AuditEventToGrpcAuditEventConverterTest method convertWithApiRequestData.
@Test
void convertWithApiRequestData() {
ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
EventData eventData = ApiRequestData.builder().withApiVersion(API_VERSION).withMutating(MUTATING).withRequestParameters(REQUEST_PARAMETERS).withUserAgent(USER_AGENT).build();
AuditEvent source = makeAuditEvent(actor, eventData);
underTest = new AuditEventToGrpcAuditEventConverter(createMockUtilizer(ApiRequestData.class), mockBuilderProvider);
underTest.convert(source);
assertGeneric();
verify(mockAuditEventBuilderUpdater, times(1)).update(any(), any());
}
use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.
the class AuditEventToGrpcAuditEventConverterTest method convertUnknownEventDataThrows.
@Test
void convertUnknownEventDataThrows() {
ActorBase actor = ActorCrn.builder().withActorCrn(USER_CRN).build();
class Unknown extends EventData {
}
AuditEvent source = makeAuditEvent(actor, new Unknown());
assertThatThrownBy(() -> underTest.convert(source)).isInstanceOf(IllegalArgumentException.class);
}
use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.
the class AuditService method auditAutoscaleServiceEvent.
@Async
public void auditAutoscaleServiceEvent(ScalingStatus scalingStatus, String auditMessage, String clusterCrn, String accountId, Long timestamp) {
AuditEvent event = null;
try {
Map<String, Object> eventDetails = new HashMap<>();
eventDetails.put(CLUSTER_CRN, clusterCrn);
eventDetails.put(TIMESTAMP, timestamp);
eventDetails.put(AUTOSCALE_ACTION, auditMessage);
eventDetails.put(AUTOSCALE_TRIGGER_STATUS, scalingStatus);
ServiceEventData serviceEventData = ServiceEventData.builder().withEventDetails(new Json(eventDetails).getValue()).withVersion(periscopeVersion).build();
event = AuditEvent.builder().withAccountId(accountId).withEventData(serviceEventData).withEventName(AuditEventName.AUTOSCALE_DATAHUB_CLUSTER).withEventSource(Crn.Service.DATAHUB).withActor(ActorService.builder().withActorServiceName(Crn.Service.DATAHUB.getName()).build()).build();
auditClient.createAuditEvent(event);
} catch (Exception ex) {
LOGGER.warn("Service Audit event creation failed, error : '{}', event : '{}'", ex.getMessage(), event, ex);
}
}
use of com.sequenceiq.cloudbreak.audit.model.AuditEvent in project cloudbreak by hortonworks.
the class AuditServiceTest method testAuditRestEvent.
@Test
public void testAuditRestEvent() {
Map requestParams = Map.of("param1", "param2");
String userCrn = "crn:altus:iam:us-west-1:05681f13-41fc-4b2a-9588-a78d640f3c23:user:5f03bc0d-83d5-40c3-8624-f7b21481c1f7";
underTest.auditRestApi(requestParams, true, "user-agent", userCrn, "user-account", "127.0.0.1");
ArgumentCaptor<AuditEvent> captor = ArgumentCaptor.forClass(AuditEvent.class);
verify(auditClient, times(1)).createAuditEvent(captor.capture());
AuditEvent auditEvent = captor.getValue();
assertEquals("user-account", auditEvent.getAccountId());
assertEquals("127.0.0.1", auditEvent.getSourceIp());
assertEquals(MANAGE_AUTOSCALE_DATAHUB_CLUSTER, auditEvent.getEventName());
assertEquals(Crn.Service.DATAHUB, auditEvent.getEventSource());
assertEquals(userCrn, ((ActorCrn) auditEvent.getActor()).getActorCrn());
ApiRequestData apiRequestData = (ApiRequestData) auditEvent.getEventData();
assertEquals(new Gson().toJson(requestParams), apiRequestData.getRequestParameters());
assertEquals("user-agent", apiRequestData.getUserAgent());
assertEquals(true, apiRequestData.isMutating());
}
Aggregations