Skip to content

Commit

Permalink
Api for group call
Browse files Browse the repository at this point in the history
  • Loading branch information
mscr06 committed Aug 12, 2020
1 parent 650f6da commit c2acf6a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
1 change: 1 addition & 0 deletions docker_build/gate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ services:
enabled: true
platform:
baseUrl: http://localhost:8095
groupPath: /platformservice/v1/users/{username}/userGroups/importAndCache
enabled: true
security:
basic:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,14 @@ class OpsmxPlatformController {
return opsmxPlatformService.updatePlatformResponse1(version, type, source, data)
}

@ApiOperation(value = "Endpoint for platform rest services")
@RequestMapping(value = "/{version}/{type}/{source}/{source1}/{source2}", method = RequestMethod.PUT)
Object updatePlatformResponse2(@PathVariable("version") String version,
@PathVariable("type") String type,
@PathVariable("source") String source,
@PathVariable("source1") String source1,
@PathVariable("source2") String source2) {

return opsmxPlatformService.updatePlatformResponse2(version, type, source, source1, source2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ import com.netflix.spinnaker.gate.config.AuthenticationRequest
import com.netflix.spinnaker.gate.config.AuthenticationResponse
import com.netflix.spinnaker.gate.config.JwtUtil
import com.netflix.spinnaker.gate.services.UserDataService
import com.netflix.spinnaker.gate.util.OesRestApi
import io.swagger.annotations.ApiOperation
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
import org.springframework.security.authentication.AuthenticationManager
import org.springframework.security.authentication.BadCredentialsException
Expand All @@ -30,6 +33,15 @@ class TokenAuthController {
@Autowired
AuthenticationManager authenticationManager

@Value('${services.platform.enabled:false}')
boolean isPlatformEnabled;

@Value('${services.platform.baseUrl:null}')
String url;

@Value('${services.platform.groupPath:null}')
String apiPath;

@ApiOperation(value = "New Login for Jwt")
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ResponseEntity<?> authenticateUser(@RequestBody AuthenticationRequest authenticationRequest ) {
Expand All @@ -45,9 +57,21 @@ class TokenAuthController {

final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername());

final String jwt = jwtTokenUtil.generateToken(userDetails);

return ResponseEntity.ok(new AuthenticationResponse(jwt));
if (isPlatformEnabled) {
String path = apiPath.replace("{username}",userDetails.getUsername());
boolean isSuccessful = OesRestApi.initiateUserGroupInPlatform(url+path);
if (isSuccessful) {
final String jwt = jwtTokenUtil.generateToken(userDetails);
return ResponseEntity.ok(new AuthenticationResponse(jwt));
}
else {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
else {
final String jwt = jwtTokenUtil.generateToken(userDetails);
return ResponseEntity.ok(new AuthenticationResponse(jwt));
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,11 @@ interface OpsmxPlatformService {
@Path('source') String source,
@Body Object data)

@PUT("/platformservice/{version}/{type}/{source}/{source1}/{source2}")
Object updatePlatformResponse2(@Path('version') String version,
@Path('type') String type,
@Path('source') String source,
@Path('source1') String source1,
@Path('source2') String source2)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.netflix.spinnaker.gate.util;

import java.io.IOException;
import okhttp3.*;

public class OesRestApi {
private static OkHttpClient httpClient = new OkHttpClient();

public static boolean initiateUserGroupInPlatform(String url) throws IOException {
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
RequestBody body = RequestBody.create(JSON, "");
Request request = new Request.Builder().url(url).put(body).build();

try (Response response = httpClient.newCall(request).execute()) {
return response.isSuccessful();
}
}
}

0 comments on commit c2acf6a

Please sign in to comment.