@@ -104,7 +104,8 @@ enum {
104104 OPT_DEBUG_TLS,
105105 OPT_API_VERSION,
106106 OPT_MEMORY,
107- OPT_USE_FUTURE_PROTOCOL_VERSION
107+ OPT_USE_FUTURE_PROTOCOL_VERSION,
108+ OPT_ENCRYPT
108109};
109110
110111CSimpleOpt::SOption g_rgOptions[] = { { OPT_CONNFILE, " -C" , SO_REQ_SEP },
@@ -130,6 +131,7 @@ CSimpleOpt::SOption g_rgOptions[] = { { OPT_CONNFILE, "-C", SO_REQ_SEP },
130131 { OPT_API_VERSION, " --api-version" , SO_REQ_SEP },
131132 { OPT_MEMORY, " --memory" , SO_REQ_SEP },
132133 { OPT_USE_FUTURE_PROTOCOL_VERSION, " --use-future-protocol-version" , SO_NONE },
134+ { OPT_ENCRYPT, " --encrypt" , SO_REQ_SEP },
133135 TLS_OPTION_FLAGS,
134136 SO_END_OF_OPTIONS };
135137
@@ -503,6 +505,11 @@ static void printProgramUsage(const char* name) {
503505 " --use-future-protocol-version\n "
504506 " Use the simulated future protocol version to connect to the cluster.\n "
505507 " This option can be used testing purposes only!\n "
508+ " --encrypt PASSWORD\n "
509+ " Encrypts the specified password and prints the encrypted password\n "
510+ " with the `encrypted:' prefix. The encrypted password can be used\n "
511+ " with --tls-password option. This option causes fdbcli to encrypt\n "
512+ " the password and exit.\n "
506513 " -v, --version Print FoundationDB CLI version information and exit.\n "
507514 " -h, --help Display this help and exit.\n " );
508515}
@@ -899,7 +906,6 @@ void LogCommand(std::string line, UID randomID, std::string errMsg) {
899906 printf (" %s\n " , errMsg.c_str ());
900907 TraceEvent (SevInfo, " CLICommandLog" , randomID).detail (" Command" , line).detail (" Error" , errMsg);
901908}
902-
903909struct CLIOptions {
904910 std::string program_name;
905911 int exit_code = -1 ;
@@ -923,6 +929,7 @@ struct CLIOptions {
923929 std::string tlsCAPath;
924930 std::string tlsPassword;
925931 uint64_t memLimit = 8uLL << 30 ;
932+ Optional<std::string> encrypt;
926933
927934 std::vector<std::pair<std::string, std::string>> knobs;
928935
@@ -1062,6 +1069,9 @@ struct CLIOptions {
10621069 knobs.emplace_back (knobName.get (), args.OptionArg ());
10631070 break ;
10641071 }
1072+ case OPT_ENCRYPT:
1073+ encrypt = args.OptionArg ();
1074+ break ;
10651075 case OPT_DEBUG_TLS:
10661076 debugTLS = true ;
10671077 break ;
@@ -2385,6 +2395,16 @@ int main(int argc, char** argv) {
23852395 if (opt.exit_code != -1 )
23862396 return opt.exit_code ;
23872397
2398+ if (opt.encrypt .present ()) {
2399+ std::string encrypted;
2400+ if (!TLSConfig::encodePassword (opt.encrypt .get (), encrypted)) {
2401+ fprintf (stderr, " ERROR: Failed to encrypt password\n " );
2402+ return 1 ;
2403+ }
2404+ printf (" %s\n " , encrypted.c_str ());
2405+ return 0 ;
2406+ }
2407+
23882408 if (opt.trace ) {
23892409 if (opt.traceDir .empty ())
23902410 setNetworkOption (FDBNetworkOptions::TRACE_ENABLE);
0 commit comments