Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Use region-specific endpoint with AuthScope #1

Merged
merged 2 commits into from

2 participants

@timf

No description provided.

timf added some commits
@timf timf Revert "Half-assed non-sense"
This reverts commit f238cef1e56d79ce229662ec7e989126de29668e.
3ad2191
@timf timf Use region-specific endpoint with AuthScope 93e4254
@greese greese merged commit eae943b into greese:develop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 1, 2013
  1. @timf

    Revert "Half-assed non-sense"

    timf authored
    This reverts commit f238cef1e56d79ce229662ec7e989126de29668e.
  2. @timf
This page is out of date. Refresh to see the latest.
View
16 pom.xml
@@ -181,22 +181,10 @@
<configuration>
<systemProperties>
<property>
- <name>providerClass</name>
- <value>${providerClass}</value>
- </property>
- <property>
<name>endpoint</name>
<value>${endpoint}</value>
</property>
<property>
- <name>accessPublic</name>
- <value>${accountNumber}</value>
- </property>
- <property>
- <name>accessPrivate</name>
- <value>${apiSharedKey}</value>
- </property>
- <property>
<name>accountNumber</name>
<value>${accountNumber}</value>
</property>
@@ -222,7 +210,7 @@
</property>
<property>
<name>test.region</name>
- <value>${regionId}</value>
+ <value>${test.region}</value>
</property>
<property>
<name>test.dataCenter</name>
@@ -238,7 +226,7 @@
</property>
</systemProperties>
<includes>
- <include>**/TestSuite.java</include>
+ <include>**/JoyentTestSuite.java</include>
</includes>
</configuration>
</plugin>
View
84 src/main/java/org/dasein/cloud/joyent/JoyentMethod.java
@@ -31,7 +31,6 @@
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
@@ -44,8 +43,6 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.client.params.CookiePolicy;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
@@ -86,20 +83,6 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
delete.addHeader("Accept", "application/json");
delete.addHeader("X-Api-Version", "~6.5");
-
- String auth;
-
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
-
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- delete.addHeader("Authorization", "Basic " + auth);
-
if( wire.isDebugEnabled() ) {
wire.debug(delete.getRequestLine().toString());
for( Header header : delete.getAllHeaders() ) {
@@ -188,23 +171,9 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
HttpClient client = getClient(endpoint);
HttpGet get = new HttpGet(endpoint + "/my/" + resource);
-
-
get.addHeader("Accept", "application/json");
get.addHeader("X-Api-Version", "~6.5");
- String auth;
-
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
-
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- get.addHeader("Authorization", "Basic " + auth);
if( wire.isDebugEnabled() ) {
wire.debug(get.getRequestLine().toString());
for( Header header : get.getAllHeaders() ) {
@@ -313,18 +282,7 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
get.addHeader("Accept", "application/json");
get.addHeader("X-Api-Version", "~6.5");
- String auth;
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
-
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- get.addHeader("Authorization", "Basic " + auth);
if( wire.isDebugEnabled() ) {
wire.debug(get.getRequestLine().toString());
for( Header header : get.getAllHeaders() ) {
@@ -418,17 +376,16 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
}
}
- protected @Nonnull HttpClient getClient(@Nonnull String endpoint) throws CloudException, InternalException {
+ protected @Nonnull HttpClient getClient(String endpoint) throws CloudException, InternalException {
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
throw new CloudException("No context was defined for this request");
}
- //String endpoint = ctx.getEndpoint();
- //if( endpoint == null ) {
- // throw new CloudException("No cloud endpoint was defined");
- //}
+ if( endpoint == null ) {
+ throw new CloudException("No cloud endpoint was defined");
+ }
boolean ssl = endpoint.startsWith("https");
int targetPort;
URI uri;
@@ -449,7 +406,7 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
//noinspection deprecation
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
- HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
+ HttpProtocolParams.setUserAgent(params, "");
Properties p = ctx.getCustomProperties();
@@ -466,20 +423,17 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port, ssl ? "https" : "http"));
}
}
-
- params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
DefaultHttpClient client = new DefaultHttpClient(params);
- /*
+
try {
String userName = new String(ctx.getAccessPublic(), "utf-8");
String password = new String(ctx.getAccessPrivate(), "utf-8");
- client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
+ client.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(userName, password));
}
catch( UnsupportedEncodingException e ) {
throw new InternalException(e);
}
- */
return client;
}
@@ -630,18 +584,7 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
}
post.addHeader("Accept", "application/json");
post.addHeader("X-Api-Version", VERSION);
- String auth;
-
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- post.addHeader("Authorization", "Basic " + auth);
try {
if( payload != null && payload.startsWith("action") ) {
//noinspection deprecation
@@ -775,18 +718,6 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
post.addHeader("Content-Type", "application/octet-stream");
post.addHeader("Accept", "application/json");
post.addHeader("X-Api-Version", VERSION);
- String auth;
-
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
-
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- post.addHeader("Authorization", "Basic " + auth);
post.setEntity(new InputStreamEntity(stream, -1L, ContentType.APPLICATION_OCTET_STREAM));
if( wire.isDebugEnabled() ) {
@@ -917,7 +848,6 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
put.addHeader("Content-Type", "application/json");
put.addHeader("Accept", "application/json");
put.addHeader("X-Auth-Token", authToken);
-
if( customHeaders != null ) {
for( Map.Entry<String, String> entry : customHeaders.entrySet() ) {
String val = (entry.getValue() == null ? "" : entry.getValue());
View
9 ...va/org/dasein/cloud/joyent/TestSuite.java → .../dasein/cloud/joyent/JoyentTestSuite.java
@@ -18,8 +18,13 @@
package org.dasein.cloud.joyent;
-import org.dasein.cloud.test.GlobalTestSuite;
+import junit.framework.Test;
-public class TestSuite extends GlobalTestSuite {
+import org.dasein.cloud.test.ComprehensiveTestSuite;
+import org.dasein.cloud.test.TestConfigurationException;
+public class JoyentTestSuite {
+ static public Test suite() throws TestConfigurationException {
+ return new ComprehensiveTestSuite(SmartDataCenter.class);
+ }
}
View
2  src/test/resources/log4j.xml
@@ -8,7 +8,7 @@
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="[%d] %m%n" />
+ <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
</layout>
</appender>
Something went wrong with that request. Please try again.