Skip to content

Commit

Permalink
Update urface cli to v2
Browse files Browse the repository at this point in the history
  • Loading branch information
project0 committed May 27, 2022
1 parent 4df5980 commit 424953c
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 114 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/gorilla/mux v1.8.0
github.com/miekg/dns v1.1.49
github.com/stretchr/testify v1.7.1
github.com/urfave/cli v1.22.9
github.com/urfave/cli/v2 v2.8.1
)

require (
Expand Down Expand Up @@ -101,6 +101,7 @@ require (
github.com/transip/gotransip/v6 v6.17.0 // indirect
github.com/vinyldns/go-vinyldns v0.9.16 // indirect
github.com/vultr/govultr/v2 v2.17.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
go.opencensus.io v0.23.0 // indirect
go.uber.org/ratelimit v0.2.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -675,9 +675,9 @@ github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLY
github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxWFFpvxTw=
github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli v1.22.9 h1:cv3/KhXGBGjEXLC4bH0sLuJ9BewaAbpk5oyMOveu4pw=
github.com/urfave/cli v1.22.9/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI=
github.com/urfave/cli/v2 v2.8.1 h1:CGuYNZF9IKZY/rfBe3lJpccSoIY1ytfvmgQT90cNOl4=
github.com/urfave/cli/v2 v2.8.1/go.mod h1:Z41J9TPoffeoqP0Iza0YbAhGvymRdZAd2uPmZ5JxRdY=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
Expand All @@ -690,6 +690,8 @@ github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673/go.mod h1:N3UwUGtsrSj3ccvlPHLoLsHnpR27oXr4ZE984MbSER8=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
222 changes: 111 additions & 111 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import (
"github.com/docker/libkv/store"
"github.com/go-acme/lego/v4/challenge"
"github.com/go-acme/lego/v4/providers/dns"

"github.com/project0/certjunkie/api"
"github.com/project0/certjunkie/certstore"
"github.com/project0/certjunkie/certstore/libkv/local"
"github.com/project0/certjunkie/provider"
"github.com/urfave/cli"
"github.com/urfave/cli/v2"
)

const ACME_STAGING = "https://acme-staging-v02.api.letsencrypt.org/directory"
Expand All @@ -27,80 +26,82 @@ const envPrefix = "CJ"

var certStore *certstore.CertStore

func flagSetHelperEnvKey(name string) string {
func flagSetHelperEnvKey(name string) []string {
envKey := strings.ToUpper(name)
envKey = strings.Replace(envKey, "-", "_", -1)
return envPrefix + "_" + envKey
return []string{envPrefix + "_" + envKey}
}

func main() {

app := cli.NewApp()
app.HideVersion = true
app.Usage = "issue certificate with ACME as a REST"

app.Commands = []cli.Command{
app.Commands = []*cli.Command{
{
Name: "server",
Description: "run DNS and API server",
Name: "server",
Usage: "run DNS and API server",

Flags: []cli.Flag{
cli.StringFlag{
Name: "server",
Value: ACME,
Usage: "ACME Directory Resource URI",
EnvVar: flagSetHelperEnvKey("SERVER"),
},
cli.StringFlag{
Name: "email",
Usage: "Registration email for the ACME server",
EnvVar: flagSetHelperEnvKey("EMAIL"),
},
cli.StringFlag{
Name: "listen",
Value: ":80",
Usage: "Bind listener address for http (api) server",
EnvVar: flagSetHelperEnvKey("LISTEN"),
},
cli.StringFlag{
Name: "provider",
Value: provider.Name,
Usage: "DNS challenge provider name",
EnvVar: flagSetHelperEnvKey("PROVIDER"),
},
cli.StringFlag{
Name: "preferred-chain",
Value: "",
Usage: "If the CA offers multiple certificate chains, prefer the chain with an issuer matching this Subject Common Name. If no match, the default offered chain will be used.",
EnvVar: flagSetHelperEnvKey("PREFERRED_CHAIN"),
},
cli.StringFlag{
Name: "dns.listen",
Value: ":53",
Usage: "Bind on this port to run the DNS server on (tcp and udp)",
EnvVar: flagSetHelperEnvKey("DNS_LISTEN"),
},
cli.StringFlag{
Name: "dns.domain",
Value: "ns.local",
Usage: "The NS domain name of this server",
EnvVar: flagSetHelperEnvKey("DNS_DOMAIN"),
},
cli.StringFlag{
Name: "dns.zone",
Value: "acme.local",
Usage: "The zone we are using to provide the txt records for challenge",
EnvVar: flagSetHelperEnvKey("DNS_ZONE"),
},
cli.StringFlag{
Name: "storage",
Value: "local",
Usage: "Storage driver to use, currently only local is supported",
EnvVar: flagSetHelperEnvKey("STORAGE"),
},
cli.StringFlag{
Name: "storage.path",
Value: os.Getenv("HOME") + "/.certjunkie",
Usage: "Path to store the certs and account data for local storage driver",
EnvVar: flagSetHelperEnvKey("STORAGE_PATH"),
&cli.StringFlag{
Name: "server",
Value: ACME,
Usage: "ACME Directory Resource URI",
EnvVars: flagSetHelperEnvKey("SERVER"),
},
&cli.StringFlag{
Name: "email",
Usage: "Registration email for the ACME server",
EnvVars: flagSetHelperEnvKey("EMAIL"),
},
&cli.StringFlag{
Name: "listen",
Value: ":80",
Usage: "Bind listener address for http (api) server",
EnvVars: flagSetHelperEnvKey("LISTEN"),
},
&cli.StringFlag{
Name: "provider",
Value: provider.Name,
Usage: "DNS challenge provider name",
EnvVars: flagSetHelperEnvKey("PROVIDER"),
},
&cli.StringFlag{
Name: "preferred-chain",
Value: "",
Usage: "If the CA offers multiple certificate chains, prefer the chain with an issuer matching this Subject Common Name. If no match, the default offered chain will be used.",
EnvVars: flagSetHelperEnvKey("PREFERRED_CHAIN"),
},
&cli.StringFlag{
Name: "dns.listen",
Value: ":53",
Usage: "Bind on this port to run the DNS server on (tcp and udp)",
EnvVars: flagSetHelperEnvKey("DNS_LISTEN"),
},
&cli.StringFlag{
Name: "dns.domain",
Value: "ns.local",
Usage: "The NS domain name of this server",
EnvVars: flagSetHelperEnvKey("DNS_DOMAIN"),
},
&cli.StringFlag{
Name: "dns.zone",
Value: "acme.local",
Usage: "The zone we are using to provide the txt records for challenge",
EnvVars: flagSetHelperEnvKey("DNS_ZONE"),
},
&cli.StringFlag{
Name: "storage",
Value: "local",
Usage: "Storage driver to use, currently only local is supported",
EnvVars: flagSetHelperEnvKey("STORAGE"),
},
&cli.StringFlag{
Name: "storage.path",
Value: os.Getenv("HOME") + "/.certjunkie",
Usage: "Path to store the certs and account data for local storage driver",
EnvVars: flagSetHelperEnvKey("STORAGE_PATH"),
},
},
Action: func(c *cli.Context) error {
Expand Down Expand Up @@ -149,51 +150,51 @@ func main() {
Name: "client",
Description: "client to retrieve cert bundle from an certjunkie api",
Flags: []cli.Flag{
cli.StringFlag{
Name: "address",
Value: "http://localhost:80",
Usage: "CertJunkie api address",
EnvVar: flagSetHelperEnvKey("CLIENT_ADDRESS"),
},
cli.StringFlag{
Name: "domain",
Usage: "Domain (common name) to obtain cert for, wildcard is allowed to use here",
EnvVar: flagSetHelperEnvKey("CLIENT_DOMAIN"),
},
cli.BoolFlag{
Name: "onlycn",
Usage: "Retrieve only certs where the common name is matching the domain",
EnvVar: flagSetHelperEnvKey("CLIENT_ONLYCN"),
},
cli.StringSliceFlag{
Name: "san",
Usage: "Additonal subject alternative names (domains) the cert must have",
EnvVar: flagSetHelperEnvKey("CLIENT_SAN"),
},
cli.IntFlag{
Name: "valid",
Usage: " How long needs the cert to be valid in days before requesting a new on",
EnvVar: flagSetHelperEnvKey("CLIENT_VALID"),
},
cli.StringFlag{
Name: "file.cert",
Usage: "Write certificate to file",
EnvVar: flagSetHelperEnvKey("CLIENT_FILE_CERT"),
},
cli.StringFlag{
Name: "file.ca",
Usage: "Write ca issuer to file",
EnvVar: flagSetHelperEnvKey("CLIENT_FILE_CA"),
},
cli.StringFlag{
Name: "file.key",
Usage: "Write private key to file",
EnvVar: flagSetHelperEnvKey("CLIENT_FILE_KEY"),
},
cli.StringFlag{
Name: "file.bundle",
Usage: "Write bundle (cert+ca) to file",
EnvVar: flagSetHelperEnvKey("CLIENT_FILE_BUNDLE"),
&cli.StringFlag{
Name: "address",
Value: "http://localhost:80",
Usage: "CertJunkie api address",
EnvVars: flagSetHelperEnvKey("CLIENT_ADDRESS"),
},
&cli.StringFlag{
Name: "domain",
Usage: "Domain (common name) to obtain cert for, wildcard is allowed to use here",
EnvVars: flagSetHelperEnvKey("CLIENT_DOMAIN"),
},
&cli.BoolFlag{
Name: "onlycn",
Usage: "Retrieve only certs where the common name is matching the domain",
EnvVars: flagSetHelperEnvKey("CLIENT_ONLYCN"),
},
&cli.StringSliceFlag{
Name: "san",
Usage: "Additonal subject alternative names (domains) the cert must have",
EnvVars: flagSetHelperEnvKey("CLIENT_SAN"),
},
&cli.IntFlag{
Name: "valid",
Usage: " How long needs the cert to be valid in days before requesting a new on",
EnvVars: flagSetHelperEnvKey("CLIENT_VALID"),
},
&cli.StringFlag{
Name: "file.cert",
Usage: "Write certificate to file",
EnvVars: flagSetHelperEnvKey("CLIENT_FILE_CERT"),
},
&cli.StringFlag{
Name: "file.ca",
Usage: "Write ca issuer to file",
EnvVars: flagSetHelperEnvKey("CLIENT_FILE_CA"),
},
&cli.StringFlag{
Name: "file.key",
Usage: "Write private key to file",
EnvVars: flagSetHelperEnvKey("CLIENT_FILE_KEY"),
},
&cli.StringFlag{
Name: "file.bundle",
Usage: "Write bundle (cert+ca) to file",
EnvVars: flagSetHelperEnvKey("CLIENT_FILE_BUNDLE"),
},
},
Action: func(c *cli.Context) error {
Expand Down Expand Up @@ -245,7 +246,6 @@ func main() {
},
},
}

app.RunAndExitOnError()

}

0 comments on commit 424953c

Please sign in to comment.