Turn off http features not intended for slave
If daemon is loaded as a slave, modules which have features intended for master won't be loaded. Change-Id: I2314bf0eef7f22c5aa439fbd5d9ecaa8ee300e34
This commit is contained in:
@@ -16,12 +16,18 @@ package com.google.gerrit.httpd;
|
||||
|
||||
public class GerritOptions {
|
||||
private final boolean headless;
|
||||
private final boolean slave;
|
||||
|
||||
public GerritOptions(boolean headless) {
|
||||
public GerritOptions(boolean headless, boolean slave) {
|
||||
this.headless = headless;
|
||||
this.slave = slave;
|
||||
}
|
||||
|
||||
public boolean enableDefaultUi() {
|
||||
return !headless;
|
||||
}
|
||||
|
||||
public boolean enableMasterFeatures() {
|
||||
return !slave;
|
||||
}
|
||||
}
|
||||
|
@@ -98,12 +98,20 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
}
|
||||
|
||||
static class Module extends AbstractModule {
|
||||
|
||||
private final boolean enableReceive;
|
||||
|
||||
public Module(boolean enableReceive) {
|
||||
this.enableReceive = enableReceive;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(Resolver.class);
|
||||
bind(UploadFactory.class);
|
||||
bind(UploadFilter.class);
|
||||
bind(ReceiveFactory.class);
|
||||
bind(new TypeLiteral<ReceivePackFactory<HttpServletRequest>>() {}).to(
|
||||
enableReceive ? ReceiveFactory.class : DisabledReceiveFactory.class);
|
||||
bind(ReceiveFilter.class);
|
||||
install(new CacheModule() {
|
||||
@Override
|
||||
@@ -119,9 +127,10 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
}
|
||||
|
||||
@Inject
|
||||
GitOverHttpServlet(Resolver resolver,
|
||||
UploadFactory upload, UploadFilter uploadFilter,
|
||||
ReceiveFactory receive, ReceiveFilter receiveFilter) {
|
||||
GitOverHttpServlet(Resolver resolver, UploadFactory upload,
|
||||
UploadFilter uploadFilter,
|
||||
ReceivePackFactory<HttpServletRequest> receive,
|
||||
ReceiveFilter receiveFilter) {
|
||||
setRepositoryResolver(resolver);
|
||||
setAsIsFileService(AsIsFileService.DISABLED);
|
||||
|
||||
@@ -308,6 +317,15 @@ public class GitOverHttpServlet extends GitServlet {
|
||||
}
|
||||
}
|
||||
|
||||
static class DisabledReceiveFactory implements
|
||||
ReceivePackFactory<HttpServletRequest> {
|
||||
@Override
|
||||
public ReceivePack create(HttpServletRequest req, Repository db)
|
||||
throws ServiceNotEnabledException {
|
||||
throw new ServiceNotEnabledException();
|
||||
}
|
||||
}
|
||||
|
||||
static class ReceiveFilter implements Filter {
|
||||
private final Cache<AdvertisedObjectsCacheKey, Set<ObjectId>> cache;
|
||||
|
||||
|
@@ -82,6 +82,36 @@ public class WebModule extends LifecycleModule {
|
||||
}
|
||||
install(new RunAsFilter.Module());
|
||||
|
||||
if (options.enableMasterFeatures()) {
|
||||
installAuthModule();
|
||||
install(new UrlModule(urlConfig, options));
|
||||
install(new UiRpcModule());
|
||||
}
|
||||
install(new GerritRequestModule());
|
||||
install(new GitOverHttpServlet.Module(options.enableMasterFeatures()));
|
||||
|
||||
bind(GitWebConfig.class).toInstance(gitWebConfig);
|
||||
if (gitWebConfig.getGitwebCGI() != null) {
|
||||
install(new GitWebModule());
|
||||
}
|
||||
|
||||
bind(ContactStore.class).toProvider(ContactStoreProvider.class).in(
|
||||
SINGLETON);
|
||||
bind(GerritConfigProvider.class);
|
||||
bind(GerritConfig.class).toProvider(GerritConfigProvider.class);
|
||||
DynamicSet.setOf(binder(), WebUiPlugin.class);
|
||||
|
||||
install(new AsyncReceiveCommits.Module());
|
||||
|
||||
bind(SocketAddress.class).annotatedWith(RemotePeer.class).toProvider(
|
||||
HttpRemotePeerProvider.class).in(RequestScoped.class);
|
||||
|
||||
bind(ProxyProperties.class).toProvider(ProxyPropertiesProvider.class);
|
||||
|
||||
listener().toInstance(registerInParentInjectors());
|
||||
}
|
||||
|
||||
private void installAuthModule() {
|
||||
switch (authConfig.getAuthType()) {
|
||||
case HTTP:
|
||||
case HTTP_LDAP:
|
||||
@@ -109,30 +139,5 @@ public class WebModule extends LifecycleModule {
|
||||
default:
|
||||
throw new ProvisionException("Unsupported loginType: " + authConfig.getAuthType());
|
||||
}
|
||||
|
||||
install(new UrlModule(urlConfig, options));
|
||||
install(new UiRpcModule());
|
||||
install(new GerritRequestModule());
|
||||
install(new GitOverHttpServlet.Module());
|
||||
|
||||
bind(GitWebConfig.class).toInstance(gitWebConfig);
|
||||
if (gitWebConfig.getGitwebCGI() != null) {
|
||||
install(new GitWebModule());
|
||||
}
|
||||
|
||||
bind(ContactStore.class).toProvider(ContactStoreProvider.class).in(
|
||||
SINGLETON);
|
||||
bind(GerritConfigProvider.class);
|
||||
bind(GerritConfig.class).toProvider(GerritConfigProvider.class);
|
||||
DynamicSet.setOf(binder(), WebUiPlugin.class);
|
||||
|
||||
install(new AsyncReceiveCommits.Module());
|
||||
|
||||
bind(SocketAddress.class).annotatedWith(RemotePeer.class).toProvider(
|
||||
HttpRemotePeerProvider.class).in(RequestScoped.class);
|
||||
|
||||
bind(ProxyProperties.class).toProvider(ProxyPropertiesProvider.class);
|
||||
|
||||
listener().toInstance(registerInParentInjectors());
|
||||
}
|
||||
}
|
||||
|
@@ -356,7 +356,7 @@ public class Daemon extends SiteProgram {
|
||||
modules.add(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritOptions.class).toInstance(new GerritOptions(headless));
|
||||
bind(GerritOptions.class).toInstance(new GerritOptions(headless, slave));
|
||||
if (test) {
|
||||
bind(SecureStore.class).toProvider(SecureStoreProvider.class);
|
||||
}
|
||||
|
@@ -310,7 +310,7 @@ public class WebAppInitializer extends GuiceServletContextListener
|
||||
modules.add(new AbstractModule() {
|
||||
@Override
|
||||
protected void configure() {
|
||||
bind(GerritOptions.class).toInstance(new GerritOptions(false));
|
||||
bind(GerritOptions.class).toInstance(new GerritOptions(false, false));
|
||||
}
|
||||
});
|
||||
modules.add(GarbageCollectionRunner.module());
|
||||
|
Reference in New Issue
Block a user