Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor cmds into subcmd package names and files (#373)
* add InfoConfigCmd * return exit(0) when no args * return status code 0 if no args * impl topaz config info * impl topaz config info * refactor flow env as kong vars, via cc.* * refactor map to struct to preserve field ordering * refactor cmds into subcmd package names and files
- Loading branch information
Showing
31 changed files
with
1,174 additions
and
1,044 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package certs | ||
|
||
import ( | ||
"fmt" | ||
"path/filepath" | ||
) | ||
|
||
type CertsCmd struct { | ||
List ListCertsCmd `cmd:"" help:"list dev certs"` | ||
Generate GenerateCertsCmd `cmd:"" help:"generate dev certs"` | ||
Trust TrustCertsCmd `cmd:"" help:"trust/untrust dev certs"` | ||
Remove RemoveCertFileCmd `cmd:"" help:"remove dev certs"` | ||
} | ||
|
||
const ( | ||
gatewayFileName = "gateway" | ||
grpcFileName = "grpc" | ||
certCommonName = "topaz" | ||
) | ||
|
||
type fileListArgs struct { | ||
inclCACerts bool | ||
inclCerts bool | ||
inclKeys bool | ||
} | ||
|
||
type fileListOption func(*fileListArgs) | ||
|
||
func withAll() fileListOption { | ||
return func(arg *fileListArgs) { | ||
arg.inclCACerts = true | ||
arg.inclCerts = true | ||
arg.inclKeys = true | ||
} | ||
} | ||
|
||
func withCerts() fileListOption { | ||
return func(arg *fileListArgs) { | ||
arg.inclCerts = true | ||
arg.inclCACerts = true | ||
} | ||
} | ||
|
||
func withCACerts() fileListOption { | ||
return func(arg *fileListArgs) { | ||
arg.inclCACerts = true | ||
} | ||
} | ||
|
||
func getFileList(certsDir string, opts ...fileListOption) []string { | ||
args := &fileListArgs{} | ||
for _, opt := range opts { | ||
opt(args) | ||
} | ||
|
||
filePaths := []string{} | ||
|
||
if args.inclCACerts { | ||
filePaths = append(filePaths, | ||
filepath.Join(certsDir, fmt.Sprintf("%s-ca.crt", grpcFileName)), | ||
filepath.Join(certsDir, fmt.Sprintf("%s-ca.crt", gatewayFileName)), | ||
) | ||
} | ||
|
||
if args.inclCerts { | ||
filePaths = append(filePaths, | ||
filepath.Join(certsDir, fmt.Sprintf("%s.crt", grpcFileName)), | ||
filepath.Join(certsDir, fmt.Sprintf("%s.crt", gatewayFileName)), | ||
) | ||
} | ||
|
||
if args.inclKeys { | ||
filePaths = append(filePaths, | ||
filepath.Join(certsDir, fmt.Sprintf("%s.key", grpcFileName)), | ||
filepath.Join(certsDir, fmt.Sprintf("%s.key", gatewayFileName)), | ||
) | ||
} | ||
|
||
return filePaths | ||
} |
Oops, something went wrong.