Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,17 @@ You can find examples on how to use the framework at <a href="https://github.com
System.out.println(response);
```

The component is on Maven central repo; to use it, you only need to add the following piece of code to your pom.xml:

```
<dependency>
<groupId>br.com.autonomiccs</groupId>
<artifactId>apache-cloudstack-java-client</artifactId>
<version>1.0.0</version>
</dependency>
```


# License
Apache CloudStack Java Client

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
*/
package br.com.autonomiccs.apacheCloudStack.client.beans;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import br.com.autonomiccs.apacheCloudStack.exceptions.ApacheCloudStackClientRuntimeException;

/**
* This class represent an Apache CloudStack users. It holds the user data that is needed to execute the authentication process.
* We can use either the username/password or the secret key and API key authentication mechanism.
Expand Down Expand Up @@ -52,15 +55,25 @@ public class ApacheCloudStackUser {
*/
private String apiKey;

private void validatePropertiesOnNewlyCreatedObject() {
boolean isAuthenticationUsingUserCredentialsConfigured = StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password) && StringUtils.isNotBlank(domain);
boolean isAuthenticationUsingKeysConfigured = StringUtils.isNotBlank(apiKey) && StringUtils.isNotBlank(secretKey);
if (!isAuthenticationUsingKeysConfigured && !isAuthenticationUsingUserCredentialsConfigured) {
throw new ApacheCloudStackClientRuntimeException("You should either configure authentication using user credentials or user private and API keys.");
}
}

public ApacheCloudStackUser(String secretKey, String apiKey) {
this.secretKey = secretKey;
this.apiKey = apiKey;
validatePropertiesOnNewlyCreatedObject();
}

public ApacheCloudStackUser(String username, String password, String domain) {
this.username = username;
this.password = password;
this.domain = domain;
validatePropertiesOnNewlyCreatedObject();
}

public String getUsername() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* It contains the returned status code and the server response.
*/
@SuppressWarnings("serial")
public class ApacheCloudStackClientRequestRuntimeException extends RuntimeException {
public class ApacheCloudStackClientRequestRuntimeException extends ApacheCloudStackClientRuntimeException {

/**
* Status of the HTTP request that generated this exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
@SuppressWarnings("serial")
public class ApacheCloudStackClientRuntimeException extends RuntimeException {

public ApacheCloudStackClientRuntimeException() {
super();
}

public ApacheCloudStackClientRuntimeException(Exception e) {
super(e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Apache CloudStack Java Client
* Copyright (C) 2016 Autonomiccs, Inc.
*
* Licensed to the Autonomiccs, Inc. under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The Autonomiccs, Inc. 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 br.com.autonomiccs.apacheCloudStack.client.beans;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import br.com.autonomiccs.apacheCloudStack.exceptions.ApacheCloudStackClientRuntimeException;

@RunWith(MockitoJUnitRunner.class)
public class ApacheCloudStackUserTest {

@Test(expected = ApacheCloudStackClientRuntimeException.class)
public void contructorTestUsingNeitherOneOfTheConfigurations() {
new ApacheCloudStackUser("", "");
new ApacheCloudStackUser("", "", "");
}

@Test
public void contructorTestUsingKeys() {
new ApacheCloudStackUser("secretKey", "API-key");
}

@Test
public void contructorTestUsingUserCredentials() {
new ApacheCloudStackUser("username", "pass", "/");
}

}