veyron/tools/principal: Fix break in principal tool.

The old tool didn't initialize a runtime for all the commands.  This is
important because for some commands like "create" initializing the runtime
interferes with the behavior of the command.

Change-Id: I1a163dbe8b060b0c87d3aa6122d4175d85bd6efc
diff --git a/tools/principal/main.go b/tools/principal/main.go
index 570af91..ed12032 100644
--- a/tools/principal/main.go
+++ b/tools/principal/main.go
@@ -25,8 +25,6 @@
 )
 
 var (
-	runtime veyron2.Runtime
-
 	// Flags for the "blessself" command
 	flagBlessSelfFor time.Duration
 
@@ -55,6 +53,12 @@
 that this tool is running in.
 `,
 		Run: func(cmd *cmdline.Command, args []string) error {
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			p := runtime.Principal()
 			fmt.Printf("Public key : %v\n", p.PublicKey())
 			fmt.Println("---------------- BlessingStore ----------------")
@@ -142,6 +146,13 @@
 				}
 				caveats = append(caveats, cav)
 			}
+
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			blessing, err := runtime.Principal().BlessSelf(name, caveats...)
 			if err != nil {
 				return fmt.Errorf("failed to create self-signed blessing for name %q: %v", name, err)
@@ -191,10 +202,16 @@
 			if len(args) != 2 {
 				return fmt.Errorf("require exactly two arguments, provided %d", len(args))
 			}
+
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			p := runtime.Principal()
 
 			var with security.Blessings
-			var err error
 			var caveats []security.Caveat
 			if len(flagBlessWith) > 0 {
 				if with, err = decodeBlessings(flagBlessWith); err != nil {
@@ -262,6 +279,12 @@
 blessings set on the store with the "..." pattern).
 `,
 		Run: func(cmd *cmdline.Command, args []string) error {
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			return dumpBlessings(runtime.Principal().BlessingStore().ForPeer(args...))
 		},
 	}
@@ -274,6 +297,12 @@
 the environment that this tool is running in.
 `,
 		Run: func(cmd *cmdline.Command, args []string) error {
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			return dumpBlessings(runtime.Principal().BlessingStore().Default())
 		},
 	}
@@ -312,6 +341,13 @@
 				return fmt.Errorf("failed to decode provided blessings: %v", err)
 			}
 			pattern := security.BlessingPattern(args[1])
+
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			p := runtime.Principal()
 			if _, err := p.BlessingStore().Set(blessings, pattern); err != nil {
 				return fmt.Errorf("failed to set blessings %v for peers %v: %v", blessings, pattern, err)
@@ -348,6 +384,13 @@
 			if err != nil {
 				return fmt.Errorf("failed to decode provided blessings: %v", err)
 			}
+
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			p := runtime.Principal()
 			if err := p.BlessingStore().SetDefault(blessings); err != nil {
 				return fmt.Errorf("failed to set blessings %v as default: %v", blessings, err)
@@ -434,6 +477,12 @@
 		Run: func(cmd *cmdline.Command, args []string) error {
 			// Initialize the runtime first so that any local errors are reported
 			// before the HTTP roundtrips for obtaining the macaroon begin.
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			blessedChan := make(chan string)
 			defer close(blessedChan)
 			macaroonChan, err := getMacaroonForBlessRPC(flagSeekBlessingsFrom, blessedChan)
@@ -514,6 +563,13 @@
 			if len(args) != 0 {
 				return fmt.Errorf("command accepts no arguments")
 			}
+
+			runtime, err := rt.New()
+			if err != nil {
+				panic(err)
+			}
+			defer runtime.Cleanup()
+
 			server, err := runtime.NewServer()
 			if err != nil {
 				return fmt.Errorf("failed to create server to listen for blessings: %v", err)
@@ -550,13 +606,6 @@
 )
 
 func main() {
-	var err error
-	runtime, err = rt.New()
-	if err != nil {
-		panic(err)
-	}
-	defer runtime.Cleanup()
-
 	cmdBlessSelf.Flags.DurationVar(&flagBlessSelfFor, "for", 0, "Duration of blessing validity (zero means no that the blessing is always valid)")
 
 	cmdBless.Flags.DurationVar(&flagBlessFor, "for", time.Minute, "Duration of blessing validity")