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

cmd/kvpctl: hardcode Ignition config key prefix; fix get argument validation #42

Merged
merged 2 commits into from
Jul 20, 2023
Merged
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
16 changes: 10 additions & 6 deletions cmd/kvpctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func printHelp() {
fmt.Printf("Usage: %s <vm name> (get|add|add-ign|rm|edit|put|clear) [<key>] [<value>]\n\n", os.Args[0])
fmt.Printf("\tget = get all keys or a specific key\n")
fmt.Printf("\tadd = create a key if it doesn't exist\n")
fmt.Printf("\tadd-ign = split and add key value pairs for an Ignition file\n")
fmt.Printf("\tadd-ign = split and add key-value pairs for an Ignition config\n")
fmt.Printf("\tedit = change a key that exists\n")
fmt.Printf("\tput = create or edit a key\n")
fmt.Printf("\trm = delete one or more keys\n")
Expand Down Expand Up @@ -102,7 +102,7 @@ func main() {
case clear:
err = clearOperation(vm)
case addIgn:
err = addIgnFile(vm, os.Args[3], os.Args[4])
err = addIgnFile(vm, os.Args[3])

default:
fmt.Printf("Operation must be get, add, add-ign, rm, edit, clear, or put\n")
Expand Down Expand Up @@ -194,24 +194,28 @@ loop:

func verifyArgs(op kvpcmd, lenArgs int) {
switch op {
case add, put, edit, addIgn:
case add, put, edit:
if lenArgs < 4 || lenArgs > 4 {
printHelp()
}
case addIgn:
if lenArgs < 3 || lenArgs > 3 {
printHelp()
}
case rm:
// nothing
case clear:
if lenArgs > 2 {
printHelp()
}
case get:
if lenArgs > 4 || lenArgs < 2 || lenArgs == 3 {
if lenArgs < 2 || lenArgs > 3 {
printHelp()
}
}
}

func addIgnFile(vm *hypervctl.VirtualMachine, inputFilename, keyName string) error {
func addIgnFile(vm *hypervctl.VirtualMachine, inputFilename string) error {
b, err := os.ReadFile(inputFilename)
if err != nil {
return err
Expand All @@ -221,7 +225,7 @@ func addIgnFile(vm *hypervctl.VirtualMachine, inputFilename, keyName string) err
return err
}
for i, v := range parts {
key := fmt.Sprintf("%s%d", keyName, i)
key := fmt.Sprintf("ignition.config.%d", i)
if err := vm.AddKeyValuePair(key, v); err != nil {
return err
}
Expand Down