List of usage examples for com.google.api.client.googleapis.auth.oauth2 GoogleCredential fromStream
@Beta public static GoogleCredential fromStream(InputStream credentialStream, HttpTransport transport, JsonFactory jsonFactory) throws IOException
From source file:com.netflix.spinnaker.halyard.backup.kms.v1.google.GoogleStorage.java
License:Apache License
private static GoogleCredential loadStorageCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException { GoogleCredential credential;//from w w w . jav a 2s .co m if (!jsonPath.isEmpty()) { FileInputStream stream = new FileInputStream(jsonPath); credential = GoogleCredential.fromStream(stream, transport, factory); log.info("Loaded storage credentials from " + jsonPath); } else { log.info("Using storage default application credentials."); credential = GoogleCredential.getApplicationDefault(); } if (credential.createScopedRequired()) { credential = credential.createScoped(StorageScopes.all()); } return credential; }
From source file:com.netflix.spinnaker.halyard.core.registry.v1.GoogleWriteableProfileRegistry.java
License:Apache License
private GoogleCredential loadCredential(HttpTransport transport, JsonFactory factory, String jsonPath) throws IOException { GoogleCredential credential;/*from w ww .ja v a 2s .c o m*/ if (!jsonPath.isEmpty()) { FileInputStream stream = new FileInputStream(jsonPath); credential = GoogleCredential.fromStream(stream, transport, factory) .createScoped(Collections.singleton(StorageScopes.DEVSTORAGE_FULL_CONTROL)); log.info("Loaded credentials from " + jsonPath); } else { log.info("Using default application credentials."); credential = GoogleCredential.getApplicationDefault(); } return credential; }
From source file:com.netflix.spinnaker.igor.gcb.GoogleCloudBuildTestConfig.java
License:Apache License
@Bean @Primary//from www . jav a 2s .c om GoogleCredentialService googleCredentialService() { return new GoogleCredentialService() { @Override GoogleCredential getFromKey(String jsonPath) { if (!jsonPath.equals("/path/to/some/file")) { return null; } // Create a mock credential whose bearer token is always "test-token" try { InputStream is = GoogleCloudBuildAccountFactory.class .getResourceAsStream("/gcb/gcb-test-account.json"); MockTokenServerTransport mockTransport = new MockTokenServerTransport( "https://accounts.google.com/o/oauth2/auth"); mockTransport.addServiceAccount("test-account@spinnaker-gcb-test.iam.gserviceaccount.com", "test-token"); return GoogleCredential.fromStream(is, mockTransport, JacksonFactory.getDefaultInstance()) .createScoped(CloudBuildScopes.all()); } catch (IOException e) { throw new RuntimeException(e); } } }; }
From source file:de.elomagic.mag.google.BatchGoogleDriveClientFactory.java
License:Apache License
/** * Authorizes the installed application to access user's protected data. * * @param clientId/*from ww w .j a v a 2 s. c om*/ * @param clientSecret * @param scopes * @return * @throws Exception */ private Credential authorize() throws Exception { Path configurationFile = Paths.get(Configuration.get(ConfigurationKey.TargetGoogleDriveCredentialFile)); try (InputStream in = Files.newInputStream(configurationFile, StandardOpenOption.READ)) { return GoogleCredential.fromStream(in, httpTransport, JacksonFactory.getDefaultInstance()) .createScoped(Arrays.asList(DriveScopes.DRIVE_FILE)); } }
From source file:gobblin.source.extractor.extract.google.GoogleCommon.java
License:Apache License
private static Credential buildCredentialFromJson(String privateKeyPath, Optional<String> fsUri, HttpTransport transport, Collection<String> serviceAccountScopes) throws IOException { FileSystem fs = getFileSystem(fsUri); Path keyPath = getPrivateKey(fs, privateKeyPath); return GoogleCredential.fromStream(fs.open(keyPath), transport, JSON_FACTORY) .createScoped(serviceAccountScopes); }