Skip to content
Snippets Groups Projects
Commit c750426c authored by Mina Otgonbold's avatar Mina Otgonbold
Browse files

Add cache-control headers for an SLB specific API

parent 10f89783
No related branches found
No related tags found
2 merge requests!346Merge branch 'aws-integration' into 'master',!306Fix swagger for indexer service
Pipeline #104723 failed
...@@ -12,7 +12,75 @@ spec: ...@@ -12,7 +12,75 @@ spec:
gateways: gateways:
- istio-gateway - istio-gateway
http: http:
- match: - name: "Settings specific to the Swagger page and resources"
match:
- uri:
prefix: "/api/indexer/v2/webjars"
- uri:
prefix: "/api/indexer/v2/swagger-resources"
- uri:
prefix: "/api/indexer/v2/v3/api-docs"
- uri:
prefix: "/api/indexer/v2/swagger-ui"
route:
- destination:
host: {{ .Chart.Name }}
port:
number: 80
headers:
response:
set:
cache-control: "private, max-age=300"
corsPolicy:
maxAge: "60m"
allowCredentials: true
allowHeaders:
- Authorization
- Data-Partition-Id
- Correlation-Id
- Content-Type
- cache-control
allowMethods:
- POST
- GET
- PUT
- PATCH
- DELETE
allowOrigins:
- prefix: "*"
- name: "Settings specific to the QueryAttributeApi API"
match:
- uri:
prefix: "/api/indexer/v2/query/attributes"
route:
- destination:
host: {{ .Chart.Name }}
port:
number: 80
headers:
response:
set:
cache-control: "private, max-age=300, stale-while-revalidate=600, stale-if-error=600"
vary: "data-partition-id,authorization"
corsPolicy:
maxAge: "60m"
allowCredentials: true
allowHeaders:
- Authorization
- Data-Partition-Id
- Correlation-Id
- Content-Type
- cache-control
allowMethods:
- POST
- GET
- PUT
- PATCH
- DELETE
allowOrigins:
- prefix: "*"
- name: "Default settings, applies to everything not matched above"
match:
- uri: - uri:
prefix: "/api/indexer/v2" prefix: "/api/indexer/v2"
route: route:
...@@ -28,6 +96,7 @@ spec: ...@@ -28,6 +96,7 @@ spec:
- Data-Partition-Id - Data-Partition-Id
- Correlation-Id - Correlation-Id
- Content-Type - Content-Type
- cache-control
allowMethods: allowMethods:
- POST - POST
- GET - GET
......
...@@ -74,7 +74,7 @@ spec: ...@@ -74,7 +74,7 @@ spec:
- containerPort: 80 - containerPort: 80
readinessProbe: readinessProbe:
httpGet: httpGet:
path: /api/indexer/v2/swagger-ui.html path: /api/indexer/v2/swagger-ui/index.html
port: 80 port: 80
volumeMounts: volumeMounts:
- name: azure-keyvault - name: azure-keyvault
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
package org.opengroup.osdu.indexer.util; package org.opengroup.osdu.indexer.util;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import javax.servlet.Filter; import javax.servlet.Filter;
import javax.servlet.FilterChain; import javax.servlet.FilterChain;
import javax.servlet.FilterConfig; import javax.servlet.FilterConfig;
...@@ -10,8 +11,10 @@ import javax.servlet.ServletRequest; ...@@ -10,8 +11,10 @@ import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse; import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import lombok.extern.java.Log; import lombok.extern.java.Log;
import org.opengroup.osdu.core.common.http.ResponseHeadersFactory;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.common.model.http.DpsHeaders;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@Log @Log
...@@ -19,6 +22,11 @@ import org.springframework.stereotype.Component; ...@@ -19,6 +22,11 @@ import org.springframework.stereotype.Component;
public class IndexerFilter implements Filter { public class IndexerFilter implements Filter {
private final DpsHeaders dpsHeaders; private final DpsHeaders dpsHeaders;
private ResponseHeadersFactory responseHeadersFactory = new ResponseHeadersFactory();
// defaults to * for any front-end, string must be comma-delimited if more than one domain
@Value("${ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS:*}")
String ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS;
@Autowired @Autowired
public IndexerFilter(DpsHeaders dpsHeaders) { public IndexerFilter(DpsHeaders dpsHeaders) {
...@@ -37,11 +45,20 @@ public class IndexerFilter implements Filter { ...@@ -37,11 +45,20 @@ public class IndexerFilter implements Filter {
HttpServletResponse httpResponse = (HttpServletResponse) servletResponse; HttpServletResponse httpResponse = (HttpServletResponse) servletResponse;
dpsHeaders.addCorrelationIdIfMissing(); dpsHeaders.addCorrelationIdIfMissing();
httpResponse.addHeader(DpsHeaders.CORRELATION_ID, dpsHeaders.getCorrelationId());
setResponseHeaders(httpResponse);
filterChain.doFilter(servletRequest, servletResponse); filterChain.doFilter(servletRequest, servletResponse);
} }
private void setResponseHeaders(HttpServletResponse httpServletResponse) {
Map<String, String> responseHeaders = responseHeadersFactory.getResponseHeaders(ACCESS_CONTROL_ALLOW_ORIGIN_DOMAINS);
for (Map.Entry<String, String> header : responseHeaders.entrySet()) {
httpServletResponse.addHeader(header.getKey(), header.getValue());
}
httpServletResponse.addHeader(DpsHeaders.CORRELATION_ID, this.dpsHeaders.getCorrelationId());
}
@Override @Override
public void destroy() { public void destroy() {
} }
......
...@@ -118,7 +118,7 @@ $ mvn spring-boot:run ...@@ -118,7 +118,7 @@ $ mvn spring-boot:run
### Test the application ### Test the application
After the service has started it should be accessible via a web browser by visiting [http://localhost:8080/swagger-ui.html](http://localhost:8080/swagger-ui.html). If the request does not fail, you can then run the integration tests. After the service has started it should be accessible via a web browser by visiting [http://localhost:8080/swagger-ui/index.html](http://localhost:8080/swagger-ui/index.html). If the request does not fail, you can then run the integration tests.
> **Note**: the integration tests for `os-indexer-azure` work by validating that records submitted to `os-storage-azure` can eventually be queried by `os-search-azure`. This only works if the messages emitted by `os-storage-azure` can be consumed by `os-indexer-queue-azure`, which will submit the indexing request to `os-indexer-azure`. > **Note**: the integration tests for `os-indexer-azure` work by validating that records submitted to `os-storage-azure` can eventually be queried by `os-search-azure`. This only works if the messages emitted by `os-storage-azure` can be consumed by `os-indexer-queue-azure`, which will submit the indexing request to `os-indexer-azure`.
> >
......
...@@ -46,7 +46,7 @@ public class AADSecurityConfig extends WebSecurityConfigurerAdapter { ...@@ -46,7 +46,7 @@ public class AADSecurityConfig extends WebSecurityConfigurerAdapter {
"/configuration/security", "/configuration/security",
"/swagger", "/swagger",
"/info", "/info",
"/swagger-ui.html", "/swagger-ui/index.html",
"/swagger-ui/**", "/swagger-ui/**",
"/webjars/**").permitAll() "/webjars/**").permitAll()
.anyRequest().authenticated() .anyRequest().authenticated()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment