LCOV - code coverage report
Current view: top level - sshd/commands - DefaultCommandModule.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 81 81 100.0 %
Date: 2022-11-19 15:00:39 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (C) 2009 The Android Open Source Project
       2             : //
       3             : // Licensed under the Apache License, Version 2.0 (the "License");
       4             : // you may not use this file except in compliance with the License.
       5             : // You may obtain a copy of the License at
       6             : //
       7             : // http://www.apache.org/licenses/LICENSE-2.0
       8             : //
       9             : // Unless required by applicable law or agreed to in writing, software
      10             : // distributed under the License is distributed on an "AS IS" BASIS,
      11             : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12             : // See the License for the specific language governing permissions and
      13             : // limitations under the License.
      14             : 
      15             : package com.google.gerrit.sshd.commands;
      16             : 
      17             : import com.google.gerrit.entities.CoreDownloadSchemes;
      18             : import com.google.gerrit.server.config.DownloadConfig;
      19             : import com.google.gerrit.sshd.CommandModule;
      20             : import com.google.gerrit.sshd.CommandName;
      21             : import com.google.gerrit.sshd.Commands;
      22             : import com.google.gerrit.sshd.DispatchCommandProvider;
      23             : import com.google.gerrit.sshd.SuExec;
      24             : import com.google.gerrit.sshd.plugin.LfsPluginAuthCommand.LfsPluginAuthCommandModule;
      25             : 
      26             : /** Register the commands a Gerrit server supports. */
      27             : public class DefaultCommandModule extends CommandModule {
      28             :   private final DownloadConfig downloadConfig;
      29             :   private final LfsPluginAuthCommandModule lfsPluginAuthModule;
      30             : 
      31             :   public DefaultCommandModule(
      32          17 :       boolean slave, DownloadConfig downloadCfg, LfsPluginAuthCommandModule module) {
      33          17 :     slaveMode = slave;
      34          17 :     downloadConfig = downloadCfg;
      35          17 :     lfsPluginAuthModule = module;
      36          17 :   }
      37             : 
      38             :   @Override
      39             :   protected void configure() {
      40          17 :     CommandName git = Commands.named("git");
      41          17 :     CommandName gerrit = Commands.named("gerrit");
      42          17 :     CommandName logging = Commands.named(gerrit, "logging");
      43          17 :     CommandName plugin = Commands.named(gerrit, "plugin");
      44          17 :     CommandName testSubmit = Commands.named(gerrit, "test-submit");
      45             : 
      46          17 :     command(gerrit).toProvider(new DispatchCommandProvider(gerrit));
      47          17 :     command(gerrit, AproposCommand.class);
      48          17 :     command(gerrit, BanCommitCommand.class);
      49          17 :     command(gerrit, CheckProjectAccessCommand.class);
      50          17 :     command(gerrit, CloseConnection.class);
      51          17 :     command(gerrit, ConvertRefStorage.class);
      52          17 :     command(gerrit, FlushCaches.class);
      53          17 :     command(gerrit, ListProjectsCommand.class);
      54          17 :     command(gerrit, ListMembersCommand.class);
      55          17 :     command(gerrit, ListGroupsCommand.class);
      56          17 :     command(gerrit, LsUserRefs.class);
      57          17 :     command(gerrit, Query.class);
      58          17 :     command(gerrit, ReloadConfig.class);
      59          17 :     command(gerrit, ShowCaches.class);
      60          17 :     command(gerrit, ShowConnections.class);
      61          17 :     command(gerrit, ShowQueue.class);
      62          17 :     command(gerrit, StreamEvents.class);
      63          17 :     command(gerrit, VersionCommand.class);
      64          17 :     command(gerrit, GarbageCollectionCommand.class);
      65             : 
      66          17 :     command(gerrit, "plugin").toProvider(new DispatchCommandProvider(plugin));
      67          17 :     command(plugin, PluginLsCommand.class);
      68          17 :     command(plugin, PluginEnableCommand.class);
      69          17 :     command(plugin, PluginInstallCommand.class);
      70          17 :     command(plugin, PluginReloadCommand.class);
      71          17 :     command(plugin, PluginRemoveCommand.class);
      72          17 :     alias(plugin, "add", PluginInstallCommand.class);
      73          17 :     alias(plugin, "rm", PluginRemoveCommand.class);
      74             : 
      75          17 :     command(git).toProvider(new DispatchCommandProvider(git));
      76             : 
      77          17 :     command("ps").to(ShowQueue.class);
      78          17 :     command("kill").to(KillCommand.class);
      79          17 :     command("scp").to(ScpCommand.class);
      80             : 
      81             :     // Honor the legacy hyphenated forms as aliases for the non-hyphenated forms
      82          17 :     if (sshEnabled()) {
      83          17 :       command("git-upload-pack").to(Commands.key(git, "upload-pack"));
      84          17 :       command(git, "upload-pack").to(Upload.class);
      85          17 :       command("git-upload-archive").to(Commands.key(git, "upload-archive"));
      86          17 :       command(git, "upload-archive").to(UploadArchive.class);
      87          17 :       if (slaveMode) {
      88           1 :         command("git-receive-pack").to(ReceiveSlaveMode.class);
      89           1 :         command("gerrit-receive-pack").to(ReceiveSlaveMode.class);
      90           1 :         command(git, "receive-pack").to(ReceiveSlaveMode.class);
      91             :       } else {
      92          17 :         command("git-receive-pack").to(Commands.key(git, "receive-pack"));
      93          17 :         command("gerrit-receive-pack").to(Commands.key(git, "receive-pack"));
      94          17 :         command(git, "receive-pack").to(Commands.key(gerrit, "receive-pack"));
      95             :       }
      96             :     }
      97             : 
      98          17 :     if (!slaveMode) {
      99          17 :       command(gerrit, "test-submit").toProvider(new DispatchCommandProvider(testSubmit));
     100             :     }
     101          17 :     command("suexec").to(SuExec.class);
     102          17 :     listener().to(ShowCaches.StartupListener.class);
     103             : 
     104          17 :     command(gerrit, CreateAccountCommand.class);
     105          17 :     command(gerrit, CreateGroupCommand.class);
     106          17 :     command(gerrit, CreateProjectCommand.class);
     107          17 :     command(gerrit, SetHeadCommand.class);
     108             : 
     109          17 :     command(gerrit, Receive.class);
     110             : 
     111          17 :     command(gerrit, RenameGroupCommand.class);
     112          17 :     command(gerrit, ReviewCommand.class);
     113          17 :     command(gerrit, SetProjectCommand.class);
     114          17 :     command(gerrit, SetReviewersCommand.class);
     115          17 :     command(gerrit, SetTopicCommand.class);
     116             : 
     117          17 :     command(gerrit, SetMembersCommand.class);
     118          17 :     command(gerrit, CreateBranchCommand.class);
     119          17 :     command(gerrit, SetAccountCommand.class);
     120          17 :     command(gerrit, SetParentCommand.class);
     121             : 
     122          17 :     command(testSubmit, TestSubmitRuleCommand.class);
     123          17 :     command(testSubmit, TestSubmitTypeCommand.class);
     124             : 
     125          17 :     command(logging).toProvider(new DispatchCommandProvider(logging));
     126          17 :     command(logging, SetLoggingLevelCommand.class);
     127          17 :     command(logging, ListLoggingLevelCommand.class);
     128          17 :     alias(logging, "ls", ListLoggingLevelCommand.class);
     129          17 :     alias(logging, "set", SetLoggingLevelCommand.class);
     130             : 
     131          17 :     install(lfsPluginAuthModule);
     132          17 :   }
     133             : 
     134             :   private boolean sshEnabled() {
     135          17 :     return downloadConfig.getDownloadSchemes().contains(CoreDownloadSchemes.SSH);
     136             :   }
     137             : }

Generated by: LCOV version 1.16+git.20220603.dfeb750