kvm

package
v1.120.4-beta Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "kvms",
	Short: "Manage Key Value Maps",
	Long:  "Manage Key Value Maps",
}

Cmd to manage kvms

View Source
var CreateCmd = &cobra.Command{
	Use:   "create",
	Short: "Create a KV Map",
	Long:  "Create a KV Map",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = kvm.Create(proxyName, name, true)
		return
	},
}

Cmd to create kvms

View Source
var CreateEntryCmd = &cobra.Command{
	Use:   "create",
	Short: "Create a KV Map entry",
	Long:  "Create a KV Map entry",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = kvm.CreateEntry(proxyName, mapName, keyName, value)
		return
	},
}

CreateEntryCmd to create kv map entry

View Source
var DelCmd = &cobra.Command{
	Use:   "delete",
	Short: "Delete a KV map",
	Long:  "Delete a KV map",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = kvm.Delete(proxyName, name)
		return
	},
}

Cmd to delete kvm

View Source
var DelEntryCmd = &cobra.Command{
	Use:   "delete",
	Short: "Delete a KVM Map entry",
	Long:  "Delete a KVM Map entry",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = kvm.DeleteEntry(proxyName, mapName, keyName)
		return
	},
}

DelEntryCmd to delete kvm map entry

View Source
var EntryCmd = &cobra.Command{
	Use:   "entries",
	Short: "Manage Key Value Map Entries",
	Long:  "Manage Key Value Map Entries",
}

EntryCmd to manage kvm entries

View Source
var ExpCmd = &cobra.Command{
	Use:   "export",
	Short: "Export all KV Map entries for all KV Maps",
	Long:  "Export all KV Map entries for all KV Maps in a given scope",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var payload [][]byte
		var fileName string

		apiclient.SetPrintOutput(false)
		listKVMBytes, err := kvm.List(proxyName)
		if err != nil {
			return err
		}

		var listKVM []string
		if err = json.Unmarshal(listKVMBytes, &listKVM); err != nil {
			return err
		}

		for _, mapName := range listKVM {
			if payload, err = kvm.ExportEntries(proxyName, mapName); err != nil {
				return
			}

			if env != "" {
				fileName = strings.Join([]string{"env", env, mapName, "kvmfile"}, "_")
			} else if proxyName != "" {
				fileName = strings.Join([]string{"proxy", proxyName, mapName, "kvmfile"}, "_")
			} else {
				fileName = strings.Join([]string{"org", mapName, "kvmfile"}, "_")
			}

			for i := range payload {
				if err = apiclient.WriteByteArrayToFile(fileName+"_"+strconv.Itoa(i)+".json", false, payload[i]); err != nil {
					return
				}
			}
		}
		apiclient.SetPrintOutput(false)
		fmt.Println("KVMs exports successfully")
		return
	},
}

ExpCmd to export map entries to files

View Source
var ExpEntryCmd = &cobra.Command{
	Use:   "export",
	Short: "Export KV Map entries",
	Long:  "Export KV Map entries",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		var payload [][]byte
		var fileName string

		clilog.Warning.Println("Running this command against a large number of KVMs or entries can exhaust the API quota")

		if payload, err = kvm.ExportEntries(proxyName, mapName); err != nil {
			return
		}

		if env != "" {
			fileName = strings.Join([]string{"env", env, mapName, "kvmfile"}, "_")
		} else if proxyName != "" {
			fileName = strings.Join([]string{"proxy", proxyName, mapName, "kvmfile"}, "_")
		} else {
			fileName = strings.Join([]string{"org", mapName, "kvmfile"}, "_")
		}

		for i := range payload {
			if err = apiclient.WriteByteArrayToFile(fileName+"_"+strconv.Itoa(i)+".json", false, payload[i]); err != nil {
				return
			}
		}
		return
	},
}

ExpEntryCmd to export map entries to files

View Source
var GetEntryCmd = &cobra.Command{
	Use:   "get",
	Short: "Get a KV Map entry",
	Long:  "Get a KV Map entry",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = kvm.GetEntry(proxyName, mapName, keyName)
		return
	},
}

GetEntryCmd to create kvm map entry

View Source
var ImpCmd = &cobra.Command{
	Use:   "import",
	Short: "Import KVM Entries from a folder containing KVM files",
	Long:  "Import KVM Entries from a folder containing KVM files",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {

		var kvmList []string

		apiclient.SetPrintOutput(false)

		orgKVMFileList, envKVMFileList, proxyKVMFileList, err := utils.ListKVMFiles(folder)
		if err != nil {
			return err
		}

		if utils.FileExists(path.Join(folder, "org_"+org+"_"+kVMFileName)) {
			fmt.Println("Importing Org scoped KVMs...")
			if kvmList, err = utils.ReadEntityFile(path.Join(folder, "org_"+org+"_"+kVMFileName)); err != nil {
				return err
			}
			for _, kvmName := range kvmList {

				fmt.Printf("\tCreating KVM %s\n", kvmName)
				if _, err = kvm.Create("", kvmName, true); err != nil {
					return err
				}
				fmt.Printf("\tImporting entries for %s\n", kvmName)
				if orgKVMFileList[kvmName] != "" {
					if err = kvm.ImportEntries("", kvmName, conn, orgKVMFileList[kvmName]); err != nil {
						return err
					}
				}
			}
		}

		if len(envKVMFileList) > 0 {
			fmt.Println("Importing env scoped KVMs...")
			for _, envKVMFile := range envKVMFileList {
				kvmMetadata := strings.Split(envKVMFile, "_")
				apiclient.SetApigeeEnv(kvmMetadata[1])
				fmt.Printf("\tCreating KVM %s\n", envKVMFile)
				if _, err = kvm.Create("", kvmMetadata[2], true); err != nil {
					return err
				}
				fmt.Printf("\tImporting entries for %s\n", envKVMFile)
				if err = kvm.ImportEntries("", kvmMetadata[2], conn, envKVMFile); err != nil {
					return err
				}
			}
		}

		if len(proxyKVMFileList) > 0 {
			fmt.Println("Importing proxy scoped KVMs...")
			for _, proxyKVMFile := range proxyKVMFileList {
				kvmMetadata := strings.Split(proxyKVMFile, "_")
				fmt.Printf("\tCreating KVM %s\n", proxyKVMFile)
				if _, err = kvm.Create(kvmMetadata[1], "", true); err != nil {
					return err
				}
				fmt.Printf("\tImporting entries for %s\n", proxyKVMFile)
				if err = kvm.ImportEntries(kvmMetadata[1], kvmMetadata[2], conn, proxyKVMFile); err != nil {
					return err
				}
			}
		}

		return err
	},
}

ImpCmd to import kvm entries from files

View Source
var ImpEntryCmd = &cobra.Command{
	Use:   "import",
	Short: "Import a file containing KVM Entries",
	Long:  "Import a file containing KVM Entries",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) error {
		return kvm.ImportEntries(proxyName, mapName, conn, filePath)
	},
}

ImpEntryCmd to import kvm entries from files

View Source
var ListCmd = &cobra.Command{
	Use:   "list",
	Short: "Returns a list of KVMs",
	Long:  "Returns a list of KVMs",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = kvm.List(proxyName)
		return
	},
}

Cmd to list kvms

View Source
var ListEntryCmd = &cobra.Command{
	Use:   "list",
	Short: "List KV Map entries",
	Long:  "List KV Map entries",
	Args: func(cmd *cobra.Command, args []string) (err error) {
		if env != "" {
			apiclient.SetApigeeEnv(env)
		}
		if env != "" && proxyName != "" {
			return fmt.Errorf("proxy and env flags cannot be used together")
		}
		return apiclient.SetApigeeOrg(org)
	},
	RunE: func(cmd *cobra.Command, args []string) (err error) {
		_, err = kvm.ListEntries(proxyName, mapName, pageSize, pageToken)
		return
	},
}

ListEntryCmd to list kvm map entries

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL