package software.amazon.devopsguru.notificationchannel; import software.amazon.awssdk.services.devopsguru.DevOpsGuruClient; import software.amazon.awssdk.services.devopsguru.model.AccessDeniedException; import software.amazon.awssdk.services.devopsguru.model.InternalServerException; import software.amazon.awssdk.services.devopsguru.model.ListNotificationChannelsRequest; import software.amazon.awssdk.services.devopsguru.model.ListNotificationChannelsResponse; import software.amazon.awssdk.services.devopsguru.model.NotificationFilterConfig; import software.amazon.awssdk.services.devopsguru.model.ResourceNotFoundException; import software.amazon.awssdk.services.devopsguru.model.ThrottlingException; import software.amazon.awssdk.services.devopsguru.model.ValidationException; import software.amazon.cloudformation.exceptions.CfnAccessDeniedException; import software.amazon.cloudformation.exceptions.CfnInvalidRequestException; import software.amazon.cloudformation.exceptions.CfnNotFoundException; import software.amazon.cloudformation.exceptions.CfnServiceInternalErrorException; import software.amazon.cloudformation.exceptions.CfnThrottlingException; import software.amazon.cloudformation.proxy.AmazonWebServicesClientProxy; import software.amazon.cloudformation.proxy.Logger; import software.amazon.cloudformation.proxy.ProgressEvent; import software.amazon.cloudformation.proxy.ProxyClient; import software.amazon.cloudformation.proxy.ResourceHandlerRequest; import java.util.List; import static software.amazon.devopsguru.notificationchannel.constants.FilterConstants.INSIGHT_SEVERITIES; // Placeholder for the functionality that could be shared across Create/Read/Update/Delete/List Handlers public abstract class BaseHandlerStd extends BaseHandler { @Override public final ProgressEvent handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest request, final CallbackContext callbackContext, final Logger logger) { return handleRequest( proxy, request, callbackContext != null ? callbackContext : new CallbackContext(), proxy.newProxy(DevOpsGuruClientBuilder::getClient), logger ); } protected abstract ProgressEvent handleRequest( final AmazonWebServicesClientProxy proxy, final ResourceHandlerRequest request, final CallbackContext callbackContext, final ProxyClient proxyClient, final Logger logger); protected ListNotificationChannelsResponse listNotificationChannel( ListNotificationChannelsRequest listNotificationChannelsRequest, final ProxyClient proxyClient){ ListNotificationChannelsResponse awsResponse = null; try { awsResponse = proxyClient.injectCredentialsAndInvokeV2(listNotificationChannelsRequest, proxyClient.client()::listNotificationChannels); } catch (final AccessDeniedException e) { throw new CfnAccessDeniedException(ResourceModel.TYPE_NAME, e); } catch (final InternalServerException e) { throw new CfnServiceInternalErrorException(ResourceModel.TYPE_NAME, e); } catch (final ResourceNotFoundException e) { throw new CfnNotFoundException(ResourceModel.TYPE_NAME, listNotificationChannelsRequest.toString(), e); } catch (final ValidationException e) { throw new CfnInvalidRequestException(ResourceModel.TYPE_NAME, e); } catch (final ThrottlingException e) { throw new CfnThrottlingException(ResourceModel.TYPE_NAME, e); } return awsResponse; } protected final List processNotificationFilters(final String fieldName, final NotificationFilterConfig filters) { if (filters == null) { return null; } if (INSIGHT_SEVERITIES.equals(fieldName)) { return filters.severitiesAsStrings().isEmpty() ? null: filters.severitiesAsStrings(); } return filters.messageTypesAsStrings().isEmpty() ? null: filters.messageTypesAsStrings(); } }