-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IM-457 Revert "Revert "Merge pull request #216 from integratedmodelli…
…ng/IM-457-Merge-develop-in-IM-384""
- Loading branch information
1 parent
861ab72
commit 4009ad0
Showing
140 changed files
with
3,767 additions
and
3,003 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
...tegratedmodelling.klab.api/src/org/integratedmodelling/klab/api/auth/KlabHttpHeaders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.integratedmodelling.klab.api.auth; | ||
|
||
/** | ||
* Defines constants for common HTTP headers. | ||
* | ||
* <p>This interface provides a set of predefined header names used | ||
* in HTTP requests and responses. These constants can be used to | ||
* avoid hardcoding string values and reduce errors.</p> | ||
* | ||
* @author Kristina | ||
*/ | ||
|
||
public interface KlabHttpHeaders { | ||
|
||
/** | ||
* Designed to send session information with requests. | ||
**/ | ||
public static final String KLAB_AUTHORIZATION = "klab-authorization"; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
klab.engine/src/main/java/org/integratedmodelling/klab/engine/rest/api/EngineProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.integratedmodelling.klab.engine.rest.api; | ||
|
||
import javax.validation.constraints.NotEmpty; | ||
|
||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.validation.annotation.Validated; | ||
|
||
@Component | ||
@ConfigurationProperties("engine") | ||
public class EngineProperties { | ||
|
||
public EnvProperties env; | ||
|
||
public EnvProperties getEnv() { | ||
return env; | ||
} | ||
|
||
public void setEnv(EnvProperties env) { | ||
this.env = env; | ||
} | ||
|
||
@Validated | ||
public static class EnvProperties { | ||
|
||
@NotEmpty | ||
private String appBaseUrl; | ||
|
||
@NotEmpty | ||
private String keycloakUrl; | ||
|
||
public String getAppBaseUrl() { | ||
return appBaseUrl; | ||
} | ||
|
||
public void setAppBaseUrl(String appBaseUrl) { | ||
this.appBaseUrl = appBaseUrl; | ||
} | ||
|
||
public String getKeycloakUrl() { | ||
return keycloakUrl; | ||
} | ||
|
||
public void setKeycloakUrl(String keycloakUrl) { | ||
this.keycloakUrl = keycloakUrl; | ||
} | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...java/org/integratedmodelling/klab/engine/rest/controllers/base/EnvironmentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.integratedmodelling.klab.engine.rest.controllers.base; | ||
|
||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
import java.util.stream.Collectors; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import org.integratedmodelling.klab.engine.rest.api.EngineProperties; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
@RestController | ||
public class EnvironmentController { | ||
|
||
@Autowired | ||
private EngineProperties engineProperties; | ||
|
||
private static final String APP_BASE_URL = "APP_BASE_URL"; | ||
private static final String KEYCLOAK_URL = "KEYCLOAK_URL"; | ||
private static final String ACTIVE_PROFILE = "ACTIVE_PROFILE"; | ||
|
||
private static final String ENGINE_REMOTE = "engine.remote"; | ||
private static final String ENGINE_LOCAL = "engine.local"; | ||
|
||
@GetMapping(value = "/engine/environments") | ||
public void getEnvironmentVariables(HttpServletRequest request, HttpServletResponse response) throws IOException { | ||
|
||
response.setContentType("text/javascript;utf-8"); | ||
|
||
List<String> activeProfiles = Pattern.compile(",").splitAsStream(System.getProperty("spring.profiles.active", "unknown")) | ||
.collect(Collectors.toList()); | ||
|
||
String activeProfile = activeProfiles.contains(ENGINE_REMOTE) ? ENGINE_REMOTE : ENGINE_LOCAL; | ||
|
||
/* | ||
* Get engine properties | ||
*/ | ||
Map<String, String> kHubEnvironmentVariables = new HashMap<>(); | ||
|
||
if (activeProfile.equals(ENGINE_REMOTE)) { | ||
kHubEnvironmentVariables = Map.ofEntries(Map.entry(APP_BASE_URL, engineProperties.env.getAppBaseUrl()), | ||
Map.entry(KEYCLOAK_URL, engineProperties.env.getKeycloakUrl()), Map.entry(ACTIVE_PROFILE, activeProfile)); | ||
} else { | ||
kHubEnvironmentVariables = Map.ofEntries(Map.entry(ACTIVE_PROFILE, activeProfile)); | ||
} | ||
|
||
ObjectMapper objectMapper = new ObjectMapper(); | ||
String jsonValue = objectMapper.writeValueAsString(kHubEnvironmentVariables); | ||
|
||
System.out.println(jsonValue); | ||
|
||
response.getWriter().append("var __ENV__= " + jsonValue + ";"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.