mirror of
https://github.com/google/nomulus.git
synced 2025-05-12 22:38:16 +02:00
Introduce simplified Default credential provision
As the first step in credential consolidation, we replace injection of application default credential in for KMS and Drive. Tests: - for Drive, tested with exportDomainLists and exportReservedTerms. - For KMS, used CLI commands (get_keyring_secret and update_kms_keyring) to change and restore secret for one key. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=211819859
This commit is contained in:
parent
4c3207647f
commit
9436ce6f0e
15 changed files with 148 additions and 42 deletions
|
@ -14,23 +14,16 @@
|
|||
|
||||
package google.registry.export;
|
||||
|
||||
import com.google.api.client.http.HttpRequestInitializer;
|
||||
import com.google.api.client.http.HttpTransport;
|
||||
import com.google.api.client.json.JsonFactory;
|
||||
import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
|
||||
import com.google.api.services.drive.Drive;
|
||||
import com.google.api.services.drive.DriveScopes;
|
||||
import dagger.Component;
|
||||
import dagger.Module;
|
||||
import dagger.Provides;
|
||||
import google.registry.config.CredentialModule;
|
||||
import google.registry.config.CredentialModule.DefaultCredential;
|
||||
import google.registry.config.RegistryConfig.Config;
|
||||
import google.registry.config.RegistryConfig.ConfigModule;
|
||||
import google.registry.request.Modules.AppIdentityCredentialModule;
|
||||
import google.registry.request.Modules.Jackson2Module;
|
||||
import google.registry.request.Modules.UrlFetchTransportModule;
|
||||
import google.registry.request.Modules.UseAppIdentityCredentialForGoogleApisModule;
|
||||
import google.registry.storage.drive.DriveConnection;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
/** Dagger module for Google {@link Drive} service connection objects. */
|
||||
|
@ -39,25 +32,14 @@ public final class DriveModule {
|
|||
|
||||
@Provides
|
||||
static Drive provideDrive(
|
||||
HttpTransport transport,
|
||||
JsonFactory jsonFactory,
|
||||
Function<Set<String>, ? extends HttpRequestInitializer> credential,
|
||||
@Config("projectId") String projectId) {
|
||||
return new Drive.Builder(transport, jsonFactory, credential.apply(DriveScopes.all()))
|
||||
@DefaultCredential GoogleCredential credential, @Config("projectId") String projectId) {
|
||||
return new Drive.Builder(credential.getTransport(), credential.getJsonFactory(), credential)
|
||||
.setApplicationName(projectId)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Singleton
|
||||
@Component(
|
||||
modules = {
|
||||
DriveModule.class,
|
||||
UrlFetchTransportModule.class,
|
||||
Jackson2Module.class,
|
||||
AppIdentityCredentialModule.class,
|
||||
UseAppIdentityCredentialForGoogleApisModule.class,
|
||||
ConfigModule.class
|
||||
})
|
||||
@Component(modules = {DriveModule.class, ConfigModule.class, CredentialModule.class})
|
||||
interface DriveComponent {
|
||||
DriveConnection driveConnection();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue