InstanceSerializer { public static InstanceRegistration registrationFromSlime(Slime slime) { Cursor root = slime.get(); return new InstanceRegistration(requireField(PROVIDER_FIELD, root).asString(), requireField(DOMAIN_FIELD, root).asString(), requireField(SERVICE_FIELD, root).asString(), attestationDataToIdentityDocument(StringUtilities.unescape(requireField(ATTESTATION_DATA_FIELD, root).asString())), Pkcs10CsrUtils.fromPem(requireField(CSR_FIELD, root).asString())); } private  InstanceSerializer(); static InstanceRegistration registrationFromSlime(Slime slime); static InstanceRefresh refreshFromSlime(Slime slime); static Slime identityToSlime(InstanceIdentity identity); static SignedIdentityDocument attestationDataToIdentityDocument(String attestationData);  }
@Test public void deserialize_instance_registration() { var csr = CertificateTester.createCsr(); var csrPem = Pkcs10CsrUtils.toPem(csr); SignedIdentityDocument signedIdentityDocument = new SignedIdentityDocument( "signature", 0, new VespaUniqueInstanceId(0, "cluster", "instance", "application", "tenant", "region", "prod", IdentityType.NODE), new AthenzService("domain", "service"), 0, "configserverhostname", "instancehostname", Instant.now(), Collections.emptySet(), IdentityType.NODE); var json = String.format("{\n" + " \"provider\": \"provider_prod_us-north-1\",\n" + " \"domain\": \"vespa.external\",\n" + " \"service\": \"tenant\",\n" + " \"attestationData\":\"%s\",\n" + " \"csr\": \"" + csrPem + "\"\n" + "}", StringUtilities.escape(EntityBindingsMapper.toAttestationData(signedIdentityDocument))); var instanceRegistration = new InstanceRegistration("provider_prod_us-north-1", "vespa.external", "tenant", signedIdentityDocument, csr); var deserialized = InstanceSerializer.registrationFromSlime(SlimeUtils.jsonToSlime(json)); assertEquals(instanceRegistration, deserialized); }