Skip to content

Commit cfae751

Browse files
committed
one more sonar
1 parent bf6545c commit cfae751

File tree

1 file changed

+36
-34
lines changed

1 file changed

+36
-34
lines changed

sdk/src/main/java/io/opentdf/platform/sdk/Autoconfigure.java

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -711,45 +711,47 @@ public static Granter newGranterFromService(AttributesServiceClient as, KASKeyCa
711711
return getGranter(keyCache, new ArrayList<>(av.getFqnAttributeValuesMap().values()));
712712
}
713713

714+
private static List<KeyAccessServer> getGrants(GetAttributeValuesByFqnsResponse.AttributeAndValue attributeAndValue) {
715+
var val = attributeAndValue.getValue();
716+
var attribute = attributeAndValue.getAttribute();
717+
String fqnstr = val.getFqn();
718+
AttributeValueFQN fqn = new AttributeValueFQN(fqnstr);
719+
720+
if (!val.getGrantsList().isEmpty()) {
721+
if (logger.isDebugEnabled()) {
722+
logger.debug("adding grants from attribute value [{}]: {}", val.getFqn(), val.getGrantsList().stream().map(KeyAccessServer::getUri).collect(Collectors.toList()));
723+
}
724+
return val.getGrantsList();
725+
} else if (!attribute.getGrantsList().isEmpty()) {
726+
var attributeGrants = attribute.getGrantsList();
727+
if (logger.isDebugEnabled()) {
728+
logger.debug("adding grants from attribute [{}]: {}", attribute.getFqn(), attributeGrants.stream().map(KeyAccessServer::getId).collect(Collectors.toList()));
729+
}
730+
return attributeGrants;
731+
} else if (!attribute.getNamespace().getGrantsList().isEmpty()) {
732+
var nsGrants = attribute.getNamespace().getGrantsList();
733+
if (logger.isDebugEnabled()) {
734+
logger.debug("adding grants from namespace [{}]: [{}]", attribute.getNamespace().getName(), nsGrants.stream().map(KeyAccessServer::getId).collect(Collectors.toList()));
735+
}
736+
return nsGrants;
737+
} else {
738+
// this is needed to mark the fact that we have an empty
739+
logger.debug("didn't find any grants on value, attribute, or namespace for attribute value [{}]", fqnstr);
740+
return Collections.emptyList();
741+
}
742+
743+
}
744+
714745
private static Granter getGranter(@Nullable KASKeyCache keyCache, List<GetAttributeValuesByFqnsResponse.AttributeAndValue> values) {
715746
Granter grants = new Granter(values.stream().map(GetAttributeValuesByFqnsResponse.AttributeAndValue::getValue).map(Value::getFqn).map(AttributeValueFQN::new).collect(Collectors.toList()));
716747

717748
for (var attributeAndValue: values) {
718-
var val = attributeAndValue.getValue();
719-
var attribute = attributeAndValue.getAttribute();
720-
String fqnstr = val.getFqn();
749+
var attributeGrants = getGrants(attributeAndValue);
750+
String fqnstr = attributeAndValue.getValue().getFqn();
721751
AttributeValueFQN fqn = new AttributeValueFQN(fqnstr);
722-
723-
if (!val.getGrantsList().isEmpty()) {
724-
if (logger.isDebugEnabled()) {
725-
logger.debug("adding grants from attribute value [{}]: {}", val.getFqn(), val.getGrantsList().stream().map(KeyAccessServer::getUri).collect(Collectors.toList()));
726-
}
727-
grants.addAllGrants(fqn, val.getGrantsList(), attribute);
728-
if (keyCache != null) {
729-
storeKeysToCache(val.getGrantsList(), keyCache);
730-
}
731-
} else if (!attribute.getGrantsList().isEmpty()) {
732-
var attributeGrants = attribute.getGrantsList();
733-
if (logger.isDebugEnabled()) {
734-
logger.debug("adding grants from attribute [{}]: {}", attribute.getFqn(), attributeGrants.stream().map(KeyAccessServer::getId).collect(Collectors.toList()));
735-
}
736-
grants.addAllGrants(fqn, attributeGrants, attribute);
737-
if (keyCache != null) {
738-
storeKeysToCache(attributeGrants, keyCache);
739-
}
740-
} else if (!attribute.getNamespace().getGrantsList().isEmpty()) {
741-
var nsGrants = attribute.getNamespace().getGrantsList();
742-
if (logger.isDebugEnabled()) {
743-
logger.debug("adding grants from namespace [{}]: [{}]", attribute.getNamespace().getName(), nsGrants.stream().map(KeyAccessServer::getId).collect(Collectors.toList()));
744-
}
745-
grants.addAllGrants(fqn, nsGrants, attribute);
746-
if (keyCache != null) {
747-
storeKeysToCache(nsGrants, keyCache);
748-
}
749-
} else {
750-
// this is needed to mark the fact that we have an empty
751-
grants.addAllGrants(fqn, List.of(), attribute);
752-
logger.debug("didn't find any grants on value, attribute, or namespace for attribute value [{}]", fqnstr);
752+
grants.addAllGrants(fqn, attributeGrants, attributeAndValue.getAttribute());
753+
if (keyCache != null) {
754+
storeKeysToCache(attributeGrants, keyCache);
753755
}
754756
}
755757

0 commit comments

Comments
 (0)