Add utility methods to (de)serialize signed identity document from/to file
@@ -10,9 +10,12 @@ import com.yahoo.vespa.athenz.identityprovider.api.bindings.SignedIdentityDocume
import com.yahoo.vespa.athenz.identityprovider.api.bindings.VespaUniqueInstanceIdEntity;
import com.yahoo.vespa.athenz.utils.AthenzIdentities;
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Path;
import java.util.Base64;
-import static com.yahoo.vespa.athenz.identityprovider.api.VespaUniqueInstanceId.*;
+import static com.yahoo.vespa.athenz.identityprovider.api.VespaUniqueInstanceId.fromDottedString;
/**
* Utility class for mapping objects model types and their Jackson binding versions.
@@ -102,4 +105,22 @@ public class EntityBindingsMapper {
}
}
+ public static SignedIdentityDocument readSignedIdentityDocumentFromFile(Path file) {
+ try {
+ SignedIdentityDocumentEntity entity = mapper.readValue(file.toFile(), SignedIdentityDocumentEntity.class);
+ return EntityBindingsMapper.toSignedIdentityDocument(entity);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
+ public static void writeSignedIdentityDocumentToFile(Path file, SignedIdentityDocument document) {
+ try {
+ SignedIdentityDocumentEntity entity = EntityBindingsMapper.toSignedIdentityDocumentEntity(document);
+ mapper.writeValue(file.toFile(), entity);
+ } catch (IOException e) {
+ throw new UncheckedIOException(e);
+ }
+ }
+
}
