| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.openstack; |
| 20 | |
| 21 | import static com.google.common.base.Preconditions.checkNotNull; |
| 22 | |
| 23 | import java.net.URI; |
| 24 | import java.util.Map; |
| 25 | |
| 26 | import javax.ws.rs.GET; |
| 27 | import javax.ws.rs.HeaderParam; |
| 28 | import javax.ws.rs.Path; |
| 29 | |
| 30 | import org.jclouds.Constants; |
| 31 | import org.jclouds.openstack.functions.ParseAuthenticationResponseFromHeaders; |
| 32 | import org.jclouds.openstack.reference.AuthHeaders; |
| 33 | import org.jclouds.rest.annotations.ResponseParser; |
| 34 | |
| 35 | import com.google.common.base.Objects; |
| 36 | import com.google.common.collect.ImmutableMap; |
| 37 | import com.google.common.util.concurrent.ListenableFuture; |
| 38 | |
| 39 | /** |
| 40 | * Provides access to Rackspace resources via their REST API. |
| 41 | * <p/> |
| 42 | * |
| 43 | * @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" /> |
| 44 | * @author Adrian Cole |
| 45 | */ |
| 46 | @Path("/v{" + Constants.PROPERTY_API_VERSION + "}") |
| 47 | public interface OpenStackAuthAsyncClient { |
| 48 | public static final String VERSION = "1.0"; |
| 49 | |
| 50 | public static class AuthenticationResponse { |
| 51 | private final String authToken; |
| 52 | private Map<String, URI> services; |
| 53 | |
| 54 | public AuthenticationResponse(String authToken, Map<String, URI> services) { |
| 55 | this.authToken = checkNotNull(authToken, "authToken"); |
| 56 | this.services = ImmutableMap.copyOf(checkNotNull(services, "services")); |
| 57 | } |
| 58 | |
| 59 | public Map<String, URI> getServices() { |
| 60 | return services; |
| 61 | } |
| 62 | |
| 63 | public void setEndpoints(Map<String, URI> services) { |
| 64 | this.services = services; |
| 65 | } |
| 66 | |
| 67 | public String getAuthToken() { |
| 68 | return authToken; |
| 69 | } |
| 70 | |
| 71 | // performance isn't a concern on a infrequent object like this, so using shortcuts; |
| 72 | |
| 73 | @Override |
| 74 | public int hashCode() { |
| 75 | return Objects.hashCode(authToken, services); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public boolean equals(Object that) { |
| 80 | if (that == null) |
| 81 | return false; |
| 82 | return Objects.equal(this.toString(), that.toString()); |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public String toString() { |
| 87 | return Objects.toStringHelper(this).add("authToken", authToken).add("services", services).toString(); |
| 88 | } |
| 89 | |
| 90 | } |
| 91 | |
| 92 | @GET |
| 93 | @ResponseParser(ParseAuthenticationResponseFromHeaders.class) |
| 94 | ListenableFuture<AuthenticationResponse> authenticate(@HeaderParam(AuthHeaders.AUTH_USER) String user, |
| 95 | @HeaderParam(AuthHeaders.AUTH_KEY) String key); |
| 96 | |
| 97 | |
| 98 | @GET |
| 99 | @ResponseParser(ParseAuthenticationResponseFromHeaders.class) |
| 100 | ListenableFuture<AuthenticationResponse> authenticateStorage(@HeaderParam(AuthHeaders.STORAGE_USER) String user, |
| 101 | @HeaderParam(AuthHeaders.STORAGE_PASS) String key); |
| 102 | } |