有沒有辦法在 Hashicorp Vault 中搜索值?我正在嘗試編寫 Golang 代碼來搜索并列出值出現在保險庫中的所有位置。它類似于 golang 在目錄上的 walk 函數。有沒有人有一個好的方法?我正在考慮使用并發來搜索保險庫中的值。謝謝下面是我想出的代碼示例。我正在研究如何通過使用并發來加快速度。有沒有辦法同時遍歷一個目錄?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}
在 HashiCorp 保險庫中搜索值
慕田峪9158850
2022-06-27 14:57:20