Skip to content

Commit

Permalink
Merge pull request #11 from RWS/add_regionalBaseUrls
Browse files Browse the repository at this point in the history
Add regional base urls
  • Loading branch information
mdipsan authored Nov 21, 2024
2 parents 2570f47 + 3bee01b commit 6f4028d
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,23 @@ public IActionResult Descriptor()
// TODO: You might need to change the baseUrl in appsettings.json
descriptor["baseUrl"] = _configuration["baseUrl"];

if (_configuration.GetValue<bool>("multiRegion:enabled"))
{
descriptor["regionalBaseUrls"] = new JsonObject();

string euBaseUrl = _configuration.GetValue<string>("multiRegion:regionalBaseUrls:eu");
string caBaseUrl = _configuration.GetValue<string>("multiRegion:regionalBaseUrls:ca");

if (!string.IsNullOrEmpty(euBaseUrl))
{
descriptor["regionalBaseUrls"]["eu"] = euBaseUrl;
}
if (!string.IsNullOrEmpty(caBaseUrl))
{
descriptor["regionalBaseUrls"]["ca"] = caBaseUrl;
}
}

return Ok(descriptor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Nodes;

namespace Rws.LC.AppBlueprint.Services
Expand All @@ -20,7 +21,7 @@ public DescriptorService()
// Reading from the descriptor.json file, the descriptor for this app.
// Customize it to represent your app behavior.
string descriptorText = File.ReadAllText("descriptor.json");
_appDescriptor = JsonNode.Parse(descriptorText);
_appDescriptor = JsonNode.Parse(descriptorText, documentOptions: new JsonDocumentOptions { CommentHandling = JsonCommentHandling.Skip });
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@
},

"baseUrl": "TODO: replace with a proper URL",
"multiRegion": {
"enabled": false,
"regionalBaseUrls": {
"eu": "TODO: replace with a proper eu URL",
"ca": "TODO: replace with a proper eu URL"
}
},

"AllowedHosts": "*",
"documentationUrl": "docUrl",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@
"email": "[email protected]"
},
"descriptorVersion": "1.4"
// will be replaced by the actual regional base URLs from appsettings.json
//"regionalBaseUrls": {
// "eu": "https://eu.api.base-url.com",
// "ca": "https://ca.api.base-url.com"
//}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package com.rws.lt.lc.blueprint.service;

import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import java.io.IOException;
Expand All @@ -18,19 +21,43 @@ public class AppMetadataService implements InitializingBean {
@Value("${baseUrl}")
private String baseUrl;

@Value("${multiRegion.enabled:false}")
private boolean isMultiRegionEnabled;

@Getter
private final ObjectNode descriptor;

private List<String> secretConfigs;

private final ObjectMapper objectMapper;

private final Environment env;

@Override
public void afterPropertiesSet() {
descriptor.put("baseUrl", baseUrl);

if (isMultiRegionEnabled) {
ObjectNode regionalBaseUrls = objectMapper.createObjectNode();
String euBaseUrl = env.getProperty("multiRegion.regionalBaseUrls.eu");
String caBaseUrl = env.getProperty("multiRegion.regionalBaseUrls.ca");

if(StringUtils.isNotEmpty(euBaseUrl)) {
regionalBaseUrls.put("eu", euBaseUrl);
}
if(StringUtils.isNotEmpty(caBaseUrl)) {
regionalBaseUrls.put("ca", caBaseUrl);
}

descriptor.put("regionalBaseUrls", regionalBaseUrls);
}
}

@Autowired
public AppMetadataService() throws IOException {
ObjectMapper objectMapper = new ObjectMapper();
public AppMetadataService(Environment environment) throws IOException {
env = environment;
objectMapper = new ObjectMapper();
objectMapper.enable(JsonParser.Feature.ALLOW_COMMENTS);
descriptor = objectMapper.readValue(getClass().getResourceAsStream("/descriptor.json"), ObjectNode.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ application:

# TODO: replace with a real URL
baseUrl: "replace-me"
multiRegion:
enabled: false
regionalBaseUrls:
eu: "replace-me-eu"
ca: "replace-me-ca"

server:
port: 5000
Expand Down

0 comments on commit 6f4028d

Please sign in to comment.