@Test public void marshalAWSKeyPair() { AWSKeyPair configKeyPair = new AWSKeyPair("PUBLIC_KEY_ID", "PRIVATE_KEY_ID"); KeyData result = KeyDataUtil.marshal(configKeyPair); assertThat(result.getAwsSecretsManagerPublicKeyId()).isEqualTo("PUBLIC_KEY_ID"); assertThat(result.getAwsSecretsManagerPrivateKeyId()).isEqualTo("PRIVATE_KEY_ID"); }
public static KeyData marshal(final ConfigKeyPair keyPair) { final KeyData keyData = new KeyData(); if (DirectKeyPair.class.isInstance(keyPair)) { DirectKeyPair kp = DirectKeyPair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setPrivateKey(kp.getPrivateKey()); return keyData; } if (InlineKeypair.class.isInstance(keyPair)) { InlineKeypair kp = InlineKeypair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setConfig(kp.getPrivateKeyConfig()); return keyData; } if (AzureVaultKeyPair.class.isInstance(keyPair)) { AzureVaultKeyPair kp = AzureVaultKeyPair.class.cast(keyPair); keyData.setAzureVaultPublicKeyId(kp.getPublicKeyId()); keyData.setAzureVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setAzureVaultPublicKeyVersion(kp.getPublicKeyVersion()); keyData.setAzureVaultPrivateKeyVersion(kp.getPrivateKeyVersion()); return keyData; } if (HashicorpVaultKeyPair.class.isInstance(keyPair)) { HashicorpVaultKeyPair kp = HashicorpVaultKeyPair.class.cast(keyPair); keyData.setHashicorpVaultPublicKeyId(kp.getPublicKeyId()); keyData.setHashicorpVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setHashicorpVaultSecretEngineName(kp.getSecretEngineName()); keyData.setHashicorpVaultSecretName(kp.getSecretName()); keyData.setHashicorpVaultSecretVersion(Objects.toString(kp.getSecretVersion(), null)); return keyData; } if (AWSKeyPair.class.isInstance(keyPair)) { AWSKeyPair kp = AWSKeyPair.class.cast(keyPair); keyData.setAwsSecretsManagerPublicKeyId(kp.getPublicKeyId()); keyData.setAwsSecretsManagerPrivateKeyId(kp.getPrivateKeyId()); return keyData; } if (FilesystemKeyPair.class.isInstance(keyPair)) { FilesystemKeyPair kp = FilesystemKeyPair.class.cast(keyPair); keyData.setPublicKeyPath(kp.getPublicKeyPath()); keyData.setPrivateKeyPath(kp.getPrivateKeyPath()); return keyData; } if (UnsupportedKeyPair.class.isInstance(keyPair)) { UnsupportedKeyPair kp = UnsupportedKeyPair.class.cast(keyPair); return new KeyData( kp.getConfig(), kp.getPrivateKey(), kp.getPublicKey(), kp.getPrivateKeyPath(), kp.getPublicKeyPath(), kp.getAzureVaultPrivateKeyId(), kp.getAzureVaultPublicKeyId(), kp.getAzureVaultPublicKeyVersion(), kp.getAzureVaultPrivateKeyVersion(), kp.getHashicorpVaultPrivateKeyId(), kp.getHashicorpVaultPublicKeyId(), kp.getHashicorpVaultSecretEngineName(), kp.getHashicorpVaultSecretName(), kp.getHashicorpVaultSecretVersion(), kp.getAwsSecretsManagerPublicKeyId(), kp.getAwsSecretsManagerPrivateKeyId()); } throw new UnsupportedOperationException("The keypair type " + keyPair.getClass() + " is not allowed"); }
KeyDataUtil { public static KeyData marshal(final ConfigKeyPair keyPair) { final KeyData keyData = new KeyData(); if (DirectKeyPair.class.isInstance(keyPair)) { DirectKeyPair kp = DirectKeyPair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setPrivateKey(kp.getPrivateKey()); return keyData; } if (InlineKeypair.class.isInstance(keyPair)) { InlineKeypair kp = InlineKeypair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setConfig(kp.getPrivateKeyConfig()); return keyData; } if (AzureVaultKeyPair.class.isInstance(keyPair)) { AzureVaultKeyPair kp = AzureVaultKeyPair.class.cast(keyPair); keyData.setAzureVaultPublicKeyId(kp.getPublicKeyId()); keyData.setAzureVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setAzureVaultPublicKeyVersion(kp.getPublicKeyVersion()); keyData.setAzureVaultPrivateKeyVersion(kp.getPrivateKeyVersion()); return keyData; } if (HashicorpVaultKeyPair.class.isInstance(keyPair)) { HashicorpVaultKeyPair kp = HashicorpVaultKeyPair.class.cast(keyPair); keyData.setHashicorpVaultPublicKeyId(kp.getPublicKeyId()); keyData.setHashicorpVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setHashicorpVaultSecretEngineName(kp.getSecretEngineName()); keyData.setHashicorpVaultSecretName(kp.getSecretName()); keyData.setHashicorpVaultSecretVersion(Objects.toString(kp.getSecretVersion(), null)); return keyData; } if (AWSKeyPair.class.isInstance(keyPair)) { AWSKeyPair kp = AWSKeyPair.class.cast(keyPair); keyData.setAwsSecretsManagerPublicKeyId(kp.getPublicKeyId()); keyData.setAwsSecretsManagerPrivateKeyId(kp.getPrivateKeyId()); return keyData; } if (FilesystemKeyPair.class.isInstance(keyPair)) { FilesystemKeyPair kp = FilesystemKeyPair.class.cast(keyPair); keyData.setPublicKeyPath(kp.getPublicKeyPath()); keyData.setPrivateKeyPath(kp.getPrivateKeyPath()); return keyData; } if (UnsupportedKeyPair.class.isInstance(keyPair)) { UnsupportedKeyPair kp = UnsupportedKeyPair.class.cast(keyPair); return new KeyData( kp.getConfig(), kp.getPrivateKey(), kp.getPublicKey(), kp.getPrivateKeyPath(), kp.getPublicKeyPath(), kp.getAzureVaultPrivateKeyId(), kp.getAzureVaultPublicKeyId(), kp.getAzureVaultPublicKeyVersion(), kp.getAzureVaultPrivateKeyVersion(), kp.getHashicorpVaultPrivateKeyId(), kp.getHashicorpVaultPublicKeyId(), kp.getHashicorpVaultSecretEngineName(), kp.getHashicorpVaultSecretName(), kp.getHashicorpVaultSecretVersion(), kp.getAwsSecretsManagerPublicKeyId(), kp.getAwsSecretsManagerPrivateKeyId()); } throw new UnsupportedOperationException("The keypair type " + keyPair.getClass() + " is not allowed"); } }
KeyDataUtil { public static KeyData marshal(final ConfigKeyPair keyPair) { final KeyData keyData = new KeyData(); if (DirectKeyPair.class.isInstance(keyPair)) { DirectKeyPair kp = DirectKeyPair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setPrivateKey(kp.getPrivateKey()); return keyData; } if (InlineKeypair.class.isInstance(keyPair)) { InlineKeypair kp = InlineKeypair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setConfig(kp.getPrivateKeyConfig()); return keyData; } if (AzureVaultKeyPair.class.isInstance(keyPair)) { AzureVaultKeyPair kp = AzureVaultKeyPair.class.cast(keyPair); keyData.setAzureVaultPublicKeyId(kp.getPublicKeyId()); keyData.setAzureVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setAzureVaultPublicKeyVersion(kp.getPublicKeyVersion()); keyData.setAzureVaultPrivateKeyVersion(kp.getPrivateKeyVersion()); return keyData; } if (HashicorpVaultKeyPair.class.isInstance(keyPair)) { HashicorpVaultKeyPair kp = HashicorpVaultKeyPair.class.cast(keyPair); keyData.setHashicorpVaultPublicKeyId(kp.getPublicKeyId()); keyData.setHashicorpVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setHashicorpVaultSecretEngineName(kp.getSecretEngineName()); keyData.setHashicorpVaultSecretName(kp.getSecretName()); keyData.setHashicorpVaultSecretVersion(Objects.toString(kp.getSecretVersion(), null)); return keyData; } if (AWSKeyPair.class.isInstance(keyPair)) { AWSKeyPair kp = AWSKeyPair.class.cast(keyPair); keyData.setAwsSecretsManagerPublicKeyId(kp.getPublicKeyId()); keyData.setAwsSecretsManagerPrivateKeyId(kp.getPrivateKeyId()); return keyData; } if (FilesystemKeyPair.class.isInstance(keyPair)) { FilesystemKeyPair kp = FilesystemKeyPair.class.cast(keyPair); keyData.setPublicKeyPath(kp.getPublicKeyPath()); keyData.setPrivateKeyPath(kp.getPrivateKeyPath()); return keyData; } if (UnsupportedKeyPair.class.isInstance(keyPair)) { UnsupportedKeyPair kp = UnsupportedKeyPair.class.cast(keyPair); return new KeyData( kp.getConfig(), kp.getPrivateKey(), kp.getPublicKey(), kp.getPrivateKeyPath(), kp.getPublicKeyPath(), kp.getAzureVaultPrivateKeyId(), kp.getAzureVaultPublicKeyId(), kp.getAzureVaultPublicKeyVersion(), kp.getAzureVaultPrivateKeyVersion(), kp.getHashicorpVaultPrivateKeyId(), kp.getHashicorpVaultPublicKeyId(), kp.getHashicorpVaultSecretEngineName(), kp.getHashicorpVaultSecretName(), kp.getHashicorpVaultSecretVersion(), kp.getAwsSecretsManagerPublicKeyId(), kp.getAwsSecretsManagerPrivateKeyId()); } throw new UnsupportedOperationException("The keypair type " + keyPair.getClass() + " is not allowed"); } private  KeyDataUtil(); }
KeyDataUtil { public static KeyData marshal(final ConfigKeyPair keyPair) { final KeyData keyData = new KeyData(); if (DirectKeyPair.class.isInstance(keyPair)) { DirectKeyPair kp = DirectKeyPair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setPrivateKey(kp.getPrivateKey()); return keyData; } if (InlineKeypair.class.isInstance(keyPair)) { InlineKeypair kp = InlineKeypair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setConfig(kp.getPrivateKeyConfig()); return keyData; } if (AzureVaultKeyPair.class.isInstance(keyPair)) { AzureVaultKeyPair kp = AzureVaultKeyPair.class.cast(keyPair); keyData.setAzureVaultPublicKeyId(kp.getPublicKeyId()); keyData.setAzureVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setAzureVaultPublicKeyVersion(kp.getPublicKeyVersion()); keyData.setAzureVaultPrivateKeyVersion(kp.getPrivateKeyVersion()); return keyData; } if (HashicorpVaultKeyPair.class.isInstance(keyPair)) { HashicorpVaultKeyPair kp = HashicorpVaultKeyPair.class.cast(keyPair); keyData.setHashicorpVaultPublicKeyId(kp.getPublicKeyId()); keyData.setHashicorpVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setHashicorpVaultSecretEngineName(kp.getSecretEngineName()); keyData.setHashicorpVaultSecretName(kp.getSecretName()); keyData.setHashicorpVaultSecretVersion(Objects.toString(kp.getSecretVersion(), null)); return keyData; } if (AWSKeyPair.class.isInstance(keyPair)) { AWSKeyPair kp = AWSKeyPair.class.cast(keyPair); keyData.setAwsSecretsManagerPublicKeyId(kp.getPublicKeyId()); keyData.setAwsSecretsManagerPrivateKeyId(kp.getPrivateKeyId()); return keyData; } if (FilesystemKeyPair.class.isInstance(keyPair)) { FilesystemKeyPair kp = FilesystemKeyPair.class.cast(keyPair); keyData.setPublicKeyPath(kp.getPublicKeyPath()); keyData.setPrivateKeyPath(kp.getPrivateKeyPath()); return keyData; } if (UnsupportedKeyPair.class.isInstance(keyPair)) { UnsupportedKeyPair kp = UnsupportedKeyPair.class.cast(keyPair); return new KeyData( kp.getConfig(), kp.getPrivateKey(), kp.getPublicKey(), kp.getPrivateKeyPath(), kp.getPublicKeyPath(), kp.getAzureVaultPrivateKeyId(), kp.getAzureVaultPublicKeyId(), kp.getAzureVaultPublicKeyVersion(), kp.getAzureVaultPrivateKeyVersion(), kp.getHashicorpVaultPrivateKeyId(), kp.getHashicorpVaultPublicKeyId(), kp.getHashicorpVaultSecretEngineName(), kp.getHashicorpVaultSecretName(), kp.getHashicorpVaultSecretVersion(), kp.getAwsSecretsManagerPublicKeyId(), kp.getAwsSecretsManagerPrivateKeyId()); } throw new UnsupportedOperationException("The keypair type " + keyPair.getClass() + " is not allowed"); } private  KeyDataUtil(); static Class<? extends ConfigKeyPair> getKeyPairTypeFor(KeyData keyData); static boolean isLocked(KeyData keyData); static boolean isDirect(KeyData keyData); static boolean isInline(KeyData keyData); static boolean isAzure(KeyData keyData); static boolean isHashicorp(KeyData keyData); static boolean isAws(KeyData keyData); static boolean isFileSystem(KeyData keyData); static boolean isUnsupported(KeyData keyData); static ConfigKeyPair unmarshal(final KeyData keyData, final KeyEncryptor keyEncryptor); static KeyData marshal(final ConfigKeyPair keyPair); }
KeyDataUtil { public static KeyData marshal(final ConfigKeyPair keyPair) { final KeyData keyData = new KeyData(); if (DirectKeyPair.class.isInstance(keyPair)) { DirectKeyPair kp = DirectKeyPair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setPrivateKey(kp.getPrivateKey()); return keyData; } if (InlineKeypair.class.isInstance(keyPair)) { InlineKeypair kp = InlineKeypair.class.cast(keyPair); keyData.setPublicKey(kp.getPublicKey()); keyData.setConfig(kp.getPrivateKeyConfig()); return keyData; } if (AzureVaultKeyPair.class.isInstance(keyPair)) { AzureVaultKeyPair kp = AzureVaultKeyPair.class.cast(keyPair); keyData.setAzureVaultPublicKeyId(kp.getPublicKeyId()); keyData.setAzureVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setAzureVaultPublicKeyVersion(kp.getPublicKeyVersion()); keyData.setAzureVaultPrivateKeyVersion(kp.getPrivateKeyVersion()); return keyData; } if (HashicorpVaultKeyPair.class.isInstance(keyPair)) { HashicorpVaultKeyPair kp = HashicorpVaultKeyPair.class.cast(keyPair); keyData.setHashicorpVaultPublicKeyId(kp.getPublicKeyId()); keyData.setHashicorpVaultPrivateKeyId(kp.getPrivateKeyId()); keyData.setHashicorpVaultSecretEngineName(kp.getSecretEngineName()); keyData.setHashicorpVaultSecretName(kp.getSecretName()); keyData.setHashicorpVaultSecretVersion(Objects.toString(kp.getSecretVersion(), null)); return keyData; } if (AWSKeyPair.class.isInstance(keyPair)) { AWSKeyPair kp = AWSKeyPair.class.cast(keyPair); keyData.setAwsSecretsManagerPublicKeyId(kp.getPublicKeyId()); keyData.setAwsSecretsManagerPrivateKeyId(kp.getPrivateKeyId()); return keyData; } if (FilesystemKeyPair.class.isInstance(keyPair)) { FilesystemKeyPair kp = FilesystemKeyPair.class.cast(keyPair); keyData.setPublicKeyPath(kp.getPublicKeyPath()); keyData.setPrivateKeyPath(kp.getPrivateKeyPath()); return keyData; } if (UnsupportedKeyPair.class.isInstance(keyPair)) { UnsupportedKeyPair kp = UnsupportedKeyPair.class.cast(keyPair); return new KeyData( kp.getConfig(), kp.getPrivateKey(), kp.getPublicKey(), kp.getPrivateKeyPath(), kp.getPublicKeyPath(), kp.getAzureVaultPrivateKeyId(), kp.getAzureVaultPublicKeyId(), kp.getAzureVaultPublicKeyVersion(), kp.getAzureVaultPrivateKeyVersion(), kp.getHashicorpVaultPrivateKeyId(), kp.getHashicorpVaultPublicKeyId(), kp.getHashicorpVaultSecretEngineName(), kp.getHashicorpVaultSecretName(), kp.getHashicorpVaultSecretVersion(), kp.getAwsSecretsManagerPublicKeyId(), kp.getAwsSecretsManagerPrivateKeyId()); } throw new UnsupportedOperationException("The keypair type " + keyPair.getClass() + " is not allowed"); } private  KeyDataUtil(); static Class<? extends ConfigKeyPair> getKeyPairTypeFor(KeyData keyData); static boolean isLocked(KeyData keyData); static boolean isDirect(KeyData keyData); static boolean isInline(KeyData keyData); static boolean isAzure(KeyData keyData); static boolean isHashicorp(KeyData keyData); static boolean isAws(KeyData keyData); static boolean isFileSystem(KeyData keyData); static boolean isUnsupported(KeyData keyData); static ConfigKeyPair unmarshal(final KeyData keyData, final KeyEncryptor keyEncryptor); static KeyData marshal(final ConfigKeyPair keyPair);  }