46 lines
1.5 KiB
Java
46 lines
1.5 KiB
Java
package eu.sekunity.riot.config;
|
||
|
||
import eu.sekunity.riot.core.EuRouting;
|
||
import lombok.Builder;
|
||
import lombok.NonNull;
|
||
import lombok.Value;
|
||
|
||
/**
|
||
* © Copyright 05.02.2026 - 15:46 – Urheberrechtshinweis Alle Inhalte dieser Software, insbesondere der Quellcode, sind
|
||
* urheberrechtlich geschützt. Das Urheberrecht liegt, soweit nicht ausdrücklich anders gekennzeichnet, bei @author
|
||
* Sekuramis | Jannik. Bitte fragen Sie mich, falls Sie die Inhalte dieser Software verwenden möchten. Diese Software
|
||
* kann soweit möglich, als API von anderen Entwicklern verwendet werden. Wer gegen das Urheberrecht verstößt (z.B.
|
||
* Quellcode unerlaubt kopiert), macht sich gem. §§ 106 ff. UrhG strafbar und wird zudem kostenpflichtig abgemahnt und
|
||
* muss Schadensersatz leisten (§ 97 UrhG).
|
||
*/
|
||
@Value
|
||
@Builder
|
||
public class RiotApiConfig {
|
||
|
||
@NonNull String apiKey;
|
||
@NonNull
|
||
EuRouting routing;
|
||
|
||
@Builder.Default int timeoutMillis = 10_000;
|
||
@Builder.Default int maxRetriesOn429 = 2;
|
||
|
||
public static RiotApiConfig fromYaml(RiotYamlConfig yaml) {
|
||
if (yaml == null || yaml.getRiot() == null) {
|
||
throw new IllegalStateException("Missing 'riot' section in config.yml");
|
||
}
|
||
|
||
var r = yaml.getRiot();
|
||
|
||
if (r.getApiKey() == null || r.getApiKey().isBlank()) {
|
||
throw new IllegalStateException("riot.api-key is missing in config.yml");
|
||
}
|
||
|
||
return RiotApiConfig.builder()
|
||
.apiKey(r.getApiKey())
|
||
.routing(EuRouting.valueOf(r.getRegion().toUpperCase()))
|
||
.timeoutMillis(r.getTimeoutMillis())
|
||
.maxRetriesOn429(r.getMaxRetriesOn429())
|
||
.build();
|
||
}
|
||
}
|