kvm

package
v1.125.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 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
	},
}

CreateCmd 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
	},
}

DelCmd 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.DisableCmdPrintHttpResponse()

		if env == "" && proxyName == "" {
			return kvm.ExportAllEntries()
		}

		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 err
			}

			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 err
				}
			}
		}

		clilog.Info.Println("KVMs exported successfully")
		return err
	},
}

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

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

		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 err
			}
		}
		return err
	},
}

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) {
		apiclient.DisableCmdPrintHttpResponse()

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

		if len(orgKVMFileList) > 0 {
			clilog.Info.Println("Importing org scoped KVMs...")
			for _, orgKVMFile := range orgKVMFileList {
				kvmFile := filepath.Base(orgKVMFile)
				kvmMetadata := strings.Split(kvmFile, "_")
				clilog.Info.Printf("\tCreating KVM %s\n", orgKVMFile)
				if _, err = kvm.Create("", kvmMetadata[1], true); err != nil {
					return err
				}
				clilog.Info.Printf("\tImporting entries for %s\n", orgKVMFile)
				if err = kvm.ImportEntries("", kvmMetadata[1], conn, orgKVMFile); err != nil {
					return err
				}
			}
		}

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

		if len(proxyKVMFileList) > 0 {
			clilog.Info.Println("Importing proxy scoped KVMs...")
			for _, proxyKVMFile := range proxyKVMFileList {
				kvmFile := filepath.Base(proxyKVMFile)
				kvmMetadata := strings.Split(kvmFile, "_")
				clilog.Info.Printf("\tCreating KVM %s\n", proxyKVMFile)
				if _, err = kvm.Create(kvmMetadata[1], kvmMetadata[2], true); err != nil {
					return err
				}
				clilog.Info.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
	},
}

ListCmd 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