mirror of https://github.com/apache/jclouds.git
Issue 988:Extra port added to swift url
This commit is contained in:
parent
09d5e8add4
commit
8311d0a4e4
|
@ -20,17 +20,12 @@ package org.jclouds.openstack.swift;
|
|||
|
||||
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.blobstore.BlobStoreContext;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
||||
import org.jclouds.openstack.services.ServiceType;
|
||||
import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
|
||||
import org.jclouds.openstack.swift.config.SwiftRestClientModule;
|
||||
import org.jclouds.openstack.swift.config.SwiftRestClientModule.StorageEndpointModule;
|
||||
|
@ -69,12 +64,8 @@ public class SwiftApiMetadata extends BaseRestApiMetadata {
|
|||
|
||||
public static Properties defaultProperties() {
|
||||
Properties properties = BaseRestApiMetadata.defaultProperties();
|
||||
properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE);
|
||||
// TODO: this doesn't actually do anything yet.
|
||||
properties.setProperty(KeystoneProperties.VERSION, "2.0");
|
||||
properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS);
|
||||
properties.setProperty(PROPERTY_REGIONS, "DEFAULT");
|
||||
properties.setProperty(PROPERTY_USER_METADATA_PREFIX, "X-Object-Meta-");
|
||||
properties.setProperty(PROPERTY_REGIONS, "DEFAULT");
|
||||
return properties;
|
||||
}
|
||||
|
||||
|
@ -82,8 +73,8 @@ public class SwiftApiMetadata extends BaseRestApiMetadata {
|
|||
protected Builder(Class<?> syncClient, Class<?> asyncClient){
|
||||
super(syncClient, asyncClient);
|
||||
id("swift")
|
||||
.name("OpenStack Swift Pre-Diablo API")
|
||||
.identityName("tenantName:user or user")
|
||||
.name("OpenStack Swift with SwiftAuth")
|
||||
.identityName("tenantId:user")
|
||||
.credentialName("password")
|
||||
.documentation(URI.create("http://api.openstack.org/"))
|
||||
.version("1.0")
|
||||
|
|
|
@ -19,10 +19,15 @@
|
|||
package org.jclouds.openstack.swift;
|
||||
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
||||
import org.jclouds.openstack.services.ServiceType;
|
||||
import org.jclouds.openstack.swift.blobstore.config.SwiftBlobStoreContextModule;
|
||||
import org.jclouds.openstack.swift.config.SwiftKeystoneRestClientModule;
|
||||
import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule;
|
||||
|
@ -64,6 +69,10 @@ public class SwiftKeystoneApiMetadata extends SwiftApiMetadata {
|
|||
|
||||
public static Properties defaultProperties() {
|
||||
Properties properties = SwiftApiMetadata.defaultProperties();
|
||||
properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE);
|
||||
// TODO: this doesn't actually do anything yet.
|
||||
properties.setProperty(KeystoneProperties.VERSION, "2.0");
|
||||
properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS);
|
||||
properties.remove(PROPERTY_REGIONS);
|
||||
return properties;
|
||||
}
|
||||
|
@ -72,6 +81,9 @@ public class SwiftKeystoneApiMetadata extends SwiftApiMetadata {
|
|||
protected Builder(){
|
||||
super(SwiftKeystoneClient.class, SwiftKeystoneAsyncClient.class);
|
||||
id("swift-keystone")
|
||||
.name("OpenStack Swift with Keystone authentication")
|
||||
.identityName("tenantName:user or user")
|
||||
.credentialName("password")
|
||||
.context(CONTEXT_TOKEN)
|
||||
.defaultModules(ImmutableSet.<Class<? extends Module>>of(KeystoneStorageEndpointModule.class, SwiftKeystoneRestClientModule.class, SwiftBlobStoreContextModule.class));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.swift;
|
||||
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.openstack.swift.internal.BaseSwiftExpectTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(testName = "SwiftClientExpectTest")
|
||||
public class SwiftClientExpectTest extends BaseSwiftExpectTest<SwiftClient> {
|
||||
|
||||
public void testContainerExistsWhenResponseIs2xxReturnsTrue() throws Exception {
|
||||
HttpRequest headContainer = HttpRequest.builder()
|
||||
.method("HEAD")
|
||||
.endpoint(URI.create(swiftEndpointWithHostReplaced + "/foo"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder()
|
||||
.put("X-Auth-Token", authToken).build()).build();
|
||||
|
||||
HttpResponse headContainerResponse = HttpResponse.builder().statusCode(200).build();
|
||||
|
||||
SwiftClient clientWhenContainerExists = requestsSendResponses(authRequest,
|
||||
authResponse, headContainer, headContainerResponse);
|
||||
|
||||
assertTrue(clientWhenContainerExists.containerExists("foo"));
|
||||
}
|
||||
|
||||
public void testContainerExistsWhenResponseIs404ReturnsFalse() throws Exception {
|
||||
HttpRequest headContainer = HttpRequest.builder()
|
||||
.method("HEAD")
|
||||
.endpoint(URI.create(swiftEndpointWithHostReplaced + "/foo"))
|
||||
.headers(
|
||||
ImmutableMultimap.<String, String> builder()
|
||||
.put("X-Auth-Token", authToken).build()).build();
|
||||
|
||||
HttpResponse headContainerResponse = HttpResponse.builder().statusCode(404).build();
|
||||
|
||||
SwiftClient clientWhenContainerDoesntExist = requestsSendResponses(authRequest,
|
||||
authResponse, headContainer, headContainerResponse);
|
||||
|
||||
assertFalse(clientWhenContainerDoesntExist.containerExists("foo"));
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.swift.internal;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.rest.internal.BaseRestClientExpectTest;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
|
||||
/**
|
||||
* Base class for writing Swift Expect tests
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
public class BaseSwiftExpectTest<T> extends BaseRestClientExpectTest<T> {
|
||||
|
||||
protected String endpoint = "http://myhost:8080/auth";
|
||||
protected HttpRequest authRequest;
|
||||
public BaseSwiftExpectTest() {
|
||||
provider = "swift";
|
||||
identity = "test:tester";
|
||||
credential = "testing";
|
||||
authRequest = HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create(endpoint+ "/v1.0"))
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("X-Auth-User", identity)
|
||||
.put("X-Auth-Key", credential)
|
||||
.put("Accept", "*/*")
|
||||
.put("Host", "myhost:8080").build()).build();
|
||||
}
|
||||
|
||||
protected String authToken = "AUTH_tk36dabe83ca744cc296a98ec46089ec35";
|
||||
|
||||
protected String swiftEndpoint = "http://127.0.0.1:8080/v1/AUTH_test";
|
||||
|
||||
/**
|
||||
* often swift returns the localhost url when requested via a dns name. this
|
||||
* test ensures that replacement works.
|
||||
*/
|
||||
protected String swiftEndpointWithHostReplaced = swiftEndpoint.replace("127.0.0.1", "myhost");
|
||||
|
||||
protected HttpResponse authResponse = HttpResponse.builder()
|
||||
.statusCode(200)
|
||||
.message("HTTP/1.1 200 OK")
|
||||
.headers(ImmutableMultimap.<String, String>builder()
|
||||
.put("X-Storage-Url", swiftEndpoint)
|
||||
.put("X-Auth-Token", authToken).build()).build();
|
||||
|
||||
protected Properties setupProperties() {
|
||||
Properties props = super.setupProperties();
|
||||
props.put(provider+".endpoint", endpoint);
|
||||
return props;
|
||||
}
|
||||
}
|
|
@ -90,9 +90,6 @@ public class ParseAuthenticationResponseFromHeaders implements Function<HttpResp
|
|||
@Override
|
||||
public ParseAuthenticationResponseFromHeaders setContext(HttpRequest request) {
|
||||
String host = request.getEndpoint().getHost();
|
||||
if (request.getEndpoint().getPort() != -1) {
|
||||
host += ":" + request.getEndpoint().getPort();
|
||||
}
|
||||
return setHostToReplace(host);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
package org.jclouds.hpcloud.objectstorage;
|
||||
|
||||
import static org.jclouds.location.reference.LocationConstants.PROPERTY_REGIONS;
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.CREDENTIAL_TYPE;
|
||||
import static org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties.SERVICE_TYPE;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
@ -26,6 +28,9 @@ import java.util.Properties;
|
|||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.hpcloud.objectstorage.blobstore.config.HPCloudObjectStorageBlobStoreContextModule;
|
||||
import org.jclouds.hpcloud.objectstorage.config.HPCloudObjectStorageRestClientModule;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.CredentialTypes;
|
||||
import org.jclouds.openstack.keystone.v2_0.config.KeystoneProperties;
|
||||
import org.jclouds.openstack.services.ServiceType;
|
||||
import org.jclouds.openstack.swift.SwiftApiMetadata;
|
||||
import org.jclouds.openstack.swift.config.SwiftRestClientModule.KeystoneStorageEndpointModule;
|
||||
import org.jclouds.rest.RestContext;
|
||||
|
@ -66,6 +71,10 @@ public class HPCloudObjectStorageApiMetadata extends SwiftApiMetadata {
|
|||
|
||||
public static Properties defaultProperties() {
|
||||
Properties properties = SwiftApiMetadata.defaultProperties();
|
||||
properties.setProperty(SERVICE_TYPE, ServiceType.OBJECT_STORE);
|
||||
// TODO: this doesn't actually do anything yet.
|
||||
properties.setProperty(KeystoneProperties.VERSION, "2.0");
|
||||
properties.setProperty(CREDENTIAL_TYPE, CredentialTypes.API_ACCESS_KEY_CREDENTIALS);
|
||||
properties.remove(PROPERTY_REGIONS);
|
||||
return properties;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue