/** * Set the URI field through {@link S3xLoginHelper}. * Exported for testing. * @param uri filesystem URI. */ @VisibleForTesting protected void setUri(URI uri) { this.uri = S3xLoginHelper.buildFSURI(uri); }
@Override protected URI canonicalizeUri(URI rawUri) { return S3xLoginHelper.canonicalizeUri(rawUri, getDefaultPort()); }
/** * Extract the login details from a URI, raising an exception if * the URI contains them. * @param name URI of the filesystem, can be null * @throws IllegalArgumentException if there is a secret in the URI. */ public static void rejectSecretsInURIs(URI name) { Login login = extractLoginDetails(name); Preconditions.checkArgument(!login.hasLogin(), LOGIN_WARNING); }
URI thisUri = canonicalizeUri(fsUri, defaultPort); String thisScheme = thisUri.getScheme(); pathUri = canonicalizeUri(pathUri, defaultPort); thatHost = pathUri.getHost(); if (thisHost == thatHost || // hosts match "Wrong FS " + S3xLoginHelper.toString(pathUri) + " -expected " + fsUri);
/** * 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()); }
/** * Check that a Path belongs to this FileSystem. * Unlike the superclass, this version does not look at authority, * only hostnames. * @param path to check * @throws IllegalArgumentException if there is an FS mismatch */ @Override public void checkPath(Path path) { S3xLoginHelper.checkPath(getConf(), getUri(), path, getDefaultPort()); }
S3xLoginHelper.toString(binding), credentials); return credentials;
/** * 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); }