hadoop-swiftfs: Allow configuring container.tenant

Implements the possibility to manipulate the storage URL
to specify the AUTH_tenant, when accessing containers
that are shared across different tenants

https://swiftstack.com/docs/cookbooks/swift_usage/auth.html

Sample config snippet:

<property>
  <name>fs.swift.service.sahara.auth.endpoint.prefix</name>
  <value>/v1/AUTH_</value>
</property>
<property>
  <name>fs.swift.service.sahara.container.tenant</name>
  <value>uuid</value>
</property>

Change-Id: Ifc349fe1fca9637e62ac05c8422887d6a51371d4
This commit is contained in:
Saverio Proto 2016-06-20 11:47:03 +02:00
parent 19dbe3bbe3
commit fffdc5ad6b
3 changed files with 45 additions and 0 deletions

View File

@ -154,6 +154,7 @@ public final class RestClientBindings {
copy(conf, prefix + DOT_TRUST_ID, props, SWIFT_TRUST_ID_PROPERTY, false);
copy(conf, prefix + DOT_DOMAIN_NAME, props, SWIFT_DOMAIN_NAME_PROPERTY, false);
copy(conf, prefix + DOT_TENANT, props, SWIFT_TENANT_PROPERTY, false);
copy(conf, prefix + DOT_CONTAINER_TENANT, props, SWIFT_CONTAINER_TENANT_PROPERTY, false);
copy(conf, prefix + DOT_REGION, props, SWIFT_REGION_PROPERTY, false);
copy(conf, prefix + DOT_HTTP_PORT, props, SWIFT_HTTP_PORT_PROPERTY, false);
copy(conf, prefix +

View File

@ -207,6 +207,7 @@ public class SwiftProtocolConstants {
public static final String DOT_AUTH_URL = ".auth.url";
public static final String DOT_AUTH_ENDPOINT_PREFIX = ".auth.endpoint.prefix";
public static final String DOT_TENANT = ".tenant";
public static final String DOT_CONTAINER_TENANT = ".container.tenant";
public static final String DOT_USERNAME = ".username";
public static final String DOT_PASSWORD = ".password";
public static final String DOT_TRUST_ID = ".trust.id";
@ -232,6 +233,7 @@ public class SwiftProtocolConstants {
public static final String SWIFT_AUTH_ENDPOINT_PREFIX =
FS_SWIFT + DOT_AUTH_ENDPOINT_PREFIX;
public static final String SWIFT_TENANT_PROPERTY = FS_SWIFT + DOT_TENANT;
public static final String SWIFT_CONTAINER_TENANT_PROPERTY = FS_SWIFT + DOT_CONTAINER_TENANT;
public static final String SWIFT_USERNAME_PROPERTY = FS_SWIFT + DOT_USERNAME;
public static final String SWIFT_PASSWORD_PROPERTY = FS_SWIFT + DOT_PASSWORD;
public static final String SWIFT_TRUST_ID_PROPERTY = FS_SWIFT + DOT_TRUST_ID;

View File

@ -175,6 +175,7 @@ public final class SwiftRestClient {
*/
private final String container;
private final String serviceDescription;
private final String containerTenant;
/**
* Access token (Secret)
@ -496,6 +497,9 @@ public final class SwiftRestClient {
region = props.getProperty(SWIFT_REGION_PROPERTY);
//tenant is optional
tenant = props.getProperty(SWIFT_TENANT_PROPERTY);
//containerTenant is optional
containerTenant = props.getProperty(SWIFT_CONTAINER_TENANT_PROPERTY);
//service is used for diagnostics
serviceProvider = props.getProperty(SWIFT_SERVICE_PROPERTY);
container = props.getProperty(SWIFT_CONTAINER_PROPERTY);
@ -1295,6 +1299,15 @@ public final class SwiftRestClient {
accessToken = access.getToken();
String path = getAuthEndpointPrefix() + accessToken.getTenant().getId();
// Overwrite the user tenant with the shared container tenant id (container.tenant)
if (containerTenant != null) {
path = getAuthEndpointPrefix() + containerTenant;
if (LOG.isDebugEnabled()) {
LOG.debug("overwritten path: " + path);
}
}
String host = endpointURI.getHost();
try {
objectLocation = new URI(endpointURI.getScheme(),
@ -1310,6 +1323,13 @@ public final class SwiftRestClient {
+ " + " + path,
e);
}
// Overwrite the user tenant with the shared container tenant id (container.tenant)
if (containerTenant != null) {
endpointURI = objectLocation;
}
setAuthDetails(endpointURI, objectLocation, accessToken);
if (LOG.isDebugEnabled()) {
@ -1369,6 +1389,15 @@ public final class SwiftRestClient {
URI objectLocation = null;
String path = getAuthEndpointPrefix() + token.getTenant().getId();
// Overwrite the user tenant with the shared container tenant id (container.tenant)
if (containerTenant != null) {
path = getAuthEndpointPrefix() + containerTenant;
if (LOG.isDebugEnabled()) {
LOG.debug("overwritten path: " + path);
}
}
try {
objectLocation = new URI(endpointURI.getScheme(),
null,
@ -1384,6 +1413,11 @@ public final class SwiftRestClient {
e);
}
// Overwrite the user tenant with the shared container tenant id (container.tenant)
if (containerTenant != null) {
endpointURI = objectLocation;
}
setAuthDetails(endpointURI, objectLocation, token);
createDefaultContainer();
return token;
@ -1962,6 +1996,14 @@ public final class SwiftRestClient {
return tenant;
}
/**
* Get the tenant to which this client is bound
* @return the tenant
*/
public String getContainerTenant() {
return containerTenant;
}
/**
* Get the username this client identifies itself as
* @return the username