@@ -105,7 +105,8 @@ enum {
105105 OPT_DEBUG_TLS,
106106 OPT_API_VERSION,
107107 OPT_MEMORY,
108- OPT_USE_FUTURE_PROTOCOL_VERSION
108+ OPT_USE_FUTURE_PROTOCOL_VERSION,
109+ OPT_ENCRYPT
109110};
110111
111112CSimpleOpt::SOption g_rgOptions[] = { { OPT_CONNFILE, " -C" , SO_REQ_SEP },
@@ -132,6 +133,7 @@ CSimpleOpt::SOption g_rgOptions[] = { { OPT_CONNFILE, "-C", SO_REQ_SEP },
132133 { OPT_API_VERSION, " --api-version" , SO_REQ_SEP },
133134 { OPT_MEMORY, " --memory" , SO_REQ_SEP },
134135 { OPT_USE_FUTURE_PROTOCOL_VERSION, " --use-future-protocol-version" , SO_NONE },
136+ { OPT_ENCRYPT, " --encrypt" , SO_REQ_SEP },
135137 TLS_OPTION_FLAGS,
136138 SO_END_OF_OPTIONS };
137139
@@ -506,6 +508,11 @@ static void printProgramUsage(const char* name) {
506508 " --use-future-protocol-version\n "
507509 " Use the simulated future protocol version to connect to the cluster.\n "
508510 " This option can be used testing purposes only!\n "
511+ " --encrypt PASSWORD\n "
512+ " Encrypts the specified password and prints the encrypted password\n "
513+ " with the `encrypted:' prefix. The encrypted password can be used\n "
514+ " with --tls-password option. This option causes fdbcli to encrypt\n "
515+ " the password and exit.\n "
509516 " -v, --version Print FoundationDB CLI version information and exit.\n "
510517 " -h, --help Display this help and exit.\n " );
511518}
@@ -906,7 +913,6 @@ void LogCommand(std::string line, UID randomID, std::string errMsg) {
906913 printf (" %s\n " , errMsg.c_str ());
907914 TraceEvent (SevInfo, " CLICommandLog" , randomID).detail (" Command" , line).detail (" Error" , errMsg);
908915}
909-
910916struct CLIOptions {
911917 std::string program_name;
912918 int exit_code = -1 ;
@@ -932,6 +938,7 @@ struct CLIOptions {
932938 std::string tlsPassword;
933939 bool tlsDisablePlainTextConnection = false ;
934940 uint64_t memLimit = 8uLL << 30 ;
941+ Optional<std::string> encrypt;
935942
936943 std::vector<std::pair<std::string, std::string>> knobs;
937944
@@ -1077,6 +1084,9 @@ struct CLIOptions {
10771084 knobs.emplace_back (knobName.get (), args.OptionArg ());
10781085 break ;
10791086 }
1087+ case OPT_ENCRYPT:
1088+ encrypt = args.OptionArg ();
1089+ break ;
10801090 case OPT_DEBUG_TLS:
10811091 debugTLS = true ;
10821092 break ;
@@ -2430,6 +2440,16 @@ int main(int argc, char** argv) {
24302440 if (opt.exit_code != -1 )
24312441 return opt.exit_code ;
24322442
2443+ if (opt.encrypt .present ()) {
2444+ std::string encrypted;
2445+ if (!TLSConfig::encodePassword (opt.encrypt .get (), encrypted)) {
2446+ fprintf (stderr, " ERROR: Failed to encrypt password\n " );
2447+ return 1 ;
2448+ }
2449+ printf (" %s\n " , encrypted.c_str ());
2450+ return 0 ;
2451+ }
2452+
24332453 if (opt.trace ) {
24342454 if (opt.traceDir .empty ())
24352455 setNetworkOption (FDBNetworkOptions::TRACE_ENABLE);
0 commit comments