Skip to content

Commit

Permalink
Added Context Controller (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
slaurenz authored May 15, 2021
1 parent 867d6f3 commit 2d29157
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*-
* ---license-start
* eu-digital-green-certificates / dgca-verifier-service
* ---
* Copyright (C) 2021 T-Systems International GmbH and all other contributors
* ---
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ---license-end
*/

package eu.europa.ec.dgc.verifier.restapi.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/context")
@Slf4j
public class ContextController {

/**
* Http Method for getting the current context.
*/
@GetMapping(produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(
summary = "Provide configuration information for the verifier app",
tags = {"Configuration"},
responses = {
@ApiResponse(
responseCode = "200",
description = "Returns the current context for the verifier app.",
content = @Content(
mediaType = MediaType.APPLICATION_JSON_VALUE,
schema = @Schema(implementation = String.class)))
}
)
public ResponseEntity<String> getContext() {
Resource resource = new ClassPathResource("/static/context.jsonc");
try {
return ResponseEntity.ok(IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8));
} catch (IOException e) {
log.error("Could not read context file");
}
return ResponseEntity.ok("");
}

}
38 changes: 38 additions & 0 deletions src/main/resources/static/context.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
// Origin in ISO alpha 2 code:
"origin": "DE",
"versions": {
"default": {
// catch-all for normal versions
"privacyUrl": "https://publications.europa.eu/en/web/about-us/legal-notices/eu-mobile-apps",
"context": {
// Currently this url is empty still, subject to change:
"url": "https://dgca-verifier-service.cfapps.eu10.hana.ondemand.com/context",
"pubKeys": [
"lKdU1EbQubxyDDm2q3N8KclZ2C94Num3xXjG0pk+3eI=",
"r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="
]
},
"endpoints": {
"status": {
"url": "https://dgca-verifier-service.cfapps.eu10.hana.ondemand.com/signercertificateStatus",
"pubKeys": [
"lKdU1EbQubxyDDm2q3N8KclZ2C94Num3xXjG0pk+3eI=",
"r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="
]
},
"update": {
"url": "https://dgca-verifier-service.cfapps.eu10.hana.ondemand.com/signercertificateUpdate",
"pubKeys": [
"lKdU1EbQubxyDDm2q3N8KclZ2C94Num3xXjG0pk+3eI=",
"r/mIkG3eEpVdm+u/ko/cwxzOMo1bk4TyHIlByibiA5E="
]
}
}
},
"0.1.0": {
// Example for a version that is insecure and shouldn't start.
"outdated": true
}
}
}

0 comments on commit 2d29157

Please sign in to comment.