mirror of https://github.com/apache/jclouds.git
Merge pull request #1043 from jclouds/keystone-minimal
fix issue #1040: tenant can be null
This commit is contained in:
commit
208b41ec38
|
@ -23,8 +23,11 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
import java.beans.ConstructorProperties;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Objects.ToStringHelper;
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
/**
|
||||
* A token is an arbitrary bit of text that is used to access resources. Each token has a scope
|
||||
|
@ -54,7 +57,7 @@ public class Token implements Comparable<Token> {
|
|||
|
||||
protected String id;
|
||||
protected Date expires;
|
||||
protected Tenant tenant;
|
||||
protected Optional<Tenant> tenant = Optional.absent();
|
||||
|
||||
/**
|
||||
* @see Token#getId()
|
||||
|
@ -76,7 +79,7 @@ public class Token implements Comparable<Token> {
|
|||
* @see Token#getTenant()
|
||||
*/
|
||||
public T tenant(Tenant tenant) {
|
||||
this.tenant = tenant;
|
||||
this.tenant = Optional.fromNullable(tenant);
|
||||
return self();
|
||||
}
|
||||
|
||||
|
@ -88,7 +91,7 @@ public class Token implements Comparable<Token> {
|
|||
return this
|
||||
.id(in.getId())
|
||||
.expires(in.getExpires())
|
||||
.tenant(in.getTenant());
|
||||
.tenant(in.getTenant().orNull());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,15 +104,15 @@ public class Token implements Comparable<Token> {
|
|||
|
||||
private final String id;
|
||||
private final Date expires;
|
||||
private final Tenant tenant;
|
||||
private final Optional<Tenant> tenant;
|
||||
|
||||
@ConstructorProperties({
|
||||
"id", "expires", "tenant"
|
||||
})
|
||||
protected Token(String id, Date expires, Tenant tenant) {
|
||||
protected Token(String id, Date expires, @Nullable Optional<Tenant> tenant) {
|
||||
this.id = checkNotNull(id, "id");
|
||||
this.expires = checkNotNull(expires, "expires");
|
||||
this.tenant = checkNotNull(tenant, "tenant");
|
||||
this.tenant = tenant == null ? Optional.<Tenant> absent() : tenant;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,7 +134,7 @@ public class Token implements Comparable<Token> {
|
|||
/**
|
||||
* @return the tenant assigned to the token
|
||||
*/
|
||||
public Tenant getTenant() {
|
||||
public Optional<Tenant> getTenant() {
|
||||
return this.tenant;
|
||||
}
|
||||
|
||||
|
@ -151,8 +154,8 @@ public class Token implements Comparable<Token> {
|
|||
}
|
||||
|
||||
protected ToStringHelper string() {
|
||||
return Objects.toStringHelper(this)
|
||||
.add("id", id).add("expires", expires).add("tenant", tenant);
|
||||
return Objects.toStringHelper(this).omitNullValues()
|
||||
.add("id", id).add("expires", expires).add("tenant", tenant.orNull());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.openstack.keystone.v2_0.parse;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import org.jclouds.date.internal.SimpleDateFormatDateService;
|
||||
import org.jclouds.json.BaseItemParserTest;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Access;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.Token;
|
||||
import org.jclouds.openstack.keystone.v2_0.domain.User;
|
||||
import org.jclouds.rest.annotations.SelectJson;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ParseMinimalAccessTest")
|
||||
public class ParseMinimalAccessTest extends BaseItemParserTest<Access> {
|
||||
|
||||
@Override
|
||||
public String resource() {
|
||||
return "/access_minimal.json";
|
||||
}
|
||||
|
||||
@Override
|
||||
@SelectJson("access")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public Access expected() {
|
||||
return Access.builder()
|
||||
.token(Token.builder()
|
||||
.expires(new SimpleDateFormatDateService().iso8601SecondsDateParse("2012-12-02T01:44:54Z"))
|
||||
.id("5afc3adea6654e758b4a9cf01bafe507").build())
|
||||
.user(User.builder()
|
||||
.id("bf45fd7586c2410c980c651b918aa850")
|
||||
.name("nova")
|
||||
// .username("nova") TODO: add optional username field!
|
||||
.build()).build();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{"access": {"token": {"expires": "2012-12-02T01:44:54Z", "id": "5afc3adea6654e758b4a9cf01bafe507"}, "serviceCatalog": [], "user": {"username": "nova", "roles_links": [], "id": "bf45fd7586c2410c980c651b918aa850", "roles": [], "name": "nova"}}}
|
|
@ -105,7 +105,7 @@ public class HPCloudObjectStorageBlobRequestSigner implements BlobRequestSigner
|
|||
@PostConstruct
|
||||
public void populateTenantId() {
|
||||
// Defer call from constructor since access.get issues an RPC.
|
||||
this.tenantId = access.get().getToken().getTenant().getId();
|
||||
this.tenantId = access.get().getToken().getTenant().get().getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue