From 1e55df1b9d5979a1b9df540c8db14163437e4058 Mon Sep 17 00:00:00 2001 From: Vivek <93896133+vivek-opsmx@users.noreply.github.com> Date: Tue, 3 Sep 2024 10:20:20 +0530 Subject: [PATCH] Added Gate end point for Notification alert service (#479) * Added Gate end point for Notification alert service * added port number and edited changes related to notification controller and service class * added id for put api call * corrected config name * corrected config name * corrected config name in gate config * Removed Logs and Print statement from the code --- docker_build/gate.yml | 3 + .../spinnaker/gate/config/GateConfig.groovy | 7 +- .../OpsmxNotificationsAlertController.groovy | 70 +++++++++++++++++++ .../OpsmxNotificationsAlertservice.groovy | 39 +++++++++++ 4 files changed, 118 insertions(+), 1 deletion(-) create mode 100644 gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxNotificationsAlertController.groovy create mode 100644 gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxNotificationsAlertservice.groovy diff --git a/docker_build/gate.yml b/docker_build/gate.yml index fa21e2814d..01e95604a2 100644 --- a/docker_build/gate.yml +++ b/docker_build/gate.yml @@ -15,6 +15,9 @@ services: visibility: baseUrl: http://localhost:8096 enabled: true + notifications: + baseUrl: http://localhost:8099 + enabled: true auditservice: baseUrl: http://localhost:8097 enabled: true diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateConfig.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateConfig.groovy index d9a4a811ab..7ca2659b65 100644 --- a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateConfig.groovy +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/config/GateConfig.groovy @@ -48,7 +48,6 @@ import com.opsmx.spinnaker.gate.services.OpsmxAuditClientService import com.opsmx.spinnaker.gate.services.OpsmxAuditService import groovy.transform.CompileStatic import groovy.util.logging.Slf4j -import org.apache.camel.spi.annotations.Component import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Qualifier import org.springframework.beans.factory.annotation.Value @@ -187,6 +186,12 @@ class GateConfig extends RedisHttpSessionConfiguration { createClient "clouddriver", ClouddriverService } + @Bean + @ConditionalOnProperty("services.notifications.enabled") + OpsmxNotificationsAlertservice opsmxNotificationsAlertservice(OkHttpClientProvider clientProvider) { + createClient "notifications", OpsmxNotificationsAlertservice + } + @Bean @ConditionalOnProperty("services.keel.enabled") KeelService keelService(OkHttpClientProvider clientProvider) { diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxNotificationsAlertController.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxNotificationsAlertController.groovy new file mode 100644 index 0000000000..07e9112a5d --- /dev/null +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/controllers/OpsmxNotificationsAlertController.groovy @@ -0,0 +1,70 @@ +/* + * Copyright 2024 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netflix.spinnaker.gate.controllers + +import com.netflix.spinnaker.gate.services.internal.OpsmxNotificationsAlertservice +import groovy.util.logging.Slf4j +import io.swagger.v3.oas.annotations.Operation +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestMethod +import org.springframework.web.bind.annotation.RestController + + + +@RequestMapping("/notifications") +@RestController +@Slf4j +@ConditionalOnExpression('${services.notifications.enabled:false}') +class OpsmxNotificationsAlertController { + + @Autowired + OpsmxNotificationsAlertservice opsmxNotificationsAlertservice + + @Operation(summary = "Endpoint for notification rest services") + @RequestMapping(value = "/{type}", method = RequestMethod.POST) + Object postNotificationServiceResponse1(@PathVariable("type") String type, + @RequestBody(required = false) Object data) { + return opsmxNotificationsAlertservice.postNotificationServiceResponse1(type, data) + } + + @Operation(summary = "Endpoint for notification rest services") + @RequestMapping(value = "/{type}/{id}", method = RequestMethod.PUT) + Object putNotificationServiceResponse1(@PathVariable("type") String type, + @PathVariable("id") String id, + @RequestBody(required = false) Object data) { + return opsmxNotificationsAlertservice.putNotificationServiceResponse2(type,id, data) + } + + @Operation(summary = "Endpoint for notification services") + @RequestMapping(value = "/{type}", method = RequestMethod.GET) + Object getNotificationServiceResponse1(@PathVariable("type") String type) { + return opsmxNotificationsAlertservice.getNotificationServiceResponse3(type) + } + + @Operation(summary = "Endpoint for notification rest services") + @RequestMapping(value = "/{type}/{id}", method = RequestMethod.DELETE) + Object deleteNotificationServiceResponse1(@PathVariable("type") String type, + @PathVariable("id") String id) { + return opsmxNotificationsAlertservice.deleteNotificationServiceResponse4(type,id) + } + + +} diff --git a/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxNotificationsAlertservice.groovy b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxNotificationsAlertservice.groovy new file mode 100644 index 0000000000..192b91155f --- /dev/null +++ b/gate-web/src/main/groovy/com/netflix/spinnaker/gate/services/internal/OpsmxNotificationsAlertservice.groovy @@ -0,0 +1,39 @@ +/* + * Copyright 2024 Netflix, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.netflix.spinnaker.gate.services.internal + +import retrofit.http.* + +interface OpsmxNotificationsAlertservice { + + @POST("/notifications/{type}") + Object postNotificationServiceResponse1(@Path('type') String type, + @Body Object data) + + @PUT("/notifications/{type}/{id}") + Object putNotificationServiceResponse2(@Path('type') String type, + @Path('id') String id, + @Body Object data) + + @GET("/notifications/{type}") + Object getNotificationServiceResponse3(@Path('type') String type) + + @DELETE("/notifications/{type}/{id}") + Object deleteNotificationServiceResponse4(@Path('type') String type, + @Path('id') String id) + +}