Skip to content
This repository has been archived by the owner on Sep 15, 2023. It is now read-only.

Commit

Permalink
add dev controller that mocks endpoints not locally available
Browse files Browse the repository at this point in the history
  • Loading branch information
ubhaller committed Jul 21, 2021
1 parent 5d01262 commit 15134a1
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.ws.config;

import ch.admin.bag.covidcertificate.backend.verifier.ws.controller.dev.DevController;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import java.util.Properties;
import javax.sql.DataSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Configuration
@Profile("local")
public class WsLocalConfig {

@Bean
public DevController devController() {
return new DevController();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2021 Ubique Innovation AG <https://www.ubique.ch>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*
* SPDX-License-Identifier: MPL-2.0
*/

package ch.admin.bag.covidcertificate.backend.verifier.ws.controller.dev;

import ch.admin.bag.covidcertificate.backend.verifier.ws.utils.CacheUtil;
import ch.ubique.openapi.docannotations.Documentation;
import java.util.ArrayList;
import java.util.List;
import org.springframework.http.CacheControl;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("")
@Documentation(description = "mocks endpoints that are not available during local development")
public class DevController {

private static final String NEXT_SINCE_HEADER = "X-Next-Since";
private static final String UP_TO_DATE_HEADER = "up-to-date";

@GetMapping(value = "/v1/revocation-list")
public @ResponseBody ResponseEntity<List<String>> getMockRevokedCerts(
@RequestParam(required = false) String since) {
List<String> response = new ArrayList<>();
for (int i = 0; i < 10; i++) {
response.add("urn:uvci:01:CH:MOCK" + i);
}
return ResponseEntity.ok()
.header(NEXT_SINCE_HEADER, "1000")
.header(UP_TO_DATE_HEADER, "true")
.cacheControl(CacheControl.maxAge(CacheUtil.REVOCATION_LIST_MAX_AGE))
.body(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ ws.authentication.apiKeys.local=4d1d5663-b4ef-46a5-85b6-3d1d376429da
ws.monitor.prometheus.user=prometheus
ws.monitor.prometheus.password=prometheus

server.port=8081
server.port=8081

revocationList.baseurl=http://localhost:8081
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@ datasource.maximumPoolSize=5
datasource.maxLifetime=1700000
datasource.idleTimeout=600000
datasource.connectionTimeout=30000

revocationList.baseurl=
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ If-None-Match: "-720957702"
Authorization: Bearer {{apiKey}}

### get revocation list
GET {{baseUrl}}/v1/revocationList
GET {{baseUrl}}/v2/revocationList
Accept: application/json
If-None-Match: "1089905096"
Authorization: Bearer {{apiKey}}

### get verification rules
Expand Down

0 comments on commit 15134a1

Please sign in to comment.