Skip to content

Commit

Permalink
remove_key fix
Browse files Browse the repository at this point in the history
Signed-off-by: JuliannaReyes <[email protected]>
  • Loading branch information
JuliannaReyes committed Jul 25, 2023
1 parent 7b85661 commit 6963b4d
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions remove_key.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package main

import (
"os"
"path/filepath"

"github.com/flynn/go-docopt"
"github.com/theupdateframework/go-tuf"


)
func init() {
register("remove-key", cmdRemoveKey, `
usage: tuf remove-key [--expires=<days>] <role> <id>
Remove a signing key
Before the key is removed the key will be first revoked
The key will then be removed from the root metadata file and if the key is present in
"keys" directory it will also be removed
Options:
--expires=<days> Set the root metadata file to expire <days> days from now.
`)
}

func cmdRemoveKey(args *docopt.Args, repo *tuf.Repo) error {
role := args.String["<roles>"]
keyID := args.String["<id>"]
if err := repo.RevokeKey(role, keyID); err != nil{
return err
}
keyPath := filepath.Join("keys", keyID)
if _ , err := os.Stat(keyPath); err==nil{
if err := os.Remove(keyPath); err != nil{
return err
}
}
return nil
}

0 comments on commit 6963b4d

Please sign in to comment.