in aws-codeguruprofiler-profilinggroup/src/main/java/software/amazon/codeguruprofiler/profilinggroup/UpdateHandler.java [58:120]
public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
AmazonWebServicesClientProxy proxy,
ResourceHandlerRequest<ResourceModel> request,
CallbackContext callbackContext,
Logger logger) {
final ResourceModel model = request.getDesiredResourceState();
final String awsAccountId = request.getAwsAccountId();
final String profilingGroupName = model.getProfilingGroupName();
final String profilingGroupArn = getResourceArnFrom(request);
Optional<List<String>> principals = principalsForAgentPermissionsFrom(model);
try {
updateTagFunction.apply(proxy, model, awsAccountId, profilingGroupArn, logger);
GetPolicyResponse getPolicyResponse = getExistingPolicy(proxy, profilingGroupName);
if (principals.isPresent()) {
putAgentPermissions(proxy, profilingGroupName, principals.get(), getPolicyResponse.revisionId());
logger.log(
String.format("Policy for [%s] for accountId [%s] has been successfully updated! actionGroup: %s, principals: %s",
profilingGroupName,
awsAccountId,
ActionGroup.AGENT_PERMISSIONS,
principals.get())
);
} else if (getPolicyResponse.policy() != null) {
removeAgentPermission(proxy, profilingGroupName, getPolicyResponse.revisionId());
logger.log(String.format("Policy for [%s] for accountId [%s] has been successfully removed!", profilingGroupName, awsAccountId));
}
Optional<List<software.amazon.codeguruprofiler.profilinggroup.Channel>> anomalyDetectionNotificationConfiguration = anomalyDetectionNotificationConfiguration(model);
if (anomalyDetectionNotificationConfiguration.isPresent()) {
updateNotificationChannels(profilingGroupName, proxy,
anomalyDetectionNotificationConfiguration.get().stream().map(channel -> {
Channel.Builder uri = Channel.builder()
.uri(channel.getChannelUri())
.eventPublishers(EventPublisher.ANOMALY_DETECTION);
// since ChannelId is an optional param, check here to avoid NPE
if (channel.getChannelId() != null) {
uri.id(channel.getChannelId());
}
return uri.build();
}).collect(Collectors.toList()));
logger.log(String.format("%s [%s] for accountId [%s] has been successfully updated!", ResourceModel.TYPE_NAME, model.getProfilingGroupName(), awsAccountId));
}
return ProgressEvent.defaultSuccessHandler(model);
} catch (ConflictException e) {
throw new CfnAlreadyExistsException(e);
} catch (InternalServerException e) {
throw new CfnServiceInternalErrorException(e);
} catch (ResourceNotFoundException e) {
throw new CfnNotFoundException(e);
} catch (ThrottlingException e) {
throw new CfnThrottlingException(e);
} catch (ValidationException e) {
throw new CfnInvalidRequestException(ResourceModel.TYPE_NAME + e.getMessage(), e);
}
}