Search in sources :

Example 1 with AthenzPublicKey

use of com.yahoo.vespa.athenz.api.AthenzPublicKey in project vespa by vespa-engine.

the class ZmsKeystoreImpl method preloadKeys.

@Override
public void preloadKeys(AthenzService service) {
    try {
        log.log(LogLevel.INFO, "Downloading keys for " + service);
        List<AthenzPublicKey> publicKeys = athenzClientFactory.createZmsClientWithServicePrincipal().getPublicKeys(service);
        for (AthenzPublicKey publicKey : publicKeys) {
            FullKeyId fullKeyId = new FullKeyId(service, publicKey.getKeyId());
            log.log(LogLevel.DEBUG, "Adding key " + fullKeyId + " to the cache");
            cachedKeys.put(fullKeyId, publicKey.getPublicKey());
        }
        log.log(LogLevel.INFO, "Successfully downloaded keys for " + service);
    } catch (ZmsException e) {
        log.log(LogLevel.WARNING, "Failed to download keys for " + service + ": " + e.getMessage());
    }
}
Also used : AthenzPublicKey(com.yahoo.vespa.athenz.api.AthenzPublicKey) ZmsException(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException)

Example 2 with AthenzPublicKey

use of com.yahoo.vespa.athenz.api.AthenzPublicKey in project vespa by vespa-engine.

the class ZmsKeystoreImpl method downloadPublicKey.

private Optional<PublicKey> downloadPublicKey(FullKeyId fullKeyId) {
    try {
        log.log(LogLevel.INFO, "Downloading key " + fullKeyId);
        AthenzPublicKey publicKey = athenzClientFactory.createZmsClientWithServicePrincipal().getPublicKey(fullKeyId.service, fullKeyId.keyId);
        return Optional.of(publicKey.getPublicKey());
    } catch (ZmsException e) {
        if (e.getCode() == 404) {
            // Key does not exist
            log.log(LogLevel.INFO, "Key " + fullKeyId + " not found");
            return Optional.empty();
        }
        String msg = String.format("Unable to retrieve public key from Athens (%s): %s", fullKeyId, e.getMessage());
        throw createException(msg, e);
    }
}
Also used : AthenzPublicKey(com.yahoo.vespa.athenz.api.AthenzPublicKey) ZmsException(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException)

Aggregations

AthenzPublicKey (com.yahoo.vespa.athenz.api.AthenzPublicKey)2 ZmsException (com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException)2