Skip to content

Commit

Permalink
Merge pull request #87 from spiegela/feature/host-based-addr
Browse files Browse the repository at this point in the history
Improve bindings & fixes. Resolves #79.
  • Loading branch information
spiegela authored Nov 28, 2017
2 parents 9346352 + 9f994d2 commit 09e9a1a
Show file tree
Hide file tree
Showing 13 changed files with 428 additions and 37 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ The following feature flags are supported by the bucket & namespace. All parame
| bucket binding | base-url | - | String | Base URL name for object URI |
| bucket binding | use-ssl | false | Boolean | Use SSL for object endpoint |
| bucket binding | permissions | - | JSON List| List of permissions for user in bucket ACL |
| bucket binding | path-style-access | true | Boolean | Use path style access for S3 URL, the alternative is to use host style access |
| namespace | domain-group-admins | - | JSON List| List of domain admins to be added to namespace |
| namespace | encrypted | false | Boolean | Enable encryption of namespace |
| namespace | compliance-enabled | false | Boolean | Enable compliance adhearance of retention |
Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ dependencies {
testCompile(group: 'com.github.tomakehurst', name: 'wiremock-standalone', version: '2.5.1')
testCompile(group: 'org.powermock', name: 'powermock-api-mockito', version: '1.7.1')
testCompile(group: 'org.powermock', name: 'powermock-module-junit4', version: '1.7.1')

testCompile(group: 'com.github.paulcwarren', name: 'ginkgo4j', version: '1.0.7')


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ public String getObjectEndpoint() {
public void setObjectEndpoint(String objectEndpoint) {
this.objectEndpoint = objectEndpoint;
}

public String getNfsMountHost() {
return nfsMountHost;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public interface BindingWorkflow {
void checkIfUserExists() throws EcsManagementClientException, IOException;
String createBindingUser() throws EcsManagementClientException, IOException, JAXBException;
void removeBinding(ServiceInstanceBinding binding) throws EcsManagementClientException, IOException, JAXBException;
Map<String, Object> getCredentials(String secretKey) throws IOException, EcsManagementClientException;
Map<String, Object> getCredentials(String secretKey, Map<String, Object> parameters)
throws IOException, EcsManagementClientException;
ServiceInstanceBinding getBinding(Map<String, Object> credentials);
CreateServiceInstanceAppBindingResponse getResponse(Map<String, Object> credentials);
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,27 +43,24 @@ public String createBindingUser() throws EcsManagementClientException, IOExcepti
ServiceInstance instance = instanceRepository.find(instanceId);
if (instance == null)
throw new ServiceInstanceDoesNotExistException(instanceId);
String bucketName = instance.getName();

String bucketName = instance.getName();
String export = "";
List<String> permissions = null;
if (parameters != null) {

@SuppressWarnings(value = "unchecked")
List<String> permissions = (List<String>) parameters.get("permissions");
if (permissions == null) {
ecs.addUserToBucket(bucketName, bindingId);
} else {
ecs.addUserToBucket(bucketName, bindingId, permissions);
}

if (ecs.getBucketFileEnabled(bucketName)) {
String export = (String) parameters.get("export");
if (export == null)
export = "";
volumeMounts = createVolumeExport(export, new URL(ecs.getObjectEndpoint()), parameters);
}

} else {
permissions = (List<String>) parameters.get("permissions");
export = (String) parameters.getOrDefault("export", "");
}

if (permissions == null) {
ecs.addUserToBucket(bucketName, bindingId);
} else {
ecs.addUserToBucket(bucketName, bindingId, permissions);
}

if (ecs.getBucketFileEnabled(bucketName)) {
volumeMounts = createVolumeExport(export,
new URL(ecs.getObjectEndpoint()), parameters);
}

return userSecretKey.getSecretKey();
Expand Down Expand Up @@ -96,7 +93,7 @@ public void removeBinding(ServiceInstanceBinding binding)
}

@Override
public Map<String, Object> getCredentials(String secretKey)
public Map<String, Object> getCredentials(String secretKey, Map<String, Object> parameters)
throws IOException, EcsManagementClientException {
ServiceInstance instance = instanceRepository.find(instanceId);
if (instance == null)
Expand All @@ -111,7 +108,15 @@ public Map<String, Object> getCredentials(String secretKey)

// Add s3 URL
URL baseUrl = new URL(endpoint);
credentials.put("s3Url", getS3Url(baseUrl, secretKey));
credentials.put("s3Url", getS3Url(baseUrl, secretKey, parameters));

if (parameters != null && parameters.containsKey("path-style-access") &&
! (Boolean) parameters.get("path-style-access"))
{
credentials.put("path-style-access", false);
} else {
credentials.put("path-style-access", true);
}

// Add bucket name from repository
credentials.put("bucket", ecs.prefix(bucketName));
Expand Down Expand Up @@ -141,11 +146,22 @@ public CreateServiceInstanceAppBindingResponse getResponse(
return resp;
}

private String getS3Url(URL baseUrl, String secretKey) {
private String getS3Url(URL baseUrl, String secretKey, Map<String, Object> parameters) {
String userInfo = getUserInfo(secretKey);
return baseUrl.getProtocol() + "://" + ecs.prefix(userInfo) + "@" +
baseUrl.getHost() + ":" + baseUrl.getPort() + "/" +
ecs.prefix(instanceId);
String s3Url = baseUrl.getProtocol() + "://" + ecs.prefix(userInfo) + "@";

String portString = "";
if (baseUrl.getPort() != -1)
portString = ":" + baseUrl.getPort();

if (parameters != null && parameters.containsKey("path-style-access") &&
! (Boolean) parameters.get("path-style-access"))
{
s3Url = s3Url + ecs.prefix(instanceId) + "." + baseUrl.getHost() + portString;
} else {
s3Url = s3Url + baseUrl.getHost() + portString + "/" + ecs.prefix(instanceId);
}
return s3Url;
}

private int createUserMap() throws EcsManagementClientException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public CreateServiceInstanceBindingResponse createServiceInstanceBinding(
String secretKey = workflow.createBindingUser();

LOG.info("building binding response");
Map<String, Object> credentials = workflow.getCredentials(secretKey);
Map<String, Object> credentials = workflow.getCredentials(secretKey,
request.getParameters());
ServiceInstanceBinding binding = workflow.getBinding(credentials);

LOG.info("saving binding...");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void removeBinding(ServiceInstanceBinding binding) throws EcsManagementCl
}

@Override
public Map<String, Object> getCredentials(String secretKey)
public Map<String, Object> getCredentials(String secretKey, Map<String, Object> parameters)
throws IOException, EcsManagementClientException {
ServiceInstance instance = instanceRepository.find(instanceId);
if (instance == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public String createBindingUser() throws ServiceBrokerException, IOException, JA
}

@Override
public Map<String, Object> getCredentials(String secretKey) throws IOException, EcsManagementClientException {
public Map<String, Object> getCredentials(String secretKey, Map<String, Object> parameters)
throws IOException, EcsManagementClientException {
Map<String, Object> credentials = new HashMap<>();
credentials.put("accessKey", bindingId);
credentials.put("secretKey", secretKey);
Expand Down
4 changes: 3 additions & 1 deletion src/test/java/com/emc/ecs/TestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.emc.ecs.cloudfoundry.broker.model.ServiceDefinitionProxyTest;
import com.emc.ecs.cloudfoundry.broker.repository.ServiceInstanceBindingRepositoryTest;
import com.emc.ecs.cloudfoundry.broker.repository.ServiceInstanceRepositoryTest;
import com.emc.ecs.cloudfoundry.broker.service.BucketBindingWorkflowTest;
import com.emc.ecs.cloudfoundry.broker.service.EcsServiceInstanceBindingServiceTest;
import com.emc.ecs.cloudfoundry.broker.service.EcsServiceInstanceServiceTest;
import com.emc.ecs.cloudfoundry.broker.service.EcsServiceTest;
Expand Down Expand Up @@ -38,7 +39,8 @@
ServiceInstanceBindingRepositoryTest.class,
ServiceInstanceRepositoryTest.class,
EcsServiceInstanceBindingServiceTest.class,
EcsServiceInstanceServiceTest.class
EcsServiceInstanceServiceTest.class,
BucketBindingWorkflowTest.class
})
public class TestSuite {

Expand Down
Loading

0 comments on commit 09e9a1a

Please sign in to comment.