Files
threshold/internal/cmd/commands/credentiallibrariescmd/vault-ssh-certificate_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

268 lines
8.2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package credentiallibrariescmd
import (
"fmt"
"strconv"
"github.com/hashicorp/boundary/api/credentiallibraries"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/common"
)
func init() {
extraVaultSshCertificateFlagsFunc = extraVaultSshCertificateFlagsFuncImpl
extraVaultSshCertificateActionsFlagsMapFunc = extraVaultSshCertificateActionsFlagsMapFuncImpl
extraVaultSshCertificateFlagsHandlingFunc = extraVaultSshCertificateFlagHandlingFuncImpl
}
const (
usernameName = "username"
keyTypeName = "key-type"
keyBitsName = "key-bits"
ttlName = "ttl"
keyIdName = "key-id"
criticalOptionsName = "critical-options"
piecewiseCriticalOptionsName = "critical-option"
extensionsName = "extensions"
piecewiseExtensionName = "extension"
)
type extraVaultSshCertificateCmdVars struct {
flagPath string
flagUsername string
flagKeyType string
flagKeyBits string
flagTtl string
flagKeyId string
flagCriticalOptions string
flagCriticalOpts []base.CombinedSliceFlagValue
flagExtensions string
flagExtens []base.CombinedSliceFlagValue
}
func extraVaultSshCertificateActionsFlagsMapFuncImpl() map[string][]string {
flags := map[string][]string{
"create": {
pathFlagName,
usernameName,
keyTypeName,
keyBitsName,
ttlName,
keyIdName,
criticalOptionsName,
piecewiseCriticalOptionsName,
extensionsName,
piecewiseExtensionName,
},
"update": {
pathFlagName,
usernameName,
keyTypeName,
keyBitsName,
ttlName,
keyIdName,
criticalOptionsName,
piecewiseCriticalOptionsName,
extensionsName,
piecewiseExtensionName,
},
}
return flags
}
func extraVaultSshCertificateFlagsFuncImpl(c *VaultSshCertificateCommand, set *base.FlagSets, _ *base.FlagSet) {
f := set.NewFlagSet("Vault SSH Certificate Credential Library Options")
for _, name := range flagsVaultSshCertificateMap[c.Func] {
switch name {
case pathFlagName:
f.StringVar(&base.StringVar{
Name: pathFlagName,
Target: &c.flagPath,
Usage: "The path in vault to request credentials from.",
})
case usernameName:
f.StringVar(&base.StringVar{
Name: usernameName,
Target: &c.flagUsername,
Usage: "The username to use with the ssh certificate.",
})
case keyTypeName:
f.StringVar(&base.StringVar{
Name: keyTypeName,
Target: &c.flagKeyType,
Usage: "The key type for the generated ssh private key. One of: ed25519, ecdsa, rsa.",
})
case keyBitsName:
f.StringVar(&base.StringVar{
Name: keyBitsName,
Target: &c.flagKeyBits,
Usage: "The number of bits when generating the ssh private key. Depends on key_type. If ed25519 this should not be set, or set to 0, if ecdsa one of 256, 384, 521, if rsa one of 2048, 3072, 4096.",
})
case ttlName:
f.StringVar(&base.StringVar{
Name: ttlName,
Target: &c.flagTtl,
Usage: "The time-to-live for the generated certificate.",
})
case keyIdName:
f.StringVar(&base.StringVar{
Name: keyIdName,
Target: &c.flagKeyId,
Usage: "The key id that the created certificate should have.",
})
}
}
criticalOptsInput := common.CombinedSliceFlagValuePopulationInput{
FlagSet: f,
FlagNames: flagsVaultSshCertificateMap[c.Func],
FullPopulationFlag: &c.flagCriticalOptions,
FullPopulationInputName: criticalOptionsName,
PiecewisePopulationFlag: &c.flagCriticalOpts,
PiecewisePopulationInputBaseName: piecewiseCriticalOptionsName,
PiecewiseNoProtoCompat: true,
}
common.PopulateCombinedSliceFlagValue(criticalOptsInput)
extensionsInput := common.CombinedSliceFlagValuePopulationInput{
FlagSet: f,
FlagNames: flagsVaultSshCertificateMap[c.Func],
FullPopulationFlag: &c.flagExtensions,
FullPopulationInputName: extensionsName,
PiecewisePopulationFlag: &c.flagExtens,
PiecewisePopulationInputBaseName: piecewiseExtensionName,
PiecewiseNoProtoCompat: true,
}
common.PopulateCombinedSliceFlagValue(extensionsInput)
}
func extraVaultSshCertificateFlagHandlingFuncImpl(c *VaultSshCertificateCommand, _ *base.FlagSets, opts *[]credentiallibraries.Option) bool {
switch c.flagPath {
case "":
default:
*opts = append(*opts, credentiallibraries.WithVaultCredentialLibraryPath(c.flagPath))
}
switch c.flagUsername {
case "":
default:
*opts = append(*opts, credentiallibraries.WithVaultSSHCertificateCredentialLibraryUsername(c.flagUsername))
}
switch c.flagKeyType {
case "":
case "null":
*opts = append(*opts, credentiallibraries.DefaultVaultSSHCertificateCredentialLibraryKeyType())
default:
*opts = append(*opts, credentiallibraries.WithVaultSSHCertificateCredentialLibraryKeyType(c.flagKeyType))
}
switch c.flagKeyBits {
case "":
case "0", "null":
*opts = append(*opts, credentiallibraries.DefaultVaultSSHCertificateCredentialLibraryKeyBits())
default:
var final uint32
keyBits, err := strconv.ParseUint(c.flagKeyBits, 10, 32)
if err != nil {
c.UI.Error(fmt.Sprintf("Error parsing %q: %s", c.flagKeyBits, err))
return false
}
final = uint32(keyBits)
*opts = append(*opts, credentiallibraries.WithVaultSSHCertificateCredentialLibraryKeyBits(final))
}
switch c.flagTtl {
case "":
case "null":
*opts = append(*opts, credentiallibraries.DefaultVaultSSHCertificateCredentialLibraryTtl())
default:
*opts = append(*opts, credentiallibraries.WithVaultSSHCertificateCredentialLibraryTtl(c.flagTtl))
}
switch c.flagKeyId {
case "":
case "null":
*opts = append(*opts, credentiallibraries.DefaultVaultSSHCertificateCredentialLibraryKeyId())
default:
*opts = append(*opts, credentiallibraries.WithVaultSSHCertificateCredentialLibraryKeyId(c.flagKeyId))
}
if err := common.HandleAttributeFlags(
c.Command,
piecewiseCriticalOptionsName,
c.flagCriticalOptions,
c.flagCriticalOpts,
func() {
*opts = append(*opts, credentiallibraries.DefaultVaultSSHCertificateCredentialLibraryCriticalOptions())
},
func(in map[string]any) {
inn := make(map[string]string, len(in))
for k, v := range in {
switch vv := v.(type) {
case nil:
inn[k] = ""
case string:
inn[k] = vv
default:
continue
}
}
*opts = append(*opts, credentiallibraries.WithVaultSSHCertificateCredentialLibraryCriticalOptions(inn))
}); err != nil {
return false
}
if err := common.HandleAttributeFlags(
c.Command,
piecewiseExtensionName,
c.flagExtensions,
c.flagExtens,
func() {
*opts = append(*opts, credentiallibraries.DefaultVaultSSHCertificateCredentialLibraryExtensions())
},
func(in map[string]any) {
inn := make(map[string]string, len(in))
for k, v := range in {
switch vv := v.(type) {
case nil:
inn[k] = ""
case string:
inn[k] = vv
default:
continue
}
}
*opts = append(*opts, credentiallibraries.WithVaultSSHCertificateCredentialLibraryExtensions(inn))
}); err != nil {
return false
}
return true
}
func (c *VaultSshCertificateCommand) extraVaultSshCertificateHelpFunc(_ map[string]func() string) string {
var helpStr string
switch c.Func {
case "create":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary credential-libraries create vault-ssh-certificate -credential-store-id [options] [args]",
"",
" Create a vault-ssh-certificate-type credential library. Example:",
"",
` $ boundary credential-libraries create vault-ssh-certificate -credential-store-id csvlt_1234567890 -vault-path "/ssh/sign/role" -username user`,
"",
"",
})
case "update":
helpStr = base.WrapForHelpText([]string{
"Usage: boundary credential-libraries update vault-ssh-certificate [options] [args]",
"",
" Update a vault-ssh-certificate-type credential library given its ID. Example:",
"",
` $ boundary credential-libraries update vault-ssh-certificate -id clvsclt_1234567890 -name devops -description "For DevOps usage"`,
"",
"",
})
}
return helpStr + c.Flags().Help()
}