vault/api/sys_reporting_scan.go
Vault Automation 56b8a14ff5
1.21 reporting scan backports (#10746) (#10754)
* VAULT-39876 Add sys/reporting/scan to Vault, allowing an output of files with paths and names of Vault secrets (#10068)

* VAULT-39876 sys/reporting/scan for KV secrets

* make fmt

* changelog

* stray t.log

* typo

* fix race probably

* Bug fix, add local mount

* remove comment

* bolster external tests

* Add missing enterprise stub for reporting scan (#10327)

* VAULT-40300 Add full directory path to sys/reporting/scan (#10362)

* add directory path

* wip

* tests, cleanup

* VAULT-40562 Use mount accessor for reporting scan file names (#10512)

* VAULT-40562 Use mount accessor for reporting scan file names

* whoopsie

* VAULT-39878 Add database support to sys/reporting/scan (#10546)

* Databases WIP

* whoopsie cleanup

* Updates for databases

Co-authored-by: Violet Hynes <violet.hynes@hashicorp.com>
2025-11-12 17:11:12 +00:00

51 lines
1.2 KiB
Go

// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package api
import (
"context"
"errors"
"net/http"
"github.com/mitchellh/mapstructure"
)
func (c *Sys) ReportingScan() (*ReportingScanOutput, error) {
return c.ReportingScanWithContext(context.Background())
}
func (c *Sys) ReportingScanWithContext(ctx context.Context) (*ReportingScanOutput, error) {
ctx, cancelFunc := c.c.withConfiguredTimeout(ctx)
defer cancelFunc()
r := c.c.NewRequest(http.MethodPost, "/v1/sys/reporting/scan")
resp, err := c.c.rawRequestWithContext(ctx, r)
if err != nil {
return nil, err
}
defer resp.Body.Close()
secret, err := ParseSecret(resp.Body)
if err != nil {
return nil, err
}
if secret == nil || secret.Data == nil {
return nil, errors.New("data from server response is empty")
}
var result ReportingScanOutput
err = mapstructure.Decode(secret.Data, &result)
if err != nil {
return nil, err
}
return &result, err
}
type ReportingScanOutput struct {
Timestamp string `json:"timestamp" structs:"timestamp" mapstructure:"timestamp"`
FullDirectoryPath string `json:"full_directory_path" structs:"full_directory_path" mapstructure:"full_directory_path"`
}