Skip to content

Commit ed4d0db

Browse files
Apoorv JainApoorv Jain
andauthored
aws s3 bucket channel (#156)
* aws s3 bucket channel * repeated * pr comments * nit * validationg * nit --------- Co-authored-by: Apoorv Jain <apoorvjain@Apoorvs-MacBook-Pro.local>
1 parent 64f601f commit ed4d0db

2 files changed

Lines changed: 59 additions & 4 deletions

File tree

notification-channel-config-service-api/src/main/proto/org/hypertrace/notification/config/service/v1/notification_channel.proto

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,22 @@ message NotificationChannelMutableData {
1313
string channel_name = 1;
1414
repeated EmailChannelConfig email_channel_config = 2;
1515
repeated WebhookChannelConfig webhook_channel_config = 3;
16+
repeated AwsS3BucketChannelConfig s3_bucket_channel_config = 4;
1617
}
1718

19+
message AwsS3BucketChannelConfig {
20+
oneof authentication_credential {
21+
WebIdentityAuthenticationCredential web_identity_auth_credential = 1;
22+
}
23+
string bucket_name = 2;
24+
string region = 3;
25+
26+
message WebIdentityAuthenticationCredential {
27+
string role_arn = 1;
28+
}
29+
}
30+
31+
1832
enum WebhookFormat {
1933
WEBHOOK_FORMAT_UNSPECIFIED = 0;
2034
WEBHOOK_FORMAT_SLACK = 1;

notification-channel-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationChannelConfigServiceRequestValidator.java

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@
55

66
import io.grpc.Status;
77
import org.hypertrace.core.grpcutils.context.RequestContext;
8+
import org.hypertrace.notification.config.service.v1.AwsS3BucketChannelConfig;
9+
import org.hypertrace.notification.config.service.v1.AwsS3BucketChannelConfig.WebIdentityAuthenticationCredential;
810
import org.hypertrace.notification.config.service.v1.CreateNotificationChannelRequest;
911
import org.hypertrace.notification.config.service.v1.DeleteNotificationChannelRequest;
12+
import org.hypertrace.notification.config.service.v1.EmailChannelConfig;
1013
import org.hypertrace.notification.config.service.v1.GetAllNotificationChannelsRequest;
1114
import org.hypertrace.notification.config.service.v1.GetNotificationChannelRequest;
1215
import org.hypertrace.notification.config.service.v1.NotificationChannelMutableData;
1316
import org.hypertrace.notification.config.service.v1.UpdateNotificationChannelRequest;
17+
import org.hypertrace.notification.config.service.v1.WebhookChannelConfig;
18+
import org.hypertrace.notification.config.service.v1.WebhookHeader;
1419

1520
public class NotificationChannelConfigServiceRequestValidator {
1621

@@ -30,11 +35,14 @@ public void validateUpdateNotificationChannelRequest(
3035
private void validateNotificationChannelMutableData(NotificationChannelMutableData data) {
3136
validateNonDefaultPresenceOrThrow(
3237
data, NotificationChannelMutableData.CHANNEL_NAME_FIELD_NUMBER);
33-
if (data.getEmailChannelConfigCount() == 0 && data.getWebhookChannelConfigCount() == 0) {
34-
throw Status.INVALID_ARGUMENT
35-
.withDescription("Either email or webhook config should be present")
36-
.asRuntimeException();
38+
if (data.getEmailChannelConfigCount() == 0
39+
&& data.getWebhookChannelConfigCount() == 0
40+
&& data.getS3BucketChannelConfigCount() == 0) {
41+
throw Status.INVALID_ARGUMENT.withDescription("No config present").asRuntimeException();
3742
}
43+
data.getEmailChannelConfigList().forEach(this::validateEmailChannelConfig);
44+
data.getWebhookChannelConfigList().forEach(this::validateWebhookChannelConfig);
45+
data.getS3BucketChannelConfigList().forEach(this::validateS3BucketConfig);
3846
}
3947

4048
public void validateGetAllNotificationChannelsRequest(
@@ -55,4 +63,37 @@ public void validateGetNotificationChannelRequest(
5563
validateNonDefaultPresenceOrThrow(
5664
request, GetNotificationChannelRequest.NOTIFICATION_CHANNEL_ID_FIELD_NUMBER);
5765
}
66+
67+
private void validateEmailChannelConfig(EmailChannelConfig emailChannelConfig) {
68+
validateNonDefaultPresenceOrThrow(emailChannelConfig, EmailChannelConfig.ADDRESS_FIELD_NUMBER);
69+
}
70+
71+
private void validateWebhookChannelConfig(WebhookChannelConfig webhookChannelConfig) {
72+
validateNonDefaultPresenceOrThrow(webhookChannelConfig, WebhookChannelConfig.URL_FIELD_NUMBER);
73+
validateNonDefaultPresenceOrThrow(
74+
webhookChannelConfig, WebhookChannelConfig.FORMAT_FIELD_NUMBER);
75+
webhookChannelConfig.getHeadersList().forEach(this::validateWebhookHeader);
76+
}
77+
78+
private void validateS3BucketConfig(AwsS3BucketChannelConfig awsS3BucketChannelConfig) {
79+
validateNonDefaultPresenceOrThrow(
80+
awsS3BucketChannelConfig, AwsS3BucketChannelConfig.BUCKET_NAME_FIELD_NUMBER);
81+
validateNonDefaultPresenceOrThrow(
82+
awsS3BucketChannelConfig, AwsS3BucketChannelConfig.REGION_FIELD_NUMBER);
83+
switch (awsS3BucketChannelConfig.getAuthenticationCredentialCase()) {
84+
case WEB_IDENTITY_AUTH_CREDENTIAL:
85+
validateNonDefaultPresenceOrThrow(
86+
awsS3BucketChannelConfig.getWebIdentityAuthCredential(),
87+
WebIdentityAuthenticationCredential.ROLE_ARN_FIELD_NUMBER);
88+
break;
89+
default:
90+
throw Status.INVALID_ARGUMENT
91+
.withDescription("No credentials present in AWS S3 bucket config")
92+
.asRuntimeException();
93+
}
94+
}
95+
96+
private void validateWebhookHeader(WebhookHeader webhookHeader) {
97+
validateNonDefaultPresenceOrThrow(webhookHeader, WebhookHeader.NAME_FIELD_NUMBER);
98+
}
5899
}

0 commit comments

Comments
 (0)