From 25f0f17db970fd334949c5c90d2e5e8fa3a46955 Mon Sep 17 00:00:00 2001 From: Ignasi Barrera Date: Mon, 19 Aug 2013 20:29:42 +0200 Subject: [PATCH] JCLOUDS-246: Joined Hosted and Private Chef apis Joined Hosted and Private Chef apis and renamed the provider to Enterprise Chef. --- README.md | 11 +- enterprise/pom.xml | 110 ++++++++++ .../jclouds/enterprisechef/EnterpriseChefApi.java | 141 +++++++++++++ .../enterprisechef/EnterpriseChefApiMetadata.java | 86 ++++++++ .../EnterpriseChefProviderMetadata.java | 88 ++++++++ .../binders/BindGroupNameToJsonPayload.java | 42 ++++ .../BindGroupToUpdateRequestJsonPayload.java | 81 ++++++++ .../jclouds/enterprisechef/binders/GroupName.java | 40 ++++ .../config/EnterpriseChefHttpApiModule.java | 38 ++++ .../org/jclouds/enterprisechef/domain/Group.java | 141 +++++++++++++ .../org/jclouds/enterprisechef/domain/User.java | 161 +++++++++++++++ .../org.jclouds.providers.ProviderMetadata | 1 + .../EnterpriseChefApiExpectTest.java | 222 +++++++++++++++++++++ .../enterprisechef/EnterpriseChefApiLiveTest.java | 121 +++++++++++ .../EnterpriseChefProviderMetadataTest.java | 35 ++++ .../binders/BindGroupNameToJsonPayloadTest.java | 52 +++++ .../BindGroupToUpdateRequestJsonPayloadTest.java | 89 +++++++++ .../enterprisechef/binders/GroupNameTest.java | 43 ++++ enterprise/src/test/resources/group-update.json | 1 + enterprise/src/test/resources/group.json | 14 ++ enterprise/src/test/resources/groups.json | 7 + enterprise/src/test/resources/user.json | 9 + labs/hostedchef/pom.xml | 110 ---------- .../java/org/jclouds/hostedchef/HostedChefApi.java | 145 -------------- .../jclouds/hostedchef/HostedChefApiMetadata.java | 86 -------- .../hostedchef/HostedChefProviderMetadata.java | 78 -------- .../binders/BindGroupNameToJsonPayload.java | 42 ---- .../BindGroupToUpdateRequestJsonPayload.java | 81 -------- .../org/jclouds/hostedchef/binders/GroupName.java | 40 ---- .../hostedchef/config/HostedChefHttpApiModule.java | 38 ---- .../java/org/jclouds/hostedchef/domain/Group.java | 141 ------------- .../java/org/jclouds/hostedchef/domain/User.java | 161 --------------- .../org.jclouds.providers.ProviderMetadata | 1 - .../hostedchef/HostedChefApiContextTest.java | 67 ------- .../hostedchef/HostedChefApiExpectTest.java | 220 -------------------- .../jclouds/hostedchef/HostedChefApiLiveTest.java | 120 ----------- .../hostedchef/HostedChefProviderMetadataTest.java | 34 ---- .../binders/BindGroupNameToJsonPayloadTest.java | 51 ----- .../BindGroupToUpdateRequestJsonPayloadTest.java | 88 -------- .../jclouds/hostedchef/binders/GroupNameTest.java | 42 ---- .../src/test/resources/group-update.json | 1 - labs/hostedchef/src/test/resources/group.json | 14 -- labs/hostedchef/src/test/resources/groups.json | 7 - labs/hostedchef/src/test/resources/user.json | 9 - labs/pom.xml | 36 ---- labs/privatechef/pom.xml | 122 ----------- .../org/jclouds/privatechef/PrivateChefApi.java | 39 ---- .../privatechef/PrivateChefApiMetadata.java | 86 -------- .../config/PrivateChefHttpApiModule.java | 38 ---- .../META-INF/services/org.jclouds.apis.ApiMetadata | 1 - .../privatechef/PrivateChefApiContextTest.java | 67 ------- .../privatechef/PrivateChefApiMetadataTest.java | 35 ---- labs/privatechef/src/test/resources/user.json | 1 - pom.xml | 2 +- project/pom.xml | 2 +- 55 files changed, 1527 insertions(+), 2011 deletions(-) create mode 100644 enterprise/pom.xml create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApiMetadata.java create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefProviderMetadata.java create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayload.java create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupToUpdateRequestJsonPayload.java create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/binders/GroupName.java create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/config/EnterpriseChefHttpApiModule.java create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/domain/Group.java create mode 100644 enterprise/src/main/java/org/jclouds/enterprisechef/domain/User.java create mode 100644 enterprise/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata create mode 100644 enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefApiExpectTest.java create mode 100644 enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefApiLiveTest.java create mode 100644 enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefProviderMetadataTest.java create mode 100644 enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayloadTest.java create mode 100644 enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupToUpdateRequestJsonPayloadTest.java create mode 100644 enterprise/src/test/java/org/jclouds/enterprisechef/binders/GroupNameTest.java create mode 100644 enterprise/src/test/resources/group-update.json create mode 100644 enterprise/src/test/resources/group.json create mode 100644 enterprise/src/test/resources/groups.json create mode 100644 enterprise/src/test/resources/user.json delete mode 100644 labs/hostedchef/pom.xml delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefApi.java delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefApiMetadata.java delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefProviderMetadata.java delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/BindGroupNameToJsonPayload.java delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/BindGroupToUpdateRequestJsonPayload.java delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/GroupName.java delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/config/HostedChefHttpApiModule.java delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/domain/Group.java delete mode 100644 labs/hostedchef/src/main/java/org/jclouds/hostedchef/domain/User.java delete mode 100644 labs/hostedchef/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata delete mode 100644 labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java delete mode 100644 labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiExpectTest.java delete mode 100644 labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiLiveTest.java delete mode 100644 labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefProviderMetadataTest.java delete mode 100644 labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/BindGroupNameToJsonPayloadTest.java delete mode 100644 labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/BindGroupToUpdateRequestJsonPayloadTest.java delete mode 100644 labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/GroupNameTest.java delete mode 100644 labs/hostedchef/src/test/resources/group-update.json delete mode 100644 labs/hostedchef/src/test/resources/group.json delete mode 100644 labs/hostedchef/src/test/resources/groups.json delete mode 100644 labs/hostedchef/src/test/resources/user.json delete mode 100644 labs/pom.xml delete mode 100644 labs/privatechef/pom.xml delete mode 100644 labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefApi.java delete mode 100644 labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefApiMetadata.java delete mode 100644 labs/privatechef/src/main/java/org/jclouds/privatechef/config/PrivateChefHttpApiModule.java delete mode 100644 labs/privatechef/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata delete mode 100644 labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java delete mode 100644 labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiMetadataTest.java delete mode 100644 labs/privatechef/src/test/resources/user.json diff --git a/README.md b/README.md index bceec3e..ed2c40e 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,18 @@ jclouds Chef ============ -[![Build Status](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-chef/badge/icon)](https://buildhive.cloudbees.com/job/jclouds/job/jclouds-chef/) +[![Build Status](https://jclouds.ci.cloudbees.com/buildStatus/icon?job=jclouds-chef)](https://jclouds.ci.cloudbees.com/job/jclouds-chef/) This is the jclouds Chef api. It provides access to the different flavours of the Chef server api: * [Chef community](http://www.opscode.com/chef/) -* [Hosted Chef](http://www.opscode.com/hosted-chef/) -* [Private Chef](http://www.opscode.com/private-chef/) +* [Enterprise Chef](http://www.opscode.com/enterprise-chef/) It currently supports versions **0.9** and **0.10** of the standard Chef server apis, and an initial -and very basic (still in progress) implementation of the user and organization api of the Hosted and -Private Chef flavours. +and very basic (still in progress) implementation of the user and organization api of the Enterprise Chef. Also provides a set of utility methods to combine Chef features with the jclouds Compute service, allowing users to customize the bootstrap process and manage the configuration of the deployed nodes. -Documentation -============= - You will find all documentation in www.jclouds.org diff --git a/enterprise/pom.xml b/enterprise/pom.xml new file mode 100644 index 0000000..849c9b6 --- /dev/null +++ b/enterprise/pom.xml @@ -0,0 +1,110 @@ + + + + 4.0.0 + + org.apache.jclouds.chef + chef-project + 1.7.0-SNAPSHOT + ../project/pom.xml + + org.apache.jclouds.provider + enterprisechef + Apache jclouds Chef :: Enterprise + jclouds components to access Enterprise Chef + + + YOUR_ORG + https://api.opscode.com/organizations/${test.enterprisechef.org} + + + YOUR_USER + ${user.home}/.chef/${test.enterprisechef.org}/${test.enterprisechef.identity}.pem + org.jclouds.enterprisechef*;version="${project.version}" + org.jclouds*;version="${jclouds.version}",* + + + + + org.apache.jclouds.api + chef + ${project.version} + + + org.apache.jclouds.api + chef + ${project.version} + test-jar + test + + + org.apache.jclouds + jclouds-core + ${jclouds.version} + test-jar + test + + + org.apache.jclouds.driver + jclouds-slf4j + ${jclouds.version} + test + + + ch.qos.logback + logback-classic + 1.0.9 + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + ${test.enterprisechef.org} + ${test.enterprisechef.endpoint} + ${test.enterprisechef.api-version} + ${test.enterprisechef.build-version} + ${test.enterprisechef.identity} + ${test.enterprisechef.credential} + + + + + + + + + + diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java b/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java new file mode 100644 index 0000000..04a7dda --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApi.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef; + +import java.util.Set; + +import javax.inject.Named; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.MediaType; + +import org.jclouds.Constants; +import org.jclouds.Fallbacks.FalseOnNotFoundOr404; +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.chef.ChefApi; +import org.jclouds.chef.filters.SignedHeaderAuth; +import org.jclouds.chef.functions.ParseKeySetFromJson; +import org.jclouds.enterprisechef.binders.BindGroupNameToJsonPayload; +import org.jclouds.enterprisechef.binders.BindGroupToUpdateRequestJsonPayload; +import org.jclouds.enterprisechef.binders.GroupName; +import org.jclouds.enterprisechef.domain.Group; +import org.jclouds.enterprisechef.domain.User; +import org.jclouds.rest.annotations.BinderParam; +import org.jclouds.rest.annotations.Fallback; +import org.jclouds.rest.annotations.Headers; +import org.jclouds.rest.annotations.ParamParser; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; + +/** + * Provides synchronous access to the Enterprise Chef Api. + * + * @author Ignasi Barrera + */ +@RequestFilters(SignedHeaderAuth.class) +@Consumes(MediaType.APPLICATION_JSON) +@Headers(keys = "X-Chef-Version", values = "{" + Constants.PROPERTY_API_VERSION + "}") +public interface EnterpriseChefApi extends ChefApi +{ + + /** + * Check if there exists a node with the given name. + * + * @return true if the specified node name exists. + */ + @Override + // Use get instead of HEAD + @Named("node:exists") + @GET + @Path("/nodes/{nodename}") + @Fallback(FalseOnNotFoundOr404.class) + boolean nodeExists(@PathParam("nodename") String nodename); + + /** + * Retrieves an existing user. + * + * @param name The name of the user to get. + * @return The details of the user or null if not found. + */ + @Named("user:get") + @GET + @Path("/users/{name}") + @Fallback(NullOnNotFoundOr404.class) + User getUser(@PathParam("name") String name); + + /** + * List all existing groups. + * + * @return The list of groups. + */ + @Named("group:list") + @GET + @Path("/groups") + @ResponseParser(ParseKeySetFromJson.class) + Set listGroups(); + + /** + * Retrieves an existing group. + * + * @param name The name of the group to get. + * @return The details of the group or null if not found. + */ + @Named("group:get") + @GET + @Path("/groups/{name}") + @Fallback(NullOnNotFoundOr404.class) + Group getGroup(@PathParam("name") String name); + + /** + * Creates a new group. + * + * @param name The name of the group to create. + */ + @Named("group:create") + @POST + @Path("/groups") + void createGroup(@BinderParam(BindGroupNameToJsonPayload.class) String name); + + /** + * Updates a group. + *

+ * This method can be used to add actors (clients, groups) to the group. + * + * @param group The group with the updated information. + */ + @Named("group:update") + @PUT + @Path("/groups/{name}") + void updateGroup( + @PathParam("name") @ParamParser(GroupName.class) @BinderParam(BindGroupToUpdateRequestJsonPayload.class) Group group); + + /** + * Deletes a group. + * + * @param name The name of the group to delete. + */ + @Named("group:delete") + @DELETE + @Path("/groups/{name}") + void deleteGroup(@PathParam("name") String name); + +} diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApiMetadata.java b/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApiMetadata.java new file mode 100644 index 0000000..5251209 --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefApiMetadata.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.chef.ChefApi; +import org.jclouds.chef.ChefApiMetadata; +import org.jclouds.chef.ChefContext; +import org.jclouds.chef.config.ChefBootstrapModule; +import org.jclouds.chef.config.ChefParserModule; +import org.jclouds.enterprisechef.config.EnterpriseChefHttpApiModule; +import org.jclouds.ohai.config.JMXOhaiModule; +import org.jclouds.rest.internal.BaseHttpApiMetadata; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Implementation of {@link ApiMetadata} for the Enterprise Chef api. + * + * @author Adrian Cole + */ +public class EnterpriseChefApiMetadata extends BaseHttpApiMetadata { + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public EnterpriseChefApiMetadata() { + this(new Builder()); + } + + protected EnterpriseChefApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + return ChefApiMetadata.defaultProperties(); + } + + public static class Builder extends BaseHttpApiMetadata.Builder { + + protected Builder() { + id("enterprisechef") + .name("Enterprise Chef Api") + .identityName("User") + .credentialName("Certificate") + .version(ChefApi.VERSION) + .documentation(URI.create("http://www.opscode.com/support")) + .defaultEndpoint("https://api.opscode.com") + .view(ChefContext.class) + .defaultProperties(EnterpriseChefApiMetadata.defaultProperties()) + .defaultModules( + ImmutableSet.> of(EnterpriseChefHttpApiModule.class, + ChefParserModule.class, ChefBootstrapModule.class, JMXOhaiModule.class)); + } + + @Override + public EnterpriseChefApiMetadata build() { + return new EnterpriseChefApiMetadata(this); + } + + @Override + protected Builder self() { + return this; + } + } +} diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefProviderMetadata.java b/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefProviderMetadata.java new file mode 100644 index 0000000..89c6db8 --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/EnterpriseChefProviderMetadata.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadata; + +/** + * Implementation of @ link org.jclouds.types.ProviderMetadata} for Enterprise Chef + * + * @author Adrian Cole + */ +public class EnterpriseChefProviderMetadata extends BaseProviderMetadata +{ + + public static Builder builder() + { + return new Builder(); + } + + @Override + public Builder toBuilder() + { + return builder().fromProviderMetadata(this); + } + + public EnterpriseChefProviderMetadata() + { + super(builder()); + } + + public EnterpriseChefProviderMetadata(Builder builder) + { + super(builder); + } + + public static Properties defaultProperties() + { + Properties properties = new Properties(); + return properties; + } + + public static class Builder extends BaseProviderMetadata.Builder + { + + protected Builder() + { + id("enterprisechef") // + .name("OpsCode Enterprise Chef") // + .endpoint("https://api.opscode.com") // + .homepage(URI.create("https://manage.opscode.com")) // + .console(URI.create("https://manage.opscode.com")) // + .apiMetadata(new EnterpriseChefApiMetadata()) // + .defaultProperties(EnterpriseChefProviderMetadata.defaultProperties()); + } + + @Override + public EnterpriseChefProviderMetadata build() + { + return new EnterpriseChefProviderMetadata(this); + } + + @Override + public Builder fromProviderMetadata(ProviderMetadata in) + { + super.fromProviderMetadata(in); + return this; + } + + } +} diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayload.java b/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayload.java new file mode 100644 index 0000000..47f1a9a --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayload.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.binders; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.binders.BindToStringPayload; + +/** + * Binds the name of a group to the json payload. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindGroupNameToJsonPayload extends BindToStringPayload { + + @Override + public R bindToRequest(R request, Object payload) { + super.bindToRequest(request, String.format("{\"groupname\":\"%s\"}", checkNotNull(payload, "payload"))); + request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); + return request; + } + +} diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupToUpdateRequestJsonPayload.java b/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupToUpdateRequestJsonPayload.java new file mode 100644 index 0000000..0b24341 --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/binders/BindGroupToUpdateRequestJsonPayload.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.binders; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.enterprisechef.domain.Group; +import org.jclouds.http.HttpRequest; +import org.jclouds.json.Json; +import org.jclouds.rest.binders.BindToJsonPayload; + +/** + * Binds a group to the payload expected for the Put method in the Enterprise Chef + * Api. + * + * @author Ignasi Barrera + */ +@Singleton +public class BindGroupToUpdateRequestJsonPayload extends BindToJsonPayload { + + @Inject + public BindGroupToUpdateRequestJsonPayload(Json jsonBinder) { + super(jsonBinder); + } + + @Override + public R bindToRequest(R request, Object payload) { + checkArgument(checkNotNull(payload, "payload") instanceof Group, "this binder is only valid for Group objects"); + GroupUpdateRequest updateGroup = new GroupUpdateRequest((Group) payload); + return super.bindToRequest(request, updateGroup); + } + + @SuppressWarnings("unused") + private static class GroupUpdateRequest { + private String name; + private String groupname; + private String orgname; + private ActorConfiguration actors; + + public GroupUpdateRequest(Group group) { + this.name = group.getName(); + this.groupname = group.getGroupname(); + this.orgname = group.getOrgname(); + this.actors = new ActorConfiguration(group); + } + } + + @SuppressWarnings("unused") + private static class ActorConfiguration { + private Set clients; + private Set groups; + private Set users; + + public ActorConfiguration(Group group) { + this.clients = group.getClients(); + this.groups = group.getGroups(); + this.users = group.getUsers(); + } + } + +} diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/binders/GroupName.java b/enterprise/src/main/java/org/jclouds/enterprisechef/binders/GroupName.java new file mode 100644 index 0000000..ec79567 --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/binders/GroupName.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.binders; + +import static com.google.common.base.Preconditions.checkNotNull; + +import javax.inject.Singleton; + +import org.jclouds.enterprisechef.domain.Group; + +import com.google.common.base.Function; + +/** + * Gets the name of a group. + * + * @author Ignasi Barrera + */ +@Singleton +public class GroupName implements Function { + + @Override + public String apply(Object from) { + return ((Group) checkNotNull(from, "from")).getGroupname(); + } + +} diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/config/EnterpriseChefHttpApiModule.java b/enterprise/src/main/java/org/jclouds/enterprisechef/config/EnterpriseChefHttpApiModule.java new file mode 100644 index 0000000..d1e16c7 --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/config/EnterpriseChefHttpApiModule.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.config; + +import org.jclouds.chef.ChefApi; +import org.jclouds.chef.config.BaseChefHttpApiModule; +import org.jclouds.enterprisechef.EnterpriseChefApi; +import org.jclouds.rest.ConfiguresHttpApi; + +/** + * Configures the Enterprise Chef connection. + * + * @author Ignasi Barrera + */ +@ConfiguresHttpApi +public class EnterpriseChefHttpApiModule extends BaseChefHttpApiModule { + + @Override + protected void configure() { + super.configure(); + bind(ChefApi.class).to(EnterpriseChefApi.class); + } + +} diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/domain/Group.java b/enterprise/src/main/java/org/jclouds/enterprisechef/domain/Group.java new file mode 100644 index 0000000..056acf4 --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/domain/Group.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.domain; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.Set; + +import com.google.common.collect.Sets; + +/** + * Group object. + * + * @author Ignasi Barrera + */ +public class Group { + private String name; + private String groupname; + private String orgname; + private Set actors = Sets.newHashSet(); + private Set clients = Sets.newHashSet(); + private Set groups = Sets.newHashSet(); + private Set users = Sets.newHashSet(); + + // When creating groups, only the group name property is considered + public Group(String groupname) { + this.groupname = checkNotNull(groupname, "groupname"); + } + + // Only for deserialization + Group() { + + } + + public String getName() { + return name; + } + + public String getGroupname() { + return groupname; + } + + public String getOrgname() { + return orgname; + } + + public Set getActors() { + return actors; + } + + public Set getClients() { + return clients; + } + + public Set getGroups() { + return groups; + } + + public Set getUsers() { + return users; + } + + public void setClients(Set clients) { + this.clients = clients; + } + + public void setGroups(Set groups) { + this.groups = groups; + } + + public void setUsers(Set users) { + this.users = users; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (groupname == null ? 0 : groupname.hashCode()); + result = prime * result + (name == null ? 0 : name.hashCode()); + result = prime * result + (orgname == null ? 0 : orgname.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + Group other = (Group) obj; + if (groupname == null) { + if (other.groupname != null) { + return false; + } + } else if (!groupname.equals(other.groupname)) { + return false; + } + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (orgname == null) { + if (other.orgname != null) { + return false; + } + } else if (!orgname.equals(other.orgname)) { + return false; + } + return true; + } + + @Override + public String toString() { + return "Group [name=" + name + ", groupname=" + groupname + ", orgname=" + orgname + ", actors=" + actors + + ", clients=" + clients + ", groups=" + groups + ", users=" + users + "]"; + } + +} diff --git a/enterprise/src/main/java/org/jclouds/enterprisechef/domain/User.java b/enterprise/src/main/java/org/jclouds/enterprisechef/domain/User.java new file mode 100644 index 0000000..247d1a8 --- /dev/null +++ b/enterprise/src/main/java/org/jclouds/enterprisechef/domain/User.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.domain; + +import java.security.PublicKey; + +import com.google.gson.annotations.SerializedName; + +/** + * User object. + * + * @author Ignasi Barrera + */ +public class User { + private String username; + @SerializedName("first_name") + private String firstName; + @SerializedName("middle_name") + private String middleName; + @SerializedName("last_name") + private String lastName; + @SerializedName("display_name") + private String displayName; + private String email; + @SerializedName("public_key") + private PublicKey publicKey; + + // TODO: Add a constructor to allow creating users. Need an Enterprise Chef instance! + + // Only for deserialization + User() { + + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (displayName == null ? 0 : displayName.hashCode()); + result = prime * result + (email == null ? 0 : email.hashCode()); + result = prime * result + (firstName == null ? 0 : firstName.hashCode()); + result = prime * result + (lastName == null ? 0 : lastName.hashCode()); + result = prime * result + (middleName == null ? 0 : middleName.hashCode()); + result = prime * result + (publicKey == null ? 0 : publicKey.hashCode()); + result = prime * result + (username == null ? 0 : username.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + User other = (User) obj; + if (displayName == null) { + if (other.displayName != null) { + return false; + } + } else if (!displayName.equals(other.displayName)) { + return false; + } + if (email == null) { + if (other.email != null) { + return false; + } + } else if (!email.equals(other.email)) { + return false; + } + if (firstName == null) { + if (other.firstName != null) { + return false; + } + } else if (!firstName.equals(other.firstName)) { + return false; + } + if (lastName == null) { + if (other.lastName != null) { + return false; + } + } else if (!lastName.equals(other.lastName)) { + return false; + } + if (middleName == null) { + if (other.middleName != null) { + return false; + } + } else if (!middleName.equals(other.middleName)) { + return false; + } + if (publicKey == null) { + if (other.publicKey != null) { + return false; + } + } else if (!publicKey.equals(other.publicKey)) { + return false; + } + if (username == null) { + if (other.username != null) { + return false; + } + } else if (!username.equals(other.username)) { + return false; + } + return true; + } + + public String getUsername() { + return username; + } + + public String getFirstName() { + return firstName; + } + + public String getMiddleName() { + return middleName; + } + + public String getLastName() { + return lastName; + } + + public String getDisplayName() { + return displayName; + } + + public String getEmail() { + return email; + } + + public PublicKey getPublicKey() { + return publicKey; + } + + @Override + public String toString() { + return "User [username=" + username + ", firstName=" + firstName + ", middleName=" + middleName + ", lastName=" + + lastName + ", displayName=" + displayName + ", email=" + email + ", publicKey=" + publicKey + "]"; + } + +} diff --git a/enterprise/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/enterprise/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata new file mode 100644 index 0000000..7861cbb --- /dev/null +++ b/enterprise/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata @@ -0,0 +1 @@ +org.jclouds.enterprisechef.EnterpriseChefProviderMetadata diff --git a/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefApiExpectTest.java b/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefApiExpectTest.java new file mode 100644 index 0000000..e859dc2 --- /dev/null +++ b/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefApiExpectTest.java @@ -0,0 +1,222 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.Set; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.chef.BaseChefApiExpectTest; +import org.jclouds.chef.ChefApi; +import org.jclouds.date.TimeStamp; +import org.jclouds.enterprisechef.EnterpriseChefApi; +import org.jclouds.enterprisechef.EnterpriseChefProviderMetadata; +import org.jclouds.enterprisechef.config.EnterpriseChefHttpApiModule; +import org.jclouds.enterprisechef.domain.Group; +import org.jclouds.enterprisechef.domain.User; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.providers.ProviderMetadata; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import com.google.common.base.Supplier; +import com.google.common.collect.ImmutableSet; +import com.google.inject.Module; + +/** + * Expect tests for the {@link EnterpriseChefApi} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "EnterpriseChefApiExpectTest") +public class EnterpriseChefApiExpectTest extends BaseChefApiExpectTest { + public EnterpriseChefApiExpectTest() { + provider = "enterprisechef"; + } + + public void testGetUserReturns2xx() { + EnterpriseChefApi api = requestSendsResponse( + signed(HttpRequest.builder() // + .method("GET") // + .endpoint("https://api.opscode.com/users/nacx") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON).build()), // + HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/user.json", MediaType.APPLICATION_JSON)) // + .build()); + + User user = api.getUser("nacx"); + assertEquals(user.getUsername(), "nacx"); + assertEquals(user.getDisplayName(), "Ignasi Barrera"); + } + + public void testGetUserReturns404() { + EnterpriseChefApi api = requestSendsResponse(signed(HttpRequest.builder() // + .method("GET") // + .endpoint("https://api.opscode.com/users/foo") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON) // + .build()), // + HttpResponse.builder().statusCode(404).build()); + + assertNull(api.getUser("foo")); + } + + public void testListGroups() { + EnterpriseChefApi api = requestSendsResponse( + signed(HttpRequest.builder() // + .method("GET") // + .endpoint("https://api.opscode.com/groups") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON).build()), // + HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/groups.json", MediaType.APPLICATION_JSON)) // + .build()); + + Set groups = api.listGroups(); + assertEquals(groups.size(), 5); + assertTrue(groups.contains("admins")); + } + + public void testGetGroupReturns2xx() { + EnterpriseChefApi api = requestSendsResponse( + signed(HttpRequest.builder() // + .method("GET") // + .endpoint("https://api.opscode.com/groups/admins") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON).build()), // + HttpResponse.builder().statusCode(200) + .payload(payloadFromResourceWithContentType("/group.json", MediaType.APPLICATION_JSON)) // + .build()); + + Group group = api.getGroup("admins"); + assertEquals(group.getName(), "admins"); + assertEquals(group.getGroupname(), "admins"); + } + + public void testGetGroupReturns404() { + EnterpriseChefApi api = requestSendsResponse(signed(HttpRequest.builder() // + .method("GET") // + .endpoint("https://api.opscode.com/groups/foo") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON) // + .build()), // + HttpResponse.builder().statusCode(404).build()); + + assertNull(api.getGroup("foo")); + } + + public void testCreateGroupReturns2xx() { + EnterpriseChefApi api = requestSendsResponse(signed(HttpRequest.builder() // + .method("POST") // + .endpoint("https://api.opscode.com/groups") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON) // + .payload(payloadFromStringWithContentType("{\"groupname\":\"foo\"}", MediaType.APPLICATION_JSON)) // + .build()), // + HttpResponse.builder().statusCode(201).build()); + + api.createGroup("foo"); + } + + public void testDeleteGroupReturns2xx() { + EnterpriseChefApi api = requestSendsResponse(signed(HttpRequest.builder() // + .method("DELETE") // + .endpoint("https://api.opscode.com/groups/foo") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON) // + .build()), // + HttpResponse.builder().statusCode(200).build()); + + api.deleteGroup("foo"); + } + + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testDeleteGroupFailsOn404() { + EnterpriseChefApi api = requestSendsResponse(signed(HttpRequest.builder() // + .method("DELETE") // + .endpoint("https://api.opscode.com/groups/foo") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON) // + .build()), // + HttpResponse.builder().statusCode(404).build()); + + api.deleteGroup("foo"); + } + + public void testUpdateGroupReturns2xx() { + EnterpriseChefApi api = requestSendsResponse(signed(HttpRequest.builder() // + .method("PUT") // + .endpoint("https://api.opscode.com/groups/admins") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON) // + .payload(payloadFromResourceWithContentType("/group-update.json", MediaType.APPLICATION_JSON)) // + .build()), // + HttpResponse.builder().statusCode(200).build()); + + Group group = new Group("admins"); + group.setClients(ImmutableSet.of("abiquo")); + group.setGroups(ImmutableSet.of("admins")); + group.setUsers(ImmutableSet.of("nacx")); + + api.updateGroup(group); + } + + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testUpdateGroupFailsOn404() { + EnterpriseChefApi api = requestSendsResponse(signed(HttpRequest.builder() // + .method("PUT") // + .endpoint("https://api.opscode.com/groups/admins") // + .addHeader("X-Chef-Version", ChefApi.VERSION) // + .addHeader("Accept", MediaType.APPLICATION_JSON) // + .payload(payloadFromResourceWithContentType("/group-update.json", MediaType.APPLICATION_JSON)) // + .build()), // + HttpResponse.builder().statusCode(404).build()); + + Group group = new Group("admins"); + group.setClients(ImmutableSet.of("abiquo")); + group.setGroups(ImmutableSet.of("admins")); + group.setUsers(ImmutableSet.of("nacx")); + + api.updateGroup(group); + } + + @Override + protected Module createModule() { + return new TestEnterpriseChefRestClientModule(); + } + + @ConfiguresRestClient + static class TestEnterpriseChefRestClientModule extends EnterpriseChefHttpApiModule { + @Override + protected String provideTimeStamp(@TimeStamp Supplier cache) { + return "timestamp"; + } + } + + @Override + protected ProviderMetadata createProviderMetadata() { + return new EnterpriseChefProviderMetadata(); + } + +} diff --git a/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefApiLiveTest.java b/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefApiLiveTest.java new file mode 100644 index 0000000..576351a --- /dev/null +++ b/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefApiLiveTest.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertNotNull; +import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; + +import java.util.Set; +import java.util.UUID; + +import org.jclouds.chef.internal.BaseChefApiLiveTest; +import org.jclouds.enterprisechef.EnterpriseChefApi; +import org.jclouds.enterprisechef.domain.Group; +import org.jclouds.enterprisechef.domain.User; +import org.jclouds.rest.ResourceNotFoundException; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +/** + * Tests behavior of the EnterpriseChefApi. + * + * @author Adrian Cole + */ +@Test(groups = "live", singleThreaded = true, testName = "EnterpriseChefApiLiveTest") +public class EnterpriseChefApiLiveTest extends BaseChefApiLiveTest { + + private static final String GROUP_NAME = System.getProperty("user.name") + "-jcloudstest"; + private static final String ORG_NAME = System.getProperty("test.enterprisechef.org"); + + public EnterpriseChefApiLiveTest() { + provider = "enterprisechef"; + } + + @Override + @Test + public void testSearchClientsWithOptions() throws Exception { + // This test will fail because Enterprise Chef does not index client name. + // Once it is fixes, the test should succeed. + // See: http://tickets.opscode.com/browse/CHEF-2477 + super.testSearchClientsWithOptions(); + } + + public void testGetUser() { + User user = api.getUser(identity); + assertEquals(user.getUsername(), identity); + assertNotNull(user.getPublicKey()); + } + + public void testGetUnexistingUser() { + User user = api.getUser(UUID.randomUUID().toString()); + assertNull(user); + } + + public void testListGroups() { + Set groups = api.listGroups(); + assertNotNull(groups); + assertFalse(groups.isEmpty()); + } + + public void testGetUnexistingGroup() { + Group group = api.getGroup(UUID.randomUUID().toString()); + assertNull(group); + } + + public void testCreateGroup() { + api.createGroup(GROUP_NAME); + Group group = api.getGroup(GROUP_NAME); + assertNotNull(group); + assertEquals(group.getGroupname(), GROUP_NAME); + } + + @Test(dependsOnMethods = "testCreateGroup") + public void testUpdateGroup() { + Group group = api.getGroup(GROUP_NAME); + group.setUsers(ImmutableSet.of(identity)); + group.setClients(ImmutableSet.of(ORG_NAME + "-validator")); + + api.updateGroup(group); + group = api.getGroup(GROUP_NAME); + + assertNotNull(group); + assertTrue(group.getUsers().contains(identity)); + assertTrue(group.getClients().contains(ORG_NAME + "-validator")); + } + + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testUpdateUnexistingGroup() { + api.updateGroup(new Group(UUID.randomUUID().toString())); + } + + @Test(dependsOnMethods = "testUpdateGroup") + public void testDeleteGroup() { + api.deleteGroup(GROUP_NAME); + Group group = api.getGroup(GROUP_NAME); + assertNull(group); + } + + @Test(expectedExceptions = ResourceNotFoundException.class) + public void testDeleteUnexistingGroup() { + api.deleteGroup(UUID.randomUUID().toString()); + } + +} diff --git a/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefProviderMetadataTest.java b/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefProviderMetadataTest.java new file mode 100644 index 0000000..0b7ddc3 --- /dev/null +++ b/enterprise/src/test/java/org/jclouds/enterprisechef/EnterpriseChefProviderMetadataTest.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef; + +import org.jclouds.enterprisechef.EnterpriseChefApiMetadata; +import org.jclouds.enterprisechef.EnterpriseChefProviderMetadata; +import org.jclouds.providers.internal.BaseProviderMetadataTest; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link EnterpriseChefProviderMetadata} class. + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "EnterpriseChefProviderTest") +public class EnterpriseChefProviderMetadataTest extends BaseProviderMetadataTest { + + public EnterpriseChefProviderMetadataTest() { + super(new EnterpriseChefProviderMetadata(), new EnterpriseChefApiMetadata()); + } +} diff --git a/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayloadTest.java b/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayloadTest.java new file mode 100644 index 0000000..4cb399f --- /dev/null +++ b/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupNameToJsonPayloadTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.binders; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.enterprisechef.binders.BindGroupNameToJsonPayload; +import org.jclouds.http.HttpRequest; +import org.jclouds.util.Strings2; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link BindGroupNameToJsonPayload} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindGroupNameToJsonPayloadTest") +public class BindGroupNameToJsonPayloadTest { + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() { + BindGroupNameToJsonPayload binder = new BindGroupNameToJsonPayload(); + HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + public void testBindString() throws IOException { + BindGroupNameToJsonPayload binder = new BindGroupNameToJsonPayload(); + HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); + HttpRequest newRequest = binder.bindToRequest(request, "foo"); + + String payload = Strings2.toStringAndClose(newRequest.getPayload().getInput()); + assertEquals(payload, "{\"groupname\":\"foo\"}"); + } +} diff --git a/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupToUpdateRequestJsonPayloadTest.java b/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupToUpdateRequestJsonPayloadTest.java new file mode 100644 index 0000000..90e84dd --- /dev/null +++ b/enterprise/src/test/java/org/jclouds/enterprisechef/binders/BindGroupToUpdateRequestJsonPayloadTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.binders; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.chef.ChefApi; +import org.jclouds.chef.config.ChefParserModule; +import org.jclouds.enterprisechef.binders.BindGroupToUpdateRequestJsonPayload; +import org.jclouds.enterprisechef.domain.Group; +import org.jclouds.http.HttpRequest; +import org.jclouds.json.config.GsonModule; +import org.jclouds.rest.annotations.ApiVersion; +import org.jclouds.util.Strings2; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Unit tests for the {@link BindGroupToUpdateRequestJsonPayload} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "BindGroupToUpdateRequestJsonPayloadTest") +public class BindGroupToUpdateRequestJsonPayloadTest { + + private Injector injector = Guice.createInjector(new AbstractModule() { + @Override + protected void configure() { + bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApi.VERSION); + } + }, new ChefParserModule(), new GsonModule()); + + private BindGroupToUpdateRequestJsonPayload binder = injector.getInstance(BindGroupToUpdateRequestJsonPayload.class); + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() { + HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, null); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testInvalidTypeInput() { + HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); + binder.bindToRequest(request, new Object()); + } + + public void testBindOnlyName() throws IOException { + HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); + HttpRequest newRequest = binder.bindToRequest(request, new Group("foo")); + + String payload = Strings2.toStringAndClose(newRequest.getPayload().getInput()); + assertEquals(payload, "{\"groupname\":\"foo\",\"actors\":{\"clients\":[],\"groups\":[],\"users\":[]}}"); + } + + public void testBindNameAndLists() throws IOException { + Group group = new Group("foo"); + group.setClients(ImmutableSet.of("nacx-validator")); + group.setGroups(ImmutableSet.of("admins")); + group.setUsers(ImmutableSet.of("nacx")); + + HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); + HttpRequest newRequest = binder.bindToRequest(request, group); + + String payload = Strings2.toStringAndClose(newRequest.getPayload().getInput()); + assertEquals(payload, + "{\"groupname\":\"foo\",\"actors\":{\"clients\":[\"nacx-validator\"],\"groups\":[\"admins\"],\"users\":[\"nacx\"]}}"); + } +} diff --git a/enterprise/src/test/java/org/jclouds/enterprisechef/binders/GroupNameTest.java b/enterprise/src/test/java/org/jclouds/enterprisechef/binders/GroupNameTest.java new file mode 100644 index 0000000..b93c68a --- /dev/null +++ b/enterprise/src/test/java/org/jclouds/enterprisechef/binders/GroupNameTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF 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.enterprisechef.binders; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; + +import org.jclouds.enterprisechef.binders.GroupName; +import org.jclouds.enterprisechef.domain.Group; +import org.testng.annotations.Test; + +/** + * Unit tests for the {@link GroupName} class. + * + * @author Ignasi Barrera + */ +@Test(groups = "unit", testName = "GroupNameTest") +public class GroupNameTest { + + @Test(expectedExceptions = NullPointerException.class) + public void testInvalidNullInput() { + new GroupName().apply(null); + } + + public void testApplyGroupName() throws IOException { + assertEquals(new GroupName().apply(new Group("foo")), "foo"); + } +} diff --git a/enterprise/src/test/resources/group-update.json b/enterprise/src/test/resources/group-update.json new file mode 100644 index 0000000..cc7bf6a --- /dev/null +++ b/enterprise/src/test/resources/group-update.json @@ -0,0 +1 @@ +{"groupname":"admins","actors":{"clients":["abiquo"],"groups":["admins"],"users":["nacx"]}} \ No newline at end of file diff --git a/enterprise/src/test/resources/group.json b/enterprise/src/test/resources/group.json new file mode 100644 index 0000000..df3eb28 --- /dev/null +++ b/enterprise/src/test/resources/group.json @@ -0,0 +1,14 @@ +{ + "actors" : [ "abiquo", + "nacx", + "pivotal" + ], + "clients" : [ "abiquo" ], + "groupname" : "admins", + "groups" : [ "billing-admins" ], + "name" : "admins", + "orgname" : "nacx", + "users" : [ "nacx", + "pivotal" + ] +} diff --git a/enterprise/src/test/resources/groups.json b/enterprise/src/test/resources/groups.json new file mode 100644 index 0000000..30c8aa6 --- /dev/null +++ b/enterprise/src/test/resources/groups.json @@ -0,0 +1,7 @@ +{ + "965f2db33d302ed4625d172e0bc36920" : "https://api.opscode.com/organizations/nacx/groups/965f2db33d302ed4625d172e0bc36920", + "admins" : "https://api.opscode.com/organizations/nacx/groups/admins", + "billing-admins" : "https://api.opscode.com/organizations/nacx/groups/billing-admins", + "clients" : "https://api.opscode.com/organizations/nacx/groups/clients", + "users" : "https://api.opscode.com/organizations/nacx/groups/users" +} \ No newline at end of file diff --git a/enterprise/src/test/resources/user.json b/enterprise/src/test/resources/user.json new file mode 100644 index 0000000..ee35a95 --- /dev/null +++ b/enterprise/src/test/resources/user.json @@ -0,0 +1,9 @@ +{ + "display_name" : "Ignasi Barrera", + "email" : "myemail@enterprisechef.org", + "first_name" : "Ignasi", + "last_name" : "Barrera", + "middle_name" : "", + "public_key" : "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAp0ytgXbPzqJwOOixn7bTa6VAiNvVIOn+yDPoWbyEfc0li93BHIwv\n01KW/mn55IXnSbMw86rdxisvwPHFfb7URuKuTzME6yrphBiancmNjushZZeBWb8j\nqJhnFIKbaaOqew0LZSyG9ycYODB/HDK/pWTV4Bd1OtLHBNFrnIf+r3HOjJsa4rmK\nWXgSQIQO7be/iRHysApV9tfVH8lo1ETnA08JTrQwDgo9St9YNbydb5V0CiLiQsOa\nIbY09buUK9lXthh/rrRVbGbSwQM6OYdXIEZTN2BFvQ0p5pH8AiTwFqb0ICO46a0S\njfGcXNjC/QfHljAPY3T5xyIOODM8afHCnwIDAQAB\n-----END RSA PUBLIC KEY-----\n", + "username" : "nacx" +} \ No newline at end of file diff --git a/labs/hostedchef/pom.xml b/labs/hostedchef/pom.xml deleted file mode 100644 index 0bb6df4..0000000 --- a/labs/hostedchef/pom.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - - 4.0.0 - - org.apache.jclouds.chef - chef-project - 1.7.0-SNAPSHOT - ../../project/pom.xml - - org.apache.jclouds.labs - hostedchef - Apache jclouds Chef :: Hosted Chef - jclouds components to access Hosted Chef - - - YOUR_ORG - https://api.opscode.com/organizations/${test.hostedchef.org} - - - YOUR_USER - ${user.home}/.chef/${test.hostedchef.org}/${test.hostedchef.identity}.pem - org.jclouds.hostedchef*;version="${project.version}" - org.jclouds*;version="${jclouds.version}",* - - - - - org.apache.jclouds.api - chef - ${project.version} - - - org.apache.jclouds.api - chef - ${project.version} - test-jar - test - - - org.apache.jclouds - jclouds-core - ${jclouds.version} - test-jar - test - - - org.apache.jclouds.driver - jclouds-slf4j - ${jclouds.version} - test - - - ch.qos.logback - logback-classic - 1.0.9 - test - - - - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.hostedchef.org} - ${test.hostedchef.endpoint} - ${test.hostedchef.api-version} - ${test.hostedchef.build-version} - ${test.hostedchef.identity} - ${test.hostedchef.credential} - - - - - - - - - - diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefApi.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefApi.java deleted file mode 100644 index 0f06750..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefApi.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef; - -import java.util.Set; - -import javax.inject.Named; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.core.MediaType; - -import org.jclouds.Constants; -import org.jclouds.Fallbacks.FalseOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.filters.SignedHeaderAuth; -import org.jclouds.chef.functions.ParseKeySetFromJson; -import org.jclouds.hostedchef.binders.BindGroupNameToJsonPayload; -import org.jclouds.hostedchef.binders.BindGroupToUpdateRequestJsonPayload; -import org.jclouds.hostedchef.binders.GroupName; -import org.jclouds.hostedchef.domain.Group; -import org.jclouds.hostedchef.domain.User; -import org.jclouds.rest.annotations.BinderParam; -import org.jclouds.rest.annotations.Fallback; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.ParamParser; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; - -/** - * Provides synchronous access to the Hosted Chef Api. - * - * @author Ignasi Barrera - */ -@RequestFilters(SignedHeaderAuth.class) -@Consumes(MediaType.APPLICATION_JSON) -@Headers(keys = "X-Chef-Version", values = "{" + Constants.PROPERTY_API_VERSION + "}") -public interface HostedChefApi extends ChefApi { - - /** - * Check if there exists a node with the given name. - * - * @return true if the specified node name exists. - */ - @Override - // Use get instead of HEAD - @Named("node:exists") - @GET - @Path("/nodes/{nodename}") - @Fallback(FalseOnNotFoundOr404.class) - boolean nodeExists(@PathParam("nodename") String nodename); - - /** - * Retrieves an existing user. - * - * @param name - * The name of the user to get. - * @return The details of the user or null if not found. - */ - @Named("user:get") - @GET - @Path("/users/{name}") - @Fallback(NullOnNotFoundOr404.class) - User getUser(@PathParam("name") String name); - - /** - * List all existing groups. - * - * @return The list of groups. - */ - @Named("group:list") - @GET - @Path("/groups") - @ResponseParser(ParseKeySetFromJson.class) - Set listGroups(); - - /** - * Retrieves an existing group. - * - * @param name - * The name of the group to get. - * @return The details of the group or null if not found. - */ - @Named("group:get") - @GET - @Path("/groups/{name}") - @Fallback(NullOnNotFoundOr404.class) - Group getGroup(@PathParam("name") String name); - - /** - * Creates a new group. - * - * @param name - * The name of the group to create. - */ - @Named("group:create") - @POST - @Path("/groups") - void createGroup(@BinderParam(BindGroupNameToJsonPayload.class) String name); - - /** - * Updates a group. - *

- * This method can be used to add actors (clients, groups) to the group. - * - * @param group - * The group with the updated information. - */ - @Named("group:update") - @PUT - @Path("/groups/{name}") - void updateGroup( - @PathParam("name") @ParamParser(GroupName.class) @BinderParam(BindGroupToUpdateRequestJsonPayload.class) Group group); - - /** - * Deletes a group. - * - * @param name - * The name of the group to delete. - */ - @Named("group:delete") - @DELETE - @Path("/groups/{name}") - void deleteGroup(@PathParam("name") String name); - -} diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefApiMetadata.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefApiMetadata.java deleted file mode 100644 index 50f0b1a..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefApiMetadata.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.apis.ApiMetadata; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.ChefContext; -import org.jclouds.chef.config.ChefBootstrapModule; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.hostedchef.config.HostedChefHttpApiModule; -import org.jclouds.ohai.config.JMXOhaiModule; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Implementation of {@link ApiMetadata} for Hosted Chef api. - * - * @author Adrian Cole - */ -public class HostedChefApiMetadata extends BaseHttpApiMetadata { - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public HostedChefApiMetadata() { - this(new Builder()); - } - - protected HostedChefApiMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - return ChefApiMetadata.defaultProperties(); - } - - public static class Builder extends BaseHttpApiMetadata.Builder { - - protected Builder() { - id("hostedchef") - .name("Hosted Chef Api") - .identityName("User") - .credentialName("Certificate") - .version(ChefApi.VERSION) - .documentation(URI.create("http://www.opscode.com/support")) - .defaultEndpoint("https://api.opscode.com") - .view(ChefContext.class) - .defaultProperties(HostedChefApiMetadata.defaultProperties()) - .defaultModules( - ImmutableSet.> of(HostedChefHttpApiModule.class, - ChefParserModule.class, ChefBootstrapModule.class, JMXOhaiModule.class)); - } - - @Override - public HostedChefApiMetadata build() { - return new HostedChefApiMetadata(this); - } - - @Override - protected Builder self() { - return this; - } - } -} diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefProviderMetadata.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefProviderMetadata.java deleted file mode 100644 index 6c62407..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/HostedChefProviderMetadata.java +++ /dev/null @@ -1,78 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.providers.ProviderMetadata; -import org.jclouds.providers.internal.BaseProviderMetadata; - -/** - * Implementation of @ link org.jclouds.types.ProviderMetadata} for Hosted Chef - * - * @author Adrian Cole - */ -public class HostedChefProviderMetadata extends BaseProviderMetadata { - - public static Builder builder() { - return new Builder(); - } - - @Override - public Builder toBuilder() { - return builder().fromProviderMetadata(this); - } - - public HostedChefProviderMetadata() { - super(builder()); - } - - public HostedChefProviderMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - Properties properties = new Properties(); - return properties; - } - - public static class Builder extends BaseProviderMetadata.Builder { - - protected Builder() { - id("hostedchef") // - .name("OpsCode Hosted Chef") // - .endpoint("https://api.opscode.com") // - .homepage(URI.create("https://manage.opscode.com")) // - .console(URI.create("https://manage.opscode.com")) // - .apiMetadata(new HostedChefApiMetadata()) // - .defaultProperties(HostedChefProviderMetadata.defaultProperties()); - } - - @Override - public HostedChefProviderMetadata build() { - return new HostedChefProviderMetadata(this); - } - - @Override - public Builder fromProviderMetadata(ProviderMetadata in) { - super.fromProviderMetadata(in); - return this; - } - - } -} diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/BindGroupNameToJsonPayload.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/BindGroupNameToJsonPayload.java deleted file mode 100644 index d8c25e8..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/BindGroupNameToJsonPayload.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.binders; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.http.HttpRequest; -import org.jclouds.rest.binders.BindToStringPayload; - -/** - * Binds the name of a group to the json payload. - * - * @author Ignasi Barrera - */ -@Singleton -public class BindGroupNameToJsonPayload extends BindToStringPayload { - - @Override - public R bindToRequest(R request, Object payload) { - super.bindToRequest(request, String.format("{\"groupname\":\"%s\"}", checkNotNull(payload, "payload"))); - request.getPayload().getContentMetadata().setContentType(MediaType.APPLICATION_JSON); - return request; - } - -} diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/BindGroupToUpdateRequestJsonPayload.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/BindGroupToUpdateRequestJsonPayload.java deleted file mode 100644 index 8d832be..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/BindGroupToUpdateRequestJsonPayload.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.binders; - -import static com.google.common.base.Preconditions.checkArgument; -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Set; - -import javax.inject.Inject; -import javax.inject.Singleton; - -import org.jclouds.hostedchef.domain.Group; -import org.jclouds.http.HttpRequest; -import org.jclouds.json.Json; -import org.jclouds.rest.binders.BindToJsonPayload; - -/** - * Binds a group to the payload expected for the Put method in the Hosted Chef - * Api. - * - * @author Ignasi Barrera - */ -@Singleton -public class BindGroupToUpdateRequestJsonPayload extends BindToJsonPayload { - - @Inject - public BindGroupToUpdateRequestJsonPayload(Json jsonBinder) { - super(jsonBinder); - } - - @Override - public R bindToRequest(R request, Object payload) { - checkArgument(checkNotNull(payload, "payload") instanceof Group, "this binder is only valid for Group objects"); - GroupUpdateRequest updateGroup = new GroupUpdateRequest((Group) payload); - return super.bindToRequest(request, updateGroup); - } - - @SuppressWarnings("unused") - private static class GroupUpdateRequest { - private String name; - private String groupname; - private String orgname; - private ActorConfiguration actors; - - public GroupUpdateRequest(Group group) { - this.name = group.getName(); - this.groupname = group.getGroupname(); - this.orgname = group.getOrgname(); - this.actors = new ActorConfiguration(group); - } - } - - @SuppressWarnings("unused") - private static class ActorConfiguration { - private Set clients; - private Set groups; - private Set users; - - public ActorConfiguration(Group group) { - this.clients = group.getClients(); - this.groups = group.getGroups(); - this.users = group.getUsers(); - } - } - -} diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/GroupName.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/GroupName.java deleted file mode 100644 index a62ab86..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/binders/GroupName.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.binders; - -import static com.google.common.base.Preconditions.checkNotNull; - -import javax.inject.Singleton; - -import org.jclouds.hostedchef.domain.Group; - -import com.google.common.base.Function; - -/** - * Gets the name of a group. - * - * @author Ignasi Barrera - */ -@Singleton -public class GroupName implements Function { - - @Override - public String apply(Object from) { - return ((Group) checkNotNull(from, "from")).getGroupname(); - } - -} diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/config/HostedChefHttpApiModule.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/config/HostedChefHttpApiModule.java deleted file mode 100644 index c9c9503..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/config/HostedChefHttpApiModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.config; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.BaseChefHttpApiModule; -import org.jclouds.hostedchef.HostedChefApi; -import org.jclouds.rest.ConfiguresHttpApi; - -/** - * Configures the Hosted Chef connection. - * - * @author Ignasi Barrera - */ -@ConfiguresHttpApi -public class HostedChefHttpApiModule extends BaseChefHttpApiModule { - - @Override - protected void configure() { - super.configure(); - bind(ChefApi.class).to(HostedChefApi.class); - } - -} diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/domain/Group.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/domain/Group.java deleted file mode 100644 index 18f9983..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/domain/Group.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.domain; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.Set; - -import com.google.common.collect.Sets; - -/** - * Group object. - * - * @author Ignasi Barrera - */ -public class Group { - private String name; - private String groupname; - private String orgname; - private Set actors = Sets.newHashSet(); - private Set clients = Sets.newHashSet(); - private Set groups = Sets.newHashSet(); - private Set users = Sets.newHashSet(); - - // When creating groups, only the group name property is considered - public Group(String groupname) { - this.groupname = checkNotNull(groupname, "groupname"); - } - - // Only for deserialization - Group() { - - } - - public String getName() { - return name; - } - - public String getGroupname() { - return groupname; - } - - public String getOrgname() { - return orgname; - } - - public Set getActors() { - return actors; - } - - public Set getClients() { - return clients; - } - - public Set getGroups() { - return groups; - } - - public Set getUsers() { - return users; - } - - public void setClients(Set clients) { - this.clients = clients; - } - - public void setGroups(Set groups) { - this.groups = groups; - } - - public void setUsers(Set users) { - this.users = users; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (groupname == null ? 0 : groupname.hashCode()); - result = prime * result + (name == null ? 0 : name.hashCode()); - result = prime * result + (orgname == null ? 0 : orgname.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - Group other = (Group) obj; - if (groupname == null) { - if (other.groupname != null) { - return false; - } - } else if (!groupname.equals(other.groupname)) { - return false; - } - if (name == null) { - if (other.name != null) { - return false; - } - } else if (!name.equals(other.name)) { - return false; - } - if (orgname == null) { - if (other.orgname != null) { - return false; - } - } else if (!orgname.equals(other.orgname)) { - return false; - } - return true; - } - - @Override - public String toString() { - return "Group [name=" + name + ", groupname=" + groupname + ", orgname=" + orgname + ", actors=" + actors - + ", clients=" + clients + ", groups=" + groups + ", users=" + users + "]"; - } - -} diff --git a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/domain/User.java b/labs/hostedchef/src/main/java/org/jclouds/hostedchef/domain/User.java deleted file mode 100644 index 6e87e6d..0000000 --- a/labs/hostedchef/src/main/java/org/jclouds/hostedchef/domain/User.java +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.domain; - -import java.security.PublicKey; - -import com.google.gson.annotations.SerializedName; - -/** - * User object. - * - * @author Ignasi Barrera - */ -public class User { - private String username; - @SerializedName("first_name") - private String firstName; - @SerializedName("middle_name") - private String middleName; - @SerializedName("last_name") - private String lastName; - @SerializedName("display_name") - private String displayName; - private String email; - @SerializedName("public_key") - private PublicKey publicKey; - - // In Hosted Chef users cannot be manually created. - - // Only for deserialization - User() { - - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (displayName == null ? 0 : displayName.hashCode()); - result = prime * result + (email == null ? 0 : email.hashCode()); - result = prime * result + (firstName == null ? 0 : firstName.hashCode()); - result = prime * result + (lastName == null ? 0 : lastName.hashCode()); - result = prime * result + (middleName == null ? 0 : middleName.hashCode()); - result = prime * result + (publicKey == null ? 0 : publicKey.hashCode()); - result = prime * result + (username == null ? 0 : username.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - User other = (User) obj; - if (displayName == null) { - if (other.displayName != null) { - return false; - } - } else if (!displayName.equals(other.displayName)) { - return false; - } - if (email == null) { - if (other.email != null) { - return false; - } - } else if (!email.equals(other.email)) { - return false; - } - if (firstName == null) { - if (other.firstName != null) { - return false; - } - } else if (!firstName.equals(other.firstName)) { - return false; - } - if (lastName == null) { - if (other.lastName != null) { - return false; - } - } else if (!lastName.equals(other.lastName)) { - return false; - } - if (middleName == null) { - if (other.middleName != null) { - return false; - } - } else if (!middleName.equals(other.middleName)) { - return false; - } - if (publicKey == null) { - if (other.publicKey != null) { - return false; - } - } else if (!publicKey.equals(other.publicKey)) { - return false; - } - if (username == null) { - if (other.username != null) { - return false; - } - } else if (!username.equals(other.username)) { - return false; - } - return true; - } - - public String getUsername() { - return username; - } - - public String getFirstName() { - return firstName; - } - - public String getMiddleName() { - return middleName; - } - - public String getLastName() { - return lastName; - } - - public String getDisplayName() { - return displayName; - } - - public String getEmail() { - return email; - } - - public PublicKey getPublicKey() { - return publicKey; - } - - @Override - public String toString() { - return "User [username=" + username + ", firstName=" + firstName + ", middleName=" + middleName + ", lastName=" - + lastName + ", displayName=" + displayName + ", email=" + email + ", publicKey=" + publicKey + "]"; - } - -} diff --git a/labs/hostedchef/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata b/labs/hostedchef/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata deleted file mode 100644 index 6d23c9a..0000000 --- a/labs/hostedchef/src/main/resources/META-INF/services/org.jclouds.providers.ProviderMetadata +++ /dev/null @@ -1 +0,0 @@ -org.jclouds.hostedchef.HostedChefProviderMetadata diff --git a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java deleted file mode 100644 index ccdb53d..0000000 --- a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiContextTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef; - -import static com.google.common.base.Throwables.propagate; -import static org.testng.Assert.assertNotNull; - -import java.io.IOException; - -import org.jclouds.ContextBuilder; -import org.jclouds.chef.ChefContext; -import org.jclouds.chef.filters.SignedHeaderAuthTest; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.internal.BaseRestApiTest.MockModule; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Tests the access to the underlying API from the context. - * - * @author Ignasi Barrera - */ -@Test(groups = "unit", testName = "HostedChefContextApiTest") -public class HostedChefApiContextTest { - - private ChefContext context; - - @BeforeClass - public void setup() { - context = ContextBuilder.newBuilder(new HostedChefProviderMetadata()) - .credentials(SignedHeaderAuthTest.USER_ID, SignedHeaderAuthTest.PRIVATE_KEY) - .modules(ImmutableSet. of(new MockModule(), new NullLoggingModule())) // - .buildView(ChefContext.class); - } - - public void testCanAccessHostedChefApi() { - HostedChefApi api = context.unwrapApi(HostedChefApi.class); - assertNotNull(api); - } - - @AfterClass - public void tearDown() { - try { - context.close(); - } catch (IOException e) { - throw propagate(e); - } - } -} diff --git a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiExpectTest.java b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiExpectTest.java deleted file mode 100644 index d1d68ec..0000000 --- a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiExpectTest.java +++ /dev/null @@ -1,220 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import java.util.Set; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.chef.BaseChefApiExpectTest; -import org.jclouds.chef.ChefApi; -import org.jclouds.date.TimeStamp; -import org.jclouds.hostedchef.config.HostedChefHttpApiModule; -import org.jclouds.hostedchef.domain.Group; -import org.jclouds.hostedchef.domain.User; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.providers.ProviderMetadata; -import org.jclouds.rest.ConfiguresRestClient; -import org.jclouds.rest.ResourceNotFoundException; -import org.testng.annotations.Test; - -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Expect tests for the {@link HostedChefApi} class. - * - * @author Ignasi Barrera - */ -@Test(groups = "unit", testName = "HostedChefApiExpectTest") -public class HostedChefApiExpectTest extends BaseChefApiExpectTest { - public HostedChefApiExpectTest() { - provider = "hostedchef"; - } - - public void testGetUserReturns2xx() { - HostedChefApi api = requestSendsResponse( - signed(HttpRequest.builder() // - .method("GET") // - .endpoint("https://api.opscode.com/users/nacx") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON).build()), // - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/user.json", MediaType.APPLICATION_JSON)) // - .build()); - - User user = api.getUser("nacx"); - assertEquals(user.getUsername(), "nacx"); - assertEquals(user.getDisplayName(), "Ignasi Barrera"); - } - - public void testGetUserReturns404() { - HostedChefApi api = requestSendsResponse(signed(HttpRequest.builder() // - .method("GET") // - .endpoint("https://api.opscode.com/users/foo") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON) // - .build()), // - HttpResponse.builder().statusCode(404).build()); - - assertNull(api.getUser("foo")); - } - - public void testListGroups() { - HostedChefApi api = requestSendsResponse( - signed(HttpRequest.builder() // - .method("GET") // - .endpoint("https://api.opscode.com/groups") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON).build()), // - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/groups.json", MediaType.APPLICATION_JSON)) // - .build()); - - Set groups = api.listGroups(); - assertEquals(groups.size(), 5); - assertTrue(groups.contains("admins")); - } - - public void testGetGroupReturns2xx() { - HostedChefApi api = requestSendsResponse( - signed(HttpRequest.builder() // - .method("GET") // - .endpoint("https://api.opscode.com/groups/admins") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON).build()), // - HttpResponse.builder().statusCode(200) - .payload(payloadFromResourceWithContentType("/group.json", MediaType.APPLICATION_JSON)) // - .build()); - - Group group = api.getGroup("admins"); - assertEquals(group.getName(), "admins"); - assertEquals(group.getGroupname(), "admins"); - } - - public void testGetGroupReturns404() { - HostedChefApi api = requestSendsResponse(signed(HttpRequest.builder() // - .method("GET") // - .endpoint("https://api.opscode.com/groups/foo") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON) // - .build()), // - HttpResponse.builder().statusCode(404).build()); - - assertNull(api.getGroup("foo")); - } - - public void testCreateGroupReturns2xx() { - HostedChefApi api = requestSendsResponse(signed(HttpRequest.builder() // - .method("POST") // - .endpoint("https://api.opscode.com/groups") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON) // - .payload(payloadFromStringWithContentType("{\"groupname\":\"foo\"}", MediaType.APPLICATION_JSON)) // - .build()), // - HttpResponse.builder().statusCode(201).build()); - - api.createGroup("foo"); - } - - public void testDeleteGroupReturns2xx() { - HostedChefApi api = requestSendsResponse(signed(HttpRequest.builder() // - .method("DELETE") // - .endpoint("https://api.opscode.com/groups/foo") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON) // - .build()), // - HttpResponse.builder().statusCode(200).build()); - - api.deleteGroup("foo"); - } - - @Test(expectedExceptions = ResourceNotFoundException.class) - public void testDeleteGroupFailsOn404() { - HostedChefApi api = requestSendsResponse(signed(HttpRequest.builder() // - .method("DELETE") // - .endpoint("https://api.opscode.com/groups/foo") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON) // - .build()), // - HttpResponse.builder().statusCode(404).build()); - - api.deleteGroup("foo"); - } - - public void testUpdateGroupReturns2xx() { - HostedChefApi api = requestSendsResponse(signed(HttpRequest.builder() // - .method("PUT") // - .endpoint("https://api.opscode.com/groups/admins") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON) // - .payload(payloadFromResourceWithContentType("/group-update.json", MediaType.APPLICATION_JSON)) // - .build()), // - HttpResponse.builder().statusCode(200).build()); - - Group group = new Group("admins"); - group.setClients(ImmutableSet.of("abiquo")); - group.setGroups(ImmutableSet.of("admins")); - group.setUsers(ImmutableSet.of("nacx")); - - api.updateGroup(group); - } - - @Test(expectedExceptions = ResourceNotFoundException.class) - public void testUpdateGroupFailsOn404() { - HostedChefApi api = requestSendsResponse(signed(HttpRequest.builder() // - .method("PUT") // - .endpoint("https://api.opscode.com/groups/admins") // - .addHeader("X-Chef-Version", ChefApi.VERSION) // - .addHeader("Accept", MediaType.APPLICATION_JSON) // - .payload(payloadFromResourceWithContentType("/group-update.json", MediaType.APPLICATION_JSON)) // - .build()), // - HttpResponse.builder().statusCode(404).build()); - - Group group = new Group("admins"); - group.setClients(ImmutableSet.of("abiquo")); - group.setGroups(ImmutableSet.of("admins")); - group.setUsers(ImmutableSet.of("nacx")); - - api.updateGroup(group); - } - - @Override - protected Module createModule() { - return new TestHostedChefRestClientModule(); - } - - @ConfiguresRestClient - static class TestHostedChefRestClientModule extends HostedChefHttpApiModule { - @Override - protected String provideTimeStamp(@TimeStamp Supplier cache) { - return "timestamp"; - } - } - - @Override - protected ProviderMetadata createProviderMetadata() { - return new HostedChefProviderMetadata(); - } - -} diff --git a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiLiveTest.java b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiLiveTest.java deleted file mode 100644 index d862943..0000000 --- a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefApiLiveTest.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import java.util.Set; -import java.util.UUID; - -import org.jclouds.chef.internal.BaseChefApiLiveTest; -import org.jclouds.hostedchef.domain.Group; -import org.jclouds.hostedchef.domain.User; -import org.jclouds.rest.ResourceNotFoundException; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; - -/** - * Tests behavior of the HostedChefApi. - * - * @author Adrian Cole - */ -@Test(groups = "live", singleThreaded = true, testName = "HostedChefApiLiveTest") -public class HostedChefApiLiveTest extends BaseChefApiLiveTest { - - private static final String GROUP_NAME = System.getProperty("user.name") + "-jcloudstest"; - private static final String ORG_NAME = System.getProperty("test.hostedchef.org"); - - public HostedChefApiLiveTest() { - provider = "hostedchef"; - } - - @Override - @Test - public void testSearchClientsWithOptions() throws Exception { - // This test will fail because Hosted Chef does not index client name. - // Once it is fixes, the test should suceed. - // See: http://tickets.opscode.com/browse/CHEF-2477 - super.testSearchClientsWithOptions(); - } - - public void testGetUser() { - User user = api.getUser(identity); - assertEquals(user.getUsername(), identity); - assertNotNull(user.getPublicKey()); - } - - public void testGetUnexistingUser() { - User user = api.getUser(UUID.randomUUID().toString()); - assertNull(user); - } - - public void testListGroups() { - Set groups = api.listGroups(); - assertNotNull(groups); - assertFalse(groups.isEmpty()); - } - - public void testGetUnexistingGroup() { - Group group = api.getGroup(UUID.randomUUID().toString()); - assertNull(group); - } - - public void testCreateGroup() { - api.createGroup(GROUP_NAME); - Group group = api.getGroup(GROUP_NAME); - assertNotNull(group); - assertEquals(group.getGroupname(), GROUP_NAME); - } - - @Test(dependsOnMethods = "testCreateGroup") - public void testUpdateGroup() { - Group group = api.getGroup(GROUP_NAME); - group.setUsers(ImmutableSet.of(identity)); - group.setClients(ImmutableSet.of(ORG_NAME + "-validator")); - - api.updateGroup(group); - group = api.getGroup(GROUP_NAME); - - assertNotNull(group); - assertTrue(group.getUsers().contains(identity)); - assertTrue(group.getClients().contains(ORG_NAME + "-validator")); - } - - @Test(expectedExceptions = ResourceNotFoundException.class) - public void testUpdateUnexistingGroup() { - api.updateGroup(new Group(UUID.randomUUID().toString())); - } - - @Test(dependsOnMethods = "testUpdateGroup") - public void testDeleteGroup() { - api.deleteGroup(GROUP_NAME); - Group group = api.getGroup(GROUP_NAME); - assertNull(group); - } - - @Test(expectedExceptions = ResourceNotFoundException.class) - public void testDeleteUnexistingGroup() { - api.deleteGroup(UUID.randomUUID().toString()); - } - -} diff --git a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefProviderMetadataTest.java b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefProviderMetadataTest.java deleted file mode 100644 index c3653ab..0000000 --- a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/HostedChefProviderMetadataTest.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef; - -import org.jclouds.providers.internal.BaseProviderMetadataTest; -import org.testng.annotations.Test; - -/** - * The HostedChefProviderTest tests the org.jclouds.providers.HostedChefProvider - * class. - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "HostedChefProviderTest") -public class HostedChefProviderMetadataTest extends BaseProviderMetadataTest { - - public HostedChefProviderMetadataTest() { - super(new HostedChefProviderMetadata(), new HostedChefApiMetadata()); - } -} diff --git a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/BindGroupNameToJsonPayloadTest.java b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/BindGroupNameToJsonPayloadTest.java deleted file mode 100644 index f810d75..0000000 --- a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/BindGroupNameToJsonPayloadTest.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.binders; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.http.HttpRequest; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link BindGroupNameToJsonPayload} class. - * - * @author Ignasi Barrera - */ -@Test(groups = "unit", testName = "BindGroupNameToJsonPayloadTest") -public class BindGroupNameToJsonPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindGroupNameToJsonPayload binder = new BindGroupNameToJsonPayload(); - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - public void testBindString() throws IOException { - BindGroupNameToJsonPayload binder = new BindGroupNameToJsonPayload(); - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); - HttpRequest newRequest = binder.bindToRequest(request, "foo"); - - String payload = Strings2.toStringAndClose(newRequest.getPayload().getInput()); - assertEquals(payload, "{\"groupname\":\"foo\"}"); - } -} diff --git a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/BindGroupToUpdateRequestJsonPayloadTest.java b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/BindGroupToUpdateRequestJsonPayloadTest.java deleted file mode 100644 index 90bd846..0000000 --- a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/BindGroupToUpdateRequestJsonPayloadTest.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.binders; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.hostedchef.domain.Group; -import org.jclouds.http.HttpRequest; -import org.jclouds.json.config.GsonModule; -import org.jclouds.rest.annotations.ApiVersion; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Unit tests for the {@link BindGroupToUpdateRequestJsonPayload} class. - * - * @author Ignasi Barrera - */ -@Test(groups = "unit", testName = "BindGroupToUpdateRequestJsonPayloadTest") -public class BindGroupToUpdateRequestJsonPayloadTest { - - private Injector injector = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - bind(String.class).annotatedWith(ApiVersion.class).toInstance(ChefApi.VERSION); - } - }, new ChefParserModule(), new GsonModule()); - - private BindGroupToUpdateRequestJsonPayload binder = injector.getInstance(BindGroupToUpdateRequestJsonPayload.class); - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() { - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, new Object()); - } - - public void testBindOnlyName() throws IOException { - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); - HttpRequest newRequest = binder.bindToRequest(request, new Group("foo")); - - String payload = Strings2.toStringAndClose(newRequest.getPayload().getInput()); - assertEquals(payload, "{\"groupname\":\"foo\",\"actors\":{\"clients\":[],\"groups\":[],\"users\":[]}}"); - } - - public void testBindNameAndLists() throws IOException { - Group group = new Group("foo"); - group.setClients(ImmutableSet.of("nacx-validator")); - group.setGroups(ImmutableSet.of("admins")); - group.setUsers(ImmutableSet.of("nacx")); - - HttpRequest request = HttpRequest.builder().method("POST").endpoint(URI.create("http://localhost")).build(); - HttpRequest newRequest = binder.bindToRequest(request, group); - - String payload = Strings2.toStringAndClose(newRequest.getPayload().getInput()); - assertEquals(payload, - "{\"groupname\":\"foo\",\"actors\":{\"clients\":[\"nacx-validator\"],\"groups\":[\"admins\"],\"users\":[\"nacx\"]}}"); - } -} diff --git a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/GroupNameTest.java b/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/GroupNameTest.java deleted file mode 100644 index d457e3f..0000000 --- a/labs/hostedchef/src/test/java/org/jclouds/hostedchef/binders/GroupNameTest.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.hostedchef.binders; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.hostedchef.domain.Group; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link GroupName} class. - * - * @author Ignasi Barrera - */ -@Test(groups = "unit", testName = "GroupNameTest") -public class GroupNameTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - new GroupName().apply(null); - } - - public void testApplyGroupName() throws IOException { - assertEquals(new GroupName().apply(new Group("foo")), "foo"); - } -} diff --git a/labs/hostedchef/src/test/resources/group-update.json b/labs/hostedchef/src/test/resources/group-update.json deleted file mode 100644 index cc7bf6a..0000000 --- a/labs/hostedchef/src/test/resources/group-update.json +++ /dev/null @@ -1 +0,0 @@ -{"groupname":"admins","actors":{"clients":["abiquo"],"groups":["admins"],"users":["nacx"]}} \ No newline at end of file diff --git a/labs/hostedchef/src/test/resources/group.json b/labs/hostedchef/src/test/resources/group.json deleted file mode 100644 index df3eb28..0000000 --- a/labs/hostedchef/src/test/resources/group.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "actors" : [ "abiquo", - "nacx", - "pivotal" - ], - "clients" : [ "abiquo" ], - "groupname" : "admins", - "groups" : [ "billing-admins" ], - "name" : "admins", - "orgname" : "nacx", - "users" : [ "nacx", - "pivotal" - ] -} diff --git a/labs/hostedchef/src/test/resources/groups.json b/labs/hostedchef/src/test/resources/groups.json deleted file mode 100644 index 30c8aa6..0000000 --- a/labs/hostedchef/src/test/resources/groups.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "965f2db33d302ed4625d172e0bc36920" : "https://api.opscode.com/organizations/nacx/groups/965f2db33d302ed4625d172e0bc36920", - "admins" : "https://api.opscode.com/organizations/nacx/groups/admins", - "billing-admins" : "https://api.opscode.com/organizations/nacx/groups/billing-admins", - "clients" : "https://api.opscode.com/organizations/nacx/groups/clients", - "users" : "https://api.opscode.com/organizations/nacx/groups/users" -} \ No newline at end of file diff --git a/labs/hostedchef/src/test/resources/user.json b/labs/hostedchef/src/test/resources/user.json deleted file mode 100644 index d8515b9..0000000 --- a/labs/hostedchef/src/test/resources/user.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "display_name" : "Ignasi Barrera", - "email" : "myemail@hostedchef.org", - "first_name" : "Ignasi", - "last_name" : "Barrera", - "middle_name" : "", - "public_key" : "-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAp0ytgXbPzqJwOOixn7bTa6VAiNvVIOn+yDPoWbyEfc0li93BHIwv\n01KW/mn55IXnSbMw86rdxisvwPHFfb7URuKuTzME6yrphBiancmNjushZZeBWb8j\nqJhnFIKbaaOqew0LZSyG9ycYODB/HDK/pWTV4Bd1OtLHBNFrnIf+r3HOjJsa4rmK\nWXgSQIQO7be/iRHysApV9tfVH8lo1ETnA08JTrQwDgo9St9YNbydb5V0CiLiQsOa\nIbY09buUK9lXthh/rrRVbGbSwQM6OYdXIEZTN2BFvQ0p5pH8AiTwFqb0ICO46a0S\njfGcXNjC/QfHljAPY3T5xyIOODM8afHCnwIDAQAB\n-----END RSA PUBLIC KEY-----\n", - "username" : "nacx" -} \ No newline at end of file diff --git a/labs/pom.xml b/labs/pom.xml deleted file mode 100644 index fa362a2..0000000 --- a/labs/pom.xml +++ /dev/null @@ -1,36 +0,0 @@ - - - - 4.0.0 - - org.apache.jclouds.chef - chef-project - 1.7.0-SNAPSHOT - ../project/pom.xml - - org.apache.jclouds.labs - chef-labs - pom - Apache jclouds Chef :: Labs - - privatechef - hostedchef - - diff --git a/labs/privatechef/pom.xml b/labs/privatechef/pom.xml deleted file mode 100644 index 0f3fc58..0000000 --- a/labs/privatechef/pom.xml +++ /dev/null @@ -1,122 +0,0 @@ - - - - 4.0.0 - - org.apache.jclouds.chef - chef-project - 1.7.0-SNAPSHOT - ../../project/pom.xml - - org.apache.jclouds.labs - privatechef - Apache jclouds Chef :: Private Chef - jclouds components to access Private Chef - - - YOUR_ORG - https://api.opscode.com/organizations/${test.privatechef.org} - - - YOUR_USER - ${user.home}/.chef/${test.privatechef.org}/${jclouds.privatechef.identity}.pem - org.jclouds.privatechef*;version="${project.version}" - org.jclouds*;version="${jclouds.version}",* - - - - - org.apache.jclouds.labs - hostedchef - ${project.version} - - - org.apache.jclouds.labs - hostedchef - ${project.version} - test-jar - test - - - org.apache.jclouds.api - chef - ${project.version} - - - org.apache.jclouds.api - chef - ${project.version} - test-jar - test - - - org.apache.jclouds - jclouds-core - ${jclouds.version} - test-jar - test - - - org.apache.jclouds.driver - jclouds-slf4j - ${jclouds.version} - test - - - ch.qos.logback - logback-classic - 1.0.9 - test - - - - - - live - - - - org.apache.maven.plugins - maven-surefire-plugin - - - integration - integration-test - - test - - - - ${test.privatechef.org} - ${test.privatechef.endpoint} - ${test.privatechef.api-version} - ${test.privatechef.build-version} - ${test.privatechef.identity} - ${test.privatechef.credential} - - - - - - - - - - diff --git a/labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefApi.java b/labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefApi.java deleted file mode 100644 index b57bd45..0000000 --- a/labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefApi.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.privatechef; - -import javax.ws.rs.Consumes; -import javax.ws.rs.core.MediaType; - -import org.jclouds.Constants; -import org.jclouds.chef.filters.SignedHeaderAuth; -import org.jclouds.hostedchef.HostedChefApi; -import org.jclouds.rest.annotations.Headers; -import org.jclouds.rest.annotations.RequestFilters; - -/** - * Provides synchronous access to the Private Chef Api. - * - * @see HostedChefApi - * @author Ignasi Barrera - */ -@RequestFilters(SignedHeaderAuth.class) -@Consumes(MediaType.APPLICATION_JSON) -@Headers(keys = "X-Chef-Version", values = "{" + Constants.PROPERTY_API_VERSION + "}") -public interface PrivateChefApi extends HostedChefApi { - -} diff --git a/labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefApiMetadata.java b/labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefApiMetadata.java deleted file mode 100644 index f024a1b..0000000 --- a/labs/privatechef/src/main/java/org/jclouds/privatechef/PrivateChefApiMetadata.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.privatechef; - -import java.net.URI; -import java.util.Properties; - -import org.jclouds.apis.ApiMetadata; -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.ChefApiMetadata; -import org.jclouds.chef.ChefContext; -import org.jclouds.chef.config.ChefBootstrapModule; -import org.jclouds.chef.config.ChefParserModule; -import org.jclouds.ohai.config.JMXOhaiModule; -import org.jclouds.privatechef.config.PrivateChefHttpApiModule; -import org.jclouds.rest.internal.BaseHttpApiMetadata; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Implementation of {@link ApiMetadata} for Private Chef api. - * - * @author Adrian Cole - */ -public class PrivateChefApiMetadata extends BaseHttpApiMetadata { - - @Override - public Builder toBuilder() { - return new Builder().fromApiMetadata(this); - } - - public PrivateChefApiMetadata() { - this(new Builder()); - } - - protected PrivateChefApiMetadata(Builder builder) { - super(builder); - } - - public static Properties defaultProperties() { - return ChefApiMetadata.defaultProperties(); - } - - public static class Builder extends BaseHttpApiMetadata.Builder { - - protected Builder() { - id("privatechef") - .name("Private Chef Api") - .identityName("User") - .credentialName("Certificate") - .version(ChefApi.VERSION) - .documentation(URI.create("http://www.opscode.com/support/")) - .defaultEndpoint("https://api.opscode.com") - .defaultProperties(PrivateChefApiMetadata.defaultProperties()) - .view(ChefContext.class) - .defaultModules( - ImmutableSet.> of(PrivateChefHttpApiModule.class, ChefParserModule.class, - ChefBootstrapModule.class, JMXOhaiModule.class)); - } - - @Override - public PrivateChefApiMetadata build() { - return new PrivateChefApiMetadata(this); - } - - @Override - protected Builder self() { - return this; - } - } -} diff --git a/labs/privatechef/src/main/java/org/jclouds/privatechef/config/PrivateChefHttpApiModule.java b/labs/privatechef/src/main/java/org/jclouds/privatechef/config/PrivateChefHttpApiModule.java deleted file mode 100644 index 344a5ac..0000000 --- a/labs/privatechef/src/main/java/org/jclouds/privatechef/config/PrivateChefHttpApiModule.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.privatechef.config; - -import org.jclouds.chef.ChefApi; -import org.jclouds.chef.config.BaseChefHttpApiModule; -import org.jclouds.privatechef.PrivateChefApi; -import org.jclouds.rest.ConfiguresHttpApi; - -/** - * Configures the Private Chef connection. - * - * @author Ignasi Barrera - */ -@ConfiguresHttpApi -public class PrivateChefHttpApiModule extends BaseChefHttpApiModule { - - @Override - protected void configure() { - super.configure(); - bind(ChefApi.class).to(PrivateChefApi.class); - } - -} diff --git a/labs/privatechef/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/labs/privatechef/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata deleted file mode 100644 index 2844492..0000000 --- a/labs/privatechef/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata +++ /dev/null @@ -1 +0,0 @@ -org.jclouds.privatechef.PrivateChefApiMetadata \ No newline at end of file diff --git a/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java b/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java deleted file mode 100644 index 98fe2b9..0000000 --- a/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiContextTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.privatechef; - -import static com.google.common.base.Throwables.propagate; -import static org.testng.Assert.assertNotNull; - -import java.io.IOException; - -import org.jclouds.ContextBuilder; -import org.jclouds.chef.ChefContext; -import org.jclouds.chef.filters.SignedHeaderAuthTest; -import org.jclouds.logging.config.NullLoggingModule; -import org.jclouds.rest.internal.BaseRestApiTest.MockModule; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Tests the access to the underlying API from the context. - * - * @author Ignasi Barrera - */ -@Test(groups = "unit", testName = "PrivateChefApiContextTest") -public class PrivateChefApiContextTest { - - private ChefContext context; - - @BeforeClass - public void setup() { - context = ContextBuilder.newBuilder(new PrivateChefApiMetadata()) - .credentials(SignedHeaderAuthTest.USER_ID, SignedHeaderAuthTest.PRIVATE_KEY) - .modules(ImmutableSet. of(new MockModule(), new NullLoggingModule())) // - .buildView(ChefContext.class); - } - - public void testCanAccessPrivateChefApi() { - PrivateChefApi api = context.unwrapApi(PrivateChefApi.class); - assertNotNull(api); - } - - @AfterClass - public void tearDown() { - try { - context.close(); - } catch (IOException e) { - throw propagate(e); - } - } -} diff --git a/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiMetadataTest.java b/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiMetadataTest.java deleted file mode 100644 index 7c75af7..0000000 --- a/labs/privatechef/src/test/java/org/jclouds/privatechef/PrivateChefApiMetadataTest.java +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF 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.privatechef; - -import org.jclouds.View; -import org.jclouds.rest.internal.BaseHttpApiMetadataTest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSet; -import com.google.common.reflect.TypeToken; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "PrivateChefApiMetadataTest") -public class PrivateChefApiMetadataTest extends BaseHttpApiMetadataTest { - - public PrivateChefApiMetadataTest() { - super(new PrivateChefApiMetadata(), ImmutableSet.> of()); - } -} diff --git a/labs/privatechef/src/test/resources/user.json b/labs/privatechef/src/test/resources/user.json deleted file mode 100644 index 25c2e34..0000000 --- a/labs/privatechef/src/test/resources/user.json +++ /dev/null @@ -1 +0,0 @@ -{"public_key":"-----BEGIN RSA PUBLIC KEY-----\nMIIBCgKCAQEAvCKTqPdHv7GsHTjk02g91Aw3T6xQmdRaI70X6E6GGFxZtcH+tb1X\nqHxwhFydECVXhu0WVjTcWvxZ1aMFzn9BLHQYWzZxU/fIKVNR6ujyZ3jRxDXRFpX5\n/zvMdvNbdsJ+8foEbdoP1iujUMZuy6ZMvcbTDCgWjYVQ2omR9CkH/5Fwlbk3cSrF\n6qfGaM7340OGknKUfXdvhCq4vxydlOwfHJyNDWY0PW+8rDKHWxxNtYDDDeIMw2z/\nYC34f1bcAkR+/lyx5b25RwDomZNqXJqp1hjOVJVlo+UMvzWfXph5hgjcgtwzc5Iu\nmWWMUdxLcdw+/iQm6NW9cmU28bvHu0q7FwIDAQAB\n-----END RSA PUBLIC KEY-----\n","middle_name":"","certificate":"-----BEGIN CERTIFICATE-----\nMIIClzCCAgCgAwIBAgIBATANBgkqhkiG9w0BAQUFADCBnjELMAkGA1UEBhMCVVMx\nEzARBgNVBAgMCldhc2hpbmd0b24xEDAOBgNVBAcMB1NlYXR0bGUxFjAUBgNVBAoM\nDU9wc2NvZGUsIEluYy4xHDAaBgNVBAsME0NlcnRpZmljYXRlIFNlcnZpY2UxMjAw\nBgNVBAMMKW9wc2NvZGUuY29tL2VtYWlsQWRkcmVzcz1hdXRoQG9wc2NvZGUuY29t\nMB4XDTEwMDgwMzA0MDUzNVoXDTIwMDczMTA0MDUzNVowADCCASIwDQYJKoZIhvcN\nAQEBBQADggEPADCCAQoCggEBALwik6j3R7+xrB045NNoPdQMN0+sUJnUWiO9F+hO\nhhhcWbXB/rW9V6h8cIRcnRAlV4btFlY03Fr8WdWjBc5/QSx0GFs2cVP3yClTUero\n8md40cQ10RaV+f87zHbzW3bCfvH6BG3aD9Yro1DGbsumTL3G0wwoFo2FUNqJkfQp\nB/+RcJW5N3EqxeqnxmjO9+NDhpJylH13b4QquL8cnZTsHxycjQ1mND1vvKwyh1sc\nTbWAww3iDMNs/2At+H9W3AJEfv5cseW9uUcA6JmTalyaqdYYzlSVZaPlDL81n16Y\neYYI3ILcM3OSLplljFHcS3HcPv4kJujVvXJlNvG7x7tKuxcCAwEAATANBgkqhkiG\n9w0BAQUFAAOBgQBcoSP/2tFhP8yjF/dRDRdDed0/Cg0xnpp2wvM38gBRgvhpZbQ3\nI2rqpw5THNzrzBVnrYxd57uAa+y2MMG57XnvNWOmyL6WIYXLfN1QI3nHdpHS/QVF\nCRWpDWxLM1TkqAD9xQZOpUDdByF2exiCDNTzSYYg/ISLlIEzicNJeoPNbA==\n-----END CERTIFICATE-----\n","city":null,"email":"adrian+dopey@opscode.com","country":null,"first_name":"Adrian","password":"abcdef","twitter_account":null,"salt":"xBOmipWikVEicS7tNOPdQzPsPmsROMgPme5O19ZHh6R7N9MQT7d5olDiGFpO","display_name":"Adrian Cole","last_name":"Cole","image_file_name":null,"username":"dopey"} \ No newline at end of file diff --git a/pom.xml b/pom.xml index 3734c45..255edd0 100644 --- a/pom.xml +++ b/pom.xml @@ -34,7 +34,7 @@ project core compute - labs + enterprise diff --git a/project/pom.xml b/project/pom.xml index 81f4a5e..a859a13 100644 --- a/project/pom.xml +++ b/project/pom.xml @@ -28,7 +28,7 @@ chef-project 1.7.0-SNAPSHOT pom - Apache jclouds Chef :: Project POM + Apache jclouds Chef :: Project jclouds Chef parent POM for Maven configuration -- 1.7.12.4 (Apple Git-37)