<commit_before>package commands

import (
	"context"
	"encoding/hex"
	"fmt"
	"os"

	"time"

	"io/ioutil"

	"github.com/howeyc/gopass"
	"github.com/hyperledger/burrow/config"
	"github.com/hyperledger/burrow/crypto"
	"github.com/hyperledger/burrow/keys"
	"github.com/hyperledger/burrow/keys/pbkeys"
	"github.com/hyperledger/burrow/logging/lifecycle"
	"github.com/jawher/mow.cli"
	"google.golang.org/grpc"
)

func Keys(output Output) func(cmd *cli.Cmd) {
	return func(cmd *cli.Cmd) {
		keysHost := cmd.String(cli.StringOpt{
			Name:   "host",
			Desc:   "set the host for talking to the key daemon",
			Value:  keys.DefaultHost,
			EnvVar: "MONAX_KEYS_HOST",
		})

		keysPort := cmd.String(cli.StringOpt{
			Name:   "port",
			Desc:   "set the port for key daemon",
			Value:  keys.DefaultPort,
			EnvVar: "MONAX_KEYS_PORT",
		})

		grpcKeysClient := func(output Output) pbkeys.KeysClient {
			var opts []grpc.DialOption
			opts = append(opts, grpc.WithInsecure())
			conn, err := grpc.Dial(*keysHost+":"+*keysPort, opts...)
			if err != nil {
				output.Fatalf("Failed to connect to grpc server: %v", err)
			}
			return pbkeys.NewKeysClient(conn)
		}

		cmd.Command("server", "run keys server", func(cmd *cli.Cmd) {
			keysDir := cmd.StringOpt("dir", "", "specify the location of the directory containing key files")
			badPerm := cmd.BoolOpt("allow-bad-perm", false, "Allow unix key file permissions to be readable other than user")
			configOpt := cmd.StringOpt("c config", "", "Use the a specified burrow config file")

			var conf *config.BurrowConfig

			cmd.Before = func() {
				var err error
				conf, err = obtainBurrowConfig(*configOpt, "")
				if err != nil {
					output.Fatalf("Could not obtain config: %v", err)
				}
			}

			cmd.Action = func() {
				logger, err := lifecycle.NewLoggerFromLoggingConfig(conf.Logging)
				if err != nil {
					output.Fatalf("could not generate logger from logging config: %v", err)
				}

				if badPerm != nil {
					conf.Keys.AllowBadFilePermissions = *badPerm
				}
				if keysDir != nil {
					conf.Keys.KeysDirectory = *keysDir
				}

				err = keys.StartStandAloneServer(conf.Keys.KeysDirectory, *keysHost, *keysPort, conf.Keys.AllowBadFilePermissions, logger)
				if err != nil {
					output.Fatalf("Failed to start server: %v", err)
				}<commit_msg>keys server should default to .keys, not "" for standalone keys server<commit_after>package commands

import (
	"context"
	"encoding/hex"
	"fmt"
	"os"

	"time"

	"io/ioutil"

	"github.com/howeyc/gopass"
	"github.com/hyperledger/burrow/config"
	"github.com/hyperledger/burrow/crypto"
	"github.com/hyperledger/burrow/keys"
	"github.com/hyperledger/burrow/keys/pbkeys"
	"github.com/hyperledger/burrow/logging/lifecycle"
	"github.com/jawher/mow.cli"
	"google.golang.org/grpc"
)

func Keys(output Output) func(cmd *cli.Cmd) {
	return func(cmd *cli.Cmd) {
		keysHost := cmd.String(cli.StringOpt{
			Name:   "host",
			Desc:   "set the host for talking to the key daemon",
			Value:  keys.DefaultHost,
			EnvVar: "MONAX_KEYS_HOST",
		})

		keysPort := cmd.String(cli.StringOpt{
			Name:   "port",
			Desc:   "set the port for key daemon",
			Value:  keys.DefaultPort,
			EnvVar: "MONAX_KEYS_PORT",
		})

		grpcKeysClient := func(output Output) pbkeys.KeysClient {
			var opts []grpc.DialOption
			opts = append(opts, grpc.WithInsecure())
			conn, err := grpc.Dial(*keysHost+":"+*keysPort, opts...)
			if err != nil {
				output.Fatalf("Failed to connect to grpc server: %v", err)
			}
			return pbkeys.NewKeysClient(conn)
		}

		cmd.Command("server", "run keys server", func(cmd *cli.Cmd) {
			keysDir := cmd.StringOpt("dir", "", "specify the location of the directory containing key files")
			badPerm := cmd.BoolOpt("allow-bad-perm", false, "Allow unix key file permissions to be readable other than user")
			configOpt := cmd.StringOpt("c config", "", "Use the a specified burrow config file")

			var conf *config.BurrowConfig

			cmd.Before = func() {
				var err error
				conf, err = obtainBurrowConfig(*configOpt, "")
				if err != nil {
					output.Fatalf("Could not obtain config: %v", err)
				}
			}

			cmd.Action = func() {
				logger, err := lifecycle.NewLoggerFromLoggingConfig(conf.Logging)
				if err != nil {
					output.Fatalf("could not generate logger from logging config: %v", err)
				}

				if *badPerm != false {
					conf.Keys.AllowBadFilePermissions = *badPerm
				}
				if *keysDir != "" {
					conf.Keys.KeysDirectory = *keysDir
				}

				err = keys.StartStandAloneServer(conf.Keys.KeysDirectory, *keysHost, *keysPort, conf.Keys.AllowBadFilePermissions, logger)
				if err != nil {
					output.Fatalf("Failed to start server: %v", err)
				}
{'fraction_non_alphanumeric': 0.13875802997858672, 'fraction_numerical': 0.0, 'mean_word_length': 3.521781219748306, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '488520', 'n_tokens_mistral': 1857, 'n_tokens_neox': 1614, 'n_words': 385}