mirror of https://github.com/apache/jclouds.git
JCLOUDS-362 inferring project-id from identity when there is a hyphen
This commit is contained in:
parent
cd90daa8a0
commit
8f206dd120
|
@ -101,10 +101,20 @@ public class GoogleComputeEngineHttpApiModule extends HttpApiModule<GoogleComput
|
||||||
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
return MemoizedRetryOnTimeOutButNotOnAuthorizationExceptionSupplier.create(authException,
|
||||||
compose(new Function<Credentials, String>() {
|
compose(new Function<Credentials, String>() {
|
||||||
public String apply(Credentials in) {
|
public String apply(Credentials in) {
|
||||||
checkState(in.identity.indexOf("@") != 1,
|
// ID should be of the form project_id@developer.gserviceaccount.com
|
||||||
"identity should be in project_id@developer.gserviceaccount.com format");
|
// OR (increasingly often) project_id-extended_uid@developer.gserviceaccount.com
|
||||||
|
// where project_id is the NUMBER;
|
||||||
Project project = api.getProjectApi().get(Iterables.get(Splitter.on("@").split(in.identity), 0));
|
// 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();
|
return project.getName();
|
||||||
}
|
}
|
||||||
}, creds), seconds, TimeUnit.SECONDS);
|
}, creds), seconds, TimeUnit.SECONDS);
|
||||||
|
|
Loading…
Reference in New Issue