Skip to content

Commit fed8313

Browse files
committed
---
yaml --- r: 6139 b: refs/heads/tswast-patch-1 c: 210355d h: refs/heads/master i: 6137: 030178b 6135: abfecc0
1 parent 9d6e58e commit fed8313

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,5 @@ refs/tags/v0.18.0: 9d193c4c4b9d1c6f21515dd8e50836b9194ec9bb
5757
refs/tags/v0.19.0: e67b56e4d8dad5f9a7b38c9b2107c23c828f2ed5
5858
refs/tags/v0.20.0: 839f7fb7156535146aa1cb2c5aadd8d375d854e8
5959
refs/tags/v0.20.1: 370471f437f1f4f68a11e068df5cd6bf39edb1fa
60-
refs/heads/tswast-patch-1: 1318e333c2d7bae7d3de3655e9b8737fb13dd80a
60+
refs/heads/tswast-patch-1: 210355d0089e8740a186de0dd48d86f9f4f7fee3
6161
refs/heads/pubsub-streaming-pull: 19262b752ee874eb2ca3b950eb2aef44d5a5267b

branches/tswast-patch-1/gcloud-java-core/src/main/java/com/google/gcloud/AuthCredentials.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.auth.oauth2.GoogleCredentials;
3131

3232
import java.io.IOException;
33+
import java.io.InputStream;
3334
import java.io.ObjectInputStream;
3435
import java.io.ObjectStreamException;
3536
import java.io.Serializable;
@@ -133,7 +134,7 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
133134
try {
134135
computeCredential = getComputeCredential();
135136
} catch (GeneralSecurityException e) {
136-
throw new IOException(e);
137+
throw new IOException(e);
137138
}
138139
}
139140

@@ -156,7 +157,7 @@ private static class ApplicationDefaultAuthCredentials extends AuthCredentials {
156157

157158
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
158159
in.defaultReadObject();
159-
googleCredentials = GoogleCredentials.getApplicationDefault();
160+
googleCredentials = GoogleCredentials.getApplicationDefault();
160161
}
161162

162163
@Override
@@ -183,8 +184,8 @@ public static AuthCredentials createForComputeEngine()
183184
*
184185
* <p>Returns the Application Default Credentials which are credentials that identify and
185186
* authorize the whole application. This is the built-in service account if running on
186-
* Google Compute Engine or the credentials file from the path in the environment variable
187-
* GOOGLE_APPLICATION_CREDENTIALS.
187+
* Google Compute Engine or the credentials file can be read from the path in the environment
188+
* variable GOOGLE_APPLICATION_CREDENTIALS.
188189
* </p>
189190
*
190191
* @return the credentials instance.
@@ -194,10 +195,41 @@ public static AuthCredentials createApplicationDefaults() throws IOException {
194195
return new ApplicationDefaultAuthCredentials();
195196
}
196197

198+
/**
199+
* Creates Service Account Credentials given an account id and a private key.
200+
*
201+
* <p>For details on how to obtain Service Account Credentials see
202+
* <a href="https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts">Service
203+
* Account Authentication</a>.
204+
* </p>
205+
*
206+
* @param account id of the Service Account
207+
* @param privateKey private key associated to the account
208+
* @return the credentials instance.
209+
*/
197210
public static ServiceAccountAuthCredentials createFor(String account, PrivateKey privateKey) {
198211
return new ServiceAccountAuthCredentials(account, privateKey);
199212
}
200213

214+
/**
215+
* Creates Service Account Credentials given a stream for credentials in JSON format.
216+
*
217+
* <p>For details on how to obtain Service Account Credentials in JSON format see
218+
* <a href="https://cloud.google.com/storage/docs/authentication?hl=en#service_accounts">Service
219+
* Account Authentication</a>.
220+
* </p>
221+
*
222+
* @param jsonCredentialStream stream for Service Account Credentials in JSON format
223+
* @return the credentials instance.
224+
* @throws IOException if the credentials cannot be created from the stream.
225+
*/
226+
public static ServiceAccountAuthCredentials createForJson(InputStream jsonCredentialStream)
227+
throws IOException {
228+
GoogleCredential tempCredentials = GoogleCredential.fromStream(jsonCredentialStream);
229+
return new ServiceAccountAuthCredentials(tempCredentials.getServiceAccountId(),
230+
tempCredentials.getServiceAccountPrivateKey());
231+
}
232+
201233
public static AuthCredentials noCredentials() {
202234
return ServiceAccountAuthCredentials.NO_CREDENTIALS;
203235
}

0 commit comments

Comments
 (0)