mirror of
https://github.com/google/nomulus.git
synced 2025-05-15 17:07:15 +02:00
Use local GoogleCredential in the nomulus tool
The scenarios in which the credential is used are: 1) Calls to Nomulus GAE HTTP endpoints. 2) Calls to Google APIs within the tool. 3) Calls to GAE APIs within the tool. From now on the tool should not depend on ADCs created from gcloud any more (expect for beam pipeline deployments which need some more investigation as the dependency on ADC is not apparent). Using the nomulus tool requires running "nomulus login" first, but only once. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=224165735
This commit is contained in:
parent
5f9aad90fc
commit
fdda03eb53
12 changed files with 143 additions and 165 deletions
|
@ -14,9 +14,6 @@
|
|||
|
||||
package google.registry.tools;
|
||||
|
||||
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
|
||||
import com.google.appengine.tools.remoteapi.RemoteApiOptions;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkState;
|
||||
import static google.registry.model.ofy.ObjectifyService.ofy;
|
||||
import static google.registry.tools.Injector.injectReflectively;
|
||||
|
@ -26,10 +23,14 @@ import com.beust.jcommander.Parameter;
|
|||
import com.beust.jcommander.ParameterException;
|
||||
import com.beust.jcommander.Parameters;
|
||||
import com.beust.jcommander.ParametersDelegate;
|
||||
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
|
||||
import com.google.appengine.tools.remoteapi.RemoteApiOptions;
|
||||
import com.google.common.base.Throwables;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import google.registry.config.RegistryConfig;
|
||||
import google.registry.model.ofy.ObjectifyService;
|
||||
import google.registry.tools.AuthModule.LoginRequiredException;
|
||||
import google.registry.tools.params.ParameterFactory;
|
||||
import java.net.URL;
|
||||
import java.security.Security;
|
||||
|
@ -55,7 +56,6 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
|||
description = "Returns all command names.")
|
||||
private boolean showAllCommands;
|
||||
|
||||
|
||||
// Do not make this final - compile-time constant inlining may interfere with JCommander.
|
||||
@ParametersDelegate
|
||||
private LoggingParameters loggingParams = new LoggingParameters();
|
||||
|
@ -80,8 +80,7 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
|||
|
||||
Security.addProvider(new BouncyCastleProvider());
|
||||
|
||||
component = DaggerRegistryToolComponent.builder()
|
||||
.build();
|
||||
component = DaggerRegistryToolComponent.create();
|
||||
}
|
||||
|
||||
// The <? extends Class<? extends Command>> wildcard looks a little funny, but is needed so that
|
||||
|
@ -156,18 +155,32 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
|||
|
||||
try {
|
||||
runCommand(command);
|
||||
} catch (AuthModule.LoginRequiredException ex) {
|
||||
System.err.println("===================================================================");
|
||||
System.err.println("You must login using 'nomulus login' prior to running this command.");
|
||||
System.err.println("===================================================================");
|
||||
} catch (RuntimeException ex) {
|
||||
if (Throwables.getRootCause(ex) instanceof LoginRequiredException) {
|
||||
System.err.println("===================================================================");
|
||||
System.err.println("You must login using 'nomulus login' prior to running this command.");
|
||||
System.err.println("===================================================================");
|
||||
} else {
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (installer != null) {
|
||||
installer.uninstall();
|
||||
installer = null;
|
||||
try {
|
||||
installer.uninstall();
|
||||
installer = null;
|
||||
} catch (IllegalArgumentException e) {
|
||||
// There is no point throwing the error if the API is already uninstalled, which is most
|
||||
// likely caused by something wrong when installing the API. That something (e. g. no
|
||||
// credential found) must have already thrown an error message earlier (e. g. must run
|
||||
// "nomulus login" first). This error message here is non-actionable.
|
||||
if (!e.getMessage().equals("remote API is already uninstalled")) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -197,8 +210,8 @@ final class RegistryCli implements AutoCloseable, CommandRunner {
|
|||
// Use dev credentials for localhost.
|
||||
options.useDevelopmentServerCredential();
|
||||
} else {
|
||||
RemoteApiOptionsUtil.useGoogleCredentialStream(options, component
|
||||
.googleCredentialStream().get());
|
||||
RemoteApiOptionsUtil.useGoogleCredentialStream(
|
||||
options, component.googleCredentialStream().get());
|
||||
}
|
||||
installer.install(options);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue