mirror of https://github.com/apache/jclouds.git
iam user api cleanup
This commit is contained in:
parent
3dd309da2d
commit
a5cb760506
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.iam.domain;
|
package org.jclouds.iam.domain;
|
||||||
|
|
||||||
|
import static com.google.common.base.Objects.equal;
|
||||||
|
import static com.google.common.base.Objects.toStringHelper;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
@ -32,27 +34,20 @@ import com.google.common.base.Optional;
|
||||||
*/
|
*/
|
||||||
public final class User {
|
public final class User {
|
||||||
|
|
||||||
private final Optional<String> path;
|
|
||||||
private final Optional<String> name;
|
|
||||||
private final String id;
|
|
||||||
private final String arn;
|
private final String arn;
|
||||||
|
private final String id;
|
||||||
|
private final Optional<String> name;
|
||||||
|
private final Optional<String> path;
|
||||||
private final Date createDate;
|
private final Date createDate;
|
||||||
|
|
||||||
private User(String id, String arn, Optional<String> path, Optional<String> name, Date createDate) {
|
private User(String arn, String id, Optional<String> name, Optional<String> path, Date createDate) {
|
||||||
this.id = checkNotNull(id, "id");
|
this.arn = checkNotNull(arn, "arn");
|
||||||
this.arn = checkNotNull(arn, "arn for %s", id);
|
this.id = checkNotNull(id, "id for %s", arn);
|
||||||
this.path = checkNotNull(path, "path for %s", arn);
|
|
||||||
this.name = checkNotNull(name, "name for %s", arn);
|
this.name = checkNotNull(name, "name for %s", arn);
|
||||||
|
this.path = checkNotNull(path, "path for %s", arn);
|
||||||
this.createDate = checkNotNull(createDate, "createDate for %s", arn);
|
this.createDate = checkNotNull(createDate, "createDate for %s", arn);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* a globally unique identifier (GUID), returned from the api.
|
|
||||||
*/
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* how to specify the resource in the access policy language ex.
|
* how to specify the resource in the access policy language ex.
|
||||||
* {@code arn:aws:<service>:<region>:<namespace>:<relative-id>}
|
* {@code arn:aws:<service>:<region>:<namespace>:<relative-id>}
|
||||||
|
@ -62,10 +57,10 @@ public final class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* path ex {@code /division_abc/subdivision_xyz/product_1234/engineering/}
|
* a globally unique identifier (GUID), returned from the api.
|
||||||
*/
|
*/
|
||||||
public Optional<String> getPath() {
|
public String getId() {
|
||||||
return path;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,6 +70,13 @@ public final class User {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* path ex {@code /division_abc/subdivision_xyz/product_1234/engineering/}
|
||||||
|
*/
|
||||||
|
public Optional<String> getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Date the user was created
|
* Date the user was created
|
||||||
*/
|
*/
|
||||||
|
@ -82,34 +84,25 @@ public final class User {
|
||||||
return createDate;
|
return createDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(id, arn);
|
return Objects.hashCode(arn, id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
return true;
|
return true;
|
||||||
if (obj == null || getClass() != obj.getClass())
|
if (obj == null || getClass() != obj.getClass())
|
||||||
return false;
|
return false;
|
||||||
User other = (User) obj;
|
User that = User.class.cast(obj);
|
||||||
return Objects.equal(this.id, other.id) && Objects.equal(this.arn, other.arn);
|
return equal(this.arn, that.arn) && equal(this.id, that.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return Objects.toStringHelper(this).add("path", path).add("name", name).add("id", id).add("arn", arn)
|
return toStringHelper(this).omitNullValues().add("arn", arn).add("id", id).add("name", name.orNull())
|
||||||
.add("createDate", createDate).toString();
|
.add("path", path.orNull()).add("createDate", createDate).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder builder() {
|
public static Builder builder() {
|
||||||
|
@ -121,17 +114,17 @@ public final class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Builder {
|
public static class Builder {
|
||||||
private Optional<String> path = Optional.absent();
|
private String arn;
|
||||||
private String id;
|
private String id;
|
||||||
private Optional<String> name = Optional.absent();
|
private Optional<String> name = Optional.absent();
|
||||||
private String arn;
|
private Optional<String> path = Optional.absent();
|
||||||
private Date createDate;
|
private Date createDate;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see User#getPath()
|
* @see User#getArn()
|
||||||
*/
|
*/
|
||||||
public Builder path(String path) {
|
public Builder arn(String arn) {
|
||||||
this.path = Optional.fromNullable(path);
|
this.arn = arn;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,10 +145,10 @@ public final class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see User#getArn()
|
* @see User#getPath()
|
||||||
*/
|
*/
|
||||||
public Builder arn(String arn) {
|
public Builder path(String path) {
|
||||||
this.arn = arn;
|
this.path = Optional.fromNullable(path);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,11 +161,11 @@ public final class User {
|
||||||
}
|
}
|
||||||
|
|
||||||
public User build() {
|
public User build() {
|
||||||
return new User(id, arn, path, name, createDate);
|
return new User(arn, id, name, path, createDate);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder from(User in) {
|
public Builder from(User in) {
|
||||||
return this.path(in.path.orNull()).name(in.name.orNull()).id(in.id).arn(in.arn).createDate(in.createDate);
|
return arn(in.arn).id(in.id).name(in.name.orNull()).path(in.path.orNull()).createDate(in.createDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,10 +27,8 @@ import org.jclouds.iam.domain.User;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides access to Amazon IAM via the Query API
|
|
||||||
* <p/>
|
|
||||||
*
|
*
|
||||||
* @see <a href="http://docs.amazonwebservices.com/IAM/latest/APIReference" />
|
* @see UserAsyncApi
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS)
|
||||||
|
|
|
@ -21,8 +21,6 @@ package org.jclouds.iam.features;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
import org.jclouds.http.HttpRequest;
|
import org.jclouds.http.HttpRequest;
|
||||||
import org.jclouds.http.HttpResponse;
|
import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.iam.IAMApi;
|
import org.jclouds.iam.IAMApi;
|
||||||
|
@ -41,10 +39,6 @@ import com.google.common.collect.Iterables;
|
||||||
@Test(groups = "unit", testName = "UserApiExpectTest")
|
@Test(groups = "unit", testName = "UserApiExpectTest")
|
||||||
public class UserApiExpectTest extends BaseIAMApiExpectTest {
|
public class UserApiExpectTest extends BaseIAMApiExpectTest {
|
||||||
|
|
||||||
public UserApiExpectTest() {
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testGetCurrentWhenResponseIs2xx() throws Exception {
|
public void testGetCurrentWhenResponseIs2xx() throws Exception {
|
||||||
HttpRequest get = HttpRequest.builder()
|
HttpRequest get = HttpRequest.builder()
|
||||||
.method("POST")
|
.method("POST")
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.iam.features;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
import static java.util.logging.Logger.getAnonymousLogger;
|
import static java.util.logging.Logger.getAnonymousLogger;
|
||||||
import static org.testng.Assert.assertEquals;
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
import org.jclouds.iam.domain.User;
|
import org.jclouds.iam.domain.User;
|
||||||
import org.jclouds.iam.internal.BaseIAMApiLiveTest;
|
import org.jclouds.iam.internal.BaseIAMApiLiveTest;
|
||||||
|
@ -57,8 +58,10 @@ public class UserApiLiveTest extends BaseIAMApiLiveTest {
|
||||||
for (User user : users) {
|
for (User user : users) {
|
||||||
checkUser(user);
|
checkUser(user);
|
||||||
assertEquals(api().get(user.getId()), user);
|
assertEquals(api().get(user.getId()), user);
|
||||||
if (user.getPath().isPresent())
|
if (user.getPath().isPresent()) {
|
||||||
assertEquals(api().listPathPrefix(user.getPath().get()).toImmutableSet(), ImmutableSet.of(user));
|
ImmutableSet<User> usersAtPath = api().listPathPrefix(user.getPath().get()).concat().toImmutableSet();
|
||||||
|
assertTrue(usersAtPath.contains(user), user + " not in " + usersAtPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,8 @@
|
||||||
*/
|
*/
|
||||||
package org.jclouds.iam.internal;
|
package org.jclouds.iam.internal;
|
||||||
|
|
||||||
|
import java.util.TimeZone;
|
||||||
|
|
||||||
import org.jclouds.date.DateService;
|
import org.jclouds.date.DateService;
|
||||||
import org.jclouds.iam.config.IAMRestClientModule;
|
import org.jclouds.iam.config.IAMRestClientModule;
|
||||||
import org.jclouds.rest.ConfiguresRestClient;
|
import org.jclouds.rest.ConfiguresRestClient;
|
||||||
|
@ -33,6 +35,7 @@ public class BaseIAMExpectTest<T> extends BaseRestApiExpectTest<T> {
|
||||||
|
|
||||||
public BaseIAMExpectTest() {
|
public BaseIAMExpectTest() {
|
||||||
provider = "iam";
|
provider = "iam";
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ConfiguresRestClient
|
@ConfiguresRestClient
|
||||||
|
|
Loading…
Reference in New Issue