mirror of https://github.com/apache/jclouds.git
added iam instance profile support
This commit is contained in:
parent
83a36148ee
commit
58dc9b9796
|
@ -0,0 +1,32 @@
|
||||||
|
/**
|
||||||
|
* 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.aws.iam.features;
|
||||||
|
|
||||||
|
import org.jclouds.iam.features.InstanceProfileApiLiveTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", testName = "AWSInstanceProfileApiLiveTest")
|
||||||
|
public class AWSInstanceProfileApiLiveTest extends InstanceProfileApiLiveTest {
|
||||||
|
public AWSInstanceProfileApiLiveTest() {
|
||||||
|
provider = "aws-iam";
|
||||||
|
}
|
||||||
|
}
|
|
@ -21,6 +21,7 @@ package org.jclouds.iam;
|
||||||
import javax.ws.rs.FormParam;
|
import javax.ws.rs.FormParam;
|
||||||
|
|
||||||
import org.jclouds.iam.domain.User;
|
import org.jclouds.iam.domain.User;
|
||||||
|
import org.jclouds.iam.features.InstanceProfileApi;
|
||||||
import org.jclouds.iam.features.RoleApi;
|
import org.jclouds.iam.features.RoleApi;
|
||||||
import org.jclouds.iam.features.RolePolicyApi;
|
import org.jclouds.iam.features.RolePolicyApi;
|
||||||
import org.jclouds.iam.features.UserApi;
|
import org.jclouds.iam.features.UserApi;
|
||||||
|
@ -56,4 +57,10 @@ public interface IAMApi {
|
||||||
*/
|
*/
|
||||||
@Delegate
|
@Delegate
|
||||||
RolePolicyApi getPolicyApiForRole(@FormParam("RoleName") String roleName);
|
RolePolicyApi getPolicyApiForRole(@FormParam("RoleName") String roleName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides synchronous access to Instance Profile features.
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
InstanceProfileApi getInstanceProfileApi();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,7 @@ import javax.ws.rs.Path;
|
||||||
|
|
||||||
import org.jclouds.aws.filters.FormSigner;
|
import org.jclouds.aws.filters.FormSigner;
|
||||||
import org.jclouds.iam.domain.User;
|
import org.jclouds.iam.domain.User;
|
||||||
|
import org.jclouds.iam.features.InstanceProfileAsyncApi;
|
||||||
import org.jclouds.iam.features.RoleAsyncApi;
|
import org.jclouds.iam.features.RoleAsyncApi;
|
||||||
import org.jclouds.iam.features.RolePolicyAsyncApi;
|
import org.jclouds.iam.features.RolePolicyAsyncApi;
|
||||||
import org.jclouds.iam.features.UserAsyncApi;
|
import org.jclouds.iam.features.UserAsyncApi;
|
||||||
|
@ -75,4 +76,10 @@ public interface IAMAsyncApi {
|
||||||
*/
|
*/
|
||||||
@Delegate
|
@Delegate
|
||||||
RolePolicyAsyncApi getPolicyApiForRole(@FormParam("RoleName") String roleName);
|
RolePolicyAsyncApi getPolicyApiForRole(@FormParam("RoleName") String roleName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides asynchronous access to Instance Profile features.
|
||||||
|
*/
|
||||||
|
@Delegate
|
||||||
|
InstanceProfileAsyncApi getInstanceProfileApi();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,6 +25,8 @@ import java.util.Map;
|
||||||
import org.jclouds.aws.config.FormSigningRestClientModule;
|
import org.jclouds.aws.config.FormSigningRestClientModule;
|
||||||
import org.jclouds.iam.IAMApi;
|
import org.jclouds.iam.IAMApi;
|
||||||
import org.jclouds.iam.IAMAsyncApi;
|
import org.jclouds.iam.IAMAsyncApi;
|
||||||
|
import org.jclouds.iam.features.InstanceProfileApi;
|
||||||
|
import org.jclouds.iam.features.InstanceProfileAsyncApi;
|
||||||
import org.jclouds.iam.features.RoleApi;
|
import org.jclouds.iam.features.RoleApi;
|
||||||
import org.jclouds.iam.features.RoleAsyncApi;
|
import org.jclouds.iam.features.RoleAsyncApi;
|
||||||
import org.jclouds.iam.features.RolePolicyApi;
|
import org.jclouds.iam.features.RolePolicyApi;
|
||||||
|
@ -46,6 +48,7 @@ public class IAMRestClientModule extends FormSigningRestClientModule<IAMApi, IAM
|
||||||
.put(UserApi.class, UserAsyncApi.class)
|
.put(UserApi.class, UserAsyncApi.class)
|
||||||
.put(RoleApi.class, RoleAsyncApi.class)
|
.put(RoleApi.class, RoleAsyncApi.class)
|
||||||
.put(RolePolicyApi.class, RolePolicyAsyncApi.class)
|
.put(RolePolicyApi.class, RolePolicyAsyncApi.class)
|
||||||
|
.put(InstanceProfileApi.class, InstanceProfileAsyncApi.class)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
public IAMRestClientModule() {
|
public IAMRestClientModule() {
|
||||||
|
|
|
@ -0,0 +1,197 @@
|
||||||
|
/**
|
||||||
|
* 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.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 java.util.Date;
|
||||||
|
|
||||||
|
import com.google.common.base.Objects;
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see <a href="http://docs.amazonwebservices.com/IAM/latest/APIReference/API_GetInstanceProfile.html" />
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public final class InstanceProfile {
|
||||||
|
|
||||||
|
private final String arn;
|
||||||
|
private final String id;
|
||||||
|
private final String name;
|
||||||
|
private final String path;
|
||||||
|
private final Date createDate;
|
||||||
|
private final ImmutableList<Role> roles;
|
||||||
|
|
||||||
|
private InstanceProfile(String arn, String id, String name, String path, Date createDate, ImmutableList<Role> roles) {
|
||||||
|
this.arn = checkNotNull(arn, "arn");
|
||||||
|
this.id = checkNotNull(id, "id 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.roles = checkNotNull(roles, "roles for %s", arn);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* how to specify the resource in the access policy language ex.
|
||||||
|
* {@code arn:aws:<service>:<region>:<namespace>:<relative-id>}
|
||||||
|
*/
|
||||||
|
public String getArn() {
|
||||||
|
return arn;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* a globally unique identifier (GUID), returned from the api.
|
||||||
|
*/
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* friendly name ex. {@code Developers}
|
||||||
|
*/
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* path ex {@code /division_abc/subdivision_xyz/product_1234/engineering/}
|
||||||
|
*/
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Date the instance profile was created
|
||||||
|
*/
|
||||||
|
public Date getCreateDate() {
|
||||||
|
return createDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The roles assigned to the instance profile
|
||||||
|
*/
|
||||||
|
public ImmutableList<Role> getRoles() {
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(arn, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (this == obj)
|
||||||
|
return true;
|
||||||
|
if (obj == null || getClass() != obj.getClass())
|
||||||
|
return false;
|
||||||
|
InstanceProfile that = InstanceProfile.class.cast(obj);
|
||||||
|
return equal(this.arn, that.arn) && equal(this.id, that.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return toStringHelper(this).add("arn", arn).add("id", id).add("name", name).add("path", path)
|
||||||
|
.add("createDate", createDate).add("roles", roles).toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder builder() {
|
||||||
|
return new Builder();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return builder().from(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Builder {
|
||||||
|
private String arn;
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private String path;
|
||||||
|
private Date createDate;
|
||||||
|
private ImmutableList.Builder<Role> roles = ImmutableList.<Role> builder();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfile#getArn()
|
||||||
|
*/
|
||||||
|
public Builder arn(String arn) {
|
||||||
|
this.arn = arn;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfile#getId()
|
||||||
|
*/
|
||||||
|
public Builder id(String id) {
|
||||||
|
this.id = id;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfile#getName()
|
||||||
|
*/
|
||||||
|
public Builder name(String name) {
|
||||||
|
this.name = name;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfile#getPath()
|
||||||
|
*/
|
||||||
|
public Builder path(String path) {
|
||||||
|
this.path = path;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfile#getCreateDate()
|
||||||
|
*/
|
||||||
|
public Builder createDate(Date createDate) {
|
||||||
|
this.createDate = createDate;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfile#getRoles()
|
||||||
|
*/
|
||||||
|
public Builder role(Role role) {
|
||||||
|
this.roles.add(checkNotNull(role, "role"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfile#getRoles()
|
||||||
|
*/
|
||||||
|
public Builder roles(Iterable<Role> roles) {
|
||||||
|
this.roles.addAll(checkNotNull(roles, "roles"));
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public InstanceProfile build() {
|
||||||
|
return new InstanceProfile(arn, id, name, path, createDate, roles.build());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder from(InstanceProfile in) {
|
||||||
|
return arn(in.arn).id(in.id).name(in.name).path(in.path).createDate(in.createDate).roles(in.roles);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,127 @@
|
||||||
|
/**
|
||||||
|
* 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.iam.features;
|
||||||
|
|
||||||
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
|
import org.jclouds.collect.PagedIterable;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileAsyncApi
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public interface InstanceProfileApi {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new instance profile for your AWS account
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of the instance profile to create.
|
||||||
|
* @return the new instance profile
|
||||||
|
*/
|
||||||
|
InstanceProfile create(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* like {@link #create(String)}, except you can specify a path.
|
||||||
|
*/
|
||||||
|
InstanceProfile createWithPath(String name, String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns all instance profiles in order.
|
||||||
|
*/
|
||||||
|
PagedIterable<InstanceProfile> list();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieves up to 100 instance profiles in order.
|
||||||
|
*/
|
||||||
|
IterableWithMarker<InstanceProfile> listFirstPage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieves up to 100 instance profiles in order, starting at {@code marker}
|
||||||
|
*
|
||||||
|
* @param marker
|
||||||
|
* starting point to resume the list
|
||||||
|
*/
|
||||||
|
IterableWithMarker<InstanceProfile> listAt(String marker);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns all instance profiles in order at the specified {@code pathPrefix}.
|
||||||
|
*
|
||||||
|
* @param pathPrefix
|
||||||
|
* ex. {@code /division_abc/subdivision_xyz/}
|
||||||
|
*/
|
||||||
|
PagedIterable<InstanceProfile> listPathPrefix(String pathPrefix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieves up to 100 instance profiles in order at the specified {@code pathPrefix}.
|
||||||
|
*
|
||||||
|
* @param pathPrefix
|
||||||
|
* ex. {@code /division_abc/subdivision_xyz/}
|
||||||
|
*/
|
||||||
|
IterableWithMarker<InstanceProfile> listPathPrefixFirstPage(String pathPrefix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieves up to 100 instance profiles in order at the specified {@code pathPrefix}, starting at {@code marker}.
|
||||||
|
*
|
||||||
|
* @param pathPrefix
|
||||||
|
* ex. {@code /division_abc/subdivision_xyz/}
|
||||||
|
* @param marker
|
||||||
|
* starting point to resume the list
|
||||||
|
*/
|
||||||
|
IterableWithMarker<InstanceProfile> listPathPrefixAt(String pathPrefix, String marker);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves information about the specified instance profile, including the instance profile's path, GUID, and ARN.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of the instance profile to get information about.
|
||||||
|
* @return null if not found
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
InstanceProfile get(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the specified instanceProfile. The instance profile must not have any policies attached.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of the instance profile to delete
|
||||||
|
*/
|
||||||
|
void delete(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds the specified role to the specified instance profile.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of the instance profile to update.
|
||||||
|
* @param roleName
|
||||||
|
* Name of the role to add
|
||||||
|
*/
|
||||||
|
void addRole(String name, String roleName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes the specified role from the specified instance profile.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of the instance profile to update.
|
||||||
|
* @param roleName
|
||||||
|
* Name of the role to remove
|
||||||
|
*/
|
||||||
|
void removeRole(String name, String roleName);
|
||||||
|
}
|
|
@ -0,0 +1,180 @@
|
||||||
|
/**
|
||||||
|
* 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.iam.features;
|
||||||
|
|
||||||
|
import javax.inject.Named;
|
||||||
|
import javax.ws.rs.FormParam;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
|
||||||
|
import org.jclouds.Fallbacks.NullOnNotFoundOr404;
|
||||||
|
import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
||||||
|
import org.jclouds.aws.filters.FormSigner;
|
||||||
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
|
import org.jclouds.collect.PagedIterable;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.jclouds.iam.functions.InstanceProfilesToPagedIterable;
|
||||||
|
import org.jclouds.iam.xml.InstanceProfileHandler;
|
||||||
|
import org.jclouds.iam.xml.ListInstanceProfilesResultHandler;
|
||||||
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
import org.jclouds.rest.annotations.FormParams;
|
||||||
|
import org.jclouds.rest.annotations.RequestFilters;
|
||||||
|
import org.jclouds.rest.annotations.Transform;
|
||||||
|
import org.jclouds.rest.annotations.VirtualHost;
|
||||||
|
import org.jclouds.rest.annotations.XMLResponseParser;
|
||||||
|
|
||||||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides access to Amazon IAM via the Query API
|
||||||
|
* <p/>
|
||||||
|
*
|
||||||
|
* @see <a href="http://docs.amazonwebservices.com/IAM/latest/APIReference" />
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@RequestFilters(FormSigner.class)
|
||||||
|
@VirtualHost
|
||||||
|
public interface InstanceProfileAsyncApi {
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#create
|
||||||
|
*/
|
||||||
|
@Named("CreateInstanceProfile")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "CreateInstanceProfile")
|
||||||
|
@XMLResponseParser(InstanceProfileHandler.class)
|
||||||
|
ListenableFuture<InstanceProfile> create(@FormParam("InstanceProfileName") String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#createWithPath
|
||||||
|
*/
|
||||||
|
@Named("CreateInstanceProfile")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "CreateInstanceProfile")
|
||||||
|
@XMLResponseParser(InstanceProfileHandler.class)
|
||||||
|
ListenableFuture<InstanceProfile> createWithPath(@FormParam("InstanceProfileName") String name,
|
||||||
|
@FormParam("Path") String path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#list()
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfiles")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfiles")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
@Transform(InstanceProfilesToPagedIterable.class)
|
||||||
|
ListenableFuture<PagedIterable<InstanceProfile>> list();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#listFirstPage
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfiles")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfiles")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
ListenableFuture<IterableWithMarker<InstanceProfile>> listFirstPage();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#listAt(String)
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfiles")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfiles")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
ListenableFuture<IterableWithMarker<InstanceProfile>> listAt(@FormParam("Marker") String marker);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#listPathPrefix(String)
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfiles")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfiles")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
@Transform(InstanceProfilesToPagedIterable.class)
|
||||||
|
ListenableFuture<PagedIterable<InstanceProfile>> listPathPrefix(@FormParam("PathPrefix") String pathPrefix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#listPathPrefixFirstPage(String)
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfiles")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfiles")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
ListenableFuture<IterableWithMarker<InstanceProfile>> listPathPrefixFirstPage(
|
||||||
|
@FormParam("PathPrefix") String pathPrefix);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#listPathPrefixAt(String, String)
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfiles")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfiles")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
ListenableFuture<IterableWithMarker<InstanceProfile>> listPathPrefixAt(@FormParam("PathPrefix") String pathPrefix,
|
||||||
|
@FormParam("Marker") String marker);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#get()
|
||||||
|
*/
|
||||||
|
@Named("GetInstanceProfile")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@XMLResponseParser(InstanceProfileHandler.class)
|
||||||
|
@FormParams(keys = "Action", values = "GetInstanceProfile")
|
||||||
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<InstanceProfile> get(@FormParam("InstanceProfileName") String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#delete()
|
||||||
|
*/
|
||||||
|
@Named("DeleteInstanceProfile")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "DeleteInstanceProfile")
|
||||||
|
@Fallback(VoidOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Void> delete(@FormParam("InstanceProfileName") String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#addRole()
|
||||||
|
*/
|
||||||
|
@Named("AddRoleToInstanceProfile")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "AddRoleToInstanceProfile")
|
||||||
|
@Fallback(VoidOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Void> addRole(@FormParam("InstanceProfileName") String name, @FormParam("RoleName") String roleName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see InstanceProfileApi#removeRole()
|
||||||
|
*/
|
||||||
|
@Named("RemoveRoleFromInstanceProfile")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "RemoveRoleFromInstanceProfile")
|
||||||
|
@Fallback(VoidOnNotFoundOr404.class)
|
||||||
|
ListenableFuture<Void> removeRole(@FormParam("InstanceProfileName") String name,
|
||||||
|
@FormParam("RoleName") String roleName);
|
||||||
|
}
|
|
@ -20,6 +20,7 @@ package org.jclouds.iam.features;
|
||||||
|
|
||||||
import org.jclouds.collect.IterableWithMarker;
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
import org.jclouds.collect.PagedIterable;
|
import org.jclouds.collect.PagedIterable;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
import org.jclouds.iam.domain.Role;
|
import org.jclouds.iam.domain.Role;
|
||||||
import org.jclouds.javax.annotation.Nullable;
|
import org.jclouds.javax.annotation.Nullable;
|
||||||
|
|
||||||
|
@ -99,6 +100,32 @@ public interface RoleApi {
|
||||||
@Nullable
|
@Nullable
|
||||||
Role get(String name);
|
Role get(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns all instance profiles in order for this role.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of the role to get instance profiles for.
|
||||||
|
*/
|
||||||
|
PagedIterable<InstanceProfile> listInstanceProfiles(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieves up to 100 instance profiles in order for this role.
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of the role to get instance profiles for.
|
||||||
|
*/
|
||||||
|
IterableWithMarker<InstanceProfile> listFirstPageOfInstanceProfiles(String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retrieves up to 100 instance profiles in order for this role, starting at {@code marker}
|
||||||
|
*
|
||||||
|
* @param name
|
||||||
|
* Name of the role to get instance profiles for.
|
||||||
|
* @param marker
|
||||||
|
* starting point to resume the list
|
||||||
|
*/
|
||||||
|
IterableWithMarker<InstanceProfile> listInstanceProfilesAt(String name, String marker);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes the specified role. The role must not have any policies attached.
|
* Deletes the specified role. The role must not have any policies attached.
|
||||||
*
|
*
|
||||||
|
|
|
@ -28,8 +28,11 @@ import org.jclouds.Fallbacks.VoidOnNotFoundOr404;
|
||||||
import org.jclouds.aws.filters.FormSigner;
|
import org.jclouds.aws.filters.FormSigner;
|
||||||
import org.jclouds.collect.IterableWithMarker;
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
import org.jclouds.collect.PagedIterable;
|
import org.jclouds.collect.PagedIterable;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
import org.jclouds.iam.domain.Role;
|
import org.jclouds.iam.domain.Role;
|
||||||
|
import org.jclouds.iam.functions.InstanceProfilesForRoleToPagedIterable;
|
||||||
import org.jclouds.iam.functions.RolesToPagedIterable;
|
import org.jclouds.iam.functions.RolesToPagedIterable;
|
||||||
|
import org.jclouds.iam.xml.ListInstanceProfilesResultHandler;
|
||||||
import org.jclouds.iam.xml.ListRolesResultHandler;
|
import org.jclouds.iam.xml.ListRolesResultHandler;
|
||||||
import org.jclouds.iam.xml.RoleHandler;
|
import org.jclouds.iam.xml.RoleHandler;
|
||||||
import org.jclouds.rest.annotations.Fallback;
|
import org.jclouds.rest.annotations.Fallback;
|
||||||
|
@ -147,6 +150,39 @@ public interface RoleAsyncApi {
|
||||||
@Fallback(NullOnNotFoundOr404.class)
|
@Fallback(NullOnNotFoundOr404.class)
|
||||||
ListenableFuture<Role> get(@FormParam("RoleName") String name);
|
ListenableFuture<Role> get(@FormParam("RoleName") String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RoleApi#listInstanceProfiles()
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfilesForRole")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfilesForRole")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
@Transform(InstanceProfilesForRoleToPagedIterable.class)
|
||||||
|
ListenableFuture<PagedIterable<InstanceProfile>> listInstanceProfiles(@FormParam("RoleName") String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RoleApi#listFirstPageOfInstanceProfiles
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfilesForRole")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfilesForRole")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
ListenableFuture<IterableWithMarker<InstanceProfile>> listFirstPageOfInstanceProfiles(
|
||||||
|
@FormParam("RoleName") String name);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see RoleApi#listInstanceProfilesAt(String)
|
||||||
|
*/
|
||||||
|
@Named("ListInstanceProfilesForRole")
|
||||||
|
@POST
|
||||||
|
@Path("/")
|
||||||
|
@FormParams(keys = "Action", values = "ListInstanceProfilesForRole")
|
||||||
|
@XMLResponseParser(ListInstanceProfilesResultHandler.class)
|
||||||
|
ListenableFuture<IterableWithMarker<InstanceProfile>> listInstanceProfilesAt(@FormParam("RoleName") String name,
|
||||||
|
@FormParam("Marker") String marker);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see RoleApi#delete()
|
* @see RoleApi#delete()
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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.iam.functions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
|
import org.jclouds.collect.internal.Arg0ToPagedIterable;
|
||||||
|
import org.jclouds.iam.IAMApi;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.jclouds.iam.features.RoleApi;
|
||||||
|
|
||||||
|
import com.google.common.annotations.Beta;
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Beta
|
||||||
|
public class InstanceProfilesForRoleToPagedIterable extends
|
||||||
|
Arg0ToPagedIterable<InstanceProfile, InstanceProfilesForRoleToPagedIterable> {
|
||||||
|
|
||||||
|
private final RoleApi api;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected InstanceProfilesForRoleToPagedIterable(IAMApi api) {
|
||||||
|
this.api = checkNotNull(api, "api").getRoleApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Function<Object, IterableWithMarker<InstanceProfile>> markerToNextForArg0(Optional<Object> name) {
|
||||||
|
return new ListInstanceProfilesPrefixAtMarker(api, name.get().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ListInstanceProfilesPrefixAtMarker implements
|
||||||
|
Function<Object, IterableWithMarker<InstanceProfile>> {
|
||||||
|
private final RoleApi api;
|
||||||
|
private final String name;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected ListInstanceProfilesPrefixAtMarker(RoleApi api, String name) {
|
||||||
|
this.api = checkNotNull(api, "api");
|
||||||
|
this.name = checkNotNull(name, "name");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IterableWithMarker<InstanceProfile> apply(Object input) {
|
||||||
|
return api.listInstanceProfilesAt(name, input.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "ListInstanceProfilesPrefixAtMarker(" + name + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,90 @@
|
||||||
|
/**
|
||||||
|
* 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.iam.functions;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
|
import org.jclouds.collect.internal.Arg0ToPagedIterable;
|
||||||
|
import org.jclouds.iam.IAMApi;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.jclouds.iam.features.InstanceProfileApi;
|
||||||
|
|
||||||
|
import com.google.common.annotations.Beta;
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.base.Optional;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Beta
|
||||||
|
public class InstanceProfilesToPagedIterable extends Arg0ToPagedIterable<InstanceProfile, InstanceProfilesToPagedIterable> {
|
||||||
|
|
||||||
|
private final InstanceProfileApi api;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected InstanceProfilesToPagedIterable(IAMApi api) {
|
||||||
|
this.api = checkNotNull(api, "api").getInstanceProfileApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Function<Object, IterableWithMarker<InstanceProfile>> markerToNextForArg0(Optional<Object> pathPrefix) {
|
||||||
|
if (pathPrefix.isPresent())
|
||||||
|
return new ListInstanceProfilesUnderPathPrefixAtMarker(api, pathPrefix.get().toString());
|
||||||
|
return new ListInstanceProfilesAtMarker(api);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ListInstanceProfilesUnderPathPrefixAtMarker implements Function<Object, IterableWithMarker<InstanceProfile>> {
|
||||||
|
private final InstanceProfileApi api;
|
||||||
|
private final String pathPrefix;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected ListInstanceProfilesUnderPathPrefixAtMarker(InstanceProfileApi api, String pathPrefix) {
|
||||||
|
this.api = checkNotNull(api, "api");
|
||||||
|
this.pathPrefix = checkNotNull(pathPrefix, "pathPrefix");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IterableWithMarker<InstanceProfile> apply(Object input) {
|
||||||
|
return api.listPathPrefixAt(pathPrefix, input.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "ListInstanceProfilesUnderPathPrefixAtMarker(" + pathPrefix + ")";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ListInstanceProfilesAtMarker implements Function<Object, IterableWithMarker<InstanceProfile>> {
|
||||||
|
private final InstanceProfileApi api;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected ListInstanceProfilesAtMarker(InstanceProfileApi api) {
|
||||||
|
this.api = checkNotNull(api, "api");
|
||||||
|
}
|
||||||
|
|
||||||
|
public IterableWithMarker<InstanceProfile> apply(Object input) {
|
||||||
|
return api.listAt(input.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return "listInstanceProfilesAtMarker()";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,108 @@
|
||||||
|
/**
|
||||||
|
* 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.iam.xml;
|
||||||
|
|
||||||
|
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||||
|
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see <a href="http://docs.aws.amazon.com/IAM/latest/APIReference/API_GetInstanceProfile.html" />
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class InstanceProfileHandler extends ParseSax.HandlerForGeneratedRequestWithResult<InstanceProfile> {
|
||||||
|
|
||||||
|
private final DateService dateService;
|
||||||
|
private final RoleHandler roleHandler;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
protected InstanceProfileHandler(DateService dateService, RoleHandler roleHandler) {
|
||||||
|
this.dateService = dateService;
|
||||||
|
this.roleHandler = roleHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
private StringBuilder currentText = new StringBuilder();
|
||||||
|
private InstanceProfile.Builder builder = InstanceProfile.builder();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InstanceProfile getResult() {
|
||||||
|
try {
|
||||||
|
return builder.build();
|
||||||
|
} finally {
|
||||||
|
builder = InstanceProfile.builder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean inRoles;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String url, String name, String qName, Attributes attributes) {
|
||||||
|
if (equalsOrSuffix(qName, "Roles")) {
|
||||||
|
inRoles = true;
|
||||||
|
}
|
||||||
|
if (inRoles) {
|
||||||
|
roleHandler.startElement(url, name, qName, attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String name, String qName) {
|
||||||
|
if (inRoles) {
|
||||||
|
if (qName.equals("Roles")) {
|
||||||
|
inRoles = false;
|
||||||
|
} else if (qName.equals("member")) {
|
||||||
|
builder.role(roleHandler.getResult());
|
||||||
|
} else {
|
||||||
|
roleHandler.endElement(uri, name, qName);
|
||||||
|
}
|
||||||
|
} else if (qName.equals("Path")) {
|
||||||
|
builder.path(currentOrNull(currentText));
|
||||||
|
} else if (qName.equals("InstanceProfileName")) {
|
||||||
|
builder.name(currentOrNull(currentText));
|
||||||
|
} else if (qName.equals("InstanceProfileId")) {
|
||||||
|
builder.id(currentOrNull(currentText));
|
||||||
|
} else if (qName.equals("Arn")) {
|
||||||
|
builder.arn(currentOrNull(currentText));
|
||||||
|
} else if (qName.equals("CreateDate")) {
|
||||||
|
try {
|
||||||
|
builder.createDate(dateService.iso8601SecondsDateParse(currentOrNull(currentText)));
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// on create, milliseconds are present
|
||||||
|
builder.createDate(dateService.iso8601DateParse(currentOrNull(currentText)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currentText = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char ch[], int start, int length) {
|
||||||
|
if (inRoles) {
|
||||||
|
roleHandler.characters(ch, start, length);
|
||||||
|
} else {
|
||||||
|
currentText.append(ch, start, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,104 @@
|
||||||
|
/**
|
||||||
|
* 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.iam.xml;
|
||||||
|
|
||||||
|
import static org.jclouds.util.SaxUtils.currentOrNull;
|
||||||
|
import static org.jclouds.util.SaxUtils.equalsOrSuffix;
|
||||||
|
|
||||||
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
|
import org.jclouds.collect.IterableWithMarkers;
|
||||||
|
import org.jclouds.http.functions.ParseSax;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.xml.sax.Attributes;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableList.Builder;
|
||||||
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see <a href="http://docs.aws.amazon.com/IAM/latest/APIReference/API_ListInstanceProfiles.html" />
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class ListInstanceProfilesResultHandler extends
|
||||||
|
ParseSax.HandlerForGeneratedRequestWithResult<IterableWithMarker<InstanceProfile>> {
|
||||||
|
|
||||||
|
private final InstanceProfileHandler instanceProfileHandler;
|
||||||
|
|
||||||
|
private StringBuilder currentText = new StringBuilder();
|
||||||
|
private Builder<InstanceProfile> instanceProfiles = ImmutableList.<InstanceProfile> builder();
|
||||||
|
private String afterMarker;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public ListInstanceProfilesResultHandler(InstanceProfileHandler instanceProfileHandler) {
|
||||||
|
this.instanceProfileHandler = instanceProfileHandler;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IterableWithMarker<InstanceProfile> getResult() {
|
||||||
|
try {
|
||||||
|
return IterableWithMarkers.from(instanceProfiles.build(), afterMarker);
|
||||||
|
} finally {
|
||||||
|
instanceProfiles = ImmutableList.<InstanceProfile> builder();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean inInstanceProfiles;
|
||||||
|
private boolean inRoles;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startElement(String url, String name, String qName, Attributes attributes) {
|
||||||
|
if (equalsOrSuffix(qName, "InstanceProfiles")) {
|
||||||
|
inInstanceProfiles = true;
|
||||||
|
} else if (equalsOrSuffix(qName, "Roles")) {
|
||||||
|
inRoles = true;
|
||||||
|
}
|
||||||
|
if (inInstanceProfiles) {
|
||||||
|
instanceProfileHandler.startElement(url, name, qName, attributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void endElement(String uri, String name, String qName) {
|
||||||
|
if (inInstanceProfiles) {
|
||||||
|
if (qName.equals("Roles"))
|
||||||
|
inRoles = false;
|
||||||
|
if (qName.equals("InstanceProfiles")) {
|
||||||
|
inInstanceProfiles = false;
|
||||||
|
} else if (qName.equals("member") && !inRoles) {
|
||||||
|
instanceProfiles.add(instanceProfileHandler.getResult());
|
||||||
|
} else {
|
||||||
|
instanceProfileHandler.endElement(uri, name, qName);
|
||||||
|
}
|
||||||
|
} else if (qName.equals("Marker")) {
|
||||||
|
afterMarker = currentOrNull(currentText);
|
||||||
|
}
|
||||||
|
|
||||||
|
currentText = new StringBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void characters(char ch[], int start, int length) {
|
||||||
|
if (inInstanceProfiles) {
|
||||||
|
instanceProfileHandler.characters(ch, start, length);
|
||||||
|
} else {
|
||||||
|
currentText.append(ch, start, length);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,314 @@
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*
|
||||||
|
* Unles 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 expres or implied. See the License for the
|
||||||
|
* specific language governing permisions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.jclouds.iam.features;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.http.HttpResponse;
|
||||||
|
import org.jclouds.iam.IAMApi;
|
||||||
|
import org.jclouds.iam.internal.BaseIAMApiExpectTest;
|
||||||
|
import org.jclouds.iam.parse.GetInstanceProfileResponseTest;
|
||||||
|
import org.jclouds.iam.parse.ListInstanceProfilesResponseTest;
|
||||||
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "unit", testName = "InstanceProfileApiExpectTest")
|
||||||
|
public class InstanceProfileApiExpectTest extends BaseIAMApiExpectTest {
|
||||||
|
HttpRequest create = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "CreateInstanceProfile")
|
||||||
|
.addFormParam("InstanceProfileName", "name")
|
||||||
|
.addFormParam("Signature", "UIosTnnvBVHY7m7rqz1489RQ90Mf81/aOXgh8x2mLWU%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
public void testCreateWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/get_instance_profile.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestSendsResponse(create, getResponse);
|
||||||
|
|
||||||
|
assertEquals(apiWhenExist.getInstanceProfileApi().create("name").toString(), new GetInstanceProfileResponseTest().expected().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpRequest get = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "GetInstanceProfile")
|
||||||
|
.addFormParam("InstanceProfileName", "name")
|
||||||
|
.addFormParam("Signature", "uw5Ix/UFRqENsSWProK3%2BDMIezmvd3fFhTFMaooxFMg%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
public void testGetWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse getResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/get_instance_profile.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestSendsResponse(get, getResponse);
|
||||||
|
|
||||||
|
assertEquals(apiWhenExist.getInstanceProfileApi().get("name").toString(), new GetInstanceProfileResponseTest().expected().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testGetWhenResponseIs404() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse getResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenDontExist = requestSendsResponse(
|
||||||
|
get, getResponse);
|
||||||
|
|
||||||
|
assertNull(apiWhenDontExist.getInstanceProfileApi().get("name"));
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpRequest delete = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "DeleteInstanceProfile")
|
||||||
|
.addFormParam("InstanceProfileName", "name")
|
||||||
|
.addFormParam("Signature", "7W47Gj/6NE6p6drXMtqozYOlUOQN7CzbXgrIup4iowk%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
public void testDeleteWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse deleteResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/delete_instance_profile.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestSendsResponse(delete, deleteResponse);
|
||||||
|
|
||||||
|
apiWhenExist.getInstanceProfileApi().delete("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testDeleteWhenResponseIs404() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse deleteResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenDontExist = requestSendsResponse(delete, deleteResponse);
|
||||||
|
|
||||||
|
apiWhenDontExist.getInstanceProfileApi().delete("name");
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpRequest list = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "ListInstanceProfiles")
|
||||||
|
.addFormParam("Signature", "i2V6ZeplNRVaZ/9XfD4jv53Qh%2BNQdl3ZuoZc%2BLguf0o%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
public void testListWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestSendsResponse(list, listResponse);
|
||||||
|
|
||||||
|
assertEquals(apiWhenExist.getInstanceProfileApi().list().get(0).toString(), new ListInstanceProfilesResponseTest().expected().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testList2PagesWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles_marker.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
HttpRequest list2 = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "ListInstanceProfiles")
|
||||||
|
.addFormParam("Marker", "MARKER")
|
||||||
|
.addFormParam("Signature", "x7G5OvKxTIMEjl58OVurKrwf7wEA7exXSml63T89mSY%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
HttpResponse list2Response = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestsSendResponses(list, listResponse, list2, list2Response);
|
||||||
|
|
||||||
|
assertEquals(apiWhenExist.getInstanceProfileApi().list().concat().toList(),
|
||||||
|
ImmutableList.copyOf(Iterables.concat(new ListInstanceProfilesResponseTest().expected(), new ListInstanceProfilesResponseTest().expected())));
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpRequest listPathPrefix = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "ListInstanceProfiles")
|
||||||
|
.addFormParam("PathPrefix", "/subdivision")
|
||||||
|
.addFormParam("Signature", "EEVeWhJhORpibHahIj1skQ3rhHaVb/iaqD22vIFQH7o%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
public void testListPathPrefixWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestSendsResponse(listPathPrefix, listResponse);
|
||||||
|
|
||||||
|
assertEquals(apiWhenExist.getInstanceProfileApi().listPathPrefix("/subdivision").get(0).toString(), new ListInstanceProfilesResponseTest().expected().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testListPathPrefix2PagesWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse listResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles_marker.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
HttpRequest listPathPrefix2 = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "ListInstanceProfiles")
|
||||||
|
.addFormParam("Marker", "MARKER")
|
||||||
|
.addFormParam("PathPrefix", "/subdivision")
|
||||||
|
.addFormParam("Signature", "8xo94VlrqsoMoa6bpbqQbuVx8TLh8UmiQnc9QC58EhU%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
HttpResponse list2Response = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestsSendResponses(listPathPrefix, listResponse, listPathPrefix2, list2Response);
|
||||||
|
|
||||||
|
assertEquals(apiWhenExist.getInstanceProfileApi().listPathPrefix("/subdivision").concat().toList(),
|
||||||
|
ImmutableList.copyOf(Iterables.concat(new ListInstanceProfilesResponseTest().expected(), new ListInstanceProfilesResponseTest().expected())));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: this should really be an empty set
|
||||||
|
@Test(expectedExceptions = ResourceNotFoundException.class)
|
||||||
|
public void testListWhenResponseIs404() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse listResponse = HttpResponse.builder().statusCode(404).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenDontExist = requestSendsResponse(
|
||||||
|
list, listResponse);
|
||||||
|
|
||||||
|
apiWhenDontExist.getInstanceProfileApi().list().get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testListPathPrefixAtWhenResponseIs2xx() throws Exception {
|
||||||
|
HttpRequest listWithOptions =
|
||||||
|
HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "ListInstanceProfiles")
|
||||||
|
.addFormParam("Marker", "MARKER")
|
||||||
|
.addFormParam("PathPrefix", "/foo")
|
||||||
|
.addFormParam("Signature", "IBRktzqZ/GE8Y7DZqsjuOUNfJZTbkCnOZnHAmzwtju8%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
HttpResponse listWithOptionsResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenWithOptionsExist = requestSendsResponse(listWithOptions,
|
||||||
|
listWithOptionsResponse);
|
||||||
|
|
||||||
|
assertEquals(apiWhenWithOptionsExist.getInstanceProfileApi().listPathPrefixAt("/foo", "MARKER").toString(),
|
||||||
|
new ListInstanceProfilesResponseTest().expected().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpRequest addRole = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "AddRoleToInstanceProfile")
|
||||||
|
.addFormParam("InstanceProfileName", "name")
|
||||||
|
.addFormParam("RoleName", "WebServer")
|
||||||
|
.addFormParam("Signature", "QTM12yD9GwUKEE9wqbt03VlfZ/%2BfO0UWe9SbNoI9d3c%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
public void testAddRoleWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse addRoleResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/delete_instance_profile.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestSendsResponse(addRole, addRoleResponse);
|
||||||
|
|
||||||
|
apiWhenExist.getInstanceProfileApi().addRole("name", "WebServer");
|
||||||
|
}
|
||||||
|
|
||||||
|
HttpRequest removeRole = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "RemoveRoleFromInstanceProfile")
|
||||||
|
.addFormParam("InstanceProfileName", "name")
|
||||||
|
.addFormParam("RoleName", "WebServer")
|
||||||
|
.addFormParam("Signature", "o1Uz2bOwe8H3DOnyNL5TK9lNDoKvWo7CNhspN7ml5Sc%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
public void testRemoveRoleWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse removeRoleResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/delete_instance_profile.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestSendsResponse(removeRole, removeRoleResponse);
|
||||||
|
|
||||||
|
apiWhenExist.getInstanceProfileApi().removeRole("name", "WebServer");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,124 @@
|
||||||
|
/**
|
||||||
|
* 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.iam.features;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static java.util.logging.Logger.getAnonymousLogger;
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
import static org.testng.Assert.assertNull;
|
||||||
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.jclouds.iam.domain.Role;
|
||||||
|
import org.jclouds.iam.internal.BaseIAMApiLiveTest;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = "live", testName = "InstanceProfileApiLiveTest")
|
||||||
|
public class InstanceProfileApiLiveTest extends BaseIAMApiLiveTest {
|
||||||
|
|
||||||
|
static void checkInstanceProfile(InstanceProfile instanceProfile) {
|
||||||
|
checkNotNull(instanceProfile.getArn(), "Arn cannot be null for InstanceProfile %s", instanceProfile);
|
||||||
|
checkNotNull(instanceProfile.getId(), "Id cannot be null for InstanceProfile %s", instanceProfile);
|
||||||
|
checkNotNull(instanceProfile.getName(), "Name cannot be null for InstanceProfile %s", instanceProfile);
|
||||||
|
checkNotNull(instanceProfile.getPath(), "Path cannot be null for InstanceProfile %s", instanceProfile);
|
||||||
|
checkNotNull(instanceProfile.getRoles(), "Roles cannot be null for InstanceProfile %s", instanceProfile);
|
||||||
|
checkNotNull(instanceProfile.getCreateDate(),
|
||||||
|
"CreateDate cannot be null for a InstanceProfile InstanceProfile %s", instanceProfile);
|
||||||
|
for (Role role : instanceProfile.getRoles()) {
|
||||||
|
RoleApiLiveTest.checkRole(role);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
protected void testListInstanceProfiles() {
|
||||||
|
ImmutableList<InstanceProfile> instanceProfiles = api().list().concat().toList();
|
||||||
|
getAnonymousLogger().info("instanceProfiles: " + instanceProfiles.size());
|
||||||
|
|
||||||
|
for (InstanceProfile instanceProfile : instanceProfiles) {
|
||||||
|
checkInstanceProfile(instanceProfile);
|
||||||
|
assertEquals(api().get(instanceProfile.getName()), instanceProfile);
|
||||||
|
ImmutableSet<InstanceProfile> instanceProfilesAtPath = api().listPathPrefix(instanceProfile.getPath())
|
||||||
|
.concat().toSet();
|
||||||
|
assertTrue(instanceProfilesAtPath.contains(instanceProfile), instanceProfile + " not in "
|
||||||
|
+ instanceProfilesAtPath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetInstanceProfileWhenNotFound() {
|
||||||
|
assertNull(api().get("AAAAAAAAAAAAAAAA"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeleteInstanceProfileWhenNotFound() {
|
||||||
|
api().delete("AAAAAAAAAAAAAAAA");
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = System.getProperty("user.name").replace('.', '-') + ".instanceProfile.iamtest.jclouds.org.";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCreateInstanceProfile() {
|
||||||
|
InstanceProfile newInstanceProfile = api().create(name);
|
||||||
|
getAnonymousLogger().info("created instanceProfile: " + newInstanceProfile);
|
||||||
|
checkInstanceProfile(newInstanceProfile);
|
||||||
|
assertEquals(newInstanceProfile.getName(), name);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testCreateInstanceProfile")
|
||||||
|
public void testAddRoleRemoveRoleFromInstanceProfile() {
|
||||||
|
try {
|
||||||
|
createRoleWithPolicy(name);
|
||||||
|
api().addRole(name, name);
|
||||||
|
InstanceProfile updated = api().get(name);
|
||||||
|
RoleApiLiveTest.checkRole(updated.getRoles().get(0));
|
||||||
|
|
||||||
|
api().removeRole(name, name);
|
||||||
|
updated = api().get(name);
|
||||||
|
assertEquals(updated.getRoles(), ImmutableList.of());
|
||||||
|
} finally {
|
||||||
|
tearDownRoleWithPolicy(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testAddRoleRemoveRoleFromInstanceProfile")
|
||||||
|
public void testDeleteInstanceProfile() {
|
||||||
|
api().delete(name);
|
||||||
|
assertNull(api().get(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected InstanceProfileApi api() {
|
||||||
|
return context.getApi().getInstanceProfileApi();
|
||||||
|
}
|
||||||
|
|
||||||
|
void createRoleWithPolicy(String roleName) {
|
||||||
|
context.getApi().getRoleApi().createWithPolicy(roleName, RoleApiLiveTest.assumeRolePolicy);
|
||||||
|
context.getApi().getPolicyApiForRole(roleName).create("S3Access", RolePolicyApiLiveTest.s3Policy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void tearDownRoleWithPolicy(String roleName) {
|
||||||
|
context.getApi().getPolicyApiForRole(roleName).delete("S3Access");
|
||||||
|
context.getApi().getRoleApi().delete(roleName);
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import org.jclouds.http.HttpResponse;
|
||||||
import org.jclouds.iam.IAMApi;
|
import org.jclouds.iam.IAMApi;
|
||||||
import org.jclouds.iam.internal.BaseIAMApiExpectTest;
|
import org.jclouds.iam.internal.BaseIAMApiExpectTest;
|
||||||
import org.jclouds.iam.parse.GetRoleResponseTest;
|
import org.jclouds.iam.parse.GetRoleResponseTest;
|
||||||
|
import org.jclouds.iam.parse.ListInstanceProfilesResponseTest;
|
||||||
import org.jclouds.iam.parse.ListRolesResponseTest;
|
import org.jclouds.iam.parse.ListRolesResponseTest;
|
||||||
import org.jclouds.rest.ResourceNotFoundException;
|
import org.jclouds.rest.ResourceNotFoundException;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -269,4 +270,55 @@ public class RoleApiExpectTest extends BaseIAMApiExpectTest {
|
||||||
assertEquals(apiWhenWithOptionsExist.getRoleApi().listPathPrefixAt("/foo", "MARKER").toString(),
|
assertEquals(apiWhenWithOptionsExist.getRoleApi().listPathPrefixAt("/foo", "MARKER").toString(),
|
||||||
new ListRolesResponseTest().expected().toString());
|
new ListRolesResponseTest().expected().toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HttpRequest listInstanceProfiles = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "ListInstanceProfilesForRole")
|
||||||
|
.addFormParam("RoleName", "WebServer")
|
||||||
|
.addFormParam("Signature", "WLWyoNHcR09MJ9JN0qGIzzPsZtlTX6UbqsAkaxp9utg%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
public void testListInstanceProfilesWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse listInstanceProfilesResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestSendsResponse(listInstanceProfiles, listInstanceProfilesResponse);
|
||||||
|
|
||||||
|
assertEquals(apiWhenExist.getRoleApi().listInstanceProfiles("WebServer").get(0).toString(), new ListInstanceProfilesResponseTest().expected().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testListInstanceProfiles2PagesWhenResponseIs2xx() throws Exception {
|
||||||
|
|
||||||
|
HttpResponse listInstanceProfilesResponse = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles_marker.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
HttpRequest listInstanceProfiles2 = HttpRequest.builder()
|
||||||
|
.method("POST")
|
||||||
|
.endpoint("https://iam.amazonaws.com/")
|
||||||
|
.addHeader("Host", "iam.amazonaws.com")
|
||||||
|
.addFormParam("Action", "ListInstanceProfilesForRole")
|
||||||
|
.addFormParam("Marker", "MARKER")
|
||||||
|
.addFormParam("RoleName", "WebServer")
|
||||||
|
.addFormParam("Signature", "LHwKxeK/Hwqbv90tSG0tRJl/4BLrPqi%2BMvBnXvxUybs%3D")
|
||||||
|
.addFormParam("SignatureMethod", "HmacSHA256")
|
||||||
|
.addFormParam("SignatureVersion", "2")
|
||||||
|
.addFormParam("Timestamp", "2009-11-08T15%3A54%3A08.897Z")
|
||||||
|
.addFormParam("Version", "2010-05-08")
|
||||||
|
.addFormParam("AWSAccessKeyId", "identity").build();
|
||||||
|
|
||||||
|
HttpResponse listInstanceProfiles2Response = HttpResponse.builder().statusCode(200)
|
||||||
|
.payload(payloadFromResourceWithContentType("/list_instance_profiles.xml", "text/xml")).build();
|
||||||
|
|
||||||
|
IAMApi apiWhenExist = requestsSendResponses(listInstanceProfiles, listInstanceProfilesResponse, listInstanceProfiles2, listInstanceProfiles2Response);
|
||||||
|
|
||||||
|
assertEquals(apiWhenExist.getRoleApi().listInstanceProfiles("WebServer").concat().toList(),
|
||||||
|
ImmutableList.copyOf(Iterables.concat(new ListInstanceProfilesResponseTest().expected(), new ListInstanceProfilesResponseTest().expected())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
import static org.testng.Assert.assertNull;
|
import static org.testng.Assert.assertNull;
|
||||||
import static org.testng.Assert.assertTrue;
|
import static org.testng.Assert.assertTrue;
|
||||||
|
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
import org.jclouds.iam.domain.Role;
|
import org.jclouds.iam.domain.Role;
|
||||||
import org.jclouds.iam.internal.BaseIAMApiLiveTest;
|
import org.jclouds.iam.internal.BaseIAMApiLiveTest;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
@ -37,7 +38,7 @@ import com.google.common.collect.ImmutableSet;
|
||||||
@Test(groups = "live", testName = "RoleApiLiveTest")
|
@Test(groups = "live", testName = "RoleApiLiveTest")
|
||||||
public class RoleApiLiveTest extends BaseIAMApiLiveTest {
|
public class RoleApiLiveTest extends BaseIAMApiLiveTest {
|
||||||
|
|
||||||
private void checkRole(Role role) {
|
static void checkRole(Role role) {
|
||||||
checkNotNull(role.getArn(), "Arn cannot be null for Role %s", role);
|
checkNotNull(role.getArn(), "Arn cannot be null for Role %s", role);
|
||||||
checkNotNull(role.getId(), "Id cannot be null for Role %s", role);
|
checkNotNull(role.getId(), "Id cannot be null for Role %s", role);
|
||||||
checkNotNull(role.getName(), "Name cannot be null for Role %s", role);
|
checkNotNull(role.getName(), "Name cannot be null for Role %s", role);
|
||||||
|
@ -59,6 +60,15 @@ public class RoleApiLiveTest extends BaseIAMApiLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
protected void testListInstanceProfiles() {
|
||||||
|
for (Role role : api().list().concat()) {
|
||||||
|
for (InstanceProfile instanceProfile : api().listInstanceProfiles(role.getName()).concat()) {
|
||||||
|
InstanceProfileApiLiveTest.checkInstanceProfile(instanceProfile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetRoleWhenNotFound() {
|
public void testGetRoleWhenNotFound() {
|
||||||
assertNull(api().get("AAAAAAAAAAAAAAAA"));
|
assertNull(api().get("AAAAAAAAAAAAAAAA"));
|
||||||
|
@ -69,17 +79,17 @@ public class RoleApiLiveTest extends BaseIAMApiLiveTest {
|
||||||
api().delete("AAAAAAAAAAAAAAAA");
|
api().delete("AAAAAAAAAAAAAAAA");
|
||||||
}
|
}
|
||||||
|
|
||||||
String policy = "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";
|
static String assumeRolePolicy = "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateAndDeleteRole() {
|
public void testCreateAndDeleteRole() {
|
||||||
String name = System.getProperty("user.name").replace('.', '-') + ".role.iamtest.jclouds.org.";
|
String name = System.getProperty("user.name").replace('.', '-') + ".role.iamtest.jclouds.org.";
|
||||||
Role newRole;
|
Role newRole;
|
||||||
try {
|
try {
|
||||||
newRole = api().createWithPolicy(name, policy);
|
newRole = api().createWithPolicy(name, assumeRolePolicy);
|
||||||
getAnonymousLogger().info("created role: " + newRole);
|
getAnonymousLogger().info("created role: " + newRole);
|
||||||
checkRole(newRole);
|
checkRole(newRole);
|
||||||
assertEquals(newRole.getAssumeRolePolicy(), policy);
|
assertEquals(newRole.getAssumeRolePolicy(), assumeRolePolicy);
|
||||||
} finally {
|
} finally {
|
||||||
api().delete(name);
|
api().delete(name);
|
||||||
assertNull(api().get(name));
|
assertNull(api().get(name));
|
||||||
|
|
|
@ -34,7 +34,7 @@ import org.testng.annotations.Test;
|
||||||
@Test(groups = "live", testName = "RolePolicyApiLiveTest")
|
@Test(groups = "live", testName = "RolePolicyApiLiveTest")
|
||||||
public class RolePolicyApiLiveTest extends BaseIAMApiLiveTest {
|
public class RolePolicyApiLiveTest extends BaseIAMApiLiveTest {
|
||||||
|
|
||||||
private void checkPolicy(Policy policy) {
|
static void checkPolicy(Policy policy) {
|
||||||
checkNotNull(policy.getOwner(), "Owner cannot be null for Policy %s", policy);
|
checkNotNull(policy.getOwner(), "Owner cannot be null for Policy %s", policy);
|
||||||
checkNotNull(policy.getName(), "Name cannot be null for Policy %s", policy);
|
checkNotNull(policy.getName(), "Name cannot be null for Policy %s", policy);
|
||||||
checkNotNull(policy.getDocument(), "Document cannot be null for Policy %s", policy);
|
checkNotNull(policy.getDocument(), "Document cannot be null for Policy %s", policy);
|
||||||
|
@ -49,15 +49,14 @@ public class RolePolicyApiLiveTest extends BaseIAMApiLiveTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String assumeRolePolicy = "{\"Version\":\"2008-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":{\"Service\":\"ec2.amazonaws.com\"},\"Action\":\"sts:AssumeRole\"}]}";
|
static String s3Policy = "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}";
|
||||||
String s3Policy = "{\"Statement\":[{\"Effect\":\"Allow\",\"Action\":\"s3:*\",\"Resource\":\"*\"}]}";
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateAndDeleteRolePolicy() {
|
public void testCreateAndDeleteRolePolicy() {
|
||||||
String roleName = System.getProperty("user.name").replace('.', '-') + ".role_policy.iamtest.jclouds.org.";
|
String roleName = System.getProperty("user.name").replace('.', '-') + ".role_policy.iamtest.jclouds.org.";
|
||||||
Role newRole;
|
Role newRole;
|
||||||
try {
|
try {
|
||||||
newRole = context.getApi().getRoleApi().createWithPolicy(roleName, assumeRolePolicy);
|
newRole = context.getApi().getRoleApi().createWithPolicy(roleName, RoleApiLiveTest.assumeRolePolicy);
|
||||||
getAnonymousLogger().info("created role: " + newRole);
|
getAnonymousLogger().info("created role: " + newRole);
|
||||||
api(roleName).create("S3Access", s3Policy);
|
api(roleName).create("S3Access", s3Policy);
|
||||||
Policy newPolicy = api(roleName).get("S3Access");
|
Policy newPolicy = api(roleName).get("S3Access");
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class UserApiLiveTest extends BaseIAMApiLiveTest {
|
||||||
checkUser(user);
|
checkUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkUser(User user) {
|
static void checkUser(User user) {
|
||||||
checkNotNull(user.getArn(), "Arn cannot be null for User %s", user);
|
checkNotNull(user.getArn(), "Arn cannot be null for User %s", user);
|
||||||
checkNotNull(user.getId(), "Id cannot be null for User %s", user);
|
checkNotNull(user.getId(), "Id cannot be null for User %s", user);
|
||||||
checkNotNull(user.getName(), "While Name can be null for a User, its Optional wrapper cannot; user %s", user);
|
checkNotNull(user.getName(), "While Name can be null for a User, its Optional wrapper cannot; user %s", user);
|
||||||
|
|
|
@ -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.iam.parse;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.jclouds.iam.domain.Role;
|
||||||
|
import org.jclouds.iam.xml.InstanceProfileHandler;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||||
|
@Test(groups = "unit", testName = "GetInstanceProfileResponseTest")
|
||||||
|
public class GetInstanceProfileResponseTest extends BaseHandlerTest {
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/get_instance_profile.xml");
|
||||||
|
|
||||||
|
InstanceProfile expected = expected();
|
||||||
|
|
||||||
|
InstanceProfileHandler handler = injector.getInstance(InstanceProfileHandler.class);
|
||||||
|
InstanceProfile result = factory.create(handler).parse(is);
|
||||||
|
|
||||||
|
assertEquals(result, expected);
|
||||||
|
assertEquals(result.getPath(), expected.getPath());
|
||||||
|
assertEquals(result.getName(), expected.getName());
|
||||||
|
assertEquals(result.getCreateDate(), expected.getCreateDate());
|
||||||
|
assertEquals(result.getRoles(), expected.getRoles());
|
||||||
|
}
|
||||||
|
|
||||||
|
DateService date = new SimpleDateFormatDateService();
|
||||||
|
|
||||||
|
public InstanceProfile expected() {
|
||||||
|
return InstanceProfile.builder()
|
||||||
|
.arn("arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver")
|
||||||
|
.id("AIPAD5ARO2C5EXAMPLE3G")
|
||||||
|
.name("Webserver")
|
||||||
|
.path("/application_abc/component_xyz/")
|
||||||
|
.role(Role.builder()
|
||||||
|
.arn("arn:aws:iam::123456789012:role/application_abc/component_xyz/S3Access")
|
||||||
|
.id("AROACVYKSVTSZFEXAMPLE")
|
||||||
|
.name("S3Access")
|
||||||
|
.path("/application_abc/component_xyz/")
|
||||||
|
.assumeRolePolicy("{\"Version\":\"2008-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}")
|
||||||
|
.createDate(date.iso8601SecondsDateParse("2012-05-09T15:45:35Z")).build())
|
||||||
|
.createDate(date.iso8601SecondsDateParse("2012-05-09T16:11:10Z")).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,80 @@
|
||||||
|
/**
|
||||||
|
* 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.iam.parse;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
import org.jclouds.collect.IterableWithMarker;
|
||||||
|
import org.jclouds.collect.IterableWithMarkers;
|
||||||
|
import org.jclouds.date.DateService;
|
||||||
|
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||||
|
import org.jclouds.http.functions.BaseHandlerTest;
|
||||||
|
import org.jclouds.iam.domain.InstanceProfile;
|
||||||
|
import org.jclouds.iam.domain.Role;
|
||||||
|
import org.jclouds.iam.xml.ListInstanceProfilesResultHandler;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
|
||||||
|
@Test(groups = "unit", testName = "ListInstanceProfilesResponseTest")
|
||||||
|
public class ListInstanceProfilesResponseTest extends BaseHandlerTest {
|
||||||
|
|
||||||
|
public void test() {
|
||||||
|
InputStream is = getClass().getResourceAsStream("/list_instance_profiles.xml");
|
||||||
|
|
||||||
|
IterableWithMarker<InstanceProfile> expected = expected();
|
||||||
|
|
||||||
|
ListInstanceProfilesResultHandler handler = injector.getInstance(ListInstanceProfilesResultHandler.class);
|
||||||
|
IterableWithMarker<InstanceProfile> result = factory.create(handler).parse(is);
|
||||||
|
|
||||||
|
assertEquals(result.toString(), expected.toString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DateService date = new SimpleDateFormatDateService();
|
||||||
|
|
||||||
|
public IterableWithMarker<InstanceProfile> expected() {
|
||||||
|
return IterableWithMarkers.from(ImmutableSet.of(
|
||||||
|
InstanceProfile.builder()
|
||||||
|
.arn("arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Database")
|
||||||
|
.id("AIPACIFN4OZXG7EXAMPLE")
|
||||||
|
.name("Database")
|
||||||
|
.path("/application_abc/component_xyz/")
|
||||||
|
.role(Role.builder()
|
||||||
|
.arn("arn:aws:iam::123456789012:role/application_abc/component_xyz/S3Access")
|
||||||
|
.id("AROACVYKSVTSZFEXAMPLE")
|
||||||
|
.name("S3Access")
|
||||||
|
.path("/application_abc/component_xyz/")
|
||||||
|
.assumeRolePolicy("{\"Version\":\"2008-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"Service\":[\"ec2.amazonaws.com\"]},\"Action\":[\"sts:AssumeRole\"]}]}")
|
||||||
|
.createDate(date.iso8601SecondsDateParse("2012-05-09T15:45:35Z")).build())
|
||||||
|
.createDate(date.iso8601SecondsDateParse("2012-05-09T16:27:03Z")).build(),
|
||||||
|
InstanceProfile.builder()
|
||||||
|
.arn("arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver")
|
||||||
|
.id("AIPACZLSXM2EYYEXAMPLE")
|
||||||
|
.name("Webserver")
|
||||||
|
.path("/application_abc/component_xyz/")
|
||||||
|
.createDate(date.iso8601SecondsDateParse("2012-05-09T16:27:11Z")).build()));
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
<DeleteInstanceProfileResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>913e3f37-99ed-11e1-a4c3-270EXAMPLE04</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</DeleteInstanceProfileResponse>
|
|
@ -0,0 +1,24 @@
|
||||||
|
<GetInstanceProfileResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
|
||||||
|
<GetInstanceProfileResult>
|
||||||
|
<InstanceProfile>
|
||||||
|
<InstanceProfileId>AIPAD5ARO2C5EXAMPLE3G</InstanceProfileId>
|
||||||
|
<Roles>
|
||||||
|
<member>
|
||||||
|
<Path>/application_abc/component_xyz/</Path>
|
||||||
|
<Arn>arn:aws:iam::123456789012:role/application_abc/component_xyz/S3Access</Arn>
|
||||||
|
<RoleName>S3Access</RoleName>
|
||||||
|
<AssumeRolePolicyDocument>{"Version":"2008-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},"Action":["sts:AssumeRole"]}]}</AssumeRolePolicyDocument>
|
||||||
|
<CreateDate>2012-05-09T15:45:35Z</CreateDate>
|
||||||
|
<RoleId>AROACVYKSVTSZFEXAMPLE</RoleId>
|
||||||
|
</member>
|
||||||
|
</Roles>
|
||||||
|
<InstanceProfileName>Webserver</InstanceProfileName>
|
||||||
|
<Path>/application_abc/component_xyz/</Path>
|
||||||
|
<Arn>arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver</Arn>
|
||||||
|
<CreateDate>2012-05-09T16:11:10Z</CreateDate>
|
||||||
|
</InstanceProfile>
|
||||||
|
</GetInstanceProfileResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>37289fda-99f2-11e1-a4c3-27EXAMPLE804</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</GetInstanceProfileResponse>
|
|
@ -0,0 +1,37 @@
|
||||||
|
<ListInstanceProfilesResponse
|
||||||
|
xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
|
||||||
|
<ListInstanceProfilesResult>
|
||||||
|
<IsTruncated>false</IsTruncated>
|
||||||
|
<InstanceProfiles>
|
||||||
|
<member>
|
||||||
|
<InstanceProfileId>AIPACIFN4OZXG7EXAMPLE</InstanceProfileId>
|
||||||
|
<Roles>
|
||||||
|
<member>
|
||||||
|
<Path>/application_abc/component_xyz/</Path>
|
||||||
|
<Arn>arn:aws:iam::123456789012:role/application_abc/component_xyz/S3Access</Arn>
|
||||||
|
<RoleName>S3Access</RoleName>
|
||||||
|
<AssumeRolePolicyDocument>{"Version":"2008-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},"Action":["sts:AssumeRole"]}]}
|
||||||
|
</AssumeRolePolicyDocument>
|
||||||
|
<CreateDate>2012-05-09T15:45:35Z</CreateDate>
|
||||||
|
<RoleId>AROACVYKSVTSZFEXAMPLE</RoleId>
|
||||||
|
</member>
|
||||||
|
</Roles>
|
||||||
|
<InstanceProfileName>Database</InstanceProfileName>
|
||||||
|
<Path>/application_abc/component_xyz/</Path>
|
||||||
|
<Arn>arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Database</Arn>
|
||||||
|
<CreateDate>2012-05-09T16:27:03Z</CreateDate>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<InstanceProfileId>AIPACZLSXM2EYYEXAMPLE</InstanceProfileId>
|
||||||
|
<Roles />
|
||||||
|
<InstanceProfileName>Webserver</InstanceProfileName>
|
||||||
|
<Path>/application_abc/component_xyz/</Path>
|
||||||
|
<Arn>arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver</Arn>
|
||||||
|
<CreateDate>2012-05-09T16:27:11Z</CreateDate>
|
||||||
|
</member>
|
||||||
|
</InstanceProfiles>
|
||||||
|
</ListInstanceProfilesResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>fd74fa8d-99f3-11e1-a4c3-27EXAMPLE804</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</ListInstanceProfilesResponse>
|
|
@ -0,0 +1,39 @@
|
||||||
|
<ListInstanceProfilesResponse
|
||||||
|
xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
|
||||||
|
<ListInstanceProfilesResult>
|
||||||
|
<IsTruncated>false</IsTruncated>
|
||||||
|
<InstanceProfiles>
|
||||||
|
<member>
|
||||||
|
<InstanceProfileId>AIPACIFN4OZXG7EXAMPLE</InstanceProfileId>
|
||||||
|
<Roles>
|
||||||
|
<member>
|
||||||
|
<Path>/application_abc/component_xyz/</Path>
|
||||||
|
<Arn>arn:aws:iam::123456789012:role/application_abc/component_xyz/S3Access</Arn>
|
||||||
|
<RoleName>S3Access</RoleName>
|
||||||
|
<AssumeRolePolicyDocument>{"Version":"2008-10-17","Statement":[{"Effect":"Allow","Principal":{"Service":["ec2.amazonaws.com"]},"Action":["sts:AssumeRole"]}]}
|
||||||
|
</AssumeRolePolicyDocument>
|
||||||
|
<CreateDate>2012-05-09T15:45:35Z</CreateDate>
|
||||||
|
<RoleId>AROACVYKSVTSZFEXAMPLE</RoleId>
|
||||||
|
</member>
|
||||||
|
</Roles>
|
||||||
|
<InstanceProfileName>Database</InstanceProfileName>
|
||||||
|
<Path>/application_abc/component_xyz/</Path>
|
||||||
|
<Arn>arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Database</Arn>
|
||||||
|
<CreateDate>2012-05-09T16:27:03Z</CreateDate>
|
||||||
|
</member>
|
||||||
|
<member>
|
||||||
|
<InstanceProfileId>AIPACZLSXM2EYYEXAMPLE</InstanceProfileId>
|
||||||
|
<Roles />
|
||||||
|
<InstanceProfileName>Webserver</InstanceProfileName>
|
||||||
|
<Path>/application_abc/component_xyz/</Path>
|
||||||
|
<Arn>arn:aws:iam::123456789012:instance-profile/application_abc/component_xyz/Webserver</Arn>
|
||||||
|
<CreateDate>2012-05-09T16:27:11Z</CreateDate>
|
||||||
|
</member>
|
||||||
|
</InstanceProfiles>
|
||||||
|
<Marker>MARKER</Marker>
|
||||||
|
<IsTruncated>false</IsTruncated>
|
||||||
|
</ListInstanceProfilesResult>
|
||||||
|
<ResponseMetadata>
|
||||||
|
<RequestId>fd74fa8d-99f3-11e1-a4c3-27EXAMPLE804</RequestId>
|
||||||
|
</ResponseMetadata>
|
||||||
|
</ListInstanceProfilesResponse>
|
Loading…
Reference in New Issue