Skip to content

Commit

Permalink
refactor cmds into subcmd package names and files (#373)
Browse files Browse the repository at this point in the history
* 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
gertd committed May 8, 2024
1 parent f2f423e commit b68f4cb
Show file tree
Hide file tree
Showing 31 changed files with 1,174 additions and 1,044 deletions.
305 changes: 0 additions & 305 deletions pkg/cli/cmd/certs.go

This file was deleted.

80 changes: 80 additions & 0 deletions pkg/cli/cmd/certs/certs.go
@@ -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
}

0 comments on commit b68f4cb

Please sign in to comment.