Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.api.integration.certificates;
import java.util.List;
import java.util.Optional;
/**
* This holds information about an application's endpoint certificate.
*
* @author andreer
*/
public record EndpointCertificate(String keyName, String certName, int version, long lastRequested,
String rootRequestId, // The id of the first request made for this certificate. Should not change.
Optional leafRequestId, // The id of the last known request made for this certificate. Changes on refresh, may be outdated!
List requestedDnsSans, String issuer, Optional expiry,
Optional lastRefreshed, Optional generatedId) {
public EndpointCertificate withGeneratedId(String generatedId) {
return new EndpointCertificate(
this.keyName,
this.certName,
this.version,
this.lastRequested,
this.rootRequestId,
this.leafRequestId,
this.requestedDnsSans,
this.issuer,
this.expiry,
this.lastRefreshed,
Optional.of(generatedId));
}
public EndpointCertificate withKeyName(String keyName) {
return new EndpointCertificate(
keyName,
this.certName,
this.version,
this.lastRequested,
this.rootRequestId,
this.leafRequestId,
this.requestedDnsSans,
this.issuer,
this.expiry,
this.lastRefreshed,
this.generatedId);
}
public EndpointCertificate withCertName(String certName) {
return new EndpointCertificate(
this.keyName,
certName,
this.version,
this.lastRequested,
this.rootRequestId,
this.leafRequestId,
this.requestedDnsSans,
this.issuer,
this.expiry,
this.lastRefreshed,
this.generatedId);
}
public EndpointCertificate withVersion(int version) {
return new EndpointCertificate(
this.keyName,
this.certName,
version,
this.lastRequested,
this.rootRequestId,
this.leafRequestId,
this.requestedDnsSans,
this.issuer,
this.expiry,
this.lastRefreshed,
this.generatedId);
}
public EndpointCertificate withLastRequested(long lastRequested) {
return new EndpointCertificate(
this.keyName,
this.certName,
this.version,
lastRequested,
this.rootRequestId,
this.leafRequestId,
this.requestedDnsSans,
this.issuer,
this.expiry,
this.lastRefreshed,
this.generatedId);
}
public EndpointCertificate withLastRefreshed(long lastRefreshed) {
return new EndpointCertificate(
this.keyName,
this.certName,
this.version,
this.lastRequested,
this.rootRequestId,
this.leafRequestId,
this.requestedDnsSans,
this.issuer,
this.expiry,
Optional.of(lastRefreshed),
this.generatedId);
}
public EndpointCertificate withRootRequestId(String rootRequestId) {
return new EndpointCertificate(
this.keyName,
this.certName,
this.version,
this.lastRequested,
rootRequestId,
this.leafRequestId,
this.requestedDnsSans,
this.issuer,
this.expiry,
this.lastRefreshed,
this.generatedId);
}
public EndpointCertificate withLeafRequestId(Optional leafRequestId) {
return new EndpointCertificate(
this.keyName,
this.certName,
this.version,
this.lastRequested,
this.rootRequestId,
leafRequestId,
this.requestedDnsSans,
this.issuer,
this.expiry,
this.lastRefreshed,
this.generatedId);
}
/** Returns whether given DNS name matches any of the requested SANs in this */
public boolean sanMatches(String dnsName) {
return sanMatches(dnsName, requestedDnsSans);
}
static boolean sanMatches(String dnsName, List sanDnsNames) {
return sanDnsNames.stream().anyMatch(sanDnsName -> sanMatches(dnsName, sanDnsName));
}
private static boolean sanMatches(String dnsName, String sanDnsName) {
String[] sanNameParts = sanDnsName.split("\\.");
String[] dnsNameParts = dnsName.split("\\.");
if (sanNameParts.length != dnsNameParts.length || sanNameParts.length == 0) {
return false;
}
for (int i = 0; i < sanNameParts.length; i++) {
if (!sanNameParts[i].equals("*") && !sanNameParts[i].equals(dnsNameParts[i])) {
return false;
}
}
return true;
}
}