/** * Build the filesystem URI. * @param uri filesystem uri * @return the URI to use as the basis for FS operation and qualifying paths. * @throws IllegalArgumentException if the URI is in some way invalid. */ public static URI buildFSURI(URI uri) { // look for login secrets and fail if they are present. rejectSecretsInURIs(uri); Objects.requireNonNull(uri, "null uri"); Objects.requireNonNull(uri.getScheme(), "null uri.getScheme()"); if (uri.getHost() == null && uri.getAuthority() != null) { Objects.requireNonNull(uri.getHost(), "null uri host."); } Objects.requireNonNull(uri.getHost(), "null uri host."); return URI.create(uri.getScheme() + "://" + uri.getHost()); }
/** * Return the access key and secret for S3 API use. * or indicated in the UserInfo of the name URI param. * @param name the URI for which we need the access keys; may be null * @param conf the Configuration object to interrogate for keys. * @return AWSAccessKeys * @throws IOException problems retrieving passwords from KMS. */ public static S3xLoginHelper.Login getAWSAccessKeys(URI name, Configuration conf) throws IOException { S3xLoginHelper.rejectSecretsInURIs(name); Configuration c = ProviderUtils.excludeIncompatibleCredentialProviders( conf, S3AFileSystem.class); String bucket = name != null ? name.getHost() : ""; // get the secrets from the configuration // get the access key String accessKey = lookupPassword(bucket, c, ACCESS_KEY); // and the secret String secretKey = lookupPassword(bucket, c, SECRET_KEY); return new S3xLoginHelper.Login(accessKey, secretKey); }