Search in sources :

Example 1 with ZmsException

use of com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException 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 ZmsException

use of com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException in project vespa by vespa-engine.

the class ApplicationApiHandler method createApplication.

private HttpResponse createApplication(String tenantName, String applicationName, HttpRequest request) {
    Application application;
    try {
        application = controller.applications().createApplication(ApplicationId.from(tenantName, applicationName, "default"), getUserPrincipal(request).getNToken());
    } catch (ZmsException e) {
        // TODO: Push conversion down
        if (e.getCode() == com.yahoo.jdisc.Response.Status.FORBIDDEN)
            throw new ForbiddenException("Not authorized to create application", e);
        else
            throw e;
    }
    Slime slime = new Slime();
    toSlime(application, slime.setObject(), request);
    return new SlimeJsonResponse(slime);
}
Also used : ForbiddenException(javax.ws.rs.ForbiddenException) SlimeJsonResponse(com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse) ZmsException(com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException) Slime(com.yahoo.slime.Slime) Application(com.yahoo.vespa.hosted.controller.Application)

Example 3 with ZmsException

use of com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException 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

ZmsException (com.yahoo.vespa.hosted.controller.api.integration.athenz.ZmsException)3 AthenzPublicKey (com.yahoo.vespa.athenz.api.AthenzPublicKey)2 Slime (com.yahoo.slime.Slime)1 Application (com.yahoo.vespa.hosted.controller.Application)1 SlimeJsonResponse (com.yahoo.vespa.hosted.controller.restapi.SlimeJsonResponse)1 ForbiddenException (javax.ws.rs.ForbiddenException)1