2 * Copyright (c) 2024 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.keystore.legacy;
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.stream.Collectors;
13 import org.opendaylight.mdsal.binding.api.DataBroker;
14 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.Keystore;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveTrustedCertificate;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveTrustedCertificateInput;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveTrustedCertificateOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.RemoveTrustedCertificateOutputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.trusted.certificates.TrustedCertificate;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.keystore.rev171017.trusted.certificates.TrustedCertificateKey;
22 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 final class DefaultRemoveTrustedCertificate extends AbstractRpc implements RemoveTrustedCertificate {
29 private static final Logger LOG = LoggerFactory.getLogger(DefaultRemoveTrustedCertificate.class);
31 DefaultRemoveTrustedCertificate(final DataBroker dataBroker) {
36 public ListenableFuture<RpcResult<RemoveTrustedCertificateOutput>> invoke(
37 final RemoveTrustedCertificateInput input) {
38 final var names = input.getName();
39 if (names == null || names.isEmpty()) {
40 return RpcResultBuilder.success(new RemoveTrustedCertificateOutputBuilder().build()).buildFuture();
43 final var keys = names.stream().map(TrustedCertificateKey::new).collect(Collectors.toSet());
44 LOG.debug("Removing trusted certificates: {}", keys);
45 final var tx = newTransaction();
46 for (var key : keys) {
47 tx.delete(LogicalDatastoreType.CONFIGURATION,
48 InstanceIdentifier.create(Keystore.class).child(TrustedCertificate.class, key));
51 return tx.commit().transform(commitInfo -> {
52 LOG.debug("Removed trusted certificates: {}", keys);
53 return RpcResultBuilder.success(new RemoveTrustedCertificateOutputBuilder().build()).build();
54 }, MoreExecutors.directExecutor());