From 2ad70a38a3d8c785fbb948108c5bb3885f5127c9 Mon Sep 17 00:00:00 2001 From: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> Date: Fri, 5 Dec 2025 12:24:18 -0600 Subject: [PATCH 1/5] fix(examples): improve logging and setup logic in examples Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> --- .github/workflows/checks.yaml | 6 +- .../io/opentdf/platform/CreateAttribute.java | 71 ++++++-- .../io/opentdf/platform/CreateNamespace.java | 36 ++-- .../platform/CreateSubjectConditionSet.java | 70 +++++--- .../platform/CreateSubjectMapping.java | 159 ++++++++++++++++-- .../io/opentdf/platform/GetDecisions.java | 76 ++++++--- .../io/opentdf/platform/GetEntitlements.java | 57 ++++--- .../io/opentdf/platform/ListAttributes.java | 57 ++++--- .../io/opentdf/platform/ListNamespaces.java | 43 +++-- .../opentdf/platform/ListSubjectMappings.java | 57 ++++--- 10 files changed, 455 insertions(+), 177 deletions(-) diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml index c1507f1e..d24e2275 100644 --- a/.github/workflows/checks.yaml +++ b/.github/workflows/checks.yaml @@ -42,11 +42,12 @@ jobs: revert # Scopes include: # - ci: anything related to ci - # - cmdline: changes to @opentdf/ctl + # - cmdline: changes to cmdline # - docs: anything related solely to documentation # - main: bot generated commits - # - sdk: changes to @opentdf/sdk (was lib) + # - sdk: changes to sdk # - tests: test only changes + # - examples: examples only changes scopes: | ci cmdline @@ -54,6 +55,7 @@ jobs: main sdk tests + examples mavenverify: runs-on: ubuntu-latest diff --git a/examples/src/main/java/io/opentdf/platform/CreateAttribute.java b/examples/src/main/java/io/opentdf/platform/CreateAttribute.java index e81f556b..ea704085 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateAttribute.java +++ b/examples/src/main/java/io/opentdf/platform/CreateAttribute.java @@ -1,37 +1,74 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; -import io.opentdf.platform.policy.Attribute; import io.opentdf.platform.policy.AttributeRuleTypeEnum; +import io.opentdf.platform.policy.Namespace; import io.opentdf.platform.policy.attributes.CreateAttributeRequest; import io.opentdf.platform.policy.attributes.CreateAttributeResponse; +import io.opentdf.platform.policy.namespaces.GetNamespaceRequest; import io.opentdf.platform.sdk.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collections; -import java.util.concurrent.ExecutionException; import java.util.Arrays; public class CreateAttribute { - public static void main(String[] args) { - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; + private static final Logger logger = LogManager.getLogger(CreateAttribute.class); - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) - .build(); + public static void main(String[] args) { - CreateAttributeRequest request = CreateAttributeRequest.newBuilder() - .setNamespaceId("877990d1-609b-42ab-a273-4253b8b321eb") - .setName("test") - .setRule(AttributeRuleTypeEnum.forNumber(AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF_VALUE)) - .addAllValues(Arrays.asList("test1", "test2")).build(); + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; - CreateAttributeResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().attributes().createAttributeBlocking(request, Collections.emptyMap()).execute()); + SDKBuilder builder = new SDKBuilder(); + SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build(); - Attribute attribute = resp.getAttribute(); + Namespace namespace; + String namespaceName = "mynamespace.com"; + try { + namespace = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .namespaces() + .getNamespaceBlocking( + GetNamespaceRequest.newBuilder() + .setFqn("https://" + namespaceName) + .build(), + Collections.emptyMap()) + .execute()) + .getNamespace(); + } catch (Exception e) { + logger.error("Namespace '{}' not found", namespaceName); + throw e; } + + CreateAttributeRequest request = + CreateAttributeRequest.newBuilder() + .setNamespaceId(namespace.getId()) + .setName("test") + .setRule( + AttributeRuleTypeEnum.forNumber( + AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF_VALUE)) + .addAllValues(Arrays.asList("test1", "test2")) + .build(); + + CreateAttributeResponse resp = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .attributes() + .createAttributeBlocking(request, Collections.emptyMap()) + .execute()); + + logger.info("Successfully created attribute with ID: {}", resp.getAttribute().getId()); + } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateNamespace.java b/examples/src/main/java/io/opentdf/platform/CreateNamespace.java index ff9b2407..7e32edc8 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateNamespace.java +++ b/examples/src/main/java/io/opentdf/platform/CreateNamespace.java @@ -1,29 +1,37 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.policy.namespaces.CreateNamespaceRequest; import io.opentdf.platform.policy.namespaces.CreateNamespaceResponse; import io.opentdf.platform.sdk.*; import java.util.Collections; -import java.util.concurrent.ExecutionException; public class CreateNamespace { - public static void main(String[] args) { + public static void main(String[] args) { - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) - .build(); + SDKBuilder builder = new SDKBuilder(); + SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build(); - CreateNamespaceRequest request = CreateNamespaceRequest.newBuilder().setName("mynamespace.com").build(); + CreateNamespaceRequest request = + CreateNamespaceRequest.newBuilder().setName("mynamespace.com").build(); - CreateNamespaceResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().namespaces().createNamespaceBlocking(request, Collections.emptyMap()).execute()); + CreateNamespaceResponse resp = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .namespaces() + .createNamespaceBlocking(request, Collections.emptyMap()) + .execute()); - System.out.println(resp.getNamespace().getName()); - - } + System.out.println(resp.getNamespace().getName()); + } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java b/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java index 2f2481b8..a6cb7bee 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java +++ b/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java @@ -1,4 +1,5 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.policy.Condition; import io.opentdf.platform.policy.ConditionBooleanTypeEnum; @@ -10,40 +11,59 @@ import io.opentdf.platform.policy.subjectmapping.CreateSubjectConditionSetResponse; import io.opentdf.platform.policy.subjectmapping.SubjectConditionSetCreate; import io.opentdf.platform.sdk.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collections; -import java.util.concurrent.ExecutionException; - public class CreateSubjectConditionSet { - public static void main(String[] args) { - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; + private static final Logger logger = LogManager.getLogger(CreateSubjectConditionSet.class); + + public static void main(String[] args) { + + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) - .build(); + SDKBuilder builder = new SDKBuilder(); + SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build(); - var subjectset = SubjectSet.newBuilder().addConditionGroups(ConditionGroup.newBuilder() - .setBooleanOperator(ConditionBooleanTypeEnum.CONDITION_BOOLEAN_TYPE_ENUM_AND) - .addConditions(Condition.newBuilder() - .setSubjectExternalSelectorValue(".myfield") - .setOperator(SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN) - .addSubjectExternalValues("myvalue") - )); + SubjectSet.Builder subjectSetBuilder = + SubjectSet.newBuilder() + .addConditionGroups( + ConditionGroup.newBuilder() + .setBooleanOperator(ConditionBooleanTypeEnum.CONDITION_BOOLEAN_TYPE_ENUM_AND) + .addConditions( + Condition.newBuilder() + .setSubjectExternalSelectorValue(".myfield") + .setOperator( + SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN) + .addSubjectExternalValues("myvalue"))); - CreateSubjectConditionSetRequest request = CreateSubjectConditionSetRequest.newBuilder() - .setSubjectConditionSet( - SubjectConditionSetCreate.newBuilder().addSubjectSets(subjectset)) - .build(); + CreateSubjectConditionSetRequest createSubjectConditionSetRequest = + CreateSubjectConditionSetRequest.newBuilder() + .setSubjectConditionSet( + SubjectConditionSetCreate.newBuilder().addSubjectSets(subjectSetBuilder)) + .build(); - CreateSubjectConditionSetResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().subjectMappings().createSubjectConditionSetBlocking(request, Collections.emptyMap()).execute()); + CreateSubjectConditionSetResponse createSubjectConditionSetResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .subjectMappings() + .createSubjectConditionSetBlocking( + createSubjectConditionSetRequest, Collections.emptyMap()) + .execute()); - SubjectConditionSet scs = resp.getSubjectConditionSet(); + SubjectConditionSet subjectConditionSet = + createSubjectConditionSetResponse.getSubjectConditionSet(); - System.out.println(scs.getId()); - } + logger.info( + "Successfully created subject condition set with ID: {}", subjectConditionSet.getId()); + } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java b/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java index 7425a7c2..cd9e3f8f 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java +++ b/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java @@ -1,36 +1,161 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.policy.Action; +import io.opentdf.platform.policy.Attribute; +import io.opentdf.platform.policy.AttributeRuleTypeEnum; +import io.opentdf.platform.policy.Condition; +import io.opentdf.platform.policy.ConditionBooleanTypeEnum; +import io.opentdf.platform.policy.ConditionGroup; +import io.opentdf.platform.policy.Namespace; +import io.opentdf.platform.policy.SubjectConditionSet; import io.opentdf.platform.policy.SubjectMapping; +import io.opentdf.platform.policy.SubjectMappingOperatorEnum; +import io.opentdf.platform.policy.SubjectSet; +import io.opentdf.platform.policy.attributes.CreateAttributeRequest; +import io.opentdf.platform.policy.attributes.CreateAttributeResponse; +import io.opentdf.platform.policy.attributes.GetAttributeRequest; +import io.opentdf.platform.policy.namespaces.GetNamespaceRequest; +import io.opentdf.platform.policy.subjectmapping.CreateSubjectConditionSetRequest; +import io.opentdf.platform.policy.subjectmapping.CreateSubjectConditionSetResponse; import io.opentdf.platform.policy.subjectmapping.CreateSubjectMappingRequest; import io.opentdf.platform.policy.subjectmapping.CreateSubjectMappingResponse; -import io.opentdf.platform.sdk.*; +import io.opentdf.platform.policy.subjectmapping.SubjectConditionSetCreate; +import io.opentdf.platform.sdk.SDK; +import io.opentdf.platform.sdk.SDKBuilder; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import java.util.Arrays; import java.util.Collections; -import java.util.concurrent.ExecutionException; public class CreateSubjectMapping { - public static void main(String[] args) { - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; + private static final Logger logger = LogManager.getLogger(CreateSubjectMapping.class); + + public static void main(String[] args) { + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; + + SDKBuilder builder = new SDKBuilder(); + try (SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build()) { + + Namespace namespace; + String namespaceName = "mynamespace.com"; + + try { + namespace = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .namespaces() + .getNamespaceBlocking( + GetNamespaceRequest.newBuilder() + .setFqn("https://" + namespaceName) + .build(), + Collections.emptyMap()) + .execute()) + .getNamespace(); + } catch (Exception e) { + logger.error("Namespace '{}' not found", namespaceName); + throw e; + } + + Attribute attribute; + String attributeName = "test-attribute"; + String attributeFqn = namespace.getFqn() + "/attr/" + attributeName; - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) + try { + logger.info("Attempting to retrieve attribute '{}'", attributeFqn); + GetAttributeRequest getAttributeRequest = + GetAttributeRequest.newBuilder().setFqn(attributeFqn).build(); + attribute = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .attributes() + .getAttributeBlocking(getAttributeRequest, Collections.emptyMap()) + .execute()) + .getAttribute(); + logger.info("Found existing attribute with ID: {}", attribute.getId()); + } catch (Exception e) { + logger.info("Attribute '{}' not found, creating it...", attributeFqn); + CreateAttributeRequest attributeRequest = + CreateAttributeRequest.newBuilder() + .setNamespaceId(namespace.getId()) + .setName(attributeName) + .setRule( + AttributeRuleTypeEnum.forNumber( + AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF_VALUE)) + .addAllValues(Arrays.asList("test1", "test2")) .build(); + CreateAttributeResponse attributeResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .attributes() + .createAttributeBlocking(attributeRequest, Collections.emptyMap()) + .execute()); + attribute = attributeResponse.getAttribute(); + logger.info("Successfully created attribute with ID: {}", attribute.getId()); + } + logger.info("Using attribute with FQN: {}", attribute.getFqn()); - CreateSubjectMappingRequest request = CreateSubjectMappingRequest.newBuilder() - .setAttributeValueId("33c47777-f3b6-492d-bcd2-5329e0aab642") - .addActions(Action.newBuilder().setStandard(Action.StandardAction.STANDARD_ACTION_DECRYPT)) - .setExistingSubjectConditionSetId("9009fde8-d22b-4dfb-a456-f9ce6943244a") - .build(); + logger.info("Creating subject condition set..."); + // Create Subject Condition Set + CreateSubjectConditionSetRequest subjectConditionSetRequest = + CreateSubjectConditionSetRequest.newBuilder() + .setSubjectConditionSet( + SubjectConditionSetCreate.newBuilder() + .addSubjectSets( + SubjectSet.newBuilder() + .addConditionGroups( + ConditionGroup.newBuilder() + .setBooleanOperator( + ConditionBooleanTypeEnum.CONDITION_BOOLEAN_TYPE_ENUM_AND) + .addConditions( + Condition.newBuilder() + .setSubjectExternalSelectorValue(".myfield") + .setOperator( + SubjectMappingOperatorEnum + .SUBJECT_MAPPING_OPERATOR_ENUM_IN) + .addSubjectExternalValues("myvalue"))))) + .build(); + CreateSubjectConditionSetResponse subjectConditionSetResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .subjectMappings() + .createSubjectConditionSetBlocking( + subjectConditionSetRequest, Collections.emptyMap()) + .execute()); + SubjectConditionSet subjectConditionSet = + subjectConditionSetResponse.getSubjectConditionSet(); + logger.info( + "Successfully created subject condition set with ID: {}", subjectConditionSet.getId()); - CreateSubjectMappingResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().subjectMappings().createSubjectMappingBlocking(request, Collections.emptyMap()).execute()); + logger.info("Creating subject mapping..."); + // Create Subject Mapping + CreateSubjectMappingRequest request = + CreateSubjectMappingRequest.newBuilder() + .setAttributeValueId(attribute.getValues(0).getId()) + .addActions(Action.newBuilder().setName("read")) + .setExistingSubjectConditionSetId(subjectConditionSet.getId()) + .build(); + CreateSubjectMappingResponse resp = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .subjectMappings() + .createSubjectMappingBlocking(request, Collections.emptyMap()) + .execute()); - SubjectMapping sm = resp.getSubjectMapping(); + SubjectMapping subjectMapping = resp.getSubjectMapping(); - System.out.println(sm.getId()); + logger.info("Successfully created subject mapping with ID: {}", subjectMapping.getId()); + } catch (Exception e) { + logger.fatal("Failed to create subject mapping", e); } + } } diff --git a/examples/src/main/java/io/opentdf/platform/GetDecisions.java b/examples/src/main/java/io/opentdf/platform/GetDecisions.java index 9dbd533e..1067eb71 100644 --- a/examples/src/main/java/io/opentdf/platform/GetDecisions.java +++ b/examples/src/main/java/io/opentdf/platform/GetDecisions.java @@ -1,4 +1,5 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.authorization.DecisionRequest; import io.opentdf.platform.authorization.DecisionResponse; @@ -9,36 +10,59 @@ import io.opentdf.platform.authorization.ResourceAttribute; import io.opentdf.platform.policy.Action; import io.opentdf.platform.sdk.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collections; -import java.util.concurrent.ExecutionException; import java.util.List; public class GetDecisions { - public static void main(String[] args) { - - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; - - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) - .build(); - - GetDecisionsRequest request = GetDecisionsRequest.newBuilder() - .addDecisionRequests(DecisionRequest.newBuilder() - .addEntityChains(EntityChain.newBuilder().setId("ec1").addEntities(Entity.newBuilder().setId("entity-1").setClientId("opentdf"))) - .addActions(Action.newBuilder().setStandard(Action.StandardAction.STANDARD_ACTION_DECRYPT)) - .addResourceAttributes(ResourceAttribute.newBuilder().setResourceAttributesId("resource-attribute-1") - .addAttributeValueFqns("https://mynamespace.com/attr/test/value/test1")) - ).build(); - - GetDecisionsResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().authorization().getDecisionsBlocking(request, Collections.emptyMap()).execute()); - - List decisions = resp.getDecisionResponsesList(); - - System.out.println(DecisionResponse.Decision.forNumber(decisions.get(0).getDecisionValue())); - } + + private static final Logger logger = LogManager.getLogger(GetDecisions.class); + + public static void main(String[] args) { + + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; + + SDKBuilder builder = new SDKBuilder(); + SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build(); + + GetDecisionsRequest request = + GetDecisionsRequest.newBuilder() + .addDecisionRequests( + DecisionRequest.newBuilder() + .addEntityChains( + EntityChain.newBuilder() + .setId("ec1") + .addEntities( + Entity.newBuilder().setId("entity-1").setClientId("opentdf"))) + .addActions( + Action.newBuilder() + .setStandard(Action.StandardAction.STANDARD_ACTION_DECRYPT)) + .addResourceAttributes( + ResourceAttribute.newBuilder() + .setResourceAttributesId("resource-attribute-1") + .addAttributeValueFqns( + "https://mynamespace.com/attr/test/value/test1"))) + .build(); + + GetDecisionsResponse resp = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .authorization() + .getDecisionsBlocking(request, Collections.emptyMap()) + .execute()); + + List decisions = resp.getDecisionResponsesList(); + + logger.info("Successfully retrieved decision {}", decisions.get(0).getDecision()); + } } diff --git a/examples/src/main/java/io/opentdf/platform/GetEntitlements.java b/examples/src/main/java/io/opentdf/platform/GetEntitlements.java index f9479577..cccb5ccf 100644 --- a/examples/src/main/java/io/opentdf/platform/GetEntitlements.java +++ b/examples/src/main/java/io/opentdf/platform/GetEntitlements.java @@ -1,35 +1,50 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.authorization.Entity; import io.opentdf.platform.authorization.EntityEntitlements; import io.opentdf.platform.authorization.GetEntitlementsRequest; import io.opentdf.platform.authorization.GetEntitlementsResponse; import io.opentdf.platform.sdk.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collections; import java.util.List; public class GetEntitlements { - public static void main(String[] args) { - - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; - - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) - .build(); - - GetEntitlementsRequest request = GetEntitlementsRequest.newBuilder() - .addEntities(Entity.newBuilder().setId("entity-1").setClientId("opentdf")) - .build(); - - GetEntitlementsResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().authorization().getEntitlementsBlocking(request, Collections.emptyMap()).execute()); - - List entitlements = resp.getEntitlementsList(); - - System.out.println(entitlements.get(0).getAttributeValueFqnsList()); - } + private static final Logger logger = LogManager.getLogger(GetEntitlements.class); + + public static void main(String[] args) { + + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; + + SDKBuilder builder = new SDKBuilder(); + SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build(); + + GetEntitlementsRequest request = + GetEntitlementsRequest.newBuilder() + .addEntities(Entity.newBuilder().setId("entity-1").setClientId("opentdf")) + .build(); + + GetEntitlementsResponse resp = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .authorization() + .getEntitlementsBlocking(request, Collections.emptyMap()) + .execute()); + + List entitlements = resp.getEntitlementsList(); + + logger.info( + "Successfully retrieved entitlements {}", entitlements.get(0).getAttributeValueFqnsList()); + } } diff --git a/examples/src/main/java/io/opentdf/platform/ListAttributes.java b/examples/src/main/java/io/opentdf/platform/ListAttributes.java index 96b17f16..9ebbd3a7 100644 --- a/examples/src/main/java/io/opentdf/platform/ListAttributes.java +++ b/examples/src/main/java/io/opentdf/platform/ListAttributes.java @@ -1,34 +1,49 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.policy.Attribute; import io.opentdf.platform.policy.attributes.ListAttributesRequest; import io.opentdf.platform.policy.attributes.ListAttributesResponse; import io.opentdf.platform.sdk.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collections; -import java.util.concurrent.ExecutionException; import java.util.List; +import java.util.stream.Collectors; public class ListAttributes { - public static void main(String[] args) { - - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; - - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) - .build(); - - ListAttributesRequest request = ListAttributesRequest.newBuilder() - .setNamespace("mynamespace.com").build(); - - ListAttributesResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().attributes().listAttributesBlocking(request, Collections.emptyMap()).execute()); - - List attributes = resp.getAttributesList(); - - System.out.println(resp.getAttributesCount()); - } + private static final Logger logger = LogManager.getLogger(ListAttributes.class); + + public static void main(String[] args) { + + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; + + SDKBuilder builder = new SDKBuilder(); + SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build(); + + ListAttributesRequest request = + ListAttributesRequest.newBuilder().setNamespace("mynamespace.com").build(); + + ListAttributesResponse resp = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .attributes() + .listAttributesBlocking(request, Collections.emptyMap()) + .execute()); + + List attributes = resp.getAttributesList(); + + logger.info( + "Successfully retrieved attributes {}", + attributes.stream().map(Attribute::getFqn).collect(Collectors.joining(", "))); + } } diff --git a/examples/src/main/java/io/opentdf/platform/ListNamespaces.java b/examples/src/main/java/io/opentdf/platform/ListNamespaces.java index 61bc0d5f..573d155e 100644 --- a/examples/src/main/java/io/opentdf/platform/ListNamespaces.java +++ b/examples/src/main/java/io/opentdf/platform/ListNamespaces.java @@ -1,30 +1,47 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.policy.Namespace; import io.opentdf.platform.policy.namespaces.ListNamespacesRequest; import io.opentdf.platform.policy.namespaces.ListNamespacesResponse; import io.opentdf.platform.sdk.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collections; import java.util.List; -import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; public class ListNamespaces { - public static void main(String[] args) { + private static final Logger logger = LogManager.getLogger(ListNamespaces.class); + + public static void main(String[] args) { + + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; + SDKBuilder builder = new SDKBuilder(); + SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build(); - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) - .build(); + ListNamespacesRequest request = ListNamespacesRequest.newBuilder().build(); - ListNamespacesRequest request = ListNamespacesRequest.newBuilder().build(); + ListNamespacesResponse resp = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .namespaces() + .listNamespacesBlocking(request, Collections.emptyMap()) + .execute()); - ListNamespacesResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().namespaces().listNamespacesBlocking(request, Collections.emptyMap()).execute()); + List namespaces = resp.getNamespacesList(); - List namespaces = resp.getNamespacesList(); - } + logger.info( + "Successfully retrieved namespaces {}", + namespaces.stream().map(Namespace::getFqn).collect(Collectors.joining(", "))); + } } diff --git a/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java b/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java index 9a771be6..410ef099 100644 --- a/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java +++ b/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java @@ -1,34 +1,49 @@ package io.opentdf.platform; + import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.policy.SubjectMapping; import io.opentdf.platform.policy.subjectmapping.ListSubjectMappingsRequest; import io.opentdf.platform.policy.subjectmapping.ListSubjectMappingsResponse; import io.opentdf.platform.sdk.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collections; -import java.util.concurrent.ExecutionException; import java.util.List; +import java.util.stream.Collectors; public class ListSubjectMappings { - public static void main(String[] args) { - - String clientId = "opentdf"; - String clientSecret = "secret"; - String platformEndpoint = "localhost:8080"; - - SDKBuilder builder = new SDKBuilder(); - SDK sdk = builder.platformEndpoint(platformEndpoint) - .clientSecret(clientId, clientSecret).useInsecurePlaintextConnection(true) - .build(); - - ListSubjectMappingsRequest request = ListSubjectMappingsRequest.newBuilder().build(); - - ListSubjectMappingsResponse resp = ResponseMessageKt.getOrThrow(sdk.getServices().subjectMappings().listSubjectMappingsBlocking(request, Collections.emptyMap()).execute()); - - List sms = resp.getSubjectMappingsList(); - - System.out.println(sms.size()); - System.out.println(sms.get(0).getId()); - } + private static final Logger logger = LogManager.getLogger(ListSubjectMappings.class); + + public static void main(String[] args) throws Exception { + + String clientId = "opentdf"; + String clientSecret = "secret"; + String platformEndpoint = "localhost:8080"; + + SDKBuilder builder = new SDKBuilder(); + SDK sdk = + builder + .platformEndpoint(platformEndpoint) + .clientSecret(clientId, clientSecret) + .useInsecurePlaintextConnection(true) + .build(); + + ListSubjectMappingsRequest listSubjectMappingsRequest = + ListSubjectMappingsRequest.newBuilder().build(); + + ListSubjectMappingsResponse listSubjectMappingsResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .subjectMappings() + .listSubjectMappingsBlocking(listSubjectMappingsRequest, Collections.emptyMap()) + .execute()); + + List subjectMappings = listSubjectMappingsResponse.getSubjectMappingsList(); + + logger.info( + "Successfully retrieved subject mappings {}", + subjectMappings.stream().map(SubjectMapping::getId).collect(Collectors.joining(", "))); + } } From c1c62f129a42e7512c43ebd135df2f2c5defb4bc Mon Sep 17 00:00:00 2001 From: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> Date: Fri, 5 Dec 2025 13:24:33 -0600 Subject: [PATCH 2/5] fix(examples): wrap sdk initialization in try-with-resources Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> --- .../io/opentdf/platform/CreateAttribute.java | 78 ++++++++++--------- .../io/opentdf/platform/CreateNamespace.java | 34 +++++--- .../platform/CreateSubjectConditionSet.java | 62 ++++++++------- .../platform/CreateSubjectMapping.java | 18 ++--- .../io/opentdf/platform/GetDecisions.java | 60 +++++++------- .../io/opentdf/platform/GetEntitlements.java | 43 +++++----- .../io/opentdf/platform/ListAttributes.java | 40 +++++----- .../io/opentdf/platform/ListNamespaces.java | 30 +++---- .../opentdf/platform/ListSubjectMappings.java | 40 +++++----- 9 files changed, 224 insertions(+), 181 deletions(-) diff --git a/examples/src/main/java/io/opentdf/platform/CreateAttribute.java b/examples/src/main/java/io/opentdf/platform/CreateAttribute.java index ea704085..2015a977 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateAttribute.java +++ b/examples/src/main/java/io/opentdf/platform/CreateAttribute.java @@ -25,50 +25,56 @@ public static void main(String[] args) { String platformEndpoint = "localhost:8080"; SDKBuilder builder = new SDKBuilder(); - SDK sdk = + + try (SDK sdk = builder .platformEndpoint(platformEndpoint) .clientSecret(clientId, clientSecret) .useInsecurePlaintextConnection(true) - .build(); + .build()) { - Namespace namespace; - String namespaceName = "mynamespace.com"; + Namespace namespace; + String namespaceName = "mynamespace.com"; - try { - namespace = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .namespaces() - .getNamespaceBlocking( - GetNamespaceRequest.newBuilder() - .setFqn("https://" + namespaceName) - .build(), - Collections.emptyMap()) - .execute()) - .getNamespace(); - } catch (Exception e) { - logger.error("Namespace '{}' not found", namespaceName); - throw e; - } + try { + namespace = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .namespaces() + .getNamespaceBlocking( + GetNamespaceRequest.newBuilder() + .setFqn("https://" + namespaceName) + .build(), + Collections.emptyMap()) + .execute()) + .getNamespace(); + } catch (Exception e) { + logger.error("Namespace '{}' not found", namespaceName); + throw e; + } - CreateAttributeRequest request = - CreateAttributeRequest.newBuilder() - .setNamespaceId(namespace.getId()) - .setName("test") - .setRule( - AttributeRuleTypeEnum.forNumber( - AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF_VALUE)) - .addAllValues(Arrays.asList("test1", "test2")) - .build(); + CreateAttributeRequest createAttributeRequest = + CreateAttributeRequest.newBuilder() + .setNamespaceId(namespace.getId()) + .setName("test") + .setRule( + AttributeRuleTypeEnum.forNumber( + AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF_VALUE)) + .addAllValues(Arrays.asList("test1", "test2")) + .build(); - CreateAttributeResponse resp = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .attributes() - .createAttributeBlocking(request, Collections.emptyMap()) - .execute()); + CreateAttributeResponse createAttributeResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .attributes() + .createAttributeBlocking(createAttributeRequest, Collections.emptyMap()) + .execute()); - logger.info("Successfully created attribute with ID: {}", resp.getAttribute().getId()); + logger.info( + "Successfully created attribute with ID: {}", + createAttributeResponse.getAttribute().getId()); + } catch (Exception e) { + logger.fatal("Failed to create attribute", e); + } } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateNamespace.java b/examples/src/main/java/io/opentdf/platform/CreateNamespace.java index 7e32edc8..8abfdef3 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateNamespace.java +++ b/examples/src/main/java/io/opentdf/platform/CreateNamespace.java @@ -4,10 +4,15 @@ import io.opentdf.platform.policy.namespaces.CreateNamespaceRequest; import io.opentdf.platform.policy.namespaces.CreateNamespaceResponse; import io.opentdf.platform.sdk.*; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.util.Collections; public class CreateNamespace { + + private static final Logger logger = LogManager.getLogger(CreateNamespace.class); + public static void main(String[] args) { String clientId = "opentdf"; @@ -15,23 +20,30 @@ public static void main(String[] args) { String platformEndpoint = "localhost:8080"; SDKBuilder builder = new SDKBuilder(); - SDK sdk = + + try (SDK sdk = builder .platformEndpoint(platformEndpoint) .clientSecret(clientId, clientSecret) .useInsecurePlaintextConnection(true) - .build(); + .build()) { + + CreateNamespaceRequest createNamespaceRequest = + CreateNamespaceRequest.newBuilder().setName("mynamespace.com").build(); - CreateNamespaceRequest request = - CreateNamespaceRequest.newBuilder().setName("mynamespace.com").build(); + CreateNamespaceResponse createNamespaceResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .namespaces() + .createNamespaceBlocking(createNamespaceRequest, Collections.emptyMap()) + .execute()); - CreateNamespaceResponse resp = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .namespaces() - .createNamespaceBlocking(request, Collections.emptyMap()) - .execute()); + logger.info( + "Successfully created namespace with ID: {}", + createNamespaceResponse.getNamespace().getId()); - System.out.println(resp.getNamespace().getName()); + } catch (Exception e) { + logger.fatal("Failed to create namespace", e); + } } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java b/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java index a6cb7bee..c1cfc898 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java +++ b/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java @@ -27,43 +27,47 @@ public static void main(String[] args) { String platformEndpoint = "localhost:8080"; SDKBuilder builder = new SDKBuilder(); - SDK sdk = + + try (SDK sdk = builder .platformEndpoint(platformEndpoint) .clientSecret(clientId, clientSecret) .useInsecurePlaintextConnection(true) - .build(); + .build()) { - SubjectSet.Builder subjectSetBuilder = - SubjectSet.newBuilder() - .addConditionGroups( - ConditionGroup.newBuilder() - .setBooleanOperator(ConditionBooleanTypeEnum.CONDITION_BOOLEAN_TYPE_ENUM_AND) - .addConditions( - Condition.newBuilder() - .setSubjectExternalSelectorValue(".myfield") - .setOperator( - SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN) - .addSubjectExternalValues("myvalue"))); + SubjectSet.Builder subjectSetBuilder = + SubjectSet.newBuilder() + .addConditionGroups( + ConditionGroup.newBuilder() + .setBooleanOperator(ConditionBooleanTypeEnum.CONDITION_BOOLEAN_TYPE_ENUM_AND) + .addConditions( + Condition.newBuilder() + .setSubjectExternalSelectorValue(".myfield") + .setOperator( + SubjectMappingOperatorEnum.SUBJECT_MAPPING_OPERATOR_ENUM_IN) + .addSubjectExternalValues("myvalue"))); - CreateSubjectConditionSetRequest createSubjectConditionSetRequest = - CreateSubjectConditionSetRequest.newBuilder() - .setSubjectConditionSet( - SubjectConditionSetCreate.newBuilder().addSubjectSets(subjectSetBuilder)) - .build(); + CreateSubjectConditionSetRequest createSubjectConditionSetRequest = + CreateSubjectConditionSetRequest.newBuilder() + .setSubjectConditionSet( + SubjectConditionSetCreate.newBuilder().addSubjectSets(subjectSetBuilder)) + .build(); - CreateSubjectConditionSetResponse createSubjectConditionSetResponse = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .subjectMappings() - .createSubjectConditionSetBlocking( - createSubjectConditionSetRequest, Collections.emptyMap()) - .execute()); + CreateSubjectConditionSetResponse createSubjectConditionSetResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .subjectMappings() + .createSubjectConditionSetBlocking( + createSubjectConditionSetRequest, Collections.emptyMap()) + .execute()); + SubjectConditionSet subjectConditionSet = + createSubjectConditionSetResponse.getSubjectConditionSet(); - SubjectConditionSet subjectConditionSet = - createSubjectConditionSetResponse.getSubjectConditionSet(); + logger.info( + "Successfully created subject condition set with ID: {}", subjectConditionSet.getId()); - logger.info( - "Successfully created subject condition set with ID: {}", subjectConditionSet.getId()); + } catch (Exception e) { + logger.fatal("Failed to create subject condition set", e); + } } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java b/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java index cd9e3f8f..1e34a7b6 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java +++ b/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java @@ -71,9 +71,9 @@ public static void main(String[] args) { String attributeFqn = namespace.getFqn() + "/attr/" + attributeName; try { - logger.info("Attempting to retrieve attribute '{}'", attributeFqn); GetAttributeRequest getAttributeRequest = GetAttributeRequest.newBuilder().setFqn(attributeFqn).build(); + attribute = ResponseMessageKt.getOrThrow( sdk.getServices() @@ -81,9 +81,10 @@ public static void main(String[] args) { .getAttributeBlocking(getAttributeRequest, Collections.emptyMap()) .execute()) .getAttribute(); + logger.info("Found existing attribute with ID: {}", attribute.getId()); + } catch (Exception e) { - logger.info("Attribute '{}' not found, creating it...", attributeFqn); CreateAttributeRequest attributeRequest = CreateAttributeRequest.newBuilder() .setNamespaceId(namespace.getId()) @@ -93,19 +94,19 @@ public static void main(String[] args) { AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF_VALUE)) .addAllValues(Arrays.asList("test1", "test2")) .build(); + CreateAttributeResponse attributeResponse = ResponseMessageKt.getOrThrow( sdk.getServices() .attributes() .createAttributeBlocking(attributeRequest, Collections.emptyMap()) .execute()); + attribute = attributeResponse.getAttribute(); + logger.info("Successfully created attribute with ID: {}", attribute.getId()); } - logger.info("Using attribute with FQN: {}", attribute.getFqn()); - logger.info("Creating subject condition set..."); - // Create Subject Condition Set CreateSubjectConditionSetRequest subjectConditionSetRequest = CreateSubjectConditionSetRequest.newBuilder() .setSubjectConditionSet( @@ -124,6 +125,7 @@ public static void main(String[] args) { .SUBJECT_MAPPING_OPERATOR_ENUM_IN) .addSubjectExternalValues("myvalue"))))) .build(); + CreateSubjectConditionSetResponse subjectConditionSetResponse = ResponseMessageKt.getOrThrow( sdk.getServices() @@ -131,19 +133,17 @@ public static void main(String[] args) { .createSubjectConditionSetBlocking( subjectConditionSetRequest, Collections.emptyMap()) .execute()); + SubjectConditionSet subjectConditionSet = subjectConditionSetResponse.getSubjectConditionSet(); - logger.info( - "Successfully created subject condition set with ID: {}", subjectConditionSet.getId()); - logger.info("Creating subject mapping..."); - // Create Subject Mapping CreateSubjectMappingRequest request = CreateSubjectMappingRequest.newBuilder() .setAttributeValueId(attribute.getValues(0).getId()) .addActions(Action.newBuilder().setName("read")) .setExistingSubjectConditionSetId(subjectConditionSet.getId()) .build(); + CreateSubjectMappingResponse resp = ResponseMessageKt.getOrThrow( sdk.getServices() diff --git a/examples/src/main/java/io/opentdf/platform/GetDecisions.java b/examples/src/main/java/io/opentdf/platform/GetDecisions.java index 1067eb71..4d79b689 100644 --- a/examples/src/main/java/io/opentdf/platform/GetDecisions.java +++ b/examples/src/main/java/io/opentdf/platform/GetDecisions.java @@ -28,41 +28,45 @@ public static void main(String[] args) { String platformEndpoint = "localhost:8080"; SDKBuilder builder = new SDKBuilder(); - SDK sdk = + + try (SDK sdk = builder .platformEndpoint(platformEndpoint) .clientSecret(clientId, clientSecret) .useInsecurePlaintextConnection(true) - .build(); + .build()) { - GetDecisionsRequest request = - GetDecisionsRequest.newBuilder() - .addDecisionRequests( - DecisionRequest.newBuilder() - .addEntityChains( - EntityChain.newBuilder() - .setId("ec1") - .addEntities( - Entity.newBuilder().setId("entity-1").setClientId("opentdf"))) - .addActions( - Action.newBuilder() - .setStandard(Action.StandardAction.STANDARD_ACTION_DECRYPT)) - .addResourceAttributes( - ResourceAttribute.newBuilder() - .setResourceAttributesId("resource-attribute-1") - .addAttributeValueFqns( - "https://mynamespace.com/attr/test/value/test1"))) - .build(); + GetDecisionsRequest request = + GetDecisionsRequest.newBuilder() + .addDecisionRequests( + DecisionRequest.newBuilder() + .addEntityChains( + EntityChain.newBuilder() + .setId("ec1") + .addEntities( + Entity.newBuilder().setId("entity-1").setClientId("opentdf"))) + .addActions( + Action.newBuilder() + .setStandard(Action.StandardAction.STANDARD_ACTION_DECRYPT)) + .addResourceAttributes( + ResourceAttribute.newBuilder() + .setResourceAttributesId("resource-attribute-1") + .addAttributeValueFqns( + "https://mynamespace.com/attr/test/value/test1"))) + .build(); - GetDecisionsResponse resp = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .authorization() - .getDecisionsBlocking(request, Collections.emptyMap()) - .execute()); + GetDecisionsResponse getDecisionsResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .authorization() + .getDecisionsBlocking(request, Collections.emptyMap()) + .execute()); - List decisions = resp.getDecisionResponsesList(); + List decisions = getDecisionsResponse.getDecisionResponsesList(); - logger.info("Successfully retrieved decision {}", decisions.get(0).getDecision()); + logger.info("Successfully retrieved decision {}", decisions.get(0).getDecision()); + } catch (Exception e) { + logger.fatal("Failed to get decisions", e); + } } } diff --git a/examples/src/main/java/io/opentdf/platform/GetEntitlements.java b/examples/src/main/java/io/opentdf/platform/GetEntitlements.java index cccb5ccf..0ac590ae 100644 --- a/examples/src/main/java/io/opentdf/platform/GetEntitlements.java +++ b/examples/src/main/java/io/opentdf/platform/GetEntitlements.java @@ -23,28 +23,33 @@ public static void main(String[] args) { String platformEndpoint = "localhost:8080"; SDKBuilder builder = new SDKBuilder(); - SDK sdk = + + try (SDK sdk = builder .platformEndpoint(platformEndpoint) .clientSecret(clientId, clientSecret) .useInsecurePlaintextConnection(true) - .build(); - - GetEntitlementsRequest request = - GetEntitlementsRequest.newBuilder() - .addEntities(Entity.newBuilder().setId("entity-1").setClientId("opentdf")) - .build(); - - GetEntitlementsResponse resp = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .authorization() - .getEntitlementsBlocking(request, Collections.emptyMap()) - .execute()); - - List entitlements = resp.getEntitlementsList(); - - logger.info( - "Successfully retrieved entitlements {}", entitlements.get(0).getAttributeValueFqnsList()); + .build()) { + + GetEntitlementsRequest request = + GetEntitlementsRequest.newBuilder() + .addEntities(Entity.newBuilder().setId("entity-1").setClientId("opentdf")) + .build(); + + GetEntitlementsResponse getEntitlementsResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .authorization() + .getEntitlementsBlocking(request, Collections.emptyMap()) + .execute()); + + List entitlements = getEntitlementsResponse.getEntitlementsList(); + + logger.info( + "Successfully retrieved entitlements {}", + entitlements.get(0).getAttributeValueFqnsList()); + } catch (Exception e) { + logger.fatal("Failed to get entitlements", e); + } } } diff --git a/examples/src/main/java/io/opentdf/platform/ListAttributes.java b/examples/src/main/java/io/opentdf/platform/ListAttributes.java index 9ebbd3a7..597cc769 100644 --- a/examples/src/main/java/io/opentdf/platform/ListAttributes.java +++ b/examples/src/main/java/io/opentdf/platform/ListAttributes.java @@ -23,27 +23,31 @@ public static void main(String[] args) { String platformEndpoint = "localhost:8080"; SDKBuilder builder = new SDKBuilder(); - SDK sdk = + + try (SDK sdk = builder .platformEndpoint(platformEndpoint) .clientSecret(clientId, clientSecret) .useInsecurePlaintextConnection(true) - .build(); - - ListAttributesRequest request = - ListAttributesRequest.newBuilder().setNamespace("mynamespace.com").build(); - - ListAttributesResponse resp = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .attributes() - .listAttributesBlocking(request, Collections.emptyMap()) - .execute()); - - List attributes = resp.getAttributesList(); - - logger.info( - "Successfully retrieved attributes {}", - attributes.stream().map(Attribute::getFqn).collect(Collectors.joining(", "))); + .build()) { + + ListAttributesRequest request = + ListAttributesRequest.newBuilder().setNamespace("mynamespace.com").build(); + + ListAttributesResponse listAttributesResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .attributes() + .listAttributesBlocking(request, Collections.emptyMap()) + .execute()); + + List attributes = listAttributesResponse.getAttributesList(); + + logger.info( + "Successfully retrieved attributes {}", + attributes.stream().map(Attribute::getFqn).collect(Collectors.joining(", "))); + } catch (Exception e) { + logger.fatal("Failed to list attributes", e); + } } } diff --git a/examples/src/main/java/io/opentdf/platform/ListNamespaces.java b/examples/src/main/java/io/opentdf/platform/ListNamespaces.java index 573d155e..bdb04e1f 100644 --- a/examples/src/main/java/io/opentdf/platform/ListNamespaces.java +++ b/examples/src/main/java/io/opentdf/platform/ListNamespaces.java @@ -22,26 +22,30 @@ public static void main(String[] args) { String platformEndpoint = "localhost:8080"; SDKBuilder builder = new SDKBuilder(); - SDK sdk = + + try (SDK sdk = builder .platformEndpoint(platformEndpoint) .clientSecret(clientId, clientSecret) .useInsecurePlaintextConnection(true) - .build(); + .build()) { - ListNamespacesRequest request = ListNamespacesRequest.newBuilder().build(); + ListNamespacesRequest request = ListNamespacesRequest.newBuilder().build(); - ListNamespacesResponse resp = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .namespaces() - .listNamespacesBlocking(request, Collections.emptyMap()) - .execute()); + ListNamespacesResponse listNamespacesResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .namespaces() + .listNamespacesBlocking(request, Collections.emptyMap()) + .execute()); - List namespaces = resp.getNamespacesList(); + List namespaces = listNamespacesResponse.getNamespacesList(); - logger.info( - "Successfully retrieved namespaces {}", - namespaces.stream().map(Namespace::getFqn).collect(Collectors.joining(", "))); + logger.info( + "Successfully retrieved namespaces {}", + namespaces.stream().map(Namespace::getFqn).collect(Collectors.joining(", "))); + } catch (Exception e) { + logger.fatal("Failed to list namespaces", e); + } } } diff --git a/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java b/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java index 410ef099..122070cf 100644 --- a/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java +++ b/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java @@ -23,27 +23,31 @@ public static void main(String[] args) throws Exception { String platformEndpoint = "localhost:8080"; SDKBuilder builder = new SDKBuilder(); - SDK sdk = + + try (SDK sdk = builder .platformEndpoint(platformEndpoint) .clientSecret(clientId, clientSecret) .useInsecurePlaintextConnection(true) - .build(); - - ListSubjectMappingsRequest listSubjectMappingsRequest = - ListSubjectMappingsRequest.newBuilder().build(); - - ListSubjectMappingsResponse listSubjectMappingsResponse = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .subjectMappings() - .listSubjectMappingsBlocking(listSubjectMappingsRequest, Collections.emptyMap()) - .execute()); - - List subjectMappings = listSubjectMappingsResponse.getSubjectMappingsList(); - - logger.info( - "Successfully retrieved subject mappings {}", - subjectMappings.stream().map(SubjectMapping::getId).collect(Collectors.joining(", "))); + .build()) { + + ListSubjectMappingsRequest listSubjectMappingsRequest = + ListSubjectMappingsRequest.newBuilder().build(); + + ListSubjectMappingsResponse listSubjectMappingsResponse = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .subjectMappings() + .listSubjectMappingsBlocking(listSubjectMappingsRequest, Collections.emptyMap()) + .execute()); + + List subjectMappings = listSubjectMappingsResponse.getSubjectMappingsList(); + + logger.info( + "Successfully retrieved subject mappings {}", + subjectMappings.stream().map(SubjectMapping::getId).collect(Collectors.joining(", "))); + } catch (Exception e) { + logger.fatal("Failed to list subject mappings", e); + } } } From c73e9ceea63be81e096270770e6624ed41b01563 Mon Sep 17 00:00:00 2001 From: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> Date: Fri, 5 Dec 2025 15:19:00 -0600 Subject: [PATCH 3/5] fix(examples): remove needless throws exception Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> --- .../src/main/java/io/opentdf/platform/ListSubjectMappings.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java b/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java index 122070cf..10a212e1 100644 --- a/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java +++ b/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java @@ -16,7 +16,7 @@ public class ListSubjectMappings { private static final Logger logger = LogManager.getLogger(ListSubjectMappings.class); - public static void main(String[] args) throws Exception { + public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; From bb3e626fecbf5e29dcf593c99c3e170208b253ac Mon Sep 17 00:00:00 2001 From: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> Date: Mon, 8 Dec 2025 08:52:19 -0600 Subject: [PATCH 4/5] fix(examples): enhance error handling and logging Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> --- .../io/opentdf/platform/CreateAttribute.java | 40 ++++++++-------- .../io/opentdf/platform/CreateNamespace.java | 10 +++- .../platform/CreateSubjectConditionSet.java | 3 +- .../platform/CreateSubjectMapping.java | 47 +++++++------------ .../io/opentdf/platform/GetDecisions.java | 10 +++- .../io/opentdf/platform/GetEntitlements.java | 10 ++-- .../io/opentdf/platform/ListAttributes.java | 4 +- .../io/opentdf/platform/ListNamespaces.java | 4 +- .../opentdf/platform/ListSubjectMappings.java | 4 +- 9 files changed, 67 insertions(+), 65 deletions(-) diff --git a/examples/src/main/java/io/opentdf/platform/CreateAttribute.java b/examples/src/main/java/io/opentdf/platform/CreateAttribute.java index 2015a977..a9dfcd52 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateAttribute.java +++ b/examples/src/main/java/io/opentdf/platform/CreateAttribute.java @@ -13,6 +13,7 @@ import java.util.Collections; import java.util.Arrays; +import java.util.Objects; public class CreateAttribute { @@ -23,6 +24,7 @@ public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; String platformEndpoint = "localhost:8080"; + String namespaceName = "mynamespace.com"; SDKBuilder builder = new SDKBuilder(); @@ -33,25 +35,17 @@ public static void main(String[] args) { .useInsecurePlaintextConnection(true) .build()) { - Namespace namespace; - String namespaceName = "mynamespace.com"; - - try { - namespace = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .namespaces() - .getNamespaceBlocking( - GetNamespaceRequest.newBuilder() - .setFqn("https://" + namespaceName) - .build(), - Collections.emptyMap()) - .execute()) - .getNamespace(); - } catch (Exception e) { - logger.error("Namespace '{}' not found", namespaceName); - throw e; - } + Namespace namespace = + ResponseMessageKt.getOrThrow( + sdk.getServices() + .namespaces() + .getNamespaceBlocking( + GetNamespaceRequest.newBuilder() + .setFqn("https://" + namespaceName) + .build(), + Collections.emptyMap()) + .execute()) + .getNamespace(); CreateAttributeRequest createAttributeRequest = CreateAttributeRequest.newBuilder() @@ -74,7 +68,13 @@ public static void main(String[] args) { "Successfully created attribute with ID: {}", createAttributeResponse.getAttribute().getId()); } catch (Exception e) { - logger.fatal("Failed to create attribute", e); + if (Objects.equals(e.getMessage(), "resource not found")) { + logger.error("Namespace '{}' not found", namespaceName, e); + } else if (Objects.equals(e.getMessage(), "resource unique field violation")) { + logger.error("Attribute already exists", e); + } else { + logger.error("Failed to create attribute", e); + } } } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateNamespace.java b/examples/src/main/java/io/opentdf/platform/CreateNamespace.java index 8abfdef3..29212ac5 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateNamespace.java +++ b/examples/src/main/java/io/opentdf/platform/CreateNamespace.java @@ -8,6 +8,7 @@ import org.apache.logging.log4j.Logger; import java.util.Collections; +import java.util.Objects; public class CreateNamespace { @@ -18,6 +19,7 @@ public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; String platformEndpoint = "localhost:8080"; + String namespaceName = "mynamespace.com"; SDKBuilder builder = new SDKBuilder(); @@ -29,7 +31,7 @@ public static void main(String[] args) { .build()) { CreateNamespaceRequest createNamespaceRequest = - CreateNamespaceRequest.newBuilder().setName("mynamespace.com").build(); + CreateNamespaceRequest.newBuilder().setName(namespaceName).build(); CreateNamespaceResponse createNamespaceResponse = ResponseMessageKt.getOrThrow( @@ -43,7 +45,11 @@ public static void main(String[] args) { createNamespaceResponse.getNamespace().getId()); } catch (Exception e) { - logger.fatal("Failed to create namespace", e); + if (Objects.equals(e.getMessage(), "resource unique field violation")) { + logger.error("Namespace '{}' already exists", namespaceName, e); + } else { + logger.error("Failed to create namespace", e); + } } } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java b/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java index c1cfc898..8d7241ea 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java +++ b/examples/src/main/java/io/opentdf/platform/CreateSubjectConditionSet.java @@ -60,6 +60,7 @@ public static void main(String[] args) { .createSubjectConditionSetBlocking( createSubjectConditionSetRequest, Collections.emptyMap()) .execute()); + SubjectConditionSet subjectConditionSet = createSubjectConditionSetResponse.getSubjectConditionSet(); @@ -67,7 +68,7 @@ public static void main(String[] args) { "Successfully created subject condition set with ID: {}", subjectConditionSet.getId()); } catch (Exception e) { - logger.fatal("Failed to create subject condition set", e); + logger.error("Failed to create subject condition set", e); } } } diff --git a/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java b/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java index 1e34a7b6..4a9d62b8 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java +++ b/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java @@ -3,7 +3,6 @@ import com.connectrpc.ResponseMessageKt; import io.opentdf.platform.policy.Action; import io.opentdf.platform.policy.Attribute; -import io.opentdf.platform.policy.AttributeRuleTypeEnum; import io.opentdf.platform.policy.Condition; import io.opentdf.platform.policy.ConditionBooleanTypeEnum; import io.opentdf.platform.policy.ConditionGroup; @@ -12,8 +11,6 @@ import io.opentdf.platform.policy.SubjectMapping; import io.opentdf.platform.policy.SubjectMappingOperatorEnum; import io.opentdf.platform.policy.SubjectSet; -import io.opentdf.platform.policy.attributes.CreateAttributeRequest; -import io.opentdf.platform.policy.attributes.CreateAttributeResponse; import io.opentdf.platform.policy.attributes.GetAttributeRequest; import io.opentdf.platform.policy.namespaces.GetNamespaceRequest; import io.opentdf.platform.policy.subjectmapping.CreateSubjectConditionSetRequest; @@ -26,8 +23,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import java.util.Arrays; import java.util.Collections; +import java.util.Objects; public class CreateSubjectMapping { @@ -37,6 +34,8 @@ public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; String platformEndpoint = "localhost:8080"; + String namespaceName = "mynamespace.com"; + String attributeName = "test-attribute"; SDKBuilder builder = new SDKBuilder(); try (SDK sdk = @@ -47,7 +46,6 @@ public static void main(String[] args) { .build()) { Namespace namespace; - String namespaceName = "mynamespace.com"; try { namespace = @@ -62,12 +60,15 @@ public static void main(String[] args) { .execute()) .getNamespace(); } catch (Exception e) { - logger.error("Namespace '{}' not found", namespaceName); - throw e; + if (Objects.equals(e.getMessage(), "resource not found")) { + logger.error("Namespace '{}' not found", namespaceName, e); + } else { + logger.error("Failed to retrieve namespace '{}'", namespaceName, e); + } + return; } Attribute attribute; - String attributeName = "test-attribute"; String attributeFqn = namespace.getFqn() + "/attr/" + attributeName; try { @@ -82,29 +83,13 @@ public static void main(String[] args) { .execute()) .getAttribute(); - logger.info("Found existing attribute with ID: {}", attribute.getId()); - } catch (Exception e) { - CreateAttributeRequest attributeRequest = - CreateAttributeRequest.newBuilder() - .setNamespaceId(namespace.getId()) - .setName(attributeName) - .setRule( - AttributeRuleTypeEnum.forNumber( - AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF_VALUE)) - .addAllValues(Arrays.asList("test1", "test2")) - .build(); - - CreateAttributeResponse attributeResponse = - ResponseMessageKt.getOrThrow( - sdk.getServices() - .attributes() - .createAttributeBlocking(attributeRequest, Collections.emptyMap()) - .execute()); - - attribute = attributeResponse.getAttribute(); - - logger.info("Successfully created attribute with ID: {}", attribute.getId()); + if (Objects.equals(e.getMessage(), "resource not found")) { + logger.error("Attribute '{}' not found", attributeFqn, e); + } else { + logger.error("Failed to retrieve attribute '{}'", attributeFqn, e); + } + return; } CreateSubjectConditionSetRequest subjectConditionSetRequest = @@ -155,7 +140,7 @@ public static void main(String[] args) { logger.info("Successfully created subject mapping with ID: {}", subjectMapping.getId()); } catch (Exception e) { - logger.fatal("Failed to create subject mapping", e); + logger.error("Failed to create subject mapping", e); } } } diff --git a/examples/src/main/java/io/opentdf/platform/GetDecisions.java b/examples/src/main/java/io/opentdf/platform/GetDecisions.java index 4d79b689..511c8d9c 100644 --- a/examples/src/main/java/io/opentdf/platform/GetDecisions.java +++ b/examples/src/main/java/io/opentdf/platform/GetDecisions.java @@ -16,6 +16,7 @@ import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; public class GetDecisions { @@ -64,9 +65,14 @@ public static void main(String[] args) { List decisions = getDecisionsResponse.getDecisionResponsesList(); - logger.info("Successfully retrieved decision {}", decisions.get(0).getDecision()); + logger.info( + "Successfully retrieved decisions: [{}]", + decisions.stream() + .map(DecisionResponse::getDecision) + .map(DecisionResponse.Decision::toString) + .collect(Collectors.joining(", "))); } catch (Exception e) { - logger.fatal("Failed to get decisions", e); + logger.error("Failed to get decisions", e); } } } diff --git a/examples/src/main/java/io/opentdf/platform/GetEntitlements.java b/examples/src/main/java/io/opentdf/platform/GetEntitlements.java index 0ac590ae..a1719626 100644 --- a/examples/src/main/java/io/opentdf/platform/GetEntitlements.java +++ b/examples/src/main/java/io/opentdf/platform/GetEntitlements.java @@ -12,6 +12,7 @@ import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; public class GetEntitlements { private static final Logger logger = LogManager.getLogger(GetEntitlements.class); @@ -46,10 +47,13 @@ public static void main(String[] args) { List entitlements = getEntitlementsResponse.getEntitlementsList(); logger.info( - "Successfully retrieved entitlements {}", - entitlements.get(0).getAttributeValueFqnsList()); + "Successfully retrieved entitlements: [{}]", + entitlements.stream() + .map(EntityEntitlements::getAttributeValueFqnsList) + .map(List::toString) + .collect(Collectors.joining(", "))); } catch (Exception e) { - logger.fatal("Failed to get entitlements", e); + logger.error("Failed to get entitlements", e); } } } diff --git a/examples/src/main/java/io/opentdf/platform/ListAttributes.java b/examples/src/main/java/io/opentdf/platform/ListAttributes.java index 597cc769..71f4fc0d 100644 --- a/examples/src/main/java/io/opentdf/platform/ListAttributes.java +++ b/examples/src/main/java/io/opentdf/platform/ListAttributes.java @@ -44,10 +44,10 @@ public static void main(String[] args) { List attributes = listAttributesResponse.getAttributesList(); logger.info( - "Successfully retrieved attributes {}", + "Successfully retrieved attributes: [{}]", attributes.stream().map(Attribute::getFqn).collect(Collectors.joining(", "))); } catch (Exception e) { - logger.fatal("Failed to list attributes", e); + logger.error("Failed to list attributes", e); } } } diff --git a/examples/src/main/java/io/opentdf/platform/ListNamespaces.java b/examples/src/main/java/io/opentdf/platform/ListNamespaces.java index bdb04e1f..f728ca63 100644 --- a/examples/src/main/java/io/opentdf/platform/ListNamespaces.java +++ b/examples/src/main/java/io/opentdf/platform/ListNamespaces.java @@ -42,10 +42,10 @@ public static void main(String[] args) { List namespaces = listNamespacesResponse.getNamespacesList(); logger.info( - "Successfully retrieved namespaces {}", + "Successfully retrieved namespaces: [{}]", namespaces.stream().map(Namespace::getFqn).collect(Collectors.joining(", "))); } catch (Exception e) { - logger.fatal("Failed to list namespaces", e); + logger.error("Failed to list namespaces", e); } } } diff --git a/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java b/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java index 10a212e1..a69e1aae 100644 --- a/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java +++ b/examples/src/main/java/io/opentdf/platform/ListSubjectMappings.java @@ -44,10 +44,10 @@ public static void main(String[] args) { List subjectMappings = listSubjectMappingsResponse.getSubjectMappingsList(); logger.info( - "Successfully retrieved subject mappings {}", + "Successfully retrieved subject mappings: [{}]", subjectMappings.stream().map(SubjectMapping::getId).collect(Collectors.joining(", "))); } catch (Exception e) { - logger.fatal("Failed to list subject mappings", e); + logger.error("Failed to list subject mappings", e); } } } From 5b7c29904a3e6b7a576f12220ce483a53c48d8f8 Mon Sep 17 00:00:00 2001 From: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> Date: Mon, 8 Dec 2025 10:37:40 -0600 Subject: [PATCH 5/5] fix(examples): update namespace name in examples Signed-off-by: Scott Hamrick <2623452+cshamrick@users.noreply.github.com> --- .../src/main/java/io/opentdf/platform/CreateAttribute.java | 4 ++-- .../src/main/java/io/opentdf/platform/CreateNamespace.java | 2 +- .../java/io/opentdf/platform/CreateSubjectMapping.java | 2 +- .../src/main/java/io/opentdf/platform/GetDecisions.java | 7 +++---- .../src/main/java/io/opentdf/platform/ListAttributes.java | 3 ++- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/examples/src/main/java/io/opentdf/platform/CreateAttribute.java b/examples/src/main/java/io/opentdf/platform/CreateAttribute.java index a9dfcd52..bd38a02f 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateAttribute.java +++ b/examples/src/main/java/io/opentdf/platform/CreateAttribute.java @@ -24,7 +24,7 @@ public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; String platformEndpoint = "localhost:8080"; - String namespaceName = "mynamespace.com"; + String namespaceName = "opentdf.io"; SDKBuilder builder = new SDKBuilder(); @@ -50,7 +50,7 @@ public static void main(String[] args) { CreateAttributeRequest createAttributeRequest = CreateAttributeRequest.newBuilder() .setNamespaceId(namespace.getId()) - .setName("test") + .setName("test-attribute") .setRule( AttributeRuleTypeEnum.forNumber( AttributeRuleTypeEnum.ATTRIBUTE_RULE_TYPE_ENUM_ALL_OF_VALUE)) diff --git a/examples/src/main/java/io/opentdf/platform/CreateNamespace.java b/examples/src/main/java/io/opentdf/platform/CreateNamespace.java index 29212ac5..ee7ac939 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateNamespace.java +++ b/examples/src/main/java/io/opentdf/platform/CreateNamespace.java @@ -19,7 +19,7 @@ public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; String platformEndpoint = "localhost:8080"; - String namespaceName = "mynamespace.com"; + String namespaceName = "opentdf.io"; SDKBuilder builder = new SDKBuilder(); diff --git a/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java b/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java index 4a9d62b8..9a1b6657 100644 --- a/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java +++ b/examples/src/main/java/io/opentdf/platform/CreateSubjectMapping.java @@ -34,7 +34,7 @@ public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; String platformEndpoint = "localhost:8080"; - String namespaceName = "mynamespace.com"; + String namespaceName = "opentdf.io"; String attributeName = "test-attribute"; SDKBuilder builder = new SDKBuilder(); diff --git a/examples/src/main/java/io/opentdf/platform/GetDecisions.java b/examples/src/main/java/io/opentdf/platform/GetDecisions.java index 511c8d9c..f9126f86 100644 --- a/examples/src/main/java/io/opentdf/platform/GetDecisions.java +++ b/examples/src/main/java/io/opentdf/platform/GetDecisions.java @@ -27,6 +27,7 @@ public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; String platformEndpoint = "localhost:8080"; + String namespaceName = "opentdf.io"; SDKBuilder builder = new SDKBuilder(); @@ -46,14 +47,12 @@ public static void main(String[] args) { .setId("ec1") .addEntities( Entity.newBuilder().setId("entity-1").setClientId("opentdf"))) - .addActions( - Action.newBuilder() - .setStandard(Action.StandardAction.STANDARD_ACTION_DECRYPT)) + .addActions(Action.newBuilder().setName("read")) .addResourceAttributes( ResourceAttribute.newBuilder() .setResourceAttributesId("resource-attribute-1") .addAttributeValueFqns( - "https://mynamespace.com/attr/test/value/test1"))) + "https://" + namespaceName + "/attr/test/value/test1"))) .build(); GetDecisionsResponse getDecisionsResponse = diff --git a/examples/src/main/java/io/opentdf/platform/ListAttributes.java b/examples/src/main/java/io/opentdf/platform/ListAttributes.java index 71f4fc0d..be7ee91f 100644 --- a/examples/src/main/java/io/opentdf/platform/ListAttributes.java +++ b/examples/src/main/java/io/opentdf/platform/ListAttributes.java @@ -21,6 +21,7 @@ public static void main(String[] args) { String clientId = "opentdf"; String clientSecret = "secret"; String platformEndpoint = "localhost:8080"; + String namespaceName = "opentdf.io"; SDKBuilder builder = new SDKBuilder(); @@ -32,7 +33,7 @@ public static void main(String[] args) { .build()) { ListAttributesRequest request = - ListAttributesRequest.newBuilder().setNamespace("mynamespace.com").build(); + ListAttributesRequest.newBuilder().setNamespace(namespaceName).build(); ListAttributesResponse listAttributesResponse = ResponseMessageKt.getOrThrow(