Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ dependencies {
implementation "io.springfox:springfox-swagger-ui:3.0.0"
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
implementation 'org.springframework.boot:spring-boot-starter-validation'

// iexec
implementation "com.iexec.common:iexec-common:$iexecCommonVersion"
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
version=0.1.1-NEXT-SNAPSHOT
iexecCommonVersion=5.6.0
iexecCommonVersion=5.7.0-NEXT-SNAPSHOT
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2021 IEXEC BLOCKCHAIN TECH
*
* 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.
*/

package com.iexec.blockchain.config;

import com.iexec.blockchain.tool.ChainConfig;
import com.iexec.common.config.PublicChainConfig;
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;

import java.time.Duration;

@RestController
@RequestMapping("/config")
public class PublicConfigurationController {
private final ChainConfig chainConfig;

public PublicConfigurationController(ChainConfig chainConfig) {
this.chainConfig = chainConfig;
}

/**
* Unauthenticated endpoint.
*/
@GetMapping("/chain")
public ResponseEntity<PublicChainConfig> getPublicChainConfig() {
final Integer blockTime = chainConfig.getBlockTime();
final PublicChainConfig publicChainConfig = PublicChainConfig
.builder()
.blockTime(Duration.ofSeconds(blockTime))
.build();
return ResponseEntity.ok(publicChainConfig);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ protected void configure(HttpSecurity http) throws Exception {
"/swagger-ui.html",
"/swagger-ui/**",
"/webjars/**").anonymous() // <--- END Anonymous swagger access
.antMatchers("/config/chain").anonymous()
.anyRequest().authenticated()
.and()
.httpBasic();
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/com/iexec/blockchain/tool/ChainConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@

package com.iexec.blockchain.tool;

import lombok.AllArgsConstructor;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

import javax.annotation.PostConstruct;
import javax.validation.ConstraintViolationException;
import javax.validation.Validator;
import javax.validation.constraints.Positive;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class ChainConfig {

@Value("${chain.id}")
Expand All @@ -35,6 +38,7 @@ public class ChainConfig {
private String nodeAddress;

@Value("${chain.block-time}")
@Positive(message = "Block time should be positive")
private Integer blockTime;

@Value("${chain.hub-address}")
Expand All @@ -52,4 +56,17 @@ public class ChainConfig {
@Value("${chain.broker-url}")
private String brokerUrl;

@Getter(AccessLevel.NONE) // no getter
private Validator validator;

public ChainConfig(Validator validator) {
this.validator = validator;
}

@PostConstruct
private void validate() {
if (!validator.validate(this).isEmpty()) {
throw new ConstraintViolationException(validator.validate(this));
}
}
}