Files
threshold/internal/cmd/commands/targetscmd/ssh_funcs.go
T
hashicorp-copywrite[bot]andJohan Brandhorst-Satzkorn 29da0bcb92 [COMPLIANCE] License changes (#3567)
* Adding explicit MPL license for sub-package.

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Adding explicit MPL license for sub-package

This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository.

* Updating the license from MPL to Business Source License

Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at https://hashi.co/bsl-blog, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl.

* Update copyright file headers to BUS-1.1

* Rerun make gen

This will pick up the last of the license changes

* Revert "Rerun make gen"

This reverts commit dbe0968bffd92745d8663c6940debae098395a6b.

* Remove copywrite from generation script

The current version of copywrite is not sophisticated enough
to only apply the copywrite changes to certain subdirectories,
so to avoid accidentally relicensing our api and sdk modules,
we will stop running the copywrite script until such time
that it can do the right thing.

* License protobuf API as MPL

The protobuf API files are used to generate the SDK,
since we want the SDK to be MPL, the protobuf files
must also be MPL. This extends to all protobuf files
whose sources end up in the SDK directory, including:

- internal/proto/controller/api
- internal/proto/controller/custom_options
- internal/proto/plugin

It also includes the generated service directory in
internal/gen/controller/api/services, since they are
generated from the protobuf sources used for the SDK.

* Change website license file name

This makes the naming scheme consistent with the rest
of the repository.

* Add note on licensing to README

* Set copywrite license to BUSL

* Revert "Add note on licensing to README"

This reverts commit 4d865a91a7a4f11605f0dc4609355d7e3c3cfffe.

---------

Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
2023-08-11 10:31:53 -07:00

276 lines
8.5 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package targetscmd
import (
"fmt"
"strconv"
"time"
"github.com/hashicorp/boundary/api/targets"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/go-bexpr"
)
func init() {
extraSshActionsFlagsMapFunc = extraSshActionsFlagsMapFuncImpl
extraSshFlagsFunc = extraSshFlagsFuncImpl
extraSshFlagsHandlingFunc = extraSshFlagsHandlingFuncImpl
extraSshSynopsisFunc = extraSshSynopsisFuncImpl
}
func extraSshActionsFlagsMapFuncImpl() map[string][]string {
return map[string][]string{
"create": {
"address", "default-port", "default-client-port", "session-max-seconds", "session-connection-limit",
"egress-worker-filter", "ingress-worker-filter", "enable-session-recording",
"storage-bucket-id",
},
"update": {
"address", "default-port", "default-client-port", "session-max-seconds", "session-connection-limit",
"worker-filter", "egress-worker-filter", "ingress-worker-filter", "enable-session-recording",
"storage-bucket-id",
},
}
}
type extraSshCmdVars struct {
flagDefaultPort string
flagDefaultClientPort string
flagSessionMaxSeconds string
flagSessionConnectionLimit string
flagWorkerFilter string
flagEgressWorkerFilter string
flagIngressWorkerFilter string
flagAddress string
flagStorageBucketId string
flagEnableSessionRecording string
}
func (c *SshCommand) extraSshHelpFunc(helpMap map[string]func() string) string {
var helpStr string
switch c.Func {
case "create":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary targets create ssh [options] [args]",
"",
" Create a ssh-type target. Example:",
"",
` $ boundary targets create ssh -name prodops -description "Ssh target for ProdOps"`,
"",
"",
})
case "update":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary targets update ssh [options] [args]",
"",
" Update a ssh-type target given its ID. Example:",
"",
` $ boundary targets update ssh -id tssh_1234567890 -name "devops" -description "Ssh target for DevOps"`,
"",
"",
})
}
return helpStr + c.Flags().Help()
}
func extraSshFlagsFuncImpl(c *SshCommand, set *base.FlagSets, f *base.FlagSet) {
fs := set.NewFlagSet("SSH Target Options")
for _, name := range flagsSshMap[c.Func] {
switch name {
case "address":
fs.StringVar(&base.StringVar{
Name: "address",
Target: &c.flagAddress,
Usage: "Optionally, a valid network address to connect to for this target. Can not be used alongside host sources.",
})
case "default-port":
fs.StringVar(&base.StringVar{
Name: "default-port",
Target: &c.flagDefaultPort,
Usage: "Optionally, the default port to set on the target. If not specified, it will be set to 22.",
})
case "default-client-port":
fs.StringVar(&base.StringVar{
Name: "default-client-port",
Target: &c.flagDefaultClientPort,
Usage: "The default client port to set on the target.",
})
case "session-max-seconds":
fs.StringVar(&base.StringVar{
Name: "session-max-seconds",
Target: &c.flagSessionMaxSeconds,
Usage: `The maximum lifetime of the session, including all connections. Can be specified as an integer number of seconds or a duration string.`,
})
case "session-connection-limit":
fs.StringVar(&base.StringVar{
Name: "session-connection-limit",
Target: &c.flagSessionConnectionLimit,
Usage: "The maximum number of connections allowed for a session. -1 means unlimited.",
})
case "worker-filter":
fs.StringVar(&base.StringVar{
Name: "worker-filter",
Target: &c.flagWorkerFilter,
Usage: "Deprecated: use egress or ingress filters instead.",
})
case "egress-worker-filter":
fs.StringVar(&base.StringVar{
Name: "egress-worker-filter",
Target: &c.flagEgressWorkerFilter,
Usage: "A boolean expression to filter which egress workers can handle sessions for this target.",
})
case "ingress-worker-filter":
fs.StringVar(&base.StringVar{
Name: "ingress-worker-filter",
Target: &c.flagIngressWorkerFilter,
Usage: "A boolean expression to filter which ingress workers can handle sessions for this target.",
})
case "storage-bucket-id":
fs.StringVar(&base.StringVar{
Name: "storage-bucket-id",
Target: &c.flagStorageBucketId,
Usage: "The public ID of the storage bucket to associate with this target.",
})
case "enable-session-recording":
fs.StringVar(&base.StringVar{
Name: "enable-session-recording",
Target: &c.flagEnableSessionRecording,
Usage: "A boolean indicating if session recording is enabled for this target.",
})
}
}
}
func extraSshFlagsHandlingFuncImpl(c *SshCommand, _ *base.FlagSets, opts *[]targets.Option) bool {
switch c.flagDefaultPort {
case "":
case "null":
*opts = append(*opts, targets.DefaultSshTargetDefaultPort())
default:
port, err := strconv.ParseUint(c.flagDefaultPort, 10, 32)
if err != nil {
c.UI.Error(fmt.Sprintf("Error parsing %q: %s", c.flagDefaultPort, err))
return false
}
*opts = append(*opts, targets.WithSshTargetDefaultPort(uint32(port)))
}
switch c.flagDefaultClientPort {
case "":
case "null":
*opts = append(*opts, targets.DefaultSshTargetDefaultClientPort())
default:
port, err := strconv.ParseUint(c.flagDefaultClientPort, 10, 32)
if err != nil {
c.UI.Error(fmt.Sprintf("Error parsing %q: %s", c.flagDefaultClientPort, err))
return false
}
*opts = append(*opts, targets.WithSshTargetDefaultClientPort(uint32(port)))
}
switch c.flagSessionMaxSeconds {
case "":
case "null":
*opts = append(*opts, targets.DefaultSessionMaxSeconds())
default:
var final uint32
dur, err := strconv.ParseUint(c.flagSessionMaxSeconds, 10, 32)
if err == nil {
final = uint32(dur)
} else {
dur, err := time.ParseDuration(c.flagSessionMaxSeconds)
if err != nil {
c.UI.Error(fmt.Sprintf("Error parsing %q: %s", c.flagSessionMaxSeconds, err))
return false
}
final = uint32(dur.Seconds())
}
*opts = append(*opts, targets.WithSessionMaxSeconds(final))
}
switch c.flagSessionConnectionLimit {
case "":
case "null":
*opts = append(*opts, targets.DefaultSessionConnectionLimit())
default:
limit, err := strconv.ParseInt(c.flagSessionConnectionLimit, 10, 32)
if err != nil {
c.UI.Error(fmt.Sprintf("Error parsing %q: %s", c.flagSessionConnectionLimit, err))
return false
}
*opts = append(*opts, targets.WithSessionConnectionLimit(int32(limit)))
}
switch c.flagWorkerFilter {
case "":
case "null":
*opts = append(*opts, targets.DefaultWorkerFilter())
default:
if _, err := bexpr.CreateEvaluator(c.flagWorkerFilter); err != nil {
c.UI.Error(fmt.Sprintf("Unable to successfully parse worker filter expression: %s", err))
return false
}
*opts = append(*opts, targets.WithWorkerFilter(c.flagWorkerFilter))
}
switch c.flagEgressWorkerFilter {
case "":
case "null":
*opts = append(*opts, targets.DefaultEgressWorkerFilter())
default:
if _, err := bexpr.CreateEvaluator(c.flagEgressWorkerFilter); err != nil {
c.UI.Error(fmt.Sprintf("Unable to successfully parse egress filter expression: %s", err))
return false
}
*opts = append(*opts, targets.WithEgressWorkerFilter(c.flagEgressWorkerFilter))
}
switch c.flagIngressWorkerFilter {
case "":
case "null":
*opts = append(*opts, targets.DefaultIngressWorkerFilter())
default:
if _, err := bexpr.CreateEvaluator(c.flagIngressWorkerFilter); err != nil {
c.UI.Error(fmt.Sprintf("Unable to successfully parse ingress filter expression: %s", err))
return false
}
*opts = append(*opts, targets.WithIngressWorkerFilter(c.flagIngressWorkerFilter))
}
switch c.flagAddress {
case "":
case "null":
*opts = append(*opts, targets.DefaultAddress())
default:
*opts = append(*opts, targets.WithAddress(c.flagAddress))
}
switch c.flagStorageBucketId {
case "":
case "null":
*opts = append(*opts, targets.DefaultSshTargetStorageBucketId())
default:
*opts = append(*opts, targets.WithSshTargetStorageBucketId(c.flagStorageBucketId))
}
switch c.flagEnableSessionRecording {
case "":
case "false":
*opts = append(*opts, targets.WithSshTargetEnableSessionRecording(false))
case "true":
*opts = append(*opts, targets.WithSshTargetEnableSessionRecording(true))
default:
c.UI.Error(fmt.Sprintf("Invalid bool value for enable-session-recording %v", c.flagEnableSessionRecording))
return false
}
return true
}
func extraSshSynopsisFuncImpl(_ *SshCommand) string {
return "Create a ssh-type target (HCP only)"
}