planetscale / cli

The CLI for PlanetScale Database
https://planetscale.com/cli
Apache License 2.0
604 stars 51 forks source link

cmd/password: Add support for renewing an existing password #815

Closed mattrobenolt closed 10 months ago

mattrobenolt commented 10 months ago

Depends on https://github.com/planetscale/planetscale-go/pull/193

$ ./pscale password list mattdb
  ID             NAME                     BRANCH   USERNAME               ROLE     ROLE DESCRIPTION               TTL   TTL REMAINING   EXPIRED
 -------------- ------------------------ -------- ---------------------- -------- ------------------------------ ----- --------------- ---------
  jxsungtbhk3g   test-ttl                 main     m51veb3195rn79uoa4zm   reader   Can Read                        60              36   No
  oddkvx4zj8y9   main-2023-11-11-e6qg9j   main     cc7elecd13x7gokz30sh   admin    Can Read, Write & Administer     0               0   No

We can renew our expiring password:

$ ./pscale password renew mattdb main jxsungtbhk3g
Password jxsungtbhk3g was successfully renewed from main.
  RESULT             PASSWORD ID    USERNAME               BRANCH
 ------------------ -------------- ---------------------- --------
  password renewed   jxsungtbhk3g   m51veb3195rn79uoa4zm   main

Now view it again:

$ ./pscale password list mattdb
  ID             NAME                     BRANCH   USERNAME               ROLE     ROLE DESCRIPTION               TTL   TTL REMAINING   EXPIRED
 -------------- ------------------------ -------- ---------------------- -------- ------------------------------ ----- --------------- ---------
  jxsungtbhk3g   test-ttl                 main     m51veb3195rn79uoa4zm   reader   Can Read                        60              56   No
  oddkvx4zj8y9   main-2023-11-11-e6qg9j   main     cc7elecd13x7gokz30sh   admin    Can Read, Write & Administer     0               0   No

Wait for it to expire:

$ ./pscale password list mattdb
  ID             NAME                     BRANCH   USERNAME               ROLE     ROLE DESCRIPTION               TTL   TTL REMAINING   EXPIRED
 -------------- ------------------------ -------- ---------------------- -------- ------------------------------ ----- --------------- ---------
  jxsungtbhk3g   test-ttl                 main     m51veb3195rn79uoa4zm   reader   Can Read                        60               0   Yes
  oddkvx4zj8y9   main-2023-11-11-e6qg9j   main     cc7elecd13x7gokz30sh   admin    Can Read, Write & Administer     0               0   No

Now try to renew it again, and it fails as expected:

$ ./pscale password renew mattdb main jxsungtbhk3g
Error: This password is expired and cannot be renewed. Please create a new password.