diff --git a/cmd/kvm/expkvm.go b/cmd/kvm/expkvm.go index b791f5963..e22dc9ad0 100644 --- a/cmd/kvm/expkvm.go +++ b/cmd/kvm/expkvm.go @@ -47,6 +47,12 @@ var ExpCmd = &cobra.Command{ var fileName string apiclient.DisableCmdPrintHttpResponse() + + // return all kvm entries from all proxies + if env == "" && proxyName == "" { + return kvm.ExportAllEntries() + } + listKVMBytes, err := kvm.List(proxyName) if err != nil { return err diff --git a/cmd/org/export.go b/cmd/org/export.go index c9806d4da..931ce2775 100644 --- a/cmd/org/export.go +++ b/cmd/org/export.go @@ -107,6 +107,11 @@ var ExportCmd = &cobra.Command{ } } + clilog.Info.Printf("Exporting Proxy scoped KV Map entries for org %s\n", org) + if err = kvm.ExportAllEntries(); err != nil { + return err + } + clilog.Info.Println("Exporting Developers...") if respBody, err = developers.Export(); proceedOnError(err) != nil { return err diff --git a/internal/client/kvm/entries.go b/internal/client/kvm/entries.go index e14ccd3c4..bc8d40be1 100644 --- a/internal/client/kvm/entries.go +++ b/internal/client/kvm/entries.go @@ -21,9 +21,11 @@ import ( "os" "path" "strconv" + "strings" "sync" "internal/apiclient" + "internal/client/apis" "internal/clilog" ) @@ -107,6 +109,66 @@ func ListEntries(proxyName string, mapName string, pageSize int, pageToken strin return respBody, err } +// ExportAllEntries +func ExportAllEntries() (err error) { + type proxy struct { + Name string `json:"name,omitempty"` + APIProxyType string `json:"apiProxyType,omitempty"` + } + + type proxies struct { + Proxies []proxy `json:"proxies,omitempty"` + } + + p := proxies{} + programmableProxies := []string{} + + apiList, err := apis.ListProxies(false) + if err != nil { + return err + } + + if err = json.Unmarshal(apiList, &p); err != nil { + return err + } + + for _, proxy := range p.Proxies { + //search for only programmable proxies. standard proxies can't have KVMs + if proxy.APIProxyType == "PROGRAMMABLE" { + programmableProxies = append(programmableProxies, proxy.Name) + } + } + + for _, programmableProxy := range programmableProxies { + kvmList := []string{} + kvmListResp, err := List(programmableProxy) + if err != nil { + return err + } + if err = json.Unmarshal(kvmListResp, &kvmList); err != nil { + return err + } + if len(kvmList) > 0 { + clilog.Info.Printf("Found %d scoped KVMs for proxy %s\n", len(kvmList), programmableProxy) + for _, proxyKVM := range kvmList { + clilog.Info.Printf("Eporting entries for KVM %s of proxy %s\n", programmableProxy, proxyKVM) + proxyKVMEntries, err := ExportEntries(programmableProxy, proxyKVM) + if err != nil { + return err + } + fileName := strings.Join([]string{"proxy", programmableProxy, proxyKVM, "kvmfile"}, "_") + for i := range proxyKVMEntries { + if err = apiclient.WriteByteArrayToFile(fileName+"_"+strconv.Itoa(i)+".json", false, proxyKVMEntries[i]); err != nil { + return err + } + } + } + } + } + + return nil +} + // ExportEntries func ExportEntries(proxyName string, mapName string) (payload [][]byte, err error) { var respBody []byte