Remove old commands

This commit is contained in:
Torjus Håkestad 2021-12-08 06:54:51 +01:00
parent 10ab3950d3
commit 98a2a1cc50
4 changed files with 88 additions and 102 deletions

View File

@ -87,3 +87,71 @@ func ActionAdminUploadBinary(c *cli.Context) error {
}
return nil
}
func ActionAdminCertList(c *cli.Context) error {
cfg, err := getConfig(c)
if err != nil {
return err
}
addr := cfg.Client.DefaultServer
if c.IsSet("addr") {
addr = c.String("addr")
}
clientCreds, err := cfg.Client.Creds()
if err != nil {
return err
}
conn, err := grpc.DialContext(c.Context, addr, grpc.WithTransportCredentials(clientCreds))
if err != nil {
return err
}
defer conn.Close()
client := pb.NewCertificateServiceClient(conn)
resp, err := client.ListCertificates(c.Context, &pb.Empty{})
if err != nil {
return cli.Exit(fmt.Sprintf("unable to list certificates: %s", err), 1)
}
for _, info := range resp.Certificates {
fmt.Printf("%s - %s", info.Serial, info.OwnerUsername)
}
return nil
}
func ActionAdminCertRevoke(c *cli.Context) error {
if c.Args().Len() < 1 {
return cli.Exit("need at least 1 argument", 1)
}
cfg, err := getConfig(c)
if err != nil {
return err
}
addr := cfg.Client.DefaultServer
if c.IsSet("addr") {
addr = c.String("addr")
}
clientCreds, err := cfg.Client.Creds()
if err != nil {
return err
}
conn, err := grpc.DialContext(c.Context, addr, grpc.WithTransportCredentials(clientCreds))
if err != nil {
return err
}
defer conn.Close()
client := pb.NewCertificateServiceClient(conn)
for _, serial := range c.Args().Slice() {
if _, err := client.RevokeCertificate(c.Context, &pb.RevokeCertificateRequest{Serial: serial}); err != nil {
fmt.Printf("Revoked %s\n", serial)
}
}
return nil
}

View File

@ -361,7 +361,7 @@ func ActionClientLogin(c *cli.Context) error {
return nil
}
func ActionClientChangePassword(c *cli.Context) error {
func ActionClientPassword(c *cli.Context) error {
cfg, err := getConfig(c)
if err != nil {
return err
@ -405,74 +405,6 @@ func ActionClientChangePassword(c *cli.Context) error {
return nil
}
func ActionClientCertList(c *cli.Context) error {
cfg, err := getConfig(c)
if err != nil {
return err
}
addr := cfg.Client.DefaultServer
if c.IsSet("addr") {
addr = c.String("addr")
}
clientCreds, err := cfg.Client.Creds()
if err != nil {
return err
}
conn, err := grpc.DialContext(c.Context, addr, grpc.WithTransportCredentials(clientCreds))
if err != nil {
return err
}
defer conn.Close()
client := pb.NewCertificateServiceClient(conn)
resp, err := client.ListCertificates(c.Context, &pb.Empty{})
if err != nil {
return cli.Exit(fmt.Sprintf("unable to list certificates: %s", err), 1)
}
for _, info := range resp.Certificates {
fmt.Printf("%s - %s", info.Serial, info.OwnerUsername)
}
return nil
}
func ActionClientCertRevoke(c *cli.Context) error {
if c.Args().Len() < 1 {
return cli.Exit("need at least 1 argument", 1)
}
cfg, err := getConfig(c)
if err != nil {
return err
}
addr := cfg.Client.DefaultServer
if c.IsSet("addr") {
addr = c.String("addr")
}
clientCreds, err := cfg.Client.Creds()
if err != nil {
return err
}
conn, err := grpc.DialContext(c.Context, addr, grpc.WithTransportCredentials(clientCreds))
if err != nil {
return err
}
defer conn.Close()
client := pb.NewCertificateServiceClient(conn)
for _, serial := range c.Args().Slice() {
if _, err := client.RevokeCertificate(c.Context, &pb.RevokeCertificateRequest{Serial: serial}); err != nil {
fmt.Printf("Revoked %s\n", serial)
}
}
return nil
}
func ActionClientUpdate(c *cli.Context) error {
cfg, err := getConfig(c)
if err != nil {

View File

@ -8,9 +8,6 @@ import (
"github.com/urfave/cli/v2"
)
// TODO: This should probably be in some more sensible package
const Version = "v0.1.1"
func ActionGencerts(c *cli.Context) error {
outDir := "."
if c.IsSet("out-dir") {
@ -23,11 +20,6 @@ func ActionGencerts(c *cli.Context) error {
return certs.GenAllCerts(outDir, hostname)
}
func ActionInitConfig(c *cli.Context) error {
defaultCfg := config.FromDefault()
return defaultCfg.ToDefaultFile()
}
func getConfig(c *cli.Context) (*config.Config, error) {
if c.IsSet("config") {
cfgPath := c.String("config")

44
main.go
View File

@ -117,15 +117,9 @@ func main() {
},
},
{
Name: "change-password",
Name: "password",
Usage: "Change password",
Action: actions.ActionClientChangePassword,
},
{
// TODO: Remove
Name: "config-init",
Usage: "Initialize default config",
Action: actions.ActionInitConfig,
Action: actions.ActionClientPassword,
},
{
Name: "update",
@ -138,23 +132,6 @@ func main() {
},
},
},
{
Name: "cert",
Usage: "Certificate-related commands",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "List certificates",
Action: actions.ActionClientCertList,
},
{
Name: "revoke",
Usage: "Revoke certificate(s)",
ArgsUsage: "SERIAL [SERIAL...]",
Action: actions.ActionClientCertRevoke,
},
},
},
},
},
{
@ -167,6 +144,23 @@ func main() {
ArgsUsage: "FILENAME [FILENAME...]",
Action: actions.ActionAdminUploadBinary,
},
{
Name: "cert",
Usage: "Certificate-related commands",
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "List certificates",
Action: actions.ActionAdminCertList,
},
{
Name: "revoke",
Usage: "Revoke certificate(s)",
ArgsUsage: "SERIAL [SERIAL...]",
Action: actions.ActionAdminCertRevoke,
},
},
},
},
},
{