Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement blackbox in Golang #250

Merged
merged 76 commits into from
Jul 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
ff792cf
vendor github.com/pkg/errors vendor/github.com/urfave/cli
tlimoncelli Apr 21, 2018
57702a1
New command: blackbox: Parses subcommands and calls bash scripts.
tlimoncelli Apr 21, 2018
3a5e4b6
Implement status and nlist commands
tlimoncelli Apr 22, 2018
5681903
Add "blackbox admin nlist" command.
tlimoncelli Apr 22, 2018
d393d7e
First draft of ndecrypt
tlimoncelli Apr 22, 2018
a6b9c17
Merge branch 'master' into golang
tlimoncelli Jul 3, 2018
3cc7e46
Partial commit
tlimoncelli Sep 10, 2018
e1e6dee
Merge branch 'master' into golang
tlimoncelli Sep 10, 2018
b62ec37
Merge branch 'master' into golang
tlimoncelli Dec 4, 2018
5671b71
Merge branch 'master' into golang
tlimoncelli Dec 9, 2018
ffde3ae
Restructure
tlimoncelli Dec 9, 2018
a5cd829
wip!
tlimoncelli Dec 18, 2018
a47f038
Merge branch 'master' into golang
tlimoncelli Mar 3, 2019
36e1774
Merge branch 'master' into golang
Apr 19, 2020
1fb5701
NEW: DESIGN.md
Apr 19, 2020
b3e052b
Merge branch 'master' into golang
tlimoncelli Jun 6, 2020
c9bd587
tmp
tlimoncelli Jun 6, 2020
a630c6b
flags.go and parse.go complete
tlimoncelli Jun 6, 2020
0bdffb3
Draft
tlimoncelli Jun 6, 2020
a6ec716
Box discovers admins and files.
tlimoncelli Jun 6, 2020
50fa2e5
Snapshot
tlimoncelli Jun 7, 2020
d7bdd49
Fixed the signature mismatch problem!!!
tlimoncelli Jun 7, 2020
ac8105c
linting
tlimoncelli Jun 7, 2020
4979113
Implement Discover()
tlimoncelli Jun 7, 2020
bc5dab7
Implement: files list
tlimoncelli Jun 7, 2020
2425c0f
"blackbox status" works.
tlimoncelli Jun 7, 2020
bf1f1e2
Unvendor
tlimoncelli Jun 7, 2020
148aa3d
Unvendor
tlimoncelli Jun 7, 2020
6c260d1
Cleanup
tlimoncelli Jun 7, 2020
126f60f
cleanup
tlimoncelli Jun 7, 2020
edad8a8
snapshot
tlimoncelli Jun 7, 2020
66eeea2
snapshot!
tlimoncelli Jun 7, 2020
9998758
Rename pkgs
tlimoncelli Jun 7, 2020
8c329b1
linting
tlimoncelli Jun 7, 2020
56665df
Implement decrypt --askagent and --umask
tlimoncelli Jun 8, 2020
f860c73
Random fixes
tlimoncelli Jun 8, 2020
b3aa045
snapshot
tlimoncelli Jun 8, 2020
df2bb78
integration test framework works
tlimoncelli Jun 9, 2020
164376f
Integration tests work all the way through "init".
tlimoncelli Jun 10, 2020
2c8400c
init completed
tlimoncelli Jun 11, 2020
b544a02
Mostly working
tlimoncelli Jun 12, 2020
e831a5a
logging works
tlimoncelli Jun 12, 2020
0a0068d
fix logging
tlimoncelli Jun 12, 2020
a189a4a
wip!
tlimoncelli Jun 14, 2020
e0e61f5
wip!
tlimoncelli Jun 15, 2020
7276fae
Now working: init, admin add, file add, encrypt, decrypt, shred
tlimoncelli Jun 15, 2020
b17a11a
Cat works!
tlimoncelli Jun 16, 2020
a47bc5d
cat and other commands now work. shell commands replaced
tlimoncelli Jun 16, 2020
fa2a643
create binv2
tlimoncelli Jun 19, 2020
0518006
integration tests working
tlimoncelli Jun 19, 2020
b963da0
Now works on CentOS 7
TomOnTime Jun 19, 2020
b3e9e52
aRough out Docs
tlimoncelli Jun 23, 2020
eccea8d
fix comment
tlimoncelli Jul 2, 2020
ac66afd
linting
tlimoncelli Jul 2, 2020
bea3af3
Refactor how NeedsCommit is done
tlimoncelli Jul 2, 2020
4f79084
add missing files
tlimoncelli Jul 3, 2020
56ecdc8
git commit messages are more pretty
tlimoncelli Jul 3, 2020
433b357
cleanup
tlimoncelli Jul 3, 2020
c0d1883
Fixing commits
tlimoncelli Jul 3, 2020
0eb9fd1
bx.* dirs are now relative
tlimoncelli Jul 4, 2020
afcec7d
linting
tlimoncelli Jul 4, 2020
6b8deb4
Clean up redact
tlimoncelli Jul 4, 2020
7ab79e0
Fix bug: filenames with spaces dont work
tlimoncelli Jul 4, 2020
6ff8d0d
macos doesn't need gpg-agent
tlimoncelli Jul 4, 2020
68a17b5
Fix umask display. All --all commands now work from any directory
tlimoncelli Jul 5, 2020
fdb2559
Fix --debug. Fix --group
tlimoncelli Jul 5, 2020
fa53022
Fix links
tlimoncelli Jul 5, 2020
b3b54fa
Refactor makesafe
tlimoncelli Jul 5, 2020
259ba65
cleanig up code
tlimoncelli Jul 6, 2020
b6d4fee
linting
tlimoncelli Jul 6, 2020
f886ea5
mDocs
tlimoncelli Jul 14, 2020
ccc2439
fix reencrypt commit messages
tlimoncelli Jul 17, 2020
92e791a
Fix
tlimoncelli Jul 18, 2020
9e088db
Rewrite shred detector
tlimoncelli Jul 18, 2020
4c47af8
do some integration tests from a funny subdir
tlimoncelli Jul 18, 2020
053b8a6
Rewrite shred detector
tlimoncelli Jul 18, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
flags.go and parse.go complete
  • Loading branch information
