ref: 69d101a4a0048201d502b4a0fd8cf7158cfa6e37
src/main/java/net/lulli/certsigner/service/CertificateSigningService.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
/* * This file is part of cert-signer * Copyright (c) 2024 Paolo Lulli. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 3. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ package net.lulli.certsigner.service; import net.lulli.certsigner.network.VaultLocal; import net.lulli.certsigner.strategy.vault.VaultSigningStrategy; import java.util.HashMap; import java.util.Map; import java.util.Objects; public class CertificateSigningService { private static String vaultEndpoint = System.getenv("VAULT_ENDPOINT"); private static String vaultToken = System.getenv("VAULT_TOKEN"); public static final String VAULT_CERTIFICATES_PATH = "certificates"; public static final String VAULT_CSR_PATH = "csr"; private final String serviceName; private final VaultLocal vaultLocal; public CertificateSigningService(String serviceName) { Objects.requireNonNull(serviceName); this.serviceName = serviceName; this.vaultLocal = new VaultLocal(vaultEndpoint, vaultToken); } public String sign(String clientName, String base64Csr) { Map map = new HashMap<>(); map.put("csr", base64Csr); vaultLocal.storeSecret(VAULT_CSR_PATH + "/" + serviceName + "/" + clientName, map); var signingStrategy = new VaultSigningStrategy(serviceName); return signingStrategy.sign(clientName); } } |