@Test (enabled=false) public void testConvertGpgRecord() throws Exception { final String expectedFileContents = "123456789"; final String passphrase = "12"; DecryptConverter converter = new DecryptConverter(); WorkUnitState workUnitState = new WorkUnitState(); try { setEncryptedPassphrase(passphrase, workUnitState); converter.init(workUnitState); FileSystem fs = FileSystem.getLocal(new Configuration()); URL url = getClass().getClassLoader().getResource("decryptConverterTest/decrypt-test.txt.gpg"); Assert.assertNotNull(url); String gpgFilePath = url.getFile(); try (FSDataInputStream gpgFileInput = fs.open(new Path(gpgFilePath))) { FileAwareInputStream fileAwareInputStream = FileAwareInputStream.builder() .file(CopyableFileUtils.getTestCopyableFile()).inputStream(gpgFileInput).build(); Iterable<FileAwareInputStream> iterable = converter.convertRecord("outputSchema", fileAwareInputStream, workUnitState); fileAwareInputStream = Iterables.getFirst(iterable, null); Assert.assertNotNull(fileAwareInputStream); String actual = IOUtils.toString(fileAwareInputStream.getInputStream(), Charsets.UTF_8); Assert.assertEquals(actual, expectedFileContents); } } finally { deleteMasterPwdFile(); converter.close(); } }
@Override public Converter<String, String, FileAwareInputStream, FileAwareInputStream> init(WorkUnitState workUnit) { Map<String, Object> config = EncryptionConfigParser.getConfigForBranch(EncryptionConfigParser.EntityType.CONVERTER_ENCRYPT, workUnit); if (config == null) { log.info("Assuming GPG decryption since no other config parameters are set"); config = Maps.newHashMap(); config.put(EncryptionConfigParser.ENCRYPTION_ALGORITHM_KEY, DEFAULT_ALGORITHM); Preconditions.checkArgument(workUnit.contains(DECRYPTION_PASSPHRASE_KEY), "Passphrase is required while using DecryptConverter. Please specify " + DECRYPTION_PASSPHRASE_KEY); String passphrase = PasswordManager.getInstance(workUnit).readPassword(workUnit.getProp(DECRYPTION_PASSPHRASE_KEY)); config.put(EncryptionConfigParser.ENCRYPTION_KEYSTORE_PASSWORD_KEY, passphrase); } decryptor = EncryptionFactory.buildStreamCryptoProvider(config); return super.init(workUnit); }
DecryptConverter extends DistcpConverter { @Override public Converter<String, String, FileAwareInputStream, FileAwareInputStream> init(WorkUnitState workUnit) { Map<String, Object> config = EncryptionConfigParser.getConfigForBranch(EncryptionConfigParser.EntityType.CONVERTER_ENCRYPT, workUnit); if (config == null) { log.info("Assuming GPG decryption since no other config parameters are set"); config = Maps.newHashMap(); config.put(EncryptionConfigParser.ENCRYPTION_ALGORITHM_KEY, DEFAULT_ALGORITHM); Preconditions.checkArgument(workUnit.contains(DECRYPTION_PASSPHRASE_KEY), "Passphrase is required while using DecryptConverter. Please specify " + DECRYPTION_PASSPHRASE_KEY); String passphrase = PasswordManager.getInstance(workUnit).readPassword(workUnit.getProp(DECRYPTION_PASSPHRASE_KEY)); config.put(EncryptionConfigParser.ENCRYPTION_KEYSTORE_PASSWORD_KEY, passphrase); } decryptor = EncryptionFactory.buildStreamCryptoProvider(config); return super.init(workUnit); } }
DecryptConverter extends DistcpConverter { @Override public Converter<String, String, FileAwareInputStream, FileAwareInputStream> init(WorkUnitState workUnit) { Map<String, Object> config = EncryptionConfigParser.getConfigForBranch(EncryptionConfigParser.EntityType.CONVERTER_ENCRYPT, workUnit); if (config == null) { log.info("Assuming GPG decryption since no other config parameters are set"); config = Maps.newHashMap(); config.put(EncryptionConfigParser.ENCRYPTION_ALGORITHM_KEY, DEFAULT_ALGORITHM); Preconditions.checkArgument(workUnit.contains(DECRYPTION_PASSPHRASE_KEY), "Passphrase is required while using DecryptConverter. Please specify " + DECRYPTION_PASSPHRASE_KEY); String passphrase = PasswordManager.getInstance(workUnit).readPassword(workUnit.getProp(DECRYPTION_PASSPHRASE_KEY)); config.put(EncryptionConfigParser.ENCRYPTION_KEYSTORE_PASSWORD_KEY, passphrase); } decryptor = EncryptionFactory.buildStreamCryptoProvider(config); return super.init(workUnit); }  }
DecryptConverter extends DistcpConverter { @Override public Converter<String, String, FileAwareInputStream, FileAwareInputStream> init(WorkUnitState workUnit) { Map<String, Object> config = EncryptionConfigParser.getConfigForBranch(EncryptionConfigParser.EntityType.CONVERTER_ENCRYPT, workUnit); if (config == null) { log.info("Assuming GPG decryption since no other config parameters are set"); config = Maps.newHashMap(); config.put(EncryptionConfigParser.ENCRYPTION_ALGORITHM_KEY, DEFAULT_ALGORITHM); Preconditions.checkArgument(workUnit.contains(DECRYPTION_PASSPHRASE_KEY), "Passphrase is required while using DecryptConverter. Please specify " + DECRYPTION_PASSPHRASE_KEY); String passphrase = PasswordManager.getInstance(workUnit).readPassword(workUnit.getProp(DECRYPTION_PASSPHRASE_KEY)); config.put(EncryptionConfigParser.ENCRYPTION_KEYSTORE_PASSWORD_KEY, passphrase); } decryptor = EncryptionFactory.buildStreamCryptoProvider(config); return super.init(workUnit); }  @Override Converter<String, String, FileAwareInputStream, FileAwareInputStream> init(WorkUnitState workUnit); @Override Function<InputStream, InputStream> inputStreamTransformation(); @Override List<String> extensionsToRemove(); }
DecryptConverter extends DistcpConverter { @Override public Converter<String, String, FileAwareInputStream, FileAwareInputStream> init(WorkUnitState workUnit) { Map<String, Object> config = EncryptionConfigParser.getConfigForBranch(EncryptionConfigParser.EntityType.CONVERTER_ENCRYPT, workUnit); if (config == null) { log.info("Assuming GPG decryption since no other config parameters are set"); config = Maps.newHashMap(); config.put(EncryptionConfigParser.ENCRYPTION_ALGORITHM_KEY, DEFAULT_ALGORITHM); Preconditions.checkArgument(workUnit.contains(DECRYPTION_PASSPHRASE_KEY), "Passphrase is required while using DecryptConverter. Please specify " + DECRYPTION_PASSPHRASE_KEY); String passphrase = PasswordManager.getInstance(workUnit).readPassword(workUnit.getProp(DECRYPTION_PASSPHRASE_KEY)); config.put(EncryptionConfigParser.ENCRYPTION_KEYSTORE_PASSWORD_KEY, passphrase); } decryptor = EncryptionFactory.buildStreamCryptoProvider(config); return super.init(workUnit); }  @Override Converter<String, String, FileAwareInputStream, FileAwareInputStream> init(WorkUnitState workUnit); @Override Function<InputStream, InputStream> inputStreamTransformation(); @Override List<String> extensionsToRemove();  }