Skip to content

Commit

Permalink
feat: --insecure option, also fix arguments to goals command.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanconway committed Jun 11, 2024
1 parent 69523b5 commit 0601c53
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 11 deletions.
13 changes: 11 additions & 2 deletions cmd/korrel8rcli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

"os"

httptransport "github.com/go-openapi/runtime/client"
rtclient "github.com/go-openapi/runtime/client"
"github.com/korrel8r/client/pkg/build"
"github.com/korrel8r/client/pkg/swagger/client"
"github.com/spf13/cobra"
Expand All @@ -27,6 +27,7 @@ var (
// Global Flags
output = EnumFlag("yaml", "json-pretty", "json")
korrel8rURL = rootCmd.PersistentFlags().StringP("url", "u", "", "URL of remote korrel8r service (you can also set the KORREL8R_URL environment variable)")
insecure = rootCmd.PersistentFlags().BoolP("insecure", "k", false, "Insecure connection, skip TLS verification.")
)

func main() {
Expand Down Expand Up @@ -58,7 +59,15 @@ func newClient() *client.RESTAPI {
if u.Path == "" || u.Path == "/" {
u.Path = client.DefaultBasePath
}
return client.New(httptransport.New(u.Host, u.Path, []string{u.Scheme}), nil)
var rt *rtclient.Runtime
if *insecure {
tlsClient, err := rtclient.TLSClient(rtclient.TLSClientOptions{InsecureSkipVerify: true})
check(err)
rt = rtclient.NewWithClient(u.Host, u.Path, []string{u.Scheme}, tlsClient)
} else {
rt = rtclient.New(u.Host, u.Path, []string{u.Scheme})
}
return client.New(rt, nil)
}

func check(err error) {
Expand Down
4 changes: 3 additions & 1 deletion cmd/korrel8rcli/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func setup(t *testing.T) *url.URL {
// Wait for server to be listening
require.Eventually(t, func() bool {
c, err := net.Dial("tcp", u.Host)
defer func() { _ = c.Close() }()
if err == nil {
_ = c.Close()
}
return err == nil
}, time.Second, time.Second/10)
require.NoError(t, err)
Expand Down
16 changes: 8 additions & 8 deletions cmd/korrel8rcli/operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ var (
queries []string
class string
objects []string
goals []string
depth int64
rules bool
)
Expand Down Expand Up @@ -63,6 +62,7 @@ func init() {
var neighboursCmd = &cobra.Command{
Use: "neighbours [FLAGS]",
Short: "Get graph of nearest neighbours",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
c := newClient()
ok, err := c.Operations.PostGraphsNeighbours(&operations.PostGraphsNeighboursParams{
Expand All @@ -78,13 +78,14 @@ var neighboursCmd = &cobra.Command{
}

var goalsCmd = &cobra.Command{
Use: "goals [FLAGS]",
Short: "Get graph of nearest goals",
Use: "goals [FLAGS] CLASS...",
Short: "Get graph of goal classes reachable from start",
Args: cobra.MinimumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
c := newClient()
ok, err := c.Operations.PostGraphsGoals(&operations.PostGraphsGoalsParams{
Request: &models.Goals{
Goals: goals,
Goals: args,
Start: makeStart(),
},
Rules: &rules,
Expand All @@ -96,15 +97,14 @@ var goalsCmd = &cobra.Command{

func commonFlags(cmd *cobra.Command) {
rootCmd.AddCommand(cmd)
cmd.Flags().StringArrayVar(&queries, "query", nil, "Query string for start objects, can be multiple.")
cmd.Flags().StringVar(&class, "class", "", "Class for serialized start objects")
cmd.Flags().StringArrayVar(&objects, "object", nil, "Serialized start object, can be multiple.")
cmd.Flags().StringArrayVarP(&queries, "query", "q", nil, "Query string for start objects, can be multiple.")
cmd.Flags().StringVarP(&class, "class", "c", "", "Class for serialized start objects")
cmd.Flags().StringArrayVarP(&objects, "object", "0", nil, "Serialized start object, can be multiple.")
cmd.Flags().BoolVar(&rules, "rules", false, "Include per-rule information in returned graph.")
}

func init() {
commonFlags(neighboursCmd)
neighboursCmd.Flags().Int64Var(&depth, "depth", 2, "Depth of neighbourhood search.")
commonFlags(goalsCmd)
goalsCmd.Flags().StringArrayVar(&goals, "goal", nil, "Goal class, can be multiple.")
}

0 comments on commit 0601c53

Please sign in to comment.