Rename root, api and sdk module paths (imports, go.mod, go_package, ldflags, build scripts, buf configs) and regenerate protobuf/gateway code with the project's pinned toolchain. Wire identifiers unchanged. api gets a local replace for sdk; root/api/sdk require v0.1.0. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
80 lines
2.4 KiB
Go
80 lines
2.4 KiB
Go
// Copyright IBM Corp. 2020, 2026
|
|
// SPDX-License-Identifier: BUSL-1.1
|
|
|
|
package connect
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"repo.anhonesthost.net/CyberCoveLLC/threshold/internal/cmd/base"
|
|
"github.com/posener/complete"
|
|
)
|
|
|
|
const (
|
|
kubeSynopsis = "Authorize a session against a target and invoke a Kubernetes client to connect"
|
|
)
|
|
|
|
func kubeOptions(c *Command, set *base.FlagSets) {
|
|
f := set.NewFlagSet("Kubernetes Options")
|
|
|
|
f.StringVar(&base.StringVar{
|
|
Name: "style",
|
|
Target: &c.flagKubeStyle,
|
|
EnvVar: fmt.Sprintf("THRESHOLD_CONNECT_%s_STYLE", strings.ToUpper(c.Func)),
|
|
Completion: complete.PredictSet("kubectl"),
|
|
Default: "kubectl",
|
|
Usage: `Specifies how the CLI will attempt to invoke a Kubernetes client. This will also set a suitable default for -exec if a value was not specified. Currently-understood values are "kubectl".`,
|
|
})
|
|
|
|
f.StringVar(&base.StringVar{
|
|
Name: "host",
|
|
Target: &c.flagKubeHost,
|
|
EnvVar: fmt.Sprintf("THRESHOLD_CONNECT_%s_HOST", strings.ToUpper(c.Func)),
|
|
Completion: complete.PredictNothing,
|
|
Usage: `Specifies the host value to use, overriding the endpoint address from the session information. The specified hostname will be passed through to the client (if supported) for use in the TLS SNI value.`,
|
|
})
|
|
|
|
f.StringVar(&base.StringVar{
|
|
Name: "scheme",
|
|
Target: &c.flagKubeScheme,
|
|
Default: "https",
|
|
EnvVar: fmt.Sprintf("THRESHOLD_CONNECT_%s_SCHEME", strings.ToUpper(c.Func)),
|
|
Completion: complete.PredictNothing,
|
|
Usage: `Specifies the scheme to use.`,
|
|
})
|
|
}
|
|
|
|
type kubeFlags struct {
|
|
flagKubeStyle string
|
|
flagKubeHost string
|
|
flagKubeScheme string
|
|
}
|
|
|
|
func (f *kubeFlags) defaultExec() string {
|
|
return strings.ToLower(f.flagKubeStyle)
|
|
}
|
|
|
|
func (f *kubeFlags) buildArgs(c *Command, port, ip, addr string) ([]string, error) {
|
|
var args []string
|
|
host := f.flagKubeHost
|
|
if host == "" && c.sessInfo.Endpoint != "" {
|
|
hostUrl := c.sessInfo.Endpoint
|
|
u, err := url.Parse(hostUrl)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("error parsing endpoint URL: %w", err)
|
|
}
|
|
host = u.Hostname()
|
|
}
|
|
switch f.flagKubeStyle {
|
|
case "kubectl":
|
|
if host != "" && f.flagKubeScheme == "https" {
|
|
host = strings.TrimSuffix(host, "/")
|
|
args = append(args, "--tls-server-name", host)
|
|
}
|
|
args = append(args, "--server", fmt.Sprintf("%s://%s", f.flagKubeScheme, addr))
|
|
}
|
|
return args, nil
|
|
}
|