feat(credentiallibraries): support vault ssh certificates

This commit is contained in:
Haotian authored and Timothy Messier committed 2023-02-02 17:43:16 +00:00
1 parent 3a78a74571
commit 43f0ba89cf
14 files changed
+2087 -239

No files matched your search

@@ -90,7 +90,7 @@ func (c *Client) ApiClient() *api.Client {
return c.client
}
func (c *Client) Create(ctx context.Context, credentialStoreId string, opt ...Option) (*CredentialLibraryCreateResult, error) {
func (c *Client) Create(ctx context.Context, resourceType string, credentialStoreId string, opt ...Option) (*CredentialLibraryCreateResult, error) {
if credentialStoreId == "" {
return nil, fmt.Errorf("empty credentialStoreId value passed into Create request")
}
@@ -100,6 +100,11 @@ func (c *Client) Create(ctx context.Context, credentialStoreId string, opt ...Op
if c.client == nil {
return nil, fmt.Errorf("nil client")
}
if resourceType == "" {
return nil, fmt.Errorf("empty resourceType value passed into Create request")
} else {
opts.postMap["type"] = resourceType
}
opts.postMap["credential_store_id"] = credentialStoreId
+168
View File
@@ -110,6 +110,30 @@ func DefaultCredentialType() Option {
}
}
func WithVaultSSHCertificateCredentialLibraryCriticalOptions(inCriticalOptions map[string]string) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["critical_options"] = inCriticalOptions
o.postMap["attributes"] = val
}
}
func DefaultVaultSSHCertificateCredentialLibraryCriticalOptions() Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["critical_options"] = nil
o.postMap["attributes"] = val
}
}
func WithDescription(inDescription string) Option {
return func(o *options) {
o.postMap["description"] = inDescription
@@ -122,6 +146,30 @@ func DefaultDescription() Option {
}
}
func WithVaultSSHCertificateCredentialLibraryExtensions(inExtensions map[string]string) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["extensions"] = inExtensions
o.postMap["attributes"] = val
}
}
func DefaultVaultSSHCertificateCredentialLibraryExtensions() Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["extensions"] = nil
o.postMap["attributes"] = val
}
}
func WithVaultCredentialLibraryHttpMethod(inHttpMethod string) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
@@ -170,6 +218,78 @@ func DefaultVaultCredentialLibraryHttpRequestBody() Option {
}
}
func WithVaultSSHCertificateCredentialLibraryKeyBits(inKeyBits uint32) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["key_bits"] = inKeyBits
o.postMap["attributes"] = val
}
}
func DefaultVaultSSHCertificateCredentialLibraryKeyBits() Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["key_bits"] = nil
o.postMap["attributes"] = val
}
}
func WithVaultSSHCertificateCredentialLibraryKeyId(inKeyId string) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["key_id"] = inKeyId
o.postMap["attributes"] = val
}
}
func DefaultVaultSSHCertificateCredentialLibraryKeyId() Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["key_id"] = nil
o.postMap["attributes"] = val
}
}
func WithVaultSSHCertificateCredentialLibraryKeyType(inKeyType string) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["key_type"] = inKeyType
o.postMap["attributes"] = val
}
}
func DefaultVaultSSHCertificateCredentialLibraryKeyType() Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["key_type"] = nil
o.postMap["attributes"] = val
}
}
func WithName(inName string) Option {
return func(o *options) {
o.postMap["name"] = inName
@@ -193,3 +313,51 @@ func WithVaultCredentialLibraryPath(inPath string) Option {
o.postMap["attributes"] = val
}
}
func WithVaultSSHCertificateCredentialLibraryPath(inPath string) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["path"] = inPath
o.postMap["attributes"] = val
}
}
func WithVaultSSHCertificateCredentialLibraryTtl(inTtl string) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["ttl"] = inTtl
o.postMap["attributes"] = val
}
}
func DefaultVaultSSHCertificateCredentialLibraryTtl() Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["ttl"] = nil
o.postMap["attributes"] = val
}
}
func WithVaultSSHCertificateCredentialLibraryUsername(inUsername string) Option {
return func(o *options) {
raw, ok := o.postMap["attributes"]
if !ok {
raw = interface{}(map[string]interface{}{})
}
val := raw.(map[string]interface{})
val["username"] = inUsername
o.postMap["attributes"] = val
}
}
@@ -0,0 +1,44 @@
// Code generated by "make api"; DO NOT EDIT.
package credentiallibraries
import (
"fmt"
"github.com/mitchellh/mapstructure"
)
type VaultSSHCertificateCredentialLibraryAttributes struct {
Path string `json:"path,omitempty"`
Username string `json:"username,omitempty"`
KeyType string `json:"key_type,omitempty"`
KeyBits uint32 `json:"key_bits,omitempty"`
Ttl string `json:"ttl,omitempty"`
KeyId string `json:"key_id,omitempty"`
CriticalOptions map[string]string `json:"critical_options,omitempty"`
Extensions map[string]string `json:"extensions,omitempty"`
}
func AttributesMapToVaultSSHCertificateCredentialLibraryAttributes(in map[string]interface{}) (*VaultSSHCertificateCredentialLibraryAttributes, error) {
if in == nil {
return nil, fmt.Errorf("nil input map")
}
var out VaultSSHCertificateCredentialLibraryAttributes
dec, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
Result: &out,
TagName: "json",
})
if err != nil {
return nil, fmt.Errorf("error creating mapstructure decoder: %w", err)
}
if err := dec.Decode(in); err != nil {
return nil, fmt.Errorf("error decoding: %w", err)
}
return &out, nil
}
func (pt *CredentialLibrary) GetVaultSSHCertificateCredentialLibraryAttributes() (*VaultSSHCertificateCredentialLibraryAttributes, error) {
if pt.Type != "vaultsshcertificate" {
return nil, fmt.Errorf("asked to fetch %s-type attributes but credential-library is of type %s", "vaultsshcertificate", pt.Type)
}
return AttributesMapToVaultSSHCertificateCredentialLibraryAttributes(pt.Attributes)
}