tlimoncelli committed Jun 6, 2020
commit a630c6b433bf79d21847550dcf333a80fabea56d
30 changes: 25 additions & 5 deletions Version2-Ideas.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ These are the things I'd like to change someday.
There should be one program, with subcommands that have names that make more sense:

* `blackbox init`
* `blackbox info`
* `blackbox admin add <key>`
* `blackbox admin remove <key>`
* `blackbox admin list`
Expand All @@ -27,14 +28,33 @@ There should be one program, with subcommands that have names that make more sen
* `blackbox files remove`
* `blackbox encrypt <filename> ...`
* `blackbox decrypt <filename> ...`
* `blackbox decrypt_all`
* `blackbox cat <filename> ...`
* `blackbox edit <filename> ...`
* `blackbox reencrypt_all`
* `blackbox shred_all`
* `blackbox reencrypt`
* `blackbox shred`
* `blackbox diff <filename> ...`
* `blackbox files unchanged`
* `blackbox files changed`
* `blackbox files list-unchanged`
* `blackbox files list-changed`

* `blackbox admin add <key>`
* `blackbox admin list`
* `blackbox admin remove <key>`
* `blackbox cat <filename> ...`
* `blackbox decrypt <filename> ...`
* `blackbox diff <filename> ...`
* `blackbox edit <filename> ...`
* `blackbox encrypt <filename> ...`
* `blackbox file add`
* `blackbox file list`
* `blackbox file remove`
* `blackbox info`
* `blackbox init`
* `blackbox reencrypt`
* `blackbox shred`
* `blackbox status all`
* `blackbox status changed`
* `blackbox status unchanged`


Flags where appropriate

