From 7edcf57ab3ba5ac90acafd3cc3745ffc06e271a3 Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Mon, 1 Mar 2021 18:42:23 -0500 Subject: [PATCH 1/3] Add undeletetree command --- cmd/undeletetree/main.go | 57 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 cmd/undeletetree/main.go diff --git a/cmd/undeletetree/main.go b/cmd/undeletetree/main.go new file mode 100644 index 0000000000..d1ae705026 --- /dev/null +++ b/cmd/undeletetree/main.go @@ -0,0 +1,57 @@ +// Copyright 2018 Google LLC. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Package main contains the implementation and entry point for the undeletetree +// command. +// +// Example usage: +// $ ./undeletetree --admin_server=host:port --log_id=logid +package main + +import ( + "context" + "flag" + + "github.com/golang/glog" + "github.com/google/trillian" + "github.com/google/trillian/client/rpcflags" + "google.golang.org/grpc" +) + +var ( + adminServerAddr = flag.String("admin_server", "", "Address of the gRPC Trillian Admin Server (host:port)") + logID = flag.Int64("log_id", 0, "Trillian LogID to undelete") +) + +func main() { + flag.Parse() + defer glog.Flush() + + dialOpts, err := rpcflags.NewClientDialOptionsFromFlags() + if err != nil { + glog.Exitf("Failed to determine dial options: %v", err) + } + + conn, err := grpc.Dial(*adminServerAddr, dialOpts...) + if err != nil { + glog.Exitf("Failed to dial %v: %v", *adminServerAddr, err) + } + defer conn.Close() + + a := trillian.NewTrillianAdminClient(conn) + _, err = a.UndeleteTree(context.Background(), &trillian.UndeleteTreeRequest{TreeId: *logID}) + if err != nil { + glog.Exitf("Undelete failed: %v", err) + } +} From 16b497f1571358bdeacde71a9506590afe7cbf80 Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Tue, 2 Mar 2021 12:35:34 -0500 Subject: [PATCH 2/3] Move undelete_tree flag into deletetree binary --- cmd/deletetree/main.go | 14 +++++++--- cmd/undeletetree/main.go | 57 ---------------------------------------- 2 files changed, 11 insertions(+), 60 deletions(-) delete mode 100644 cmd/undeletetree/main.go diff --git a/cmd/deletetree/main.go b/cmd/deletetree/main.go index e5c9d75fd8..d7223acc5e 100644 --- a/cmd/deletetree/main.go +++ b/cmd/deletetree/main.go @@ -32,6 +32,7 @@ import ( var ( adminServerAddr = flag.String("admin_server", "", "Address of the gRPC Trillian Admin Server (host:port)") logID = flag.Int64("log_id", 0, "Trillian LogID to delete") + undeleteTree = flag.Bool("undelete_tree", false, "Undelete the specified Trillian LogID (bool)") ) func main() { @@ -50,8 +51,15 @@ func main() { defer conn.Close() a := trillian.NewTrillianAdminClient(conn) - _, err = a.DeleteTree(context.Background(), &trillian.DeleteTreeRequest{TreeId: *logID}) - if err != nil { - glog.Exitf("Delete failed: %v", err) + if *undeleteTree == false { + _, err = a.DeleteTree(context.Background(), &trillian.DeleteTreeRequest{TreeId: *logID}) + if err != nil { + glog.Exitf("Delete failed: %v", err) + } + } else { + _, err = a.UndeleteTree(context.Background(), &trillian.UndeleteTreeRequest{TreeId: *logID}) + if err != nil { + glog.Exitf("Undelete failed: %v", err) + } } } diff --git a/cmd/undeletetree/main.go b/cmd/undeletetree/main.go deleted file mode 100644 index d1ae705026..0000000000 --- a/cmd/undeletetree/main.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2018 Google LLC. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package main contains the implementation and entry point for the undeletetree -// command. -// -// Example usage: -// $ ./undeletetree --admin_server=host:port --log_id=logid -package main - -import ( - "context" - "flag" - - "github.com/golang/glog" - "github.com/google/trillian" - "github.com/google/trillian/client/rpcflags" - "google.golang.org/grpc" -) - -var ( - adminServerAddr = flag.String("admin_server", "", "Address of the gRPC Trillian Admin Server (host:port)") - logID = flag.Int64("log_id", 0, "Trillian LogID to undelete") -) - -func main() { - flag.Parse() - defer glog.Flush() - - dialOpts, err := rpcflags.NewClientDialOptionsFromFlags() - if err != nil { - glog.Exitf("Failed to determine dial options: %v", err) - } - - conn, err := grpc.Dial(*adminServerAddr, dialOpts...) - if err != nil { - glog.Exitf("Failed to dial %v: %v", *adminServerAddr, err) - } - defer conn.Close() - - a := trillian.NewTrillianAdminClient(conn) - _, err = a.UndeleteTree(context.Background(), &trillian.UndeleteTreeRequest{TreeId: *logID}) - if err != nil { - glog.Exitf("Undelete failed: %v", err) - } -} From b189364863858f47c9eac05d9ce4346da780da5a Mon Sep 17 00:00:00 2001 From: Phil Porada Date: Tue, 16 Nov 2021 13:19:51 -0500 Subject: [PATCH 3/3] Address presubmit lint warning --- cmd/deletetree/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/deletetree/main.go b/cmd/deletetree/main.go index d7223acc5e..9f0e0f4924 100644 --- a/cmd/deletetree/main.go +++ b/cmd/deletetree/main.go @@ -32,7 +32,7 @@ import ( var ( adminServerAddr = flag.String("admin_server", "", "Address of the gRPC Trillian Admin Server (host:port)") logID = flag.Int64("log_id", 0, "Trillian LogID to delete") - undeleteTree = flag.Bool("undelete_tree", false, "Undelete the specified Trillian LogID (bool)") + undeleteTree = flag.Bool("undelete_tree", false, "Undelete the specified Trillian LogID (bool)") ) func main() { @@ -51,7 +51,7 @@ func main() { defer conn.Close() a := trillian.NewTrillianAdminClient(conn) - if *undeleteTree == false { + if !*undeleteTree { _, err = a.DeleteTree(context.Background(), &trillian.DeleteTreeRequest{TreeId: *logID}) if err != nil { glog.Exitf("Delete failed: %v", err)