generated from Esonhugh/go-cli-template-v2
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. update service subcommands 2. add feature of pods PTR record scan
- Loading branch information
Showing
10 changed files
with
228 additions
and
75 deletions.
There are no files selected for viewing
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
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
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
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 |
---|---|---|
@@ -1,41 +1 @@ | ||
package service | ||
|
||
import ( | ||
"fmt" | ||
|
||
command "github.com/esonhugh/k8spider/cmd" | ||
"github.com/esonhugh/k8spider/define" | ||
"github.com/esonhugh/k8spider/pkg/printer" | ||
"github.com/esonhugh/k8spider/pkg/scanner" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var Opts struct { | ||
SvcDomains []string | ||
} | ||
|
||
func init() { | ||
ServiceCmd.PersistentFlags().StringSliceVarP(&Opts.SvcDomains, "svc-domains", "s", []string{}, "service domains, like: kubernetes.default,etcd.default don't add zone like svc.cluster.local") | ||
command.RootCmd.AddCommand(ServiceCmd) | ||
} | ||
|
||
var ServiceCmd = &cobra.Command{ | ||
Use: "service", | ||
Aliases: []string{ | ||
"srv", | ||
}, | ||
Short: "service is a tool to discover k8s services ports", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if command.Opts.Zone == "" || Opts.SvcDomains == nil || len(Opts.SvcDomains) == 0 { | ||
log.Warn("zone can't empty and svc-domains can't empty") | ||
return | ||
} | ||
var records define.Records | ||
for _, domain := range Opts.SvcDomains { | ||
records = append(records, define.Record{SvcDomain: fmt.Sprintf("%s.svc.%s", domain, command.Opts.Zone)}) | ||
} | ||
records = scanner.ScanSvcForPorts(records) | ||
printer.PrintResult(records, command.Opts.OutputFile) | ||
}, | ||
} |
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
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
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
Oops, something went wrong.