diff --git a/cmdline/src/main/java/io/opentdf/platform/Command.java b/cmdline/src/main/java/io/opentdf/platform/Command.java index 64886f65..3a8d1bb8 100644 --- a/cmdline/src/main/java/io/opentdf/platform/Command.java +++ b/cmdline/src/main/java/io/opentdf/platform/Command.java @@ -31,7 +31,6 @@ import java.util.List; import java.util.Optional; import java.util.function.Consumer; -import java.util.stream.Stream; @CommandLine.Command(name = "tdf") class Command { diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/AttributesClient.java b/sdk/src/main/java/io/opentdf/platform/sdk/AttributesClient.java deleted file mode 100644 index 85be7b60..00000000 --- a/sdk/src/main/java/io/opentdf/platform/sdk/AttributesClient.java +++ /dev/null @@ -1,40 +0,0 @@ -package io.opentdf.platform.sdk; - -import io.grpc.ManagedChannel; -import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsRequest; -import io.opentdf.platform.policy.attributes.AttributesServiceGrpc; -import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsResponse; - - -public class AttributesClient implements SDK.AttributesService { - - private final ManagedChannel channel; - - /*** - * A client that communicates with KAS - * @param channelFactory A function that produces channels that can be used to communicate - * @param dpopKey - */ - public AttributesClient(ManagedChannel channel) { - this.channel = channel; - } - - - @Override - public synchronized void close() { - this.channel.shutdownNow(); - } - - - // make this protected so we can test the address normalization logic - synchronized AttributesServiceGrpc.AttributesServiceBlockingStub getStub() { - return AttributesServiceGrpc.newBlockingStub(channel); - } - - - @Override - public GetAttributeValuesByFqnsResponse getAttributeValuesByFqn(GetAttributeValuesByFqnsRequest request) { - return getStub().getAttributeValuesByFqns(request); - } - -} diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/SDK.java b/sdk/src/main/java/io/opentdf/platform/sdk/SDK.java index 3f5f7c45..426b6c3b 100644 --- a/sdk/src/main/java/io/opentdf/platform/sdk/SDK.java +++ b/sdk/src/main/java/io/opentdf/platform/sdk/SDK.java @@ -5,7 +5,6 @@ import io.opentdf.platform.authorization.AuthorizationServiceGrpc; import io.opentdf.platform.authorization.AuthorizationServiceGrpc.AuthorizationServiceFutureStub; import io.opentdf.platform.policy.attributes.AttributesServiceGrpc; -import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsRequest; import io.opentdf.platform.policy.attributes.AttributesServiceGrpc.AttributesServiceFutureStub; import io.opentdf.platform.policy.namespaces.NamespaceServiceGrpc; import io.opentdf.platform.policy.namespaces.NamespaceServiceGrpc.NamespaceServiceFutureStub; @@ -14,9 +13,6 @@ import io.opentdf.platform.policy.subjectmapping.SubjectMappingServiceGrpc; import io.opentdf.platform.policy.subjectmapping.SubjectMappingServiceGrpc.SubjectMappingServiceFutureStub; import io.opentdf.platform.sdk.nanotdf.NanoTDFType; -import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsResponse; - -import java.util.List; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,20 +45,17 @@ public interface KAS extends AutoCloseable { byte[] unwrapNanoTDF(NanoTDFType.ECCurve curve, String header, String kasURL); } - public interface AttributesService extends AutoCloseable { - GetAttributeValuesByFqnsResponse getAttributeValuesByFqn(GetAttributeValuesByFqnsRequest request); - } - // TODO: add KAS public interface Services extends AutoCloseable { AuthorizationServiceFutureStub authorization(); - AttributesService attributes(); + AttributesServiceFutureStub attributes(); NamespaceServiceFutureStub namespaces(); SubjectMappingServiceFutureStub subjectMappings(); ResourceMappingServiceFutureStub resourceMappings(); KAS kas(); - static Services newServices(ManagedChannel channel, KAS kas, AttributesService attributeService) { + static Services newServices(ManagedChannel channel, KAS kas) { + var attributeService = AttributesServiceGrpc.newFutureStub(channel); var namespaceService = NamespaceServiceGrpc.newFutureStub(channel); var subjectMappingService = SubjectMappingServiceGrpc.newFutureStub(channel); var resourceMappingService = ResourceMappingServiceGrpc.newFutureStub(channel); @@ -72,12 +65,11 @@ static Services newServices(ManagedChannel channel, KAS kas, AttributesService a @Override public void close() throws Exception { channel.shutdownNow(); - attributeService.close(); kas.close(); } @Override - public AttributesService attributes() { + public AttributesServiceFutureStub attributes() { return attributeService; } diff --git a/sdk/src/main/java/io/opentdf/platform/sdk/SDKBuilder.java b/sdk/src/main/java/io/opentdf/platform/sdk/SDKBuilder.java index 5caf0daa..ad156f42 100644 --- a/sdk/src/main/java/io/opentdf/platform/sdk/SDKBuilder.java +++ b/sdk/src/main/java/io/opentdf/platform/sdk/SDKBuilder.java @@ -193,24 +193,20 @@ ServicesAndInternals buildServices() { var authInterceptor = getGrpcAuthInterceptor(dpopKey); ManagedChannel channel; - ManagedChannel attributesChannel; Function managedChannelFactory; if (authInterceptor == null) { channel = getManagedChannelBuilder(platformEndpoint).build(); - attributesChannel = getManagedChannelBuilder(platformEndpoint).build(); managedChannelFactory = (String endpoint) -> getManagedChannelBuilder(endpoint).build(); } else { channel = getManagedChannelBuilder(platformEndpoint).intercept(authInterceptor).build(); - attributesChannel = getManagedChannelBuilder(platformEndpoint).intercept(authInterceptor).build(); managedChannelFactory = (String endpoint) -> getManagedChannelBuilder(endpoint).intercept(authInterceptor).build(); } - var kasclient = new KASClient(managedChannelFactory, dpopKey); - var attrclient = new AttributesClient(attributesChannel); + var client = new KASClient(managedChannelFactory, dpopKey); return new ServicesAndInternals( authInterceptor, sslFactory == null ? null : sslFactory.getTrustManager().orElse(null), - SDK.Services.newServices(channel, kasclient, attrclient) + SDK.Services.newServices(channel, client) ); } diff --git a/sdk/src/test/java/io/opentdf/platform/sdk/AttributeClientTest.java b/sdk/src/test/java/io/opentdf/platform/sdk/AttributeClientTest.java deleted file mode 100644 index 8dd04c50..00000000 --- a/sdk/src/test/java/io/opentdf/platform/sdk/AttributeClientTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package io.opentdf.platform.sdk; - -import io.grpc.ManagedChannel; -import io.grpc.ManagedChannelBuilder; -import io.grpc.Server; -import io.grpc.ServerBuilder; -import io.opentdf.platform.policy.attributes.AttributesServiceGrpc; -import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsRequest; -import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsResponse; -import io.opentdf.platform.policy.attributes.GetAttributeValuesByFqnsResponse.AttributeAndValue; -import io.opentdf.platform.policy.Attribute; -import io.opentdf.platform.policy.Namespace; -import io.opentdf.platform.policy.Value; -import io.opentdf.platform.policy.AttributeRuleTypeEnum; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; - -import org.junit.jupiter.api.Test; - -import static io.opentdf.platform.sdk.SDKBuilderTest.getRandomPort; -import static org.assertj.core.api.Assertions.assertThat; - - -public class AttributeClientTest { - @Test - void testGettingAttributeByFqn() throws IOException { - AttributesServiceGrpc.AttributesServiceImplBase attributesService = new AttributesServiceGrpc.AttributesServiceImplBase() { - @Override - public void getAttributeValuesByFqns(GetAttributeValuesByFqnsRequest request, - io.grpc.stub.StreamObserver responseObserver) { - Attribute attribute1 = Attribute.newBuilder().setId("CLS").setNamespace( - Namespace.newBuilder().setId("v").setName("virtru.com").setFqn("https://virtru.com").build()) - .setName("Classification").setRule(AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_HIERARCHY).setFqn("https://virtru.com/attr/classification").build(); - - Value attributeValue1 = Value.newBuilder() - .setValue("value1") - .build(); - - // Create a sample AttributeValues object - AttributeAndValue attributeAndValues = AttributeAndValue.newBuilder().setAttribute(attribute1) - .setValue(attributeValue1) - .build(); - GetAttributeValuesByFqnsResponse response = GetAttributeValuesByFqnsResponse.newBuilder() - .putFqnAttributeValues("https://virtru.com/attr/classification/value/value1",attributeAndValues) - .build(); - responseObserver.onNext(response); - responseObserver.onCompleted(); - - } - }; - - Server attrServer = null; - try { - attrServer = startServer(attributesService); - String attrServerUrl = "localhost:" + attrServer.getPort(); - ManagedChannel channel = ManagedChannelBuilder - .forTarget(attrServerUrl) - .usePlaintext() - .build(); - try (var attr = new AttributesClient(channel)) { - GetAttributeValuesByFqnsResponse resp = attr.getAttributeValuesByFqn(GetAttributeValuesByFqnsRequest.newBuilder().build()); - Set fqnSet = new HashSet<>(Arrays.asList("https://virtru.com/attr/classification/value/value1")); - assertThat(resp.getFqnAttributeValuesMap().keySet()).isEqualTo(fqnSet); - assertThat(resp.getFqnAttributeValuesCount()).isEqualTo(1); - } - } finally { - if (attrServer != null) { - attrServer.shutdownNow(); - } - } - } - private static Server startServer(AttributesServiceGrpc.AttributesServiceImplBase attrService) throws IOException { - return ServerBuilder - .forPort(getRandomPort()) - .directExecutor() - .addService(attrService) - .build() - .start(); - } - -}