Skip to content

Commit

Permalink
Merge pull request #47 from shreelakshmijoshi/make-server-items-confi…
Browse files Browse the repository at this point in the history
…gurable

Make server items configurable
  • Loading branch information
kailash authored Mar 17, 2023
2 parents 81d4215 + bfc735d commit b13e6ba
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 38 deletions.
4 changes: 3 additions & 1 deletion docs/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ info:
- **Base path**:
- Base path is the path on which API is served, relative to the host
- It is the initial part of the API
- The base path value could be configured according to the deployment
- These base path values could be configured according to the deployment
- The base path for [DX AAA Server](https://github.com/datakaveri/iudx-aaa-server) is set to `/auth/v1`
- The base path for [DX Catalogue Server](https://github.com/datakaveri/iudx-catalogue-server) is set to `/iudx/cat/v1`
Currently, the following APIs have `/ngsi-ld/v1` base path
- /entities
- /temporal/entities
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/iudx/rs/proxy/apiserver/ApiServerVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ public class ApiServerVerticle extends AbstractVerticle {
private DatabaseService databaseService;
private MeteringService meteringService;
private DatabrokerService brokerService;

private String dxCatalogueBasePath;
private String dxAuthBasePath;
private String dxApiBasePath;

@Override
Expand All @@ -97,8 +98,11 @@ public void start() throws Exception {
meteringService = MeteringService.createProxy(vertx, METERING_SERVICE_ADDRESS);
brokerService = DatabrokerService.createProxy(vertx, DATABROKER_SERVICE_ADDRESS);
validator = new ParamsValidator(catalogueService);


/* Get base paths from config */
dxApiBasePath=config().getString("dxApiBasePath");
dxCatalogueBasePath = config().getString("dxCatalogueBasePath");
dxAuthBasePath = config().getString("dxAuthBasePath");
Api apis=Api.getInstance(dxApiBasePath);

router = Router.router(vertx);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package iudx.rs.proxy.apiserver.service;

import static iudx.rs.proxy.apiserver.util.Util.toList;
import static iudx.rs.proxy.authenticator.Constants.CAT_ITEM_PATH;
import static iudx.rs.proxy.authenticator.Constants.CAT_SEARCH_PATH;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
Expand Down Expand Up @@ -36,8 +38,9 @@ public class CatalogueService {
private long cacheTimerid;
private static String catHost;
private static int catPort;;
private static String catSearchPath;
private static String catItemPath;
private String catBasePath;
private String catItemPath;
private String catSearchPath;
private Vertx vertx;

private final Cache<String, List<String>> applicableFilterCache =
Expand All @@ -48,8 +51,9 @@ public CatalogueService(Vertx vertx, JsonObject config) {
this.vertx = vertx;
catHost = config.getString("catServerHost");
catPort = config.getInteger("catServerPort");
catSearchPath = Constants.CAT_RSG_PATH;
catItemPath = Constants.CAT_ITEM_PATH;
catBasePath = config.getString("dxCatalogueBasePath");
catItemPath = catBasePath + CAT_ITEM_PATH;
catSearchPath = catBasePath + CAT_SEARCH_PATH;

WebClientOptions options =
new WebClientOptions().setTrustAll(true).setVerifyHost(false).setSsl(true);
Expand Down Expand Up @@ -189,8 +193,8 @@ private void callCatalogueAPI(String id, Handler<AsyncResult<List<String>>> hand
});
handler.handle(Future.succeededFuture(filters));
} else if (catHandler.failed()) {
LOGGER.error("catalogue call(/iudx/cat/v1/item) failed for id" + id);
handler.handle(Future.failedFuture("catalogue call(/iudx/cat/v1/item) failed for id" + id));
LOGGER.error("catalogue call ("+ catItemPath + ") failed for id" + id);
handler.handle(Future.failedFuture("catalogue call(" + catItemPath + ") failed for id" + id));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package iudx.rs.proxy.authenticator;

import static iudx.rs.proxy.authenticator.Constants.AUTH_CERTIFICATE_PATH;
import static iudx.rs.proxy.common.Constants.*;

import io.vertx.core.AbstractVerticle;
Expand Down Expand Up @@ -117,8 +118,9 @@ public void stop() {
private Future<String> getJwtPublicKey(Vertx vertx, JsonObject config) {
Promise<String> promise = Promise.promise();
webClient = createWebClient(vertx, config);
String authCert = config.getString("dxAuthBasePath") + AUTH_CERTIFICATE_PATH;
webClient
.get(443, config.getString("authServerHost"), "/auth/v1/cert")
.get(443, config.getString("authServerHost"), authCert)
.send(
handler -> {
if (handler.succeeded()) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/iudx/rs/proxy/authenticator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ public class Constants {

public static final List<String> OPEN_ENDPOINTS = List.of("/temporal/entities","/entities","/consumer/audit","/entityOperations/query");
public static final long CACHE_TIMEOUT_AMOUNT = 30;
public static final String CAT_RSG_PATH = "/iudx/cat/v1/search";
public static final String CAT_ITEM_PATH = "/iudx/cat/v1/item";
public static final String CAT_SEARCH_PATH = "/search";
public static final String AUTH_CERTIFICATE_PATH = "/cert";
public static final String CAT_ITEM_PATH = "/item";
public static final String JSON_USERID = "userid";
public static final String JSON_IID = "iid";
public static final String JSON_EXPIRY = "expiry";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package iudx.rs.proxy.authenticator;

import static iudx.rs.proxy.authenticator.Constants.JSON_EXPIRY;
import static iudx.rs.proxy.authenticator.Constants.JSON_IID;
import static iudx.rs.proxy.authenticator.Constants.JSON_USERID;
import static iudx.rs.proxy.authenticator.Constants.OPEN_ENDPOINTS;

import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import io.vertx.core.AsyncResult;
Expand Down Expand Up @@ -40,6 +35,8 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import static iudx.rs.proxy.authenticator.Constants.*;

public class JwtAuthenticationServiceImpl implements AuthenticationService {

private static final Logger LOGGER = LogManager.getLogger(JwtAuthenticationServiceImpl.class);
Expand All @@ -52,6 +49,7 @@ public class JwtAuthenticationServiceImpl implements AuthenticationService {
final CacheService cache;
static WebClient catWebClient;
final Api apis;
final String catBasePath;
// resourceGroupCache will contain ACL info about all resource group in a resource server
Cache<String, String> resourceGroupCache = CacheBuilder.newBuilder().maximumSize(1000)
.expireAfterAccess(Constants.CACHE_TIMEOUT_AMOUNT, TimeUnit.MINUTES).build();
Expand All @@ -67,7 +65,8 @@ public class JwtAuthenticationServiceImpl implements AuthenticationService {
this.audience = config.getString("audience");
this.host = config.getString("catServerHost");
this.port = config.getInteger("catServerPort");
this.path = Constants.CAT_RSG_PATH;
this.catBasePath = config.getString("dxCatalogueBasePath");
this.path = catBasePath + CAT_SEARCH_PATH;
this.apis=apis;
WebClientOptions options = new WebClientOptions();
options.setTrustAll(true).setVerifyHost(false).setSsl(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ static void init(Vertx vertx, VertxTestContext testContext) {
authConfig.put("host", "rs.iudx.io");
authConfig.put("catServerPort", 8080);
authConfig.put("dxApiBasePath","/ngsi-ld/v1");
authConfig.put("dxCatalogueBasePath", "/iudx/cat/v1");
authConfig.put("dxAuthBasePath", "/auth/v1");

JWTAuthOptions jwtAuthOptions = new JWTAuthOptions();
jwtAuthOptions.addPubSecKey(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@
}
},
"url": {
"raw": "https://{{auth-url}}/auth/v1/token",
"raw": "https://{{auth-url}}/{{dxAuthBasePath}}/token",
"protocol": "https",
"host": [
"{{auth-url}}"
],
"path": [
"auth",
"v1",
"{{dxAuthBasePath}}",
"token"
]
}
Expand Down Expand Up @@ -113,14 +112,13 @@
}
},
"url": {
"raw": "https://{{auth-url}}/auth/v1/token",
"raw": "https://{{auth-url}}/{{dxAuthBasePath}}/token",
"protocol": "https",
"host": [
"{{auth-url}}"
],
"path": [
"auth",
"v1",
"{{dxAuthBasePath}}",
"token"
]
}
Expand Down Expand Up @@ -191,16 +189,15 @@
}
},
"url": {
"raw": "https://authvertx.iudx.io/auth/v1/token",
"raw": "https://authvertx.iudx.io/{{dxAuthBasePath}}/token",
"protocol": "https",
"host": [
"authvertx",
"iudx",
"io"
],
"path": [
"auth",
"v1",
"{{dxAuthBasePath}}",
"token"
]
}
Expand Down Expand Up @@ -271,16 +268,15 @@
}
},
"url": {
"raw": "https://authvertx.iudx.io/auth/v1/token",
"raw": "https://authvertx.iudx.io/{{dxAuthBasePath}}/token",
"protocol": "https",
"host": [
"authvertx",
"iudx",
"io"
],
"path": [
"auth",
"v1",
"{{dxAuthBasePath}}",
"token"
]
}
Expand Down Expand Up @@ -351,16 +347,15 @@
}
},
"url": {
"raw": "https://authvertx.iudx.io/auth/v1/token",
"raw": "https://authvertx.iudx.io/{{dxAuthBasePath}}/token",
"protocol": "https",
"host": [
"authvertx",
"iudx",
"io"
],
"path": [
"auth",
"v1",
"{{dxAuthBasePath}}",
"token"
]
}
Expand Down Expand Up @@ -431,16 +426,15 @@
}
},
"url": {
"raw": "https://authvertx.iudx.io/auth/v1/token",
"raw": "https://authvertx.iudx.io/{{dxAuthBasePath}}/token",
"protocol": "https",
"host": [
"authvertx",
"iudx",
"io"
],
"path": [
"auth",
"v1",
"{{dxAuthBasePath}}",
"token"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
"value": "ngsi-ld/v1",
"enabled": true
},
{
"key": "dxAuthBasePath",
"value": "auth/v1",
"enabled": true
},
{
"key": "openResourceToken",
"value": "",
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### Making configurable base path
- Base path can be added in postman environment file or in postman.
- `IUDX-Resource-Proxy-Server-Consumer-APIs.postman_environment.postman_environment.json` has **values** array which has a fields named **basePath** whose **value** is currently set to `ngsi-ld/v1`.
- `IUDX-Resource-Proxy-Server-Consumer-APIs.postman_environment.postman_environment.json` has **values** array which has fields named **basePath** whose **value** is currently set to `ngsi-ld/v1`, **dxAuthBasePath** with value `auth/v1`.
- The **value** could be changed according to the deployment and then the collection with the `IUDX-Resource-Proxy-Server-Consumer-APIs.postman_environment.postman_environment.json` file can be uploaded to Postman
- For the changing the **basePath** value in postman after importing the collection and environment files, locate `Resource Proxy Environment` from **Environments** in sidebar of Postman application.
- For the changing the **basePath**, **dxAuthBasePath** value in postman after importing the collection and environment files, locate `Resource Proxy Environment` from **Environments** in sidebar of Postman application.
- To know more about Postman environments, refer : [postman environments](https://learning.postman.com/docs/sending-requests/managing-environments/)
- The **CURRENT VALUE** of the variable could be changed

Expand Down

0 comments on commit b13e6ba

Please sign in to comment.