@NotNull public static String listContainers(@NotNull final StorageInputs inputs) throws Exception { final CloudBlobClient blobClient = getCloudBlobClient(inputs); final List<String> containerList = new ArrayList<>(); for (final CloudBlobContainer blobItem : blobClient.listContainers()) { containerList.add(blobItem.getName()); } return StringUtilities.join(containerList, COMMA); }
@NotNull public static Proxy getProxy(@NotNull final String proxyHost, final int proxyPort, @NotNull final String proxyUser, @NotNull final String proxyPassword) { if (StringUtilities.isBlank(proxyHost)) { return Proxy.NO_PROXY; } if (StringUtilities.isNotEmpty(proxyUser)) { Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUser, proxyPassword.toCharArray()); } }); } return new Proxy(HTTP, InetSocketAddress.createUnresolved(proxyHost, proxyPort)); }
@NotNull private static List<String> addVerifyNotNullOrEmpty(@NotNull List<String> exceptions, @Nullable final String input, @NotNull final String inputName) { if (StringUtilities.isEmpty(input)) { exceptions.add(String.format(EXCEPTION_NULL_EMPTY, inputName)); } return exceptions; }
public static String defaultIfBlankOrEmpty(final String initialValue, @NotNull final String defaultValue, boolean validTrim) { if (validTrim) { return defaultIfBlank(initialValue, defaultValue); } return defaultIfEmpty(initialValue, defaultValue); } }
private static String getEscapedModules(final WSManRequestInputs wsManRequestInputs) { final String[] modules = StringUtilities.split(wsManRequestInputs.getModules(), COMMA_DELIMITER); final List<String> escapedModules = new ArrayList<>(); for (String module : modules) { module = StringUtilities.trim(module); module = StringUtilities.prependIfMissing(module, SINGLE_QUOTE); module = StringUtilities.appendIfMissing(module, SINGLE_QUOTE); escapedModules.add(module); } return StringUtilities.join(escapedModules, COMMA_DELIMITER); }
public static boolean parseBooleanWithDefault(String booleanValue, boolean defaultValue) { if (StringUtilities.isBlank(booleanValue)) { return defaultValue; } else { return Boolean.valueOf(booleanValue); } }
public static IdentityKey getIdentityKey(String privateKeyFile, String privateKeyString, String privateKeyPassphrase) { IdentityKey identityKey = null; if (StringUtilities.isNotEmpty(privateKeyFile)) { identityKey = new KeyFile(privateKeyFile); } if (StringUtilities.isNotEmpty(privateKeyString)) { if (identityKey != null) { throw new IllegalArgumentException(String.format("%s and %s inputs are mutually exclusive. They can't be both set at the same time.", Constants.PRIVATE_KEY_FILE, Constants.PRIVATE_KEY_DATA)); } identityKey = new KeyData(privateKeyString); } if (identityKey != null && StringUtilities.isNotEmpty(privateKeyPassphrase)) { identityKey.setPassPhrase(privateKeyPassphrase); } return identityKey; }
public static String constructCommand(final WSManRequestInputs wsManRequestInputs) { final StringBuilder command = new StringBuilder() .append(POWERSHELL_SCRIPT_PREFIX) .append(SPACE) .append(NON_INTERACTIVE_PARAMETER) .append(SPACE) .append(ENCODED_COMMAND_PARAMETER) .append(SPACE); if (StringUtilities.isNotBlank(wsManRequestInputs.getModules())) { command.append(EncoderDecoder.encodeStringInBase64( IMPORT_MODULE_PARAMETER + SPACE + getEscapedModules(wsManRequestInputs) + LF + wsManRequestInputs.getScript(), Charsets.UTF_16LE)); } else { command.append(EncoderDecoder.encodeStringInBase64(wsManRequestInputs.getScript(), Charsets.UTF_16LE)); } return command.toString(); }
public static void validateEditJsonInputs(String jsonObject, String jsonPath, String action, String name, String value) throws Exception { if (StringUtilities.isBlank(jsonObject)) { throw new Exception("Empty jsonObject provided!"); } if (StringUtilities.isBlank(jsonPath)) { throw new Exception("Empty jsonPath provided!"); } if (StringUtilities.isBlank(action)) { throw new Exception("Empty action provided!"); } final String actionString = action.toLowerCase().trim(); boolean exists = false; String actionEnumValues = ""; for (ActionsEnum actionsEnum : ActionsEnum.values()) { final String actionEnumValue = actionsEnum.getValue(); actionEnumValues += actionEnumValue + " "; if (actionString.equals(actionEnumValue)) { exists = true; } } if (!exists) { throw new Exception("Invalid action provided! Action should be one of the values: " + actionEnumValues); } if (actionString.equals(insert.getValue())) { if (StringUtilities.isBlank(name)) { throw new Exception("Empty name provided for insert action!"); } } checkForNullValue(actionString, value); }
public static IdentityKey getIdentityKey(String privateKeyFile, String privateKeyString, String privateKeyPassphrase) { IdentityKey identityKey = null; if (StringUtilities.isNotEmpty(privateKeyFile)) { identityKey = new KeyFile(privateKeyFile); } if (StringUtilities.isNotEmpty(privateKeyString)) { if (identityKey != null) { throw new IllegalArgumentException(String.format("%s and %s inputs are mutually exclusive. They can't be both set at the same time.", Constants.PRIVATE_KEY_FILE, Constants.PRIVATE_KEY_DATA)); } identityKey = new KeyData(privateKeyString); } if (identityKey != null && StringUtilities.isNotEmpty(privateKeyPassphrase)) { identityKey.setPassPhrase(privateKeyPassphrase); } return identityKey; }
int connectTimeout, boolean keepContextForExpectCommand, ProxyHTTP proxyHTTP, String allowedCiphers) throws SSHException { JSch jsch = new JSch(); String finalListOfAllowedCiphers = StringUtilities.isNotBlank(allowedCiphers) ? allowedCiphers : ALLOWED_CIPHERS; JSch.setConfig("cipher.s2c", finalListOfAllowedCiphers); JSch.setConfig("cipher.c2s", finalListOfAllowedCiphers);
@NotNull public static String listBlobs(@NotNull final StorageInputs inputs) throws Exception { final CloudBlobClient blobClient = getCloudBlobClient(inputs); final CloudBlobContainer container = blobClient.getContainerReference(inputs.getContainerName()); final List<String> blobList = new ArrayList<>(); for (final ListBlobItem blobItem : container.listBlobs()) { final String path = blobItem.getUri().getPath(); blobList.add(path.substring(path.lastIndexOf(FORWARD_SLASH) + 1)); } return StringUtilities.join(blobList, COMMA); }
public static int getPortValue(String port, int defaultValue){ if(StringUtilities.isEmpty(port)) { return defaultValue; } else { return StringUtils.validatePortNumber(port, Constants.PROXY_PORT); } } }
@NotNull public static Proxy getProxy(@NotNull final String proxyHost, final int proxyPort, @NotNull final String proxyUser, @NotNull final String proxyPassword) { if (StringUtilities.isBlank(proxyHost)) { return Proxy.NO_PROXY; } if (StringUtilities.isNotEmpty(proxyUser)) { Authenticator.setDefault(new Authenticator() { @Override public PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(proxyUser, proxyPassword.toCharArray()); } }); } return new Proxy(HTTP, InetSocketAddress.createUnresolved(proxyHost, proxyPort)); } }
if (StringUtilities.isBlank(array)) { return populateResult(returnResult, new Exception(NOT_A_VALID_JSON_ARRAY_MESSAGE));
int connectTimeout, boolean keepContextForExpectCommand, ProxyHTTP proxyHTTP, String allowedCiphers) throws SSHException { JSch jsch = new JSch(); String finalListOfAllowedCiphers = StringUtilities.isNotBlank(allowedCiphers) ? allowedCiphers : ALLOWED_CIPHERS; JSch.setConfig("cipher.s2c", finalListOfAllowedCiphers); JSch.setConfig("cipher.c2s", finalListOfAllowedCiphers);
final List<String> exceptionMessages = InputsValidation.verifySharedAccessInputs(identifier, primaryOrSecondaryKey, expiry); if (!exceptionMessages.isEmpty()) { final String errorMessage = StringUtilities.join(exceptionMessages, System.lineSeparator()); return getFailureResultsMap(errorMessage);
public static int getPortValue(String port, int defaultValue){ if(StringUtilities.isEmpty(port)) { return defaultValue; } else { return StringUtils.validatePortNumber(port, Constants.PROXY_PORT); } } }
if (StringUtilities.isBlank(array1)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY1_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, exceptionValue, new Exception(exceptionValue)); if (StringUtilities.isBlank(array2)) { final String exceptionValue = NOT_A_VALID_JSON_ARRAY_MESSAGE + ARRAY2_MESSAGE.replaceFirst("=", EMPTY_STRING); return populateResult(returnResult, new Exception(exceptionValue));
connectTimeout, socketTimeout, keepAlive, connectionsMaxPerRoute, connectionsMaxTotal); if (!exceptionMessages.isEmpty()) { return getFailureResultsMap(StringUtilities.join(exceptionMessages, NEW_LINE));