mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-10 00:27:02 +02:00
* add new plugin wif fields to AWS Secrets Engine * add changelog * go get awsutil v0.3.0 * fix up changelog * fix test and field parsing helper * godoc on new test * require role arn when audience set * make fmt --------- Co-authored-by: Austin Gebauer <agebauer@hashicorp.com> Co-authored-by: Austin Gebauer <34121980+austingebauer@users.noreply.github.com>
64 lines
2.0 KiB
Go
64 lines
2.0 KiB
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package pluginidentityutil
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
|
)
|
|
|
|
// PluginIdentityTokenParams contains a set of common parameters that plugins
|
|
// can use for setting plugin identity token behavior.
|
|
type PluginIdentityTokenParams struct {
|
|
// IdentityTokenTTL is the duration that tokens will be valid for
|
|
IdentityTokenTTL time.Duration `json:"identity_token_ttl"`
|
|
// IdentityTokenAudience identifies the recipient of the token
|
|
IdentityTokenAudience string `json:"identity_token_audience"`
|
|
}
|
|
|
|
// ParsePluginIdentityTokenFields provides common field parsing to embedding structs.
|
|
func (p *PluginIdentityTokenParams) ParsePluginIdentityTokenFields(d *framework.FieldData) error {
|
|
if tokenTTLRaw, ok := d.GetOk("identity_token_ttl"); ok {
|
|
p.IdentityTokenTTL = time.Duration(tokenTTLRaw.(int)) * time.Second
|
|
}
|
|
|
|
if tokenAudienceRaw, ok := d.GetOk("identity_token_audience"); ok {
|
|
p.IdentityTokenAudience = tokenAudienceRaw.(string)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// PopulatePluginIdentityTokenData adds PluginIdentityTokenParams info into the given map.
|
|
func (p *PluginIdentityTokenParams) PopulatePluginIdentityTokenData(m map[string]interface{}) {
|
|
m["identity_token_ttl"] = int64(p.IdentityTokenTTL.Seconds())
|
|
m["identity_token_audience"] = p.IdentityTokenAudience
|
|
}
|
|
|
|
// AddPluginIdentityTokenFields adds plugin identity token fields to the given
|
|
// field schema map.
|
|
func AddPluginIdentityTokenFields(m map[string]*framework.FieldSchema) {
|
|
fields := map[string]*framework.FieldSchema{
|
|
"identity_token_audience": {
|
|
Type: framework.TypeString,
|
|
Description: "Audience of plugin identity tokens",
|
|
Default: "",
|
|
},
|
|
"identity_token_ttl": {
|
|
Type: framework.TypeDurationSecond,
|
|
Description: "Time-to-live of plugin identity tokens",
|
|
Default: 3600,
|
|
},
|
|
}
|
|
|
|
for name, schema := range fields {
|
|
if _, ok := m[name]; ok {
|
|
panic(fmt.Sprintf("adding field %q would overwrite existing field", name))
|
|
}
|
|
m[name] = schema
|
|
}
|
|
}
|