/** * Load the home directory that should be used for the profile file. This will check the same environment variables as the CLI * to identify the location of home, before falling back to java-specific resolution. */ @SdkInternalApi static String userHomeDirectory() { boolean isWindows = JavaSystemSetting.OS_NAME.getStringValue() .map(s -> StringUtils.lowerCase(s).startsWith("windows")) .orElse(false); // To match the logic of the CLI we have to consult environment variables directly. // CHECKSTYLE:OFF String home = System.getenv("HOME"); if (home != null) { return home; } if (isWindows) { String userProfile = System.getenv("USERPROFILE"); if (userProfile != null) { return userProfile; } String homeDrive = System.getenv("HOMEDRIVE"); String homePath = System.getenv("HOMEPATH"); if (homeDrive != null && homePath != null) { return homeDrive + homePath; } } return JavaSystemSetting.USER_HOME.getStringValueOrThrow(); // CHECKSTYLE:ON }
/** * Creates a temporary bucket name using the prefix passed. * * @param prefix prefix to use for the bucket name * @return an s3 bucket name */ public static String temporaryBucketName(String prefix) { String bucketName = lowerCase(prefix) + "-" + lowerCase(USER_NAME.getStringValueOrThrow()) + "-" + RANDOM.nextInt(10000); if (bucketName.length() > 63) { throw new RuntimeException("S3 buckets can only be 63 chars in length, try a shorter prefix"); } return bucketName; }
static String userAgent() { String ua = UA_STRING; ua = ua .replace("{platform}", "java") .replace("{version}", VersionInfo.SDK_VERSION) .replace("{os.name}", sanitizeInput(JavaSystemSetting.OS_NAME.getStringValue().orElse(null))) .replace("{os.version}", sanitizeInput(JavaSystemSetting.OS_VERSION.getStringValue().orElse(null))) .replace("{java.vm.name}", sanitizeInput(JavaSystemSetting.JAVA_VM_NAME.getStringValue().orElse(null))) .replace("{java.vm.version}", sanitizeInput(JavaSystemSetting.JAVA_VM_VERSION.getStringValue().orElse(null))) .replace("{java.version}", sanitizeInput(JavaSystemSetting.JAVA_VERSION.getStringValue().orElse(null))) .replace("{additional.languages}", getAdditionalJvmLanguages()); Optional<String> language = JavaSystemSetting.USER_LANGUAGE.getStringValue(); Optional<String> region = JavaSystemSetting.USER_REGION.getStringValue(); String languageAndRegion = ""; if (language.isPresent() && region.isPresent()) { languageAndRegion = " (" + sanitizeInput(language.get()) + "_" + sanitizeInput(region.get()) + ")"; } ua = ua.replace("{language.and.region}", languageAndRegion); return ua; }
/** * Creates a temporary bucket name using the prefix passed. * * @param prefix prefix to use for the bucket name * @return an s3 bucket name */ public static String temporaryBucketName(String prefix) { String bucketName = lowerCase(prefix) + "-" + lowerCase(USER_NAME.getStringValueOrThrow()) + "-" + RANDOM.nextInt(10000); if (bucketName.length() > 63) { throw new RuntimeException("S3 buckets can only be 63 chars in length, try a shorter prefix"); } return bucketName; }
/** * Load the home directory that should be used for the profile file. This will check the same environment variables as the CLI * to identify the location of home, before falling back to java-specific resolution. */ @SdkInternalApi static String userHomeDirectory() { boolean isWindows = JavaSystemSetting.OS_NAME.getStringValue() .map(s -> StringUtils.lowerCase(s).startsWith("windows")) .orElse(false); // To match the logic of the CLI we have to consult environment variables directly. // CHECKSTYLE:OFF String home = System.getenv("HOME"); if (home != null) { return home; } if (isWindows) { String userProfile = System.getenv("USERPROFILE"); if (userProfile != null) { return userProfile; } String homeDrive = System.getenv("HOMEDRIVE"); String homePath = System.getenv("HOMEPATH"); if (homeDrive != null && homePath != null) { return homeDrive + homePath; } } return JavaSystemSetting.USER_HOME.getStringValueOrThrow(); // CHECKSTYLE:ON }