From c34358a841b0ad0c7cf2866d9c86bf58a9a66f7e Mon Sep 17 00:00:00 2001 From: Alex Heneveld Date: Thu, 28 Nov 2013 14:56:33 +0000 Subject: [PATCH] backport of JCLOUDS-362 fix (jclouds-labs-google cec667a8aed54ebd0c976758181ca7e9899008cf) --- .../config/GoogleComputeEngineHttpApiModule.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java index 214c932..9eb6a77 100644 --- a/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java +++ b/google-compute-engine/src/main/java/org/jclouds/googlecomputeengine/config/GoogleComputeEngineHttpApiModule.java @@ -16,7 +16,6 @@ */ package org.jclouds.googlecomputeengine.config; -import static com.google.common.base.Preconditions.checkState; import static com.google.common.base.Suppliers.compose; import static com.google.inject.name.Names.named; import static org.jclouds.Constants.PROPERTY_SESSION_INTERVAL; @@ -98,9 +97,20 @@ protected void bindErrorHandlers() { return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException, compose(new Function() { public String apply(Credentials in) { - checkState(in.identity.indexOf("@") != 1, - "identity should be in project_id@developer.gserviceaccount.com format"); - Project project = api.getProjectApi().get(Iterables.get(Splitter.on("@").split(in.identity), 0)); + // ID should be of the form project_id@developer.gserviceaccount.com + // OR (increasingly often) project_id-extended_uid@developer.gserviceaccount.com + // where project_id is the NUMBER; + // HERE we also accept simply "project" as the identity, if no "@" is present; + // this is used in tests, but not sure if it is valid in the wild. + String projectName = in.identity; + if (projectName.indexOf("@") != -1) { + projectName = Iterables.get(Splitter.on("@").split(projectName), 0); + if (projectName.indexOf("-") != -1) { + // if ID is of the form project_id-extended_uid@developer.gserviceaccount.com + projectName = Iterables.get(Splitter.on("-").split(projectName), 0); + } + } + Project project = api.getProjectApi().get(projectName); return project.getName(); } }, creds), seconds, TimeUnit.SECONDS); -- 1.8.5.1