@@ -100,6 +100,8 @@ public class TypeDBConsole {
100100 private static final Path TRANSACTION_HISTORY_FILE =
101101 Paths .get (System .getProperty ("user.home" ), ".typedb-console-transaction-repl-history" ).toAbsolutePath ();
102102 private static final Logger LOG = LoggerFactory .getLogger (TypeDBConsole .class );
103+
104+ private static final int PASSWORD_EXPIRY_WARN_DAYS = 7 ;
103105 private static final int ONE_HOUR_IN_MILLIS = 60 * 60 * 1000 ;
104106
105107 private final Printer printer ;
@@ -195,8 +197,17 @@ private void runREPLMode(CLIOptions options) {
195197 runUserList (client );
196198 } else if (command .isUserCreate ()) {
197199 runUserCreate (client , command .asUserCreate ().user (), command .asUserCreate ().password ());
198- } else if (command .isUserPassword ()) {
199- runUserPassword (client , command .asUserPassword ().user (), command .asUserPassword ().password ());
200+ } else if (command .isUserPasswordUpdate ()) {
201+ REPLCommand .User .PasswordUpdate userPasswordUpdate = command .asUserPasswordUpdate ();
202+ runUserPasswordUpdate (client ,
203+ options .username ,
204+ userPasswordUpdate .passwordOld (),
205+ userPasswordUpdate .passwordNew ());
206+ } else if (command .isUserPasswordSet ()) {
207+ REPLCommand .User .PasswordSet userPasswordSet = command .asUserPasswordSet ();
208+ runUserPasswordSet (client ,
209+ userPasswordSet .user (),
210+ userPasswordSet .password ());
200211 } else if (command .isUserDelete ()) {
201212 runUserDelete (client , command .asUserDelete ().user ());
202213 } else if (command .isDatabaseList ()) {
@@ -256,7 +267,8 @@ private Completers.TreeCompleter getCompleter(TypeDBClient client) {
256267 nodes .add (node (REPLCommand .User .token ,
257268 node (REPLCommand .User .List .token ),
258269 node (REPLCommand .User .Create .token ),
259- node (REPLCommand .User .Password .token ),
270+ node (REPLCommand .User .PasswordUpdate .token ),
271+ node (REPLCommand .User .PasswordSet .token ),
260272 node (REPLCommand .User .Delete .token ,
261273 node (userNameCompleter ))
262274 ));
@@ -444,6 +456,10 @@ private TypeDBClient createTypeDBClient(CLIOptions options) {
444456 String optCluster = options .cluster ();
445457 if (optCluster != null ) {
446458 client = TypeDB .clusterClient (set (optCluster .split ("," )), createTypeDBCredential (options ));
459+ Optional <Long > passwordExpiryDays = client .asCluster ().users ().get (options .username ).passwordExpiryDays ();
460+ if (passwordExpiryDays .isPresent () && passwordExpiryDays .get () <= PASSWORD_EXPIRY_WARN_DAYS ) {
461+ printer .info ("Your password will expire in " + passwordExpiryDays .get () + " days." );
462+ }
447463 } else {
448464 client = TypeDB .coreClient (TypeDB .DEFAULT_ADDRESS );
449465 }
@@ -486,47 +502,68 @@ private boolean runUserList(TypeDBClient client) {
486502 }
487503 }
488504
489- private boolean runUserCreate (TypeDBClient client , String user , String password ) {
505+ private boolean runUserCreate (TypeDBClient client , String username , String password ) {
490506 try {
491507 if (!client .isCluster ()) {
492508 printer .error ("The command 'user create' is only available in TypeDB Cluster." );
493509 return false ;
494510 }
495511 TypeDBClient .Cluster clientCluster = client .asCluster ();
496- clientCluster .users ().create (user , password );
497- printer .info ("User '" + user + "' created" );
512+ clientCluster .users ().create (username , password );
513+ printer .info ("User '" + username + "' created" );
498514 return true ;
499515 } catch (TypeDBClientException e ) {
500516 printer .error (e .getMessage ());
501517 return false ;
502518 }
503519 }
504520
505- private boolean runUserPassword (TypeDBClient client , String user , String password ) {
521+ private boolean runUserPasswordUpdate (TypeDBClient client , String username , String passwordOld , String passwordNew ) {
506522 try {
507523 if (!client .isCluster ()) {
508- printer .error ("The command 'user update' is only available in TypeDB Cluster." );
524+ printer .error ("The command 'user password- update' is only available in TypeDB Cluster." );
509525 return false ;
510526 }
511527 TypeDBClient .Cluster clientCluster = client .asCluster ();
512- clientCluster .users ().passwordSet ( user , password );
513- printer .info ("Updated password for user '" + user + "'" );
528+ clientCluster .users ().get ( username ). passwordUpdate ( passwordOld , passwordNew );
529+ printer .info ("Updated password for user '" + username + "'" );
514530 return true ;
515531 } catch (TypeDBClientException e ) {
516532 printer .error (e .getMessage ());
517533 return false ;
518534 }
519535 }
520536
521- private boolean runUserDelete (TypeDBClient client , String user ) {
537+ private boolean runUserPasswordSet (TypeDBClient client , String username , String password ) {
538+ try {
539+ if (!client .isCluster ()) {
540+ printer .error ("The command 'user password-set' is only available in TypeDB Cluster." );
541+ return false ;
542+ }
543+ TypeDBClient .Cluster clientCluster = client .asCluster ();
544+ if (clientCluster .users ().contains (username )) {
545+ clientCluster .users ().passwordSet (username , password );
546+ printer .info ("Set password for user '" + username + "'" );
547+ return true ;
548+ } else {
549+ printer .info ("No such user '" + username + "'" );
550+ return false ;
551+ }
552+ } catch (TypeDBClientException e ) {
553+ printer .error (e .getMessage ());
554+ return false ;
555+ }
556+ }
557+
558+ private boolean runUserDelete (TypeDBClient client , String username ) {
522559 try {
523560 if (!client .isCluster ()) {
524561 printer .error ("The command 'user delete' is only available in TypeDB Cluster." );
525562 return false ;
526563 }
527564 TypeDBClient .Cluster clientCluster = client .asCluster ();
528- clientCluster .users ().delete (user );
529- printer .info ("User '" + user + "' deleted" );
565+ clientCluster .users ().delete (username );
566+ printer .info ("User '" + username + "' deleted" );
530567 return true ;
531568 } catch (TypeDBClientException e ) {
532569 printer .error (e .getMessage ());
0 commit comments