storj/cmd/identity/revocations.go

63 lines
1.6 KiB
Go
Raw Normal View History

2019-02-06 16:40:55 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package main
import (
"encoding/base64"
"fmt"
"path/filepath"
"time"
"github.com/spf13/cobra"
"github.com/zeebo/errs"
"storj.io/private/cfgstruct"
"storj.io/private/process"
"storj.io/storj/private/revocation"
2019-02-06 16:40:55 +00:00
)
var (
revocationsCmd = &cobra.Command{
Use: "revocations [service]",
Short: "Print revocation information from a revocation database",
Args: cobra.MaximumNArgs(1),
RunE: cmdRevocations,
Annotations: map[string]string{"type": "setup"},
}
revCfg struct {
RevocationDBURL string `default:"bolt://$CONFDIR/revocations.db" help:"url for revocation database (e.g. bolt://some.db OR redis://127.0.0.1:6379?db=2&password=abc123)"`
2019-02-06 16:40:55 +00:00
}
)
func init() {
rootCmd.AddCommand(revocationsCmd)
process.Bind(revocationsCmd, &revCfg, defaults, cfgstruct.ConfDir(defaultConfigDir), cfgstruct.IdentityDir(defaultIdentityDir))
2019-02-06 16:40:55 +00:00
}
func cmdRevocations(cmd *cobra.Command, args []string) error {
ctx, _ := process.Ctx(cmd)
2019-02-06 16:40:55 +00:00
if len(args) > 0 {
revCfg.RevocationDBURL = "bolt://" + filepath.Join(configDir, args[0], "revocations.db")
}
revDB, err := revocation.OpenDB(ctx, revCfg.RevocationDBURL)
2019-02-06 16:40:55 +00:00
if err != nil {
return err
}
revs, err := revDB.List(ctx)
2019-02-06 16:40:55 +00:00
if err != nil {
return err
}
revErrs := new(errs.Group)
for _, rev := range revs {
2019-04-03 16:03:53 +01:00
fmt.Printf("certificate public key hash: %s\n", base64.StdEncoding.EncodeToString(rev.KeyHash))
2019-02-06 16:40:55 +00:00
fmt.Printf("\timestamp: %s\n", time.Unix(rev.Timestamp, 0).String())
fmt.Printf("\tsignature: %s\n", base64.StdEncoding.EncodeToString(rev.Signature))
}
return revErrs.Err()
}