Go 在HashiCorp vault中搜索值

Go 在HashiCorp vault中搜索值,go,hashicorp-vault,Go,Hashicorp Vault,有没有办法在Hashicorp Vault中搜索值?我试图编写Golang代码来搜索并列出vault中出现值的所有位置。它类似于golang在目录上的walk函数。有没有人对此有好的方法?我正在考虑使用并发来搜索vault中的值。多谢各位 下面是我提出的代码示例。我正在研究如何通过使用并发来加快这一过程。有没有办法同时遍历目录? func walkDir(client *api.Client, path string) { var value *api.Secret var er

有没有办法在Hashicorp Vault中搜索值?我试图编写Golang代码来搜索并列出vault中出现值的所有位置。它类似于golang在目录上的walk函数。有没有人对此有好的方法?我正在考虑使用并发来搜索vault中的值。多谢各位

下面是我提出的代码示例。我正在研究如何通过使用并发来加快这一过程。有没有办法同时遍历目录?

func walkDir(client *api.Client, path string) {
    var value *api.Secret
    var err error
    if path != "" {
        value, err = client.Logical().List(path)
    } else {
        path = vault_path
        value, err = client.Logical().List(path)
    }
    if err != nil {
        fmt.Println(err)
    }
    var datamap map[string]interface{}
    datamap = value.Data
    data := datamap["keys"].([]interface{})
    for _, item := range data {
        itemString := item.(string)
        if strings.HasSuffix(itemString, "/") {
            walkDir(client, path+itemString)
        } else {
            //its a secret
            data := read(client, path+itemString)

            if *searchKey!="" && searchForKey(data,*searchKey){
                fmt.Println(path + itemString)
            }
            if *searchValue!="" && searchForValue(data,*searchValue){
                fmt.Println(path + itemString)
            }
        }
    }
}

func read(client *api.Client, path string) map[string]interface{} {
    value, err := client.Logical().Read(path)
    if err != nil {
        fmt.Println(err)
    }
    values := value.Data
    return values
}

func searchForValue(mapp map[string]interface{}, searchValue string) bool {
    for _, value := range mapp {
        if searchValue == value {
            return true
        }
    }
    return false
}

func searchForKey(mapp map[string]interface{}, searchKey string) bool {
    for key := range mapp {
        if searchKey == key {
            return true
        }
    }
    return false
}
您可以在Vault中列出“目录”(我假设您只是在查看
kv
引擎)。因此,将其视为一个常规的文件系统:从根开始,列出条目,检查每个条目的内容以获取该值,然后遍历每个条目,列出其内容,等等


谢谢,我已经用工作代码更新了我的原始帖子。我在试图找出如何使这个递归搜索并行时遇到了困难。有什么想法吗?这是一个非常不同的问题,所以请为它创建一个单独的问题。如果此答案解决了您的原始问题,请接受它(勾选左侧)