Skip to content

Commit

Permalink
Initial implementation with User get, add, modify, and remove.
Browse files Browse the repository at this point in the history
  • Loading branch information
bensallen committed Mar 4, 2021
1 parent bac6394 commit 9d8d504
Show file tree
Hide file tree
Showing 78 changed files with 13,760 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.duocli.json
duocli.8
dist
48 changes: 48 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
builds:
- binary: duocli
flags:
- -mod=vendor
env:
- CGO_ENABLED=0
goos:
- linux
goarch:
- amd64
main: ./cmd/duocli/duocli.go
before:
hooks:
- "go run cmd/duocli/duocli.go docs --output duocli.8"
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
arm64: aarch64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
nfpms:
- description: "DuoCLI is a CLI interface to the Duo Admin API."
maintainer: "Benjamin S. Allen <[email protected]>"
homepage: "http://github.com/bensallen/duocli"
license: "BSD"
formats:
- rpm
- deb
file_name_template: "{{ .ProjectName }}-{{ .Version }}-{{ .Release }}.{{ .Arch }}"
release: 1
bindir: /usr/bin
replacements:
386: i386
amd64: x86_64
arm64: aarch64
contents:
- src: "duocli.8"
dst: /usr/share/man/man8/duocli.8
- src: scripts/bash_autocomplete
dst: /etc/bash_completion.d/duocli
98 changes: 98 additions & 0 deletions cmd/duocli/duocli.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package main

import (
"log"
"os"

"github.com/bensallen/duocli/pkg/cli/docs"
"github.com/bensallen/duocli/pkg/cli/user"
"github.com/urfave/cli/v2"
)

var version = "unknown"

func main() {

app := &cli.App{

Name: "duocli",
Usage: "CLI Interface to Duo Admin API",
Version: version,
HideHelpCommand: true,
EnableBashCompletion: true,
Flags: []cli.Flag{
&cli.StringFlag{
Name: "config",
Aliases: []string{"c"},
Usage: "load configuration from `FILE`",
DefaultText: ".duocli.json",
},
},
Commands: []*cli.Command{
{
Name: "user",
Usage: "manage users",
HideHelpCommand: true,
Subcommands: []*cli.Command{
{
Name: "add",
Usage: "add a user",
Action: user.Add,
Flags: []cli.Flag{
&cli.StringFlag{Name: "username", Aliases: []string{"u"}, Required: true, Usage: "username"},
&cli.StringSliceFlag{Name: "group", Aliases: []string{"g"}, Usage: "add user to group, can be specified multiple times to add user to multiple groups"},
&cli.StringFlag{Name: "email", Aliases: []string{"e"}, Usage: "email address of user"},
&cli.StringFlag{Name: "firstName", Aliases: []string{"f"}, Usage: "first name of user"},
&cli.StringFlag{Name: "lastName", Aliases: []string{"l"}, Usage: "last name of user"},
&cli.StringFlag{Name: "status", Aliases: []string{"s"}, Usage: "status of user: active, disabled, or bypass", Value: "active"},
},
},
{
Name: "get",
Usage: "get one or more users and display as JSON",
Action: user.Get,
Flags: []cli.Flag{
&cli.StringSliceFlag{Name: "username", Aliases: []string{"u"}, Required: true, Usage: "username, can be specified multiple times"},
},
},
{
Name: "modify",
Usage: "modify a user's attributes, add or remove group membership",
Action: user.Modify,
Flags: []cli.Flag{
&cli.StringFlag{Name: "username", Aliases: []string{"u"}, Required: true, Usage: "username"},
&cli.StringSliceFlag{Name: "addgroup", Aliases: []string{"g"}, Usage: "add user to groups, adds to existing memberships, and can be specified multiple times to add user to multiple groups"},
&cli.StringSliceFlag{Name: "delgroup", Aliases: []string{"G"}, Usage: "remove user from groups, removes from existing memberships, and can be specified multiple times to remove user from multiple groups"},
&cli.StringFlag{Name: "email", Aliases: []string{"e"}, Usage: "email address of user"},
&cli.StringFlag{Name: "firstName", Aliases: []string{"f"}, Usage: "first name of user"},
&cli.StringFlag{Name: "lastName", Aliases: []string{"l"}, Usage: "last name of user"},
&cli.StringFlag{Name: "status", Aliases: []string{"s"}, Usage: "status of user: active, disabled, or bypass"},
},
},
{
Name: "remove",
Usage: "remove user and any attached phones or tokens",
Action: user.Remove,
Flags: []cli.Flag{
&cli.StringSliceFlag{Name: "username", Aliases: []string{"u"}, Required: true, Usage: "username, can be specified multiple times"},
&cli.BoolFlag{Name: "phone", Aliases: []string{"P"}, Usage: "remove any phones found attached to the user before removing the user", Value: true},
},
},
},
},
{
Name: "docs",
Hidden: true,
Action: docs.Generate,
Flags: []cli.Flag{
&cli.StringFlag{Name: "output", Required: true, Usage: "path to write man page"},
},
},
},
}

err := app.Run(os.Args)
if err != nil {
log.Fatalf("Error, %v", err)
}
}
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module github.com/bensallen/duocli

go 1.15

replace github.com/duosecurity/duo_api_golang => github.com/bensallen/duo_api_golang v0.0.0-20210303044231-5723b6d8fe51

require (
github.com/duosecurity/duo_api_golang v0.0.0-20201112143038-0e07e9f869e3
github.com/urfave/cli/v2 v2.3.0
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/bensallen/duo_api_golang v0.0.0-20210303044231-5723b6d8fe51 h1:CU+MXTUG5uNjBM0+wOZeZYLawuyNv8aPB+0GX2MSePI=
github.com/bensallen/duo_api_golang v0.0.0-20210303044231-5723b6d8fe51/go.mod h1:jI+QUTOK3wqIOrUl0Cwnwlgc/P6vs6pZOuQY3aKggwg=
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.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
26 changes: 26 additions & 0 deletions pkg/cli/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package docs

import (
"fmt"
"os"

"github.com/urfave/cli/v2"
)

// Generate writes out man page for the application to the provide path
func Generate(c *cli.Context) error {
path := c.String("output")
f, err := os.Create(path)
if err != nil {
return err
}
defer f.Close()

man, err := c.App.ToMan()
if err != nil {
return err
}

_, err = fmt.Fprintf(f, "%s", man)
return err
}
23 changes: 23 additions & 0 deletions pkg/cli/group/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package group

import (
"fmt"

"github.com/urfave/cli/v2"
)

func Add(c *cli.Context) error {

groupNames := c.StringSlice("name")
fmt.Printf("%#v\n", groupNames)

return nil
}

func Remove(c *cli.Context) error {

groupNames := c.StringSlice("name")
fmt.Printf("%#v\n", groupNames)

return nil
}
Loading

0 comments on commit 9d8d504

Please sign in to comment.