LCOV - code coverage report
Current view: top level - sshd/commands - ExternalIdCaseSensitivityMigrationCommand.java (source / functions) Hit Total Coverage
Test: _coverage_report.dat Lines: 1 10 10.0 %
Date: 2022-11-19 15:00:39 Functions: 1 2 50.0 %

          Line data    Source code
       1             : // Copyright (C) 2021 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.common.data.GlobalCapability;
      18             : import com.google.gerrit.extensions.annotations.RequiresCapability;
      19             : import com.google.gerrit.server.account.externalids.OnlineExternalIdCaseSensivityMigrator;
      20             : import com.google.gerrit.server.config.GerritServerConfig;
      21             : import com.google.gerrit.sshd.CommandMetaData;
      22             : import com.google.gerrit.sshd.SshCommand;
      23             : import com.google.inject.Inject;
      24             : import org.eclipse.jgit.lib.Config;
      25             : 
      26             : @RequiresCapability(GlobalCapability.ADMINISTRATE_SERVER)
      27             : @CommandMetaData(
      28             :     name = "migrate-externalids-to-insensitive",
      29             :     description = "Migrate external-ids to case insensitive")
      30           1 : public class ExternalIdCaseSensitivityMigrationCommand extends SshCommand {
      31             : 
      32             :   @Inject OnlineExternalIdCaseSensivityMigrator onlineExternalIdCaseSensivityMigrator;
      33             :   @Inject @GerritServerConfig private Config globalConfig;
      34             : 
      35             :   @Override
      36             :   public void run() throws UnloggedFailure, Failure, Exception {
      37           0 :     Boolean isUserNameCaseInsensitiveMigrationMode =
      38           0 :         globalConfig.getBoolean("auth", "userNameCaseInsensitiveMigrationMode", false);
      39           0 :     Boolean isUserNameCaseInsensitive =
      40           0 :         globalConfig.getBoolean("auth", "userNameCaseInsensitive", false);
      41             : 
      42           0 :     if (!isUserNameCaseInsensitive || !isUserNameCaseInsensitiveMigrationMode) {
      43           0 :       die(
      44             :           "External IDs online migration requires auth.userNameCaseInsensitive and"
      45             :               + " auth.userNameCaseInsensitiveMigrationMode to be set to true. Cannot start"
      46             :               + " migration!");
      47             :     }
      48           0 :     onlineExternalIdCaseSensivityMigrator.migrate();
      49           0 :     stdout.println(
      50             :         "External ids case insensitivity migration started. To check if it's completed look for"
      51             :             + " \"External IDs migration completed!\" message in the Gerrit server logs");
      52           0 :   }
      53             : }

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