Skip to content

Commit

Permalink
OP-22899 Added rest api's in opsmx audit client service for account e…
Browse files Browse the repository at this point in the history
…nvironment mapping.
  • Loading branch information
sanopsmx committed Nov 29, 2024
1 parent 3ea1897 commit 00ed4ae
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 12 deletions.
2 changes: 1 addition & 1 deletion config/spinnaker.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
oes:
spinnakerVersion: "OES 1.30.1.20240300"
spinnakerVersion: "OES 1.30.1.20240300"
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import org.springframework.web.bind.annotation.ExceptionHandler
import org.springframework.web.bind.annotation.ResponseBody
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer
import org.springframework.web.servlet.config.annotation.InterceptorRegistry
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer
import org.springframework.web.servlet.handler.HandlerMappingIntrospector
Expand Down Expand Up @@ -198,4 +199,9 @@ public class GateWebConfig implements WebMvcConfigurer {
registry.addViewController("/login").setViewName("ssd-login")
}
}

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
configurer.setUseTrailingSlashMatch(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public PostConnectionConfiguringJedisConnectionFactory(
@Value("${redis.connection:redis://localhost:6379}") String connectionUri,
@Value("${redis.timeout:2000}") int timeout,
@Value(value = "${redis.certificate_location:#{null}}") String certFilePath,
@ConnectionPostProcessor Optional<ConfigureRedisAction> configureRedisAction) throws Exception {
@ConnectionPostProcessor Optional<ConfigureRedisAction> configureRedisAction)
throws Exception {

this.configureRedisAction =
configureRedisAction.orElse(new ConfigureNotifyKeyspaceEventsAction());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
*/
package com.netflix.spinnaker.gate.graphql.model;

/** @link */
/**
* @link
*/
public interface Node {

String getId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,29 @@

package com.opsmx.spinnaker.gate.controllers

import com.netflix.spinnaker.gate.config.ServiceConfiguration
import com.netflix.spinnaker.gate.exceptions.OesRequestException
import com.netflix.spinnaker.security.AuthenticatedRequest
import com.opsmx.spinnaker.gate.services.OpsmxAuditClientService
import groovy.util.logging.Slf4j
import io.swagger.v3.oas.annotations.Operation
import org.springframework.beans.factory.annotation.Autowired
import okhttp3.MultipartBody
import okhttp3.OkHttpClient
import okhttp3.Request
import okio.Buffer
import okio.BufferedSink
import okio.Okio
import okio.Source
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMethod
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import org.springframework.http.HttpHeaders
import org.springframework.web.multipart.MultipartFile
import retrofit.client.Response
import org.apache.commons.io.IOUtils
import org.springframework.http.MediaType
Expand All @@ -42,6 +54,12 @@ class OpsmxAuditClientServiceController {
@Autowired
OpsmxAuditClientService opsmxAuditClientService

@Autowired
ServiceConfiguration serviceConfiguration

@Autowired
OkHttpClient okHttpClient

@Operation(summary = "Endpoint for audit-client rest services")
@RequestMapping(value = "/{version}/{type}", method = RequestMethod.GET)
Object getAuditClientResponse1(@PathVariable("version") String version,
Expand Down Expand Up @@ -214,4 +232,86 @@ class OpsmxAuditClientServiceController {
return ResponseEntity.status(response.getStatus()).build()
}

@Operation(summary = "Rest api for audit save account environment mapping")
@RequestMapping(value = "/v3/acctEnvMapping", method = RequestMethod.POST)
Object saveAcctEnvMapping(@RequestBody Object data) {
return opsmxAuditClientService.saveAccountEnvironmentMapping(data)
}
@Operation(summary = "Rest api for updating an account environment mapping")
@RequestMapping(value = "/v3/acctEnvMapping/{id}", method = RequestMethod.PUT)
Object updateAcctEnvMapping(@PathVariable("id") Integer id, @RequestBody Object data) {
return opsmxAuditClientService.updateAccountEnvironmentMapping(id, data)
}
@Operation(summary = "Rest api for fetching all account environment mapping records")
@RequestMapping(value = "/v3/acctEnvMapping", method = RequestMethod.GET)
Object getAllAcctEnvMappings() {
return opsmxAuditClientService.getAllAccountEnvironmentMappings();
}
@Operation(summary = "Rest api for fetching account environment mapping record with id")
@RequestMapping(value = "/v3/acctEnvMapping/{id}", method = RequestMethod.GET)
Object getAcctEnvMappingWithId(@PathVariable("id") Integer id) {
return opsmxAuditClientService.getAccountEnvironmentMappingWithId(id);
}
@Operation(summary = "Rest api for deleting account environment mapping record with id")
@RequestMapping(value = "/v3/acctEnvMapping/{id}", method = RequestMethod.DELETE)
Object deleteAcctEnvMapping(@PathVariable("id") Integer id) {
return opsmxAuditClientService.deleteAccountEnvironmentMappingWithId(id);
}
@Operation(summary = "Rest api for bulk import of account environment mappings")
@RequestMapping(value = "/v3/acctEnvMapping/bulkimport", method = RequestMethod.POST, consumes = "multipart/form-data")
String bulkImportAcctEnvironmentMappings(@RequestParam("file") MultipartFile data) {
try {
return uploadToAuditService(data)
} catch (Exception e) {
throw new RuntimeException("Failed to process file: ${e.message}", e)
}
}
private String uploadToAuditService(MultipartFile data) {
def obj = AuthenticatedRequest.propagate {
def request = new Request.Builder()
.url(serviceConfiguration.getServiceEndpoint("auditclient").url +"/auditclientservice/v3/acctEnvMapping/bulkimport")
.post(uploadFileOkHttp(data))
.build()
def response = okHttpClient.newCall(request).execute()
return response
}.call() as okhttp3.Response
if (!obj.isSuccessful()) {
def error = obj.body().string();
log.error("Failed to setup the Spinnaker : {}", error)
throw new OesRequestException(error)
} else{
return obj.body()?.string() ?: "Unknown reason: " + obj.code() as Object
}
}
private okhttp3.RequestBody uploadFileOkHttp(MultipartFile multiPartfile) throws IOException {
String fileName = multiPartfile.getOriginalFilename();
MultipartBody.Builder builder = new MultipartBody.Builder();
builder.setType(MultipartBody.FORM);
builder.addFormDataPart("file", fileName, new okhttp3.RequestBody() {
@Override
public okhttp3.MediaType contentType() {
return okhttp3.MediaType.parse("application/octet-stream");
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
try {
Source source = Okio.source(multiPartfile.getInputStream());
Buffer buf = new Buffer();
long totalRead = 0;
long totalSize = multiPartfile.getSize();
long remaining = totalSize;
for (long readCount; (readCount = source.read(buf, 32000)) != -1;) {
totalRead += readCount;
remaining -= readCount;
sink.write(buf, readCount);
sink.flush();
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
return builder.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ package com.opsmx.spinnaker.gate.services
import org.springframework.web.bind.annotation.RequestParam
import retrofit.client.Response
import retrofit.http.GET
import retrofit.http.Body
import retrofit.http.DELETE
import retrofit.http.POST
import retrofit.http.PUT
import retrofit.http.Path
import retrofit.http.Query

Expand Down Expand Up @@ -133,4 +137,20 @@ interface OpsmxAuditClientService {
@Query('endTime') Long endTime,
@Query('days') Integer days,
@Query('filterBy') String filterBy)

@POST("/auditclientservice/v3/acctEnvMapping")
Object saveAccountEnvironmentMapping(@Body Object data)

@PUT("/auditclientservice/v3/acctEnvMapping/{id}")
Object updateAccountEnvironmentMapping(@Path('id') Integer id,
@Body Object data)

@GET("/auditclientservice/v3/acctEnvMapping")
Object getAllAccountEnvironmentMappings()

@GET("/auditclientservice/v3/acctEnvMapping/{id}")
Object getAccountEnvironmentMappingWithId(@Path('id') Integer id)

@DELETE("/auditclientservice/v3/acctEnvMapping/{id}")
Object deleteAccountEnvironmentMappingWithId(@Path('id') Integer id)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
@Configuration
@ConfigurationProperties("oes")
public class OESSpinnakerVersionProperties {
private String spinnakerVersion="";
private String spinnakerVersion = "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@
@RestController
@RequestMapping(value = "/oes")
public class OESSpinnakerVersionController {
@Autowired(required = false)
private OESSpinnakerVersionProperties oesSpinnakerVersionProperties;

@GetMapping(value = "/spinnakerVersion", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getOESSpinnakerVersion() {
log.debug("Get OES Spinnaker Version API invoked");
return new ResponseEntity<>(oesSpinnakerVersionProperties.getSpinnakerVersion(), HttpStatus.OK);
}
@Autowired(required = false)
private OESSpinnakerVersionProperties oesSpinnakerVersionProperties;

@GetMapping(value = "/spinnakerVersion", produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getOESSpinnakerVersion() {
log.debug("Get OES Spinnaker Version API invoked");
return new ResponseEntity<>(oesSpinnakerVersionProperties.getSpinnakerVersion(), HttpStatus.OK);
}
}

0 comments on commit 00ed4ae

Please sign in to comment.