Expand Down
20 changes: 3 additions & 17 deletions cmd/blackbox/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,9 @@ func flags() *cli.App {
Usage: "Print status of files",
Flags: []cli.Flag{
&cli.BoolFlag{Name: "name-only", Usage: "Show only names of the files"},
},
Subcommands: []*cli.Command{
{
Name: "all",
Usage: "All registered files",
Action: func(c *cli.Context) error { return cmdStatusAll(c) },
},
{
Name: "changed",
Usage: "Only include files that are newer than their .gpg file",
Action: func(c *cli.Context) error { return cmdStatusChanged(c) },
},
{
Name: "unchanged",
Usage: "Only include files that 'status changed' wouldn't list",
Action: func(c *cli.Context) error { return cmdStatusUnchanged(c) },
},
&cli.BoolFlag{Name: "all", Usage: "All registered files"},
&cli.BoolFlag{Name: "changed", Usage: "Only files newer than their .gpg"},
&cli.BoolFlag{Name: "unchanged", Usage: "Only files older than their .gpg"},
},
},

Expand Down
173 changes: 132 additions & 41 deletions cmd/blackbox/parse.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

// All the "blackbox admin" subcommands.
// Processes the flags and arguments and calls the appropriate
// business logic.

import (
"fmt"
Expand All @@ -19,10 +20,23 @@ func init() {
}
}

func allOrSomeFiles(c *cli.Context) error {
if c.Bool("all") {
if c.Args().Present() {
return fmt.Errorf("Can not specify filenames and --all")
}
} else {
if !c.Args().Present() {
return fmt.Errorf("Must specify at least one file name")
}
}
return nil
}

// Keep these functions in alphabetical order.

func cmdAdminAdd(c *cli.Context) error {
if c.Args().Present() {
if !c.Args().Present() {
return fmt.Errorf(
"Must specify at least one admin's GnuPG user-id (i.e. email address)")
}
Expand All @@ -31,91 +45,168 @@ func cmdAdminAdd(c *cli.Context) error {
}

func cmdAdminList(c *cli.Context) error {
if !c.Args().Present() {
if c.Args().Present() {
return fmt.Errorf("This command takes zero arguments")
}
bx := box.NewFromFlags(c)
return bx.AdminList(bx)
return bx.AdminList()
}

func cmdAdminRemove(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if !c.Args().Present() {
return fmt.Errorf("Must specify at least one admin's GnuPG user-id (i.e. email address)")
}
bx := box.NewFromFlags(c)
return bx.AdminRemove(c.Args().Slice())
}

func cmdCat(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if !c.Args().Present() {
return fmt.Errorf("Must specify at least one file name")
}
bx := box.NewFromFlags(c)
return bx.Cat(c.Args().Slice())
}

func cmdDecrypt(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if err := allOrSomeFiles(c); err != nil {
return err
}
bulk := false
if c.Bool("all") {
bulk = c.Bool("bulk") // Only applies to --all
}
bx := box.NewFromFlags(c)
return bx.Decrypt(c.Args().Slice(),
c.Bool("overwrite"),
bulk,
c.String("group"),
)
}

func cmdDiff(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if err := allOrSomeFiles(c); err != nil {
return err
}
bx := box.NewFromFlags(c)
return bx.Diff(c.Args().Slice())
}

func cmdEdit(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if !c.Args().Present() {
return fmt.Errorf("Must specify at least one file name")
}
bx := box.NewFromFlags(c)
return bx.Edit(c.Args().Slice())
}

func cmdEncrypt(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if err := allOrSomeFiles(c); err != nil {
return err
}
bulk := false
if c.Bool("all") {
bulk = c.Bool("bulk") // Only applies to --all
}
bx := box.NewFromFlags(c)
return bx.Encrypt(c.Args().Slice(), bulk, c.String("group"), c.Bool("overwrite"))
}

func cmdFileAdd(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if !c.Args().Present() {
return fmt.Errorf("Must specify at least one file name")
}
bx := box.NewFromFlags(c)
return bx.FileAdd(c.Args().Slice(), c.Bool("overwrite"))
}

func cmdFileList(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if c.Args().Present() {
return fmt.Errorf("This command takes zero arguments")
}
bx := box.NewFromFlags(c)
return bx.FileList()
}

func cmdFileRemove(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if !c.Args().Present() {
return fmt.Errorf("Must specify at least one file name")
}
bx := box.NewFromFlags(c)
return bx.FileRemove(c.Args().Slice())
}

func cmdInfo(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if c.Args().Present() {
return fmt.Errorf("This command takes zero arguments")
}
bx := box.NewFromFlags(c)
return bx.Info()
}

func cmdInit(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if c.Args().Present() {
return fmt.Errorf("This command takes zero arguments")
}
bx := box.NewFromFlags(c)
return bx.Init()
}

func cmdReencrypt(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if err := allOrSomeFiles(c); err != nil {
return err
}
bx := box.NewFromFlags(c)
return bx.Reencrypt(c.Args().Slice())
}

func cmdShred(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if err := allOrSomeFiles(c); err != nil {
return err
}
bx := box.NewFromFlags(c)
return bx.Shred(c.Args().Slice())
}

func cmdStatusAll(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
}
func cmdStatus(c *cli.Context) error {
if err := allOrSomeFiles(c); err != nil {
return err
}

func cmdStatusChanged(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
}
mode := box.Itemized

func cmdStatusUnchanged(c *cli.Context) error {
logErr.Println("NOT IMPLEMENTED")
return nil
if c.Bool("all") {
if c.Args().Present() {
return fmt.Errorf("Can not specify filenames and --all")
}
if mode != box.Itemized {
return fmt.Errorf("--all can not be mixed with other flags")
}
mode = box.All
}

if c.Bool("changed") {
if c.Args().Present() {
return fmt.Errorf("Can not specify filenames and --changed")
}
if mode != box.Itemized {
return fmt.Errorf("--changed can not be mixed with other flags")
}
mode = box.Changed
}

if c.Bool("unchanged") {
if c.Args().Present() {
return fmt.Errorf("Can not specify filenames and --unchanged")
}
if mode != box.Itemized {
return fmt.Errorf("--unchanged can not be mixed with other flags")
}
mode = box.Unchanged
}

bx := box.NewFromFlags(c)
return bx.Status(c.Args().Slice(), mode, c.Bool("name-only"))
}

//func cmdInfo(c *cli.Context) error {
Expand Down
3 changes: 2 additions & 1 deletion cmd/blackbox/runbash.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// package main
package main

//
// import (
// "fmt"
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/StackExchange/blackbox

go 1.14

require github.com/urfave/cli/v2 v2.2.0
13 changes: 13 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/urfave/cli/v2 v2.2.0 h1:JTTnM6wKzdA0Jqodd966MVj4vWbbquZykeX1sKbe2C4=
github.com/urfave/cli/v2 v2.2.0/go.mod h1:SE9GqnLQmjVa0iPEY0f1w3ygNIYcIJ0OKPMoW2caLfQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
3 changes: 2 additions & 1 deletion pkg/bbgit/discover.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// package bbgit
package bbgit

//
// import (
// "os/exec"
Expand Down
3 changes: 2 additions & 1 deletion pkg/bbutil/admin.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// package bbutil
package bbutil

//
// // Administrator is a description of the admininstrators.
// type Administrator struct {
Expand Down
3 changes: 2 additions & 1 deletion pkg/bbutil/adminplain.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// package bbutil
package bbutil

//
// import (
// "io/ioutil"
Expand Down
3 changes: 2 additions & 1 deletion pkg/bbutil/decrypt.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// package bbutil
package bbutil

//
// import (
// "fmt"
Expand Down
4 changes: 2 additions & 2 deletions pkg/bbutil/iterator.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// package bbutil
//
package bbutil

// import (
// "sort"
// )
Expand Down
3 changes: 2 additions & 1 deletion pkg/bbutil/reg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// package bbutil
package bbutil

//
// import (
// "io/ioutil"
Expand Down
4 changes: 2 additions & 2 deletions pkg/bbutil/repoinfo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// package bbutil
//
package bbutil

// import (
// "os"
// "path/filepath"
Expand Down
Loading