Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: export entries of proxy scoped kvms #306 #316

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions cmd/kvm/expkvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions cmd/org/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 62 additions & 0 deletions internal/client/kvm/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ import (
"os"
"path"
"strconv"
"strings"
"sync"

"internal/apiclient"
"internal/client/apis"

"internal/clilog"
)
Expand Down Expand Up @@ -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
Expand Down