Allows to use GCE service credentials to sign blobs (#150) · googleapis/google-cloud-java@79c87c7 · GitHub
Skip to content

Commit 79c87c7

Browse files
dtretyakovchingor13
authored andcommitted
Allows to use GCE service credentials to sign blobs (#150)
Fixes #141 * Allows to use GCE service credentials to sign blobs (#141) * Fix failing test (#141) * Improve error reporting (#141) * Fix issues for code review (#141) * Don't change ServiceAccountSigner method signatures * Use complete list of imports in ComputeEngineCredentials * Restore individual assert imports * No need for IAM_API_ROOT_URL constant * Add tests for failure cases
1 parent f570c86 commit 79c87c7

5 files changed

Lines changed: 441 additions & 16 deletions

File tree

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/ComputeEngineCredentials.java

Lines changed: 126 additions & 15 deletions

google-auth-library-java/oauth2_http/java/com/google/auth/oauth2/OAuth2Utils.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,23 @@ static long validateLong(Map<String, Object> map, String key, String errorPrefix
198198
return (Long) value;
199199
}
200200

201+
/**
202+
* Return the specified map from JSON or throw a helpful error message.
203+
*/
204+
@SuppressWarnings("unchecked")
205+
static Map<String, Object> validateMap(Map<String, Object> map, String key, String errorPrefix)
206+
throws IOException {
207+
Object value = map.get(key);
208+
if (value == null) {
209+
throw new IOException(String.format(VALUE_NOT_FOUND_MESSAGE, errorPrefix, key));
210+
}
211+
if (!(value instanceof Map)) {
212+
throw new IOException(
213+
String.format(VALUE_WRONG_TYPE_MESSAGE, errorPrefix, "Map", key));
214+
}
215+
return (Map) value;
216+
}
217+
201218
private OAuth2Utils() {
202219
}
203220
}

google-auth-library-java/oauth2_http/javatests/com/google/auth/TestUtils.java

Lines changed: 9 additions & 0 deletions

0 commit comments

Comments
 (0)