[Libreoffice-commits] online.git: tools/Config.cpp

Ashod Nakashian (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 17 02:29:07 UTC 2019


 tools/Config.cpp |   30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)

New commits:
commit 159e6d0f7288cb44b81ab72c9f3c99dfb69f4f4c
Author:     Ashod Nakashian <ashod.nakashian at collabora.co.uk>
AuthorDate: Mon Apr 1 00:13:03 2019 -0400
Commit:     Ashod Nakashian <ashnakash at gmail.com>
CommitDate: Sat Aug 17 04:28:49 2019 +0200

    looltool: support anonymizing strings
    
    The user is able to override the salt,
    or use the one from the config file.
    
    Change-Id: Ida634374549fb490ec2437f557d46c44d4760c56
    Reviewed-on: https://gerrit.libreoffice.org/70036
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>
    Reviewed-on: https://gerrit.libreoffice.org/71094

diff --git a/tools/Config.cpp b/tools/Config.cpp
index 3bffb0ddc..2cf45ac3f 100644
--- a/tools/Config.cpp
+++ b/tools/Config.cpp
@@ -74,6 +74,8 @@ public:
     static std::string ConfigFile;
     static std::string SupportKeyString;
     static bool SupportKeyStringProvided;
+    static std::uint64_t AnonymizationSalt;
+    static bool AnonymizationSaltProvided;
 
 protected:
     void defineOptions(OptionSet&) override;
@@ -91,6 +93,8 @@ std::string Config::ConfigFile =
 
 std::string Config::SupportKeyString;
 bool Config::SupportKeyStringProvided = false;
+std::uint64_t Config::AnonymizationSalt = 0;
+bool Config::AnonymizationSaltProvided = false;
 
 void Config::displayHelp()
 {
@@ -107,6 +111,7 @@ void Config::displayHelp()
     // Command list
     std::cout << std::endl
               << "Commands: " << std::endl
+              << "    anonymize [string-1]...[string-n]" << std::endl
               << "    set-admin-password" << std::endl
 #if ENABLE_SUPPORT_KEY
               << "    set-support-key" << std::endl
@@ -146,6 +151,11 @@ void Config::defineOptions(OptionSet& optionSet)
                         .repeatable(false)
                         .argument("key"));
 #endif
+
+    optionSet.addOption(Option("anonymization-salt", "", "Anonymize strings with the given 64-bit salt instead of the one in the config file.")
+                        .required(false)
+                        .repeatable(false)
+                        .argument("salt"));
 }
 
 void Config::handleOption(const std::string& optionName, const std::string& optionValue)
@@ -195,6 +205,12 @@ void Config::handleOption(const std::string& optionName, const std::string& opti
         SupportKeyString = optionValue;
         SupportKeyStringProvided = true;
     }
+    else if (optionName == "anonymization-salt")
+    {
+        AnonymizationSalt = std::stoull(optionValue);
+        AnonymizationSaltProvided = true;
+        std::cout << "Anonymization Salt: [" << AnonymizationSalt << "]." << std::endl;
+    }
 }
 
 int Config::main(const std::vector<std::string>& args)
@@ -354,6 +370,20 @@ int Config::main(const std::vector<std::string>& args)
         if (retval != 0)
             std::cerr << "Error when executing command." << std::endl;
     }
+    else if (args[0] == "anonymize")
+    {
+        if (!AnonymizationSaltProvided)
+        {
+            const std::string val = _loolConfig.getString("logging.anonymize.anonymization_salt");
+            AnonymizationSalt = std::stoull(val);
+            std::cout << "Anonymization Salt: [" << AnonymizationSalt << "]." << std::endl;
+        }
+
+        for (std::size_t i = 1; i < args.size(); ++i)
+        {
+            std::cout << "[" << args[i] << "]: " << Util::anonymizeUrl(args[i], AnonymizationSalt) << std::endl;
+        }
+    }
     else
     {
         std::cerr << "No such command, \"" << args[0]  << "\"" << std::endl;


More information about the Libreoffice-commits mailing list