예제 #1
0
파일: main.go 프로젝트: zennro/oyster
func main() {
	requests := make(chan *Message)
	config, err := oyster.ReadConfig()
	if err != nil {
		panic(err)
	}
	gpg := oyster.NewGpgRepo(config.GpgHome())
	fs := oyster.NewCryptoFS(rwvfs.OSPerm(config.Home(), 0600, 0700), gpg)

	handler := &RequestHandler{
		requests: requests,
		enc:      NewEncoder(os.Stdout),
		repo:     oyster.NewFormRepo(fs),
	}
	go handler.Run()

	readRequests(os.Stdin, requests)
}
예제 #2
0
파일: main.go 프로젝트: zennro/oyster
func main() {
	config, err := oyster.ReadConfig()
	if err != nil {
		fmt.Println(err)
		return
	}
	gpg := oyster.NewGpgRepo(config.GpgHome())
	fs := oyster.NewCryptoFS(rwvfs.OSPerm(config.Home(), 0600, 0700), gpg)
	repo := oyster.NewFileRepo(fs)
	app := cli.NewApp()
	app.Name = "oyster"
	app.Usage = "GPG password storage"
	app.Version = "0.2.10"
	app.EnableBashCompletion = true
	app.Action = func(c *cli.Context) {
		repo.Walk(func(file string) {
			fmt.Println(file)
		})
	}

	cli.CommandHelpTemplate = `NAME:
  {{.Name}} - {{.Usage}}

USAGE:
  oyster {{.Name}}{{if .Flags}} [command options]{{end}} [arguments...]{{if .Description}}

DESCRIPTION:
  {{.Description}}{{end}}{{if .Flags}}

OPTIONS:
  {{range .Flags}}{{.}}
  {{end}}{{ end }}
`

	app.Commands = []cli.Command{
		{
			Name:  "init",
			Usage: "Setup Oyster",
			Description: `Create Oyster home directory. If OYSTERHOME is set it will be used instead of "~/.oyster".

EXAMPLE:
   oyster init [email protected]
`,
			Action: func(c *cli.Context) {
				args := c.Args()
				if !args.Present() {
					fmt.Println("Must provide at least one GPG ID")
					return
				}
				if err := oyster.InitRepo(fs, args); err != nil {
					fmt.Println(err)
				}
			},
		},
		{
			Name:  "get",
			Usage: "Print a password to console",
			Action: func(c *cli.Context) {
				passphrase, err := getPassword()
				if err != nil {
					panic(err)
				}
				plaintext, err := repo.Open(c.Args().First(), passphrase)
				if err != nil {
					panic(err)
				}
				defer plaintext.Close()
				io.Copy(os.Stdout, plaintext)
			},
			BashComplete: bashCompleteKeys(repo),
		},
		{
			Name:  "copy",
			Usage: "Copy a password to the clipboard",
			Action: func(c *cli.Context) {
				passphrase, err := getPassword()
				if err != nil {
					panic(err)
				}
				password, err := repo.Line(c.Args().First(), passphrase)
				if err != nil {
					panic(err)
				}
				err = copyThenClear(password, 45*time.Second)
				if err != nil {
					panic(err)
				}
			},
			BashComplete: bashCompleteKeys(repo),
		},
		{
			Name:  "put",
			Usage: "Store a password",
			Action: func(c *cli.Context) {
				plaintext, err := repo.Create(c.Args().First())
				if err != nil {
					panic(err)
				}
				defer plaintext.Close()
				if terminal.IsTerminal(0) {
					fmt.Println("Enter your password...")
				}
				interruptibleCopy(plaintext, os.Stdin)
			},
			BashComplete: bashCompleteKeys(repo),
		},
		{
			Name:      "remove",
			ShortName: "rm",
			Usage:     "Remove a password",
			Action: func(c *cli.Context) {
				if err := repo.Remove(c.Args().First()); err != nil {
					panic(err)
				}
			},
			BashComplete: bashCompleteKeys(repo),
		},
	}
	app.Run(os.Args)
}