Add support for organization internal projects.

When using IAM a company can have internal-only projects, which are
referenced in the form <domain>:<project_id>. IAM account is in the
form: email@project_id.domain.tld.iam......
This commit is contained in:
Nelson Araujo 2016-08-07 16:21:56 -07:00 committed by Ignasi Barrera
parent 93028b7529
commit 52477d5e93
2 changed files with 12 additions and 2 deletions

View File

@ -38,7 +38,8 @@ public @interface CurrentProject {
public static final String DESCRIPTION = "" //
+ "client_email which usually looks like project_id@developer.gserviceaccount.com or " //
+ "project_id-extended_uid@developer.gserviceaccount.com or " //
+ "account@project_id.iam.gserviceaccount.com";
+ "account@project_id.company_domain.iam.gserviceaccount.com or " //
+ "account@project_id.iam.gserviceaccount.com or ";
private static final Pattern PROJECT_NUMBER_PATTERN = Pattern.compile("^([0-9]+)[@-].*");
private static final String IAM_ACCOUNT_SUFFIX = ".iam.gserviceaccount.com";
@ -51,7 +52,12 @@ public @interface CurrentProject {
}
private static String projectIdFromIAM(String email) {
return email.substring(email.indexOf('@') + 1, email.indexOf(IAM_ACCOUNT_SUFFIX));
String project_id = email.substring(email.indexOf('@') + 1, email.indexOf(IAM_ACCOUNT_SUFFIX));
int dot = project_id.indexOf('.');
return dot > 0
// Convert project_id.company_domain into company_domain:project_id
? String.format("%s:%s", project_id.substring(dot + 1), project_id.substring(0, dot))
: project_id;
}
}
}

View File

@ -42,4 +42,8 @@ public class ClientEmailTest {
public void testParseProjectIdFromIAMAccount() {
assertEquals(toProjectNumber("account@project_id.iam.gserviceaccount.com"), "project_id");
}
public void testParseCompanyAndProjectIdFromIAMAccount() {
assertEquals(toProjectNumber("account@project_id.company.com.iam.gserviceaccount.com"), "company.com:project_id");
}
}