Skip to content

Commit

Permalink
Merge pull request #756 from planetscale/add-ttl
Browse files Browse the repository at this point in the history
Add ability to set password `ttl` via CLI
  • Loading branch information
mscoutermarsh authored Nov 15, 2023
2 parents 6e304db + 30b39b7 commit 39e7028
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8
github.com/pkg/errors v0.9.1
github.com/planetscale/planetscale-go v0.92.0
github.com/planetscale/planetscale-go v0.93.0
github.com/planetscale/sql-proxy v0.13.0
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.17.0
github.com/stretchr/testify v1.8.4
github.com/xelabs/go-mysqlstack v1.0.0
go.uber.org/zap v1.26.0
golang.org/x/oauth2 v0.13.0
golang.org/x/oauth2 v0.14.0
golang.org/x/sync v0.5.0
golang.org/x/sys v0.14.0
golang.org/x/text v0.14.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/sftp v1.13.1/go.mod h1:3HaPG6Dq1ILlpPZRO0HVMrsydcdLt6HRDccSgb87qRg=
github.com/planetscale/planetscale-go v0.51.0/go.mod h1:+rGpW2u7iQZZx4O/nFj4MZe4xIS22CVegEgl1IkTExQ=
github.com/planetscale/planetscale-go v0.92.0 h1:ifrZCSifooYuM2bG4v+RH34H2MeHQg5m+lu65EtZ9Bw=
github.com/planetscale/planetscale-go v0.92.0/go.mod h1:fZZ8IJEB1IMrQCt3eo7D4E+hx5zt8mM3z8/aL/p1fiA=
github.com/planetscale/planetscale-go v0.93.0 h1:cogKCS4pEbHqurZWiPROaEAo16ZEPmRTSdd2IZioa8A=
github.com/planetscale/planetscale-go v0.93.0/go.mod h1:MR+LZLhZTIzmi2x91nwLQyIedMFhn6sgQDAKs0wAGNQ=
github.com/planetscale/sql-proxy v0.13.0 h1:NDjcdqgoNzwbZQTyoIDEoI+K7keC5RRKvdML2roAMn4=
github.com/planetscale/sql-proxy v0.13.0/go.mod h1:4Sk6JdoBqQhHv9V4FCOC27YIM3EjU8cLIsw5HqxN8x4=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
Expand Down Expand Up @@ -392,8 +392,8 @@ golang.org/x/oauth2 v0.0.0-20200902213428-5d25da1a8d43/go.mod h1:KelEdhl1UZF7XfJ
golang.org/x/oauth2 v0.0.0-20201109201403-9fd604954f58/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20201208152858-08078c50e5b5/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.0.0-20210218202405-ba52d332ba99/go.mod h1:KelEdhl1UZF7XfJ4dDtk6s++YSgaE7mD/BuKKDLBl4A=
golang.org/x/oauth2 v0.13.0 h1:jDDenyj+WgFtmV3zYVoi8aE2BwtXFLWOA67ZfNWftiY=
golang.org/x/oauth2 v0.13.0/go.mod h1:/JMhi4ZRXAf4HG9LiNmxvk+45+96RUlVThiH8FzNBn0=
golang.org/x/oauth2 v0.14.0 h1:P0Vrf/2538nmC0H+pEQ3MNFRRnVR7RlqyVw+bvm26z0=
golang.org/x/oauth2 v0.14.0/go.mod h1:lAtNWgaWfL4cm7j2OV8TxGi9Qb7ECORx8DktCY74OwM=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
1 change: 1 addition & 0 deletions internal/cmd/password/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,6 @@ func CreateCmd(ch *cmdutil.Helper) *cobra.Command {
}
cmd.PersistentFlags().StringVar(&flags.role, "role",
"admin", "Role defines the access level, allowed values are : reader, writer, readwriter, admin. By default it is admin.")
cmd.PersistentFlags().IntVar(&createReq.TTL, "ttl", 0, "TTL defines the time to live for the password in seconds. By default it is 0 which means it will never expire.")
return cmd
}
4 changes: 4 additions & 0 deletions internal/cmd/password/password.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Password struct {
Username string `header:"username" json:"username"`
Role string `header:"role" json:"role"`
RoleDesc string `header:"role description" json:"-"`
TTL int `header:"ttl" json:"ttl"`
CreatedAt int64 `json:"created_at"`
orig *ps.DatabaseBranchPassword
}
Expand All @@ -52,6 +53,7 @@ type PasswordWithPlainText struct {
Role string `header:"role" json:"role"`
RoleDesc string `header:"role description" json:"role_description"`
PlainText string `header:"password" json:"password"`
TTL int `header:"ttl" json:"ttl"`
ConnectionStrings ps.ConnectionStrings `json:"connection_strings"`
orig *ps.DatabaseBranchPassword
}
Expand Down Expand Up @@ -87,6 +89,7 @@ func toPassword(password *ps.DatabaseBranchPassword) *Password {
Username: password.Username,
Role: password.Role,
RoleDesc: toRoleDesc(password.Role),
TTL: password.TTL,
CreatedAt: password.CreatedAt.UTC().UnixNano() / (int64(time.Millisecond) / int64(time.Nanosecond)),
orig: password,
}
Expand All @@ -110,6 +113,7 @@ func toPasswordWithPlainText(password *ps.DatabaseBranchPassword) *PasswordWithP
AccessHostUrl: password.Branch.AccessHostURL,
Role: password.Role,
RoleDesc: toRoleDesc(password.Role),
TTL: password.TTL,
ConnectionStrings: password.ConnectionStrings,
orig: password,
}
Expand Down

0 comments on commit 39e7028

Please sign in to comment.