mirror of
https://github.com/hashicorp/vault.git
synced 2025-08-16 03:27:01 +02:00
* Make plugin-specific env take precedence over sys env * Expand the existing plugin env integration test --------- Co-authored-by: Austin Gebauer <34121980+austingebauer@users.noreply.github.com>
39 lines
950 B
Go
39 lines
950 B
Go
// Copyright (c) HashiCorp, Inc.
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
package mock
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
|
"github.com/hashicorp/vault/sdk/logical"
|
|
)
|
|
|
|
// pathEnv is used to interrogate plugin env vars.
|
|
func pathEnv(b *backend) *framework.Path {
|
|
return &framework.Path{
|
|
Pattern: "env/" + framework.GenericNameRegex("key"),
|
|
Fields: map[string]*framework.FieldSchema{
|
|
"key": {
|
|
Type: framework.TypeString,
|
|
Required: true,
|
|
Description: "The name of the environment variable to read.",
|
|
},
|
|
},
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
|
logical.ReadOperation: b.pathEnvRead,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (b *backend) pathEnvRead(_ context.Context, _ *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
|
// Return the secret
|
|
return &logical.Response{
|
|
Data: map[string]interface{}{
|
|
"key": os.Getenv(data.Get("key").(string)),
|
|
},
|
|
}, nil
|
|
}
|