Skip to content

Commit

Permalink
Merge pull request #4 from andrerod/multimodule_5
Browse files Browse the repository at this point in the history
Add management module
  • Loading branch information
André Rodrigues committed Dec 13, 2013
2 parents 0d13296 + 4646bef commit 5f3fb70
Show file tree
Hide file tree
Showing 460 changed files with 99,463 additions and 31 deletions.
5 changes: 5 additions & 0 deletions microsoft-azure-api-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@
</developers>

<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.windowsazure;

import org.apache.http.impl.client.CloseableHttpClient;

public abstract class CloudCredentials {
public abstract CloseableHttpClient initializeClient();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.windowsazure.management;

import java.io.IOException;
import java.security.GeneralSecurityException;
import javax.net.ssl.SSLContext;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;

public class CertificateCloudCredentials extends SubscriptionCloudCredentials {
private String _subscriptionId;
private KeyStoreCredential _keyStoreCredential;

public CertificateCloudCredentials(String subscriptionId)
{
this._subscriptionId = subscriptionId;
}

public CertificateCloudCredentials(String subscriptionId, KeyStoreCredential keyStoreCredential)
{
this._subscriptionId = subscriptionId;
this._keyStoreCredential = keyStoreCredential;
}

@Override
public String getSubscriptionId()
{
return _subscriptionId;
}

public void setSubscriptionId(String subscriptionId)
{
_subscriptionId = subscriptionId;
}

public KeyStoreCredential getKeyStoreCredential()
{
return _keyStoreCredential;
}

public void setKeyStoreCredential(KeyStoreCredential keyStoreCredential)
{
_keyStoreCredential = keyStoreCredential;
}

@Override
public CloseableHttpClient initializeClient()
{
try {
SSLContext sslcontext = SSLContextFactory.create(this.getKeyStoreCredential());

return HttpClients.custom()
.setSSLSocketFactory(new SSLConnectionSocketFactory(sslcontext))
.build();
}
catch (IOException e)
{
return null;
}
catch (GeneralSecurityException e)
{
return null;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.windowsazure.management;

import java.io.IOException;

/**
* The Class KeyStoreCredential.
*/
public class KeyStoreCredential {

/** The password of the keystore. */
private final String keystorePassword;

/** The key store path. */
private final String keyStorePath;

/** The key store type. */
private final KeyStoreType keyStoreType;

/**
* Creates a <code>KeyStoreCredential</code> instance from a keyStore.
*
* @param keyStorePath
* the path of the keystore.
* @param keyStorePassword
* the password for the keystore.
* @param keyStoreType
* the type of the keyStore.
* @throws IOException
* when a I/O exception has occurred.
*/
public KeyStoreCredential(String keyStorePath, String keyStorePassword, KeyStoreType keyStoreType)
throws IOException {
this.keystorePassword = keyStorePassword;
this.keyStorePath = keyStorePath;
this.keyStoreType = keyStoreType;
}

public KeyStoreCredential(String keyStorePath, String keyStorePassword) throws IOException {
this(keyStorePath, keyStorePassword, KeyStoreType.jks);
}

/**
* Gets the type of the key store.
*
* @return A <code>KeyStoreType</code> representing the type of the key store.
*/
public KeyStoreType getKeyStoreType() {
return keyStoreType;
}

/**
* Gets the keystore password.
*
* @return A <code>String</code> instance representing the password of the keystore.
*/
public String getKeystorePassword() {
return keystorePassword;
}

/**
* Gets the key store path.
*
* @return the key store path
*/
public String getKeyStorePath() {
return this.keyStorePath;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.windowsazure.management;

/**
* The Enum representing the type of the KeyStore.
*/
public enum KeyStoreType {

/** The jceks. */
jceks,
/** The jks. */
jks,
/** The pkcs12. */
pkcs12
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.windowsazure.management;

import com.microsoft.windowsazure.services.core.Configuration;

/**
* Provides functionality to create a service management configuration.
*
*/
public class ManagementConfiguration {

/**
* Defines the path of the keystore.
*
*/
public final static String KEYSTORE_PATH = "AZURE_MANAGEMENT_KEYSTORE_PATH";

/**
* Defines the password of the keystore.
*
*/
public final static String KEYSTORE_PASSWORD = "AZURE_MANAGEMENT_KEYSTORE_PASSWORD";

/**
* Defines the type of the keystore.
*/
public static final String KEYSTORE_TYPE = "AZURE_MANAGEMENT_KEYSTORE_TYPE";

/**
* Defines the URI of service management.
*
*/
public final static String URI = "AZURE_MANAGEMENT_URI";

/**
* Defines the subscription ID of the Windows Azure account.
*/
public static final String SUBSCRIPTION_ID = "AZURE_SUBSCRIPTION_ID";

public static final String SUBSCRIPTION_CLOUD_CREDENTIALS = "AZURE_SUBSCRIPTION_CLOUD_CREDENTIALS";

/**
* Creates a service management configuration using specified URI, and subscription ID.
*
* @param uri
* A <code>String</code> object that represents the root URI of the service management service.
* @param subscriptionId
* A <code>String</code> object that represents the subscription ID.
* @return the configuration
* A <code>Configuration</code> object that can be used when creating an instance of the
* <code>ManagementContract</code> class.
*/
public static Configuration configure(String uri, String subscriptionId) {
return configure(null, Configuration.getInstance(), uri, subscriptionId, null, null);
}

/**
* Creates a service management configuration with specified parameters.
*
* @param profile
* A <code>String</code> object that represents the profile.
* @param configuration
* A previously instantiated <code>Configuration</code> object.
* @param uri
* A <code>String</code> object that represents the URI of the service management service.
* @param subscriptionId
* A <code>String</code> object that represents the subscription ID.
* @param keyStoreLocation
* the key store location
* @param keyStorePassword
* A <code>String</code> object that represents the password of the keystore.
* @return A <code>Configuration</code> object that can be used when creating an instance of the
* <code>ManagementContract</code> class.
*/
public static Configuration configure(String profile, Configuration configuration, String uri,
String subscriptionId, String keyStoreLocation, String keyStorePassword) {

if (profile == null) {
profile = "";
}
else if (profile.length() != 0 && !profile.endsWith(".")) {
profile = profile + ".";
}

configuration.setProperty(profile + URI, "https://" + uri);
configuration.setProperty(profile + SUBSCRIPTION_ID, subscriptionId);
configuration.setProperty(profile + KEYSTORE_PATH, keyStoreLocation);
configuration.setProperty(profile + KEYSTORE_PASSWORD, keyStorePassword);

configuration.setProperty(profile + SUBSCRIPTION_CLOUD_CREDENTIALS,
new CertificateCloudCredentials(subscriptionId));

return configuration;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* Copyright Microsoft Corporation
*
* Licensed 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 com.microsoft.windowsazure.management;

public class OperationResponse {
private int _httpStatusCode;

/**
* Gets the HTTP status code for the request.
*/
public int getStatusCode() { return this._httpStatusCode; }

/**
* Sets the HTTP status code for the request.
*/
public void setStatusCode(int httpStatusCode) { this._httpStatusCode = httpStatusCode; }

private String _requestId;

/**
* Gets the request identifier.
*/
public String getRequestId() { return this._requestId; }

/**
* Sets the request identifier.
*/
public void setRequestId(String requestId) { this._requestId = requestId; }
}
Loading

0 comments on commit 5f3fb70

Please sign in to comment.