@Test public void testValidScript() throws Exception { if (!Shell.WINDOWS) { return; } String expectedResult = "decretedKey"; File scriptFile = new File(TEST_ROOT_DIR, "testScript.cmd"); FileUtils.writeStringToFile(scriptFile, "@echo %1 " + expectedResult); ShellDecryptionKeyProvider provider = new ShellDecryptionKeyProvider(); Configuration conf = new Configuration(); String account = "testacct"; String key = "key1"; conf.set(SimpleKeyProvider.KEY_ACCOUNT_KEY_PREFIX + account, key); conf.set(ShellDecryptionKeyProvider.KEY_ACCOUNT_SHELLKEYPROVIDER_SCRIPT, "cmd /c " + scriptFile.getAbsolutePath()); String result = provider.getStorageAccountKey(account, conf); assertEquals(key + " " + expectedResult, result); }
@Override public String getStorageAccountKey(String accountName, Configuration conf) throws KeyProviderException { String envelope = super.getStorageAccountKey(accountName, conf); final String command = conf.get(KEY_ACCOUNT_SHELLKEYPROVIDER_SCRIPT); if (command == null) { throw new KeyProviderException( "Script path is not specified via fs.azure.shellkeyprovider.script"); } String[] cmd = command.split(" "); String[] cmdWithEnvelope = Arrays.copyOf(cmd, cmd.length + 1); cmdWithEnvelope[cmdWithEnvelope.length - 1] = envelope; String decryptedKey = null; try { decryptedKey = Shell.execCommand(cmdWithEnvelope); } catch (IOException ex) { throw new KeyProviderException(ex); } return decryptedKey.trim(); }
ShellDecryptionKeyProvider extends SimpleKeyProvider { @Override public String getStorageAccountKey(String accountName, Configuration conf) throws KeyProviderException { String envelope = super.getStorageAccountKey(accountName, conf); final String command = conf.get(KEY_ACCOUNT_SHELLKEYPROVIDER_SCRIPT); if (command == null) { throw new KeyProviderException( "Script path is not specified via fs.azure.shellkeyprovider.script"); } String[] cmd = command.split(" "); String[] cmdWithEnvelope = Arrays.copyOf(cmd, cmd.length + 1); cmdWithEnvelope[cmdWithEnvelope.length - 1] = envelope; String decryptedKey = null; try { decryptedKey = Shell.execCommand(cmdWithEnvelope); } catch (IOException ex) { throw new KeyProviderException(ex); } return decryptedKey.trim(); } }
ShellDecryptionKeyProvider extends SimpleKeyProvider { @Override public String getStorageAccountKey(String accountName, Configuration conf) throws KeyProviderException { String envelope = super.getStorageAccountKey(accountName, conf); final String command = conf.get(KEY_ACCOUNT_SHELLKEYPROVIDER_SCRIPT); if (command == null) { throw new KeyProviderException( "Script path is not specified via fs.azure.shellkeyprovider.script"); } String[] cmd = command.split(" "); String[] cmdWithEnvelope = Arrays.copyOf(cmd, cmd.length + 1); cmdWithEnvelope[cmdWithEnvelope.length - 1] = envelope; String decryptedKey = null; try { decryptedKey = Shell.execCommand(cmdWithEnvelope); } catch (IOException ex) { throw new KeyProviderException(ex); } return decryptedKey.trim(); }  }
ShellDecryptionKeyProvider extends SimpleKeyProvider { @Override public String getStorageAccountKey(String accountName, Configuration conf) throws KeyProviderException { String envelope = super.getStorageAccountKey(accountName, conf); final String command = conf.get(KEY_ACCOUNT_SHELLKEYPROVIDER_SCRIPT); if (command == null) { throw new KeyProviderException( "Script path is not specified via fs.azure.shellkeyprovider.script"); } String[] cmd = command.split(" "); String[] cmdWithEnvelope = Arrays.copyOf(cmd, cmd.length + 1); cmdWithEnvelope[cmdWithEnvelope.length - 1] = envelope; String decryptedKey = null; try { decryptedKey = Shell.execCommand(cmdWithEnvelope); } catch (IOException ex) { throw new KeyProviderException(ex); } return decryptedKey.trim(); }  @Override String getStorageAccountKey(String accountName, Configuration conf); }
ShellDecryptionKeyProvider extends SimpleKeyProvider { @Override public String getStorageAccountKey(String accountName, Configuration conf) throws KeyProviderException { String envelope = super.getStorageAccountKey(accountName, conf); final String command = conf.get(KEY_ACCOUNT_SHELLKEYPROVIDER_SCRIPT); if (command == null) { throw new KeyProviderException( "Script path is not specified via fs.azure.shellkeyprovider.script"); } String[] cmd = command.split(" "); String[] cmdWithEnvelope = Arrays.copyOf(cmd, cmd.length + 1); cmdWithEnvelope[cmdWithEnvelope.length - 1] = envelope; String decryptedKey = null; try { decryptedKey = Shell.execCommand(cmdWithEnvelope); } catch (IOException ex) { throw new KeyProviderException(ex); } return decryptedKey.trim(); }  @Override String getStorageAccountKey(String accountName, Configuration conf);  }