Skip to content

Commit

Permalink
Add view key command
Browse files Browse the repository at this point in the history
  • Loading branch information
K-cermak committed Jan 31, 2025
1 parent 22cd2f9 commit 43724e6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 33 deletions.
90 changes: 61 additions & 29 deletions cli/cmd/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,41 +7,73 @@ import (
)


func ViewAllKeys() {
func ViewKeys(key string) {
if !db.DatabaseExist() {
helpers.PrintError(true, "Database does not exist, run <kprobe db init> first")
}

fmt.Println("\033[1m*probe_name\033[0m")
fmt.Println(" -> " + db.GetValue("probe_name"))
fmt.Println(" \033[3mProbe name is used to identify the probe in the API requests.\033[0m")
found := false

fmt.Println("\033[1mdb_version\033[0m")
fmt.Println(" -> " + db.GetValue("db_version"))
fmt.Println(" \033[3mDatabase version.\033[0m")

fmt.Println("\033[1mdb_init_time\033[0m")
fmt.Println(" -> " + db.GetValue("db_init_time"))
fmt.Println(" \033[3mDatabase initialization time.\033[0m")

fmt.Println("\033[1mconfig_set\033[0m")
fmt.Println(" -> " + db.GetValue("config_set"))
fmt.Println(" \033[3mConfig set status, if set to true, you already set the config file.\033[0m")

//delete_after
fmt.Println("\033[1m*delete_after\033[0m")
fmt.Println(" -> " + db.GetValue("delete_after"))
fmt.Println(" \033[3mDelete after is used to set the time to delete the scan history data after. Updating this value will not affect the existing data.\033[0m")

fmt.Println("\033[1m*api_port\033[0m")
fmt.Println(" -> " + db.GetValue("api_port"))
fmt.Println(" \033[3mAPI port is used to set the port for the API server.\033[0m")

fmt.Println("\033[1m*editor_endpoint\033[0m")
fmt.Println(" -> " + db.GetValue("editor_endpoint"))
fmt.Println(" \033[3mEditor endpoint is used to enable/disable the /editor endpoint.\033[0m")
if key == "all" || key == "probe_name" {
found = true
fmt.Println("\033[1m*probe_name\033[0m")
fmt.Println(" -> " + db.GetValue("probe_name"))
fmt.Println(" \033[3mProbe name is used to identify the probe in the API requests.\033[0m")
}

fmt.Println("\n(values with * can be changed using <kprobe keys set <key> <value>> command)")
if key == "all" || key == "probe_name" {
found = true
fmt.Println("\033[1m*probe_name\033[0m")
fmt.Println(" -> " + db.GetValue("probe_name"))
fmt.Println(" \033[3mProbe name is used to identify the probe in the API requests.\033[0m")
}

if key == "all" || key == "db_version" {
found = true
fmt.Println("\033[1mdb_version\033[0m")
fmt.Println(" -> " + db.GetValue("db_version"))
fmt.Println(" \033[3mDatabase version.\033[0m")
}

if key == "all" || key == "db_init_time" {
found = true
fmt.Println("\033[1mdb_init_time\033[0m")
fmt.Println(" -> " + db.GetValue("db_init_time"))
fmt.Println(" \033[3mDatabase initialization time.\033[0m")
}

if key == "all" || key == "config_set" {
found = true
fmt.Println("\033[1mconfig_set\033[0m")
fmt.Println(" -> " + db.GetValue("config_set"))
fmt.Println(" \033[3mConfig set status, if set to true, you already set the config file.\033[0m")
}

if key == "all" || key == "delete_after" {
found = true
fmt.Println("\033[1m*delete_after\033[0m")
fmt.Println(" -> " + db.GetValue("delete_after"))
fmt.Println(" \033[3mDelete after is used to set the time to delete the scan history data after. Updating this value will not affect the existing data.\033[0m")
}

if key == "all" || key == "api_port" {
found = true
fmt.Println("\033[1m*api_port\033[0m")
fmt.Println(" -> " + db.GetValue("api_port"))
fmt.Println(" \033[3mAPI port is used to set the port for the API server.\033[0m")
}

if key == "all" || key == "editor_endpoint" {
found = true
fmt.Println("\033[1m*editor_endpoint\033[0m")
fmt.Println(" -> " + db.GetValue("editor_endpoint"))
fmt.Println(" \033[3mEditor endpoint is used to enable/disable the /editor endpoint.\033[0m")
}

if found {
fmt.Println("\n\033[3m(values with\033[0m \033[1m*\033[0m \033[3mcan be changed using <kprobe keys set <key> <value>> command)\033[0m")
} else {
helpers.PrintError(true, "Key " + key + " not found")
}

}
7 changes: 3 additions & 4 deletions cli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ func main() {
return
}

//keys view all
if (helpers.ArgsMatch(args, []string{"*", "keys", "view", "all"})) {
cmd.ViewAllKeys()
//keys view all / keys view <key>
if (helpers.ArgsMatch(args, []string{"*", "keys", "view", "*"})) {
cmd.ViewKeys(args[3])
return
}

//keys view <key>

//keys set <key> <value>

Expand Down

0 comments on commit 43724e6

Please sign in to comment.