-
Notifications
You must be signed in to change notification settings - Fork 3
feat(core): Add attributes client #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
01cd832
add it to the manifest
elizabethhealy 35f0a71
add split logic on decrypt
elizabethhealy ec5e91b
update cli exception handling
elizabethhealy 484dcaa
make custom exception type
elizabethhealy 4552d07
null check
elizabethhealy 8b006dd
check for null pointer
elizabethhealy fb889a3
encrypt w key splits
elizabethhealy 03fae78
try to fix test, exception fix, sets
elizabethhealy ee193e3
fix test
elizabethhealy 93bae72
Merge branch 'main' into split-key-implementation
elizabethhealy 44a8d96
set up attributes client
elizabethhealy 7828af8
Merge branch 'main' into add-attributes-client
elizabethhealy f5deb9b
add test for attribute client
elizabethhealy 5b222b2
suggested changes
elizabethhealy 64e8dd7
add attributes to cli
elizabethhealy 7d8a347
fix optional attr cli
elizabethhealy 19ebb47
fix attr splitting cmd
elizabethhealy d4b4127
remove extra lines
elizabethhealy 968382b
Merge branch 'main' into autoconfiguration-key-splitting
elizabethhealy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
sdk/src/main/java/io/opentdf/platform/sdk/AttributesClient.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
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); | ||
} | ||
|
||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
sdk/src/test/java/io/opentdf/platform/sdk/AttributeClientTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
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<GetAttributeValuesByFqnsResponse> 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<String> 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(); | ||
} | ||
|
||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.