fix(paymentcryptography): a member the request carries as null is absent (#8975)

* fix(paymentcryptography): a member the request carries as null is absent
This commit is contained in:
Murtuza Chhil authored and GitHub committed 2026-11-19 11:25:17 -04:00
1 parent 030ba3d72b
commit c2721ca938
5 files changed
+213 -59

No files matched your search

@@ -9,7 +9,6 @@ import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HexFormat;
import java.util.LinkedHashMap;
import java.util.List;
@@ -23,6 +22,7 @@ import static io.floci.aws.services.paymentcryptography.PaymentCryptographyKeyRu
import static io.floci.aws.services.paymentcryptography.PaymentCryptographyKeyRules.requireFamily;
import static io.floci.aws.services.paymentcryptography.PaymentCryptographyKeyRules.requireMode;
import static io.floci.aws.services.paymentcryptography.PaymentCryptographyKeyRules.requireUsage;
import static io.floci.aws.services.paymentcryptography.PaymentCryptographyMembers.members;
import static io.floci.aws.services.paymentcryptography.PaymentCryptographyService.isAes;
import static io.floci.aws.services.paymentcryptography.PaymentCryptographyService.isTdes;
@@ -221,29 +221,6 @@ public class PaymentCryptographyCryptoHandler {
return service.translateKeyMaterial(region, members(request));
}
/** The members of a request, as the map the exchange reads. */
private static Map<String, Object> members(JsonNode node) {
Map<String, Object> out = new LinkedHashMap<>();
if (node == null || !node.isObject()) {
return out;
}
node.properties().forEach(entry -> out.put(entry.getKey(), member(entry.getValue())));
return out;
}
/** The value of a member, as the exchange reads it. */
private static Object member(JsonNode node) {
if (node.isObject()) {
return members(node);
}
if (node.isArray()) {
List<Object> values = new ArrayList<>();
node.forEach(value -> values.add(member(value)));
return values;
}
return node.asText();
}
/**
* The operation is not served, and says so.
*/
@@ -21,6 +21,8 @@ import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import static io.floci.aws.services.paymentcryptography.PaymentCryptographyMembers.members;
/**
* The Payment Cryptography control plane.
*
@@ -831,38 +833,6 @@ public class PaymentCryptographyJsonHandler {
return form;
}
/** The members of a form, as the service reads them. */
private static Map<String, Object> members(JsonNode node) {
Map<String, Object> out = new LinkedHashMap<>();
if (node == null || !node.isObject()) {
return out;
}
node.properties().forEach(entry -> out.put(entry.getKey(), value(entry.getValue())));
return out;
}
/** One member of a form, as the service reads it. */
private static Object value(JsonNode node) {
if (node == null || node.isNull()) {
return null;
}
if (node.isObject()) {
return members(node);
}
if (node.isArray()) {
List<Object> values = new ArrayList<>();
node.forEach(child -> values.add(value(child)));
return values;
}
if (node.isBoolean()) {
return node.asBoolean();
}
if (node.isNumber()) {
return node.asText();
}
return node.asText();
}
/**
* The key with the regions the request names added to its replication.
*/
@@ -0,0 +1,65 @@
package io.floci.aws.services.paymentcryptography;
import com.fasterxml.jackson.databind.JsonNode;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* How the members of a request are read.
*
* <p>The control plane's handler and the data plane's handler both turn the JSON of a
* request into the map the service reads, and the map is the same either way: the
* members of the request, in the order they came in, with an object a map of its own and
* a list a list of its own. Reading them is therefore read in one place.
*/
final class PaymentCryptographyMembers {
private PaymentCryptographyMembers() {
}
/**
* The members of a node, as the service reads them.
*
* @param node the object to read
* @return the members of the object, in the order they came in
*/
static Map<String, Object> members(JsonNode node) {
Map<String, Object> out = new LinkedHashMap<>();
if (node == null || !node.isObject()) {
return out;
}
node.properties().forEach(entry -> out.put(entry.getKey(), value(entry.getValue())));
return out;
}
/**
* One member of a node, as the service reads it.
*
* <p>A member the request carries as a null is a member the request does not carry,
* and not a member that carries the text {@code "null"}. A boolean is a boolean, and
* not its text.
*
* @param node the value to read
* @return the value, as the service reads it
*/
static Object value(JsonNode node) {
if (node == null || node.isNull()) {
return null;
}
if (node.isObject()) {
return members(node);
}
if (node.isArray()) {
List<Object> values = new ArrayList<>();
node.forEach(child -> values.add(value(child)));
return values;
}
if (node.isBoolean()) {
return node.asBoolean();
}
return node.asText();
}
}