@Override public GoogleCredentials getGoogleCredentials(Map<PropertyDescriptor, String> properties, HttpTransportFactory transportFactory) throws IOException { return GoogleCredentials.getApplicationDefault(transportFactory); }
private static GoogleCredentials defaultCredentials() { try { return GoogleCredentials.getApplicationDefault(); } catch (Exception ex) { return null; } }
@Override public GoogleCredentials getGoogleCredentials(Map<PropertyDescriptor, String> properties, HttpTransportFactory transportFactory) throws IOException { return GoogleCredentials.getApplicationDefault(transportFactory); }
/** * Constructs a ContainerRegistryAuthSupplier using the Application Default Credentials. * * @see Builder */ public static Builder forApplicationDefaultCredentials() throws IOException { return new Builder(GoogleCredentials.getApplicationDefault()); }
private GoogleCredentials loadGoogleCredentials( final boolean useDefaultCredentials, final File credentialsFile) throws ArgumentParserException, IOException { if (useDefaultCredentials && credentialsFile != null) { final String msg = String.format("Cannot set both %s and %s", this.googleCloudCredentialsFile.getDest(), this.useGoogleDefaultApplicationCredentials.getDest()); throw new IllegalArgumentException(msg); } if (useDefaultCredentials) { return GoogleCredentials.getApplicationDefault(); } try (final FileInputStream stream = new FileInputStream(credentialsFile)) { return GoogleCredentials.fromStream(stream); } }
credentials = GoogleCredentials.getApplicationDefault(); LOG.info("Using Google Application Default Credentials");
return GoogleCredentials.getApplicationDefault(); } catch (IOException e) { throw new GoogleCredentialException(
credentials = GoogleCredentials.getApplicationDefault(); getLog().info("Using Google application default credentials"); } catch (IOException ex) {
private synchronized Storage getService() throws IOException, GeneralSecurityException { logger.trace("Getting Google Cloud Storage service"); // leave this here for tests because they do things like manipulate properties dynamically to test invalid values this.bucketName = properties.getProperty( "usergrid.binary.bucketname" ); if (instance == null) { // Google provides different authentication types which are different based on if the application is // running within GCE(Google Compute Engine) or GAE (Google App Engine). If Usergrid is running in // GCE or GAE, the SDK will automatically authenticate and get access to // cloud storage. Else, the full path to a credential file should be provided in the following environment variable // // GOOGLE_APPLICATION_CREDENTIALS // // The SDK will attempt to load the credential file for a service account. See the following // for more info: https://developers.google.com/identity/protocols/application-default-credentials#howtheywork GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(StorageScopes.all()); final TransportOptions transportOptions = HttpTransportOptions.newBuilder() .setConnectTimeout(30000) // in milliseconds .setReadTimeout(30000) // in milliseconds .build(); instance = StorageOptions.newBuilder() .setCredentials(credentials) .setTransportOptions(transportOptions) .build() .getService(); } return instance; }
private static AddressClient createCredentialedClient() throws IOException { Credentials myCredentials = GoogleCredentials.getApplicationDefault(); String myEndpoint = AddressSettings.getDefaultEndpoint(); AddressSettings addressSettings = AddressSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(myCredentials)) .setTransportChannelProvider( AddressSettings.defaultHttpJsonTransportProviderBuilder() .setEndpoint(myEndpoint) .build()) .build(); return AddressClient.create(addressSettings); }
@BeforeClass public static void beforeClass() throws IOException { Credentials credentials = GoogleCredentials.getApplicationDefault() .createScoped(DiskTypeSettings.getDefaultServiceScopes()); diskTypeSettings = DiskTypeSettings.newBuilder() .setCredentialsProvider(FixedCredentialsProvider.create(credentials)) .build(); diskTypeClient = DiskTypeClient.create(diskTypeSettings); }
private static ServiceAccountCredentials getCredentials() throws Exception { GoogleCredentials credentials = GoogleCredentials.getApplicationDefault().createScoped(Collections.singleton(IAM_SCOPE)); // service account credentials are required to sign the jwt token if (credentials == null || !(credentials instanceof ServiceAccountCredentials)) { throw new Exception("Google credentials : service accounts credentials expected"); } return (ServiceAccountCredentials) credentials; }
public static GoogleCredentials loadCredentials(S3UploadMetadata uploadMetadata, JsonObjectFileHelper jsonHelper) { try { if (!uploadMetadata.getGcsCredentials().isEmpty()) { return GoogleCredentials.fromStream(jsonHelper.toInputStream(uploadMetadata.getGcsCredentials())); } // Load from default credentials as determined by GOOGLE_APPLICATION_CREDENTIALS var if none provided in metadata return GoogleCredentials.getApplicationDefault(); } catch (IOException e) { throw new RuntimeException("Issue reading credentials file specified in `GOOGLE_APPLICATION_CREDENTIALS`", e); } }
private static void prepareKmsKeys() throws IOException { String projectId = remoteStorageHelper.getOptions().getProjectId(); GoogleCredentials credentials = GoogleCredentials.getApplicationDefault(); ManagedChannel kmsChannel = ManagedChannelBuilder.forTarget("cloudkms.googleapis.com:443").build(); KeyManagementServiceBlockingStub kmsStub = KeyManagementServiceGrpc.newBlockingStub(kmsChannel) .withCallCredentials(MoreCallCredentials.from(credentials)); IAMPolicyGrpc.IAMPolicyBlockingStub iamStub = IAMPolicyGrpc.newBlockingStub(kmsChannel) .withCallCredentials(MoreCallCredentials.from(credentials)); ensureKmsKeyRingExistsForTests(kmsStub, projectId, KMS_KEY_RING_LOCATION, KMS_KEY_RING_NAME); ensureKmsKeyRingIamPermissionsForTests( iamStub, projectId, KMS_KEY_RING_LOCATION, KMS_KEY_RING_NAME); kmsKeyOneResourcePath = ensureKmsKeyExistsForTests( kmsStub, projectId, KMS_KEY_RING_LOCATION, KMS_KEY_RING_NAME, KMS_KEY_ONE_NAME); kmsKeyTwoResourcePath = ensureKmsKeyExistsForTests( kmsStub, projectId, KMS_KEY_RING_LOCATION, KMS_KEY_RING_NAME, KMS_KEY_TWO_NAME); }
private static GoogleCredentials defaultCredentials() { try { return GoogleCredentials.getApplicationDefault(); } catch (Exception ex) { return null; } }
/** Returns a default GCP {@link Credentials} or null when it fails. */ @Override public Credentials getCredential() { try { return GoogleCredentials.getApplicationDefault().createScoped(SCOPES); } catch (IOException e) { // Ignore the exception // Pipelines that only access to public data should be able to run without credentials. return null; } } }
@Bean @ConditionalOnMissingBean(Credentials.class) Credentials googleCredentials() throws IOException { return GoogleCredentials.getApplicationDefault() .createScoped(Collections.singletonList("https://www.googleapis.com/auth/trace.append")); }
@Bean @ConditionalOnMissingBean(Credentials.class) Credentials googleCredentials() throws IOException { return GoogleCredentials.getApplicationDefault() .createScoped(Collections.singletonList("https://www.googleapis.com/auth/trace.append")); }
@Override public Credentials getCredentials() throws IOException { if (this.credentials == null) { return GoogleCredentials.getApplicationDefault().createScoped(this.CPS_SCOPE); } else { return this.credentials.createScoped(this.CPS_SCOPE); } }
@Test public void getApplicationDefault_nullTransport_throws() throws IOException { try { GoogleCredentials.getApplicationDefault(null); fail(); } catch (NullPointerException expected) { // Expected } }