class IdentityDocumentGenerator {

    public SignedIdentityDocument generateSignedIdentityDocument(String hostname, IdentityType identityType) {
        try {
            Node node = nodeRepository.getNode(hostname).orElseThrow(() -> new RuntimeException("Unable to find node " + hostname));
            Allocation allocation = node.allocation().orElseThrow(() -> new RuntimeException("No allocation for node " + node.hostname()));
            VespaUniqueInstanceId providerUniqueId = new VespaUniqueInstanceId(
                    allocation.membership().index(),
                    allocation.membership().cluster().id().value(),
                    allocation.owner().instance().value(),
                    allocation.owner().application().value(),
                    allocation.owner().tenant().value(),
                    zone.region().value(),
                    zone.environment().value(),
                    identityType);

            Set<String> ips = new HashSet<>(node.ipConfig().primary());

            PrivateKey privateKey = keyProvider.getPrivateKey(athenzProviderServiceConfig.secretVersion());
            AthenzService providerService = new AthenzService(athenzProviderServiceConfig.domain(), athenzProviderServiceConfig.serviceName());

            String configServerHostname = HostName.getLocalhost();
            Instant createdAt = Instant.now();
            String signature = signer.generateSignature(
                    providerUniqueId, providerService, configServerHostname,
                    node.hostname(), createdAt, ips, identityType, privateKey);

            return new SignedIdentityDocument(
                    signature,
                    SignedIdentityDocument.DEFAULT_KEY_VERSION,
                    providerUniqueId,
                    providerService,
                    SignedIdentityDocument.DEFAULT_DOCUMENT_VERSION,
                    configServerHostname,
                    node.hostname(),
                    createdAt,
                    ips,
                    identityType);
        } catch (Exception e) {
            throw new RuntimeException("Exception generating identity document: " + e.getMessage(), e);
        }
    }

    @Inject public  IdentityDocumentGenerator(AthenzProviderServiceConfig config,
                                     NodeRepository nodeRepository,
                                     Zone zone,
                                     KeyProvider keyProvider);

}