All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.helidon.integrations.vault.secrets.database.DbSecretsImpl Maven / Gradle / Ivy

There is a newer version: 4.1.4
Show newest version
/*
 * Copyright (c) 2021, 2023 Oracle and/or its affiliates.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.helidon.integrations.vault.secrets.database;

import io.helidon.integrations.common.rest.RestApi;
import io.helidon.integrations.vault.ListSecrets;
import io.helidon.integrations.vault.Vault;
import io.helidon.integrations.vault.VaultOptionalResponse;

import jakarta.json.JsonObject;

class DbSecretsImpl implements DbSecrets {
    private final RestApi restApi;
    private final String mount;

    DbSecretsImpl(RestApi restApi, String mount) {
        this.restApi = restApi;
        this.mount = mount;
    }

    @Override
    public VaultOptionalResponse list(ListSecrets.Request request) {
        String apiPath = mount + "/config";

        return restApi.invokeOptional(Vault.LIST,
                apiPath,
                request,
                VaultOptionalResponse.vaultResponseBuilder()
                                     .entityProcessor(ListSecrets.Response::create));
    }

    @Override
    public VaultOptionalResponse get(DbGet.Request request) {
        String name = request.name();
        String apiPath = mount + "/creds/" + name;

        return restApi.get(apiPath, request, VaultOptionalResponse.vaultResponseBuilder()
                                                                  .entityProcessor(json -> DbGet.Response.create(name, json)));
    }

    @Override
    public DbCreateRole.Response createRole(DbCreateRole.Request request) {
        String apiPath = mount + "/roles/" + request.name();

        return restApi.post(apiPath, request, DbCreateRole.Response.builder());
    }

    @Override
    public DbConfigure.Response configure(DbConfigure.Request dbRequest) {
        String apiPath = mount + "/config/" + dbRequest.name();

        return restApi.post(apiPath, dbRequest, DbConfigure.Response.builder());
    }

    @Override
    public DbDelete.Response delete(DbDelete.Request request) {
        String apiPath = mount + "/config/" + request.name();
        return restApi.delete(apiPath, request, DbDelete.Response.builder());
    }

    @Override
    public DbDeleteRole.Response deleteRole(DbDeleteRole.Request request) {
        String apiPath = mount + "/roles/" + request.name();

        return restApi.delete(apiPath, request, DbDeleteRole.Response.builder());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy