2023-07-17 04:23:26 +03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2023-12-30 20:53:01 +03:00
|
|
|
"fmt"
|
|
|
|
|
2023-09-20 04:05:44 +03:00
|
|
|
"github.com/quexten/goldwarden/ipc/messages"
|
2023-07-17 04:23:26 +03:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var setApiUrlCmd = &cobra.Command{
|
|
|
|
Use: "set-api-url",
|
|
|
|
Short: "Set the api url",
|
|
|
|
Long: `Set the api url.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
url := args[0]
|
2023-09-20 04:05:44 +03:00
|
|
|
request := messages.SetApiURLRequest{}
|
2023-07-17 04:23:26 +03:00
|
|
|
request.Value = url
|
|
|
|
|
2023-08-21 14:52:06 +03:00
|
|
|
result, err := commandClient.SendToAgent(request)
|
2023-07-17 04:23:26 +03:00
|
|
|
if err != nil {
|
2023-09-11 23:45:01 +03:00
|
|
|
handleSendToAgentError(err)
|
2023-07-17 04:23:26 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch result.(type) {
|
2023-09-20 04:05:44 +03:00
|
|
|
case messages.ActionResponse:
|
|
|
|
if result.(messages.ActionResponse).Success {
|
2023-07-17 04:23:26 +03:00
|
|
|
println("Done")
|
|
|
|
} else {
|
2023-09-20 04:05:44 +03:00
|
|
|
println("Setting api url failed: " + result.(messages.ActionResponse).Message)
|
2023-07-17 04:23:26 +03:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
println("Wrong IPC response type")
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var setIdentityURLCmd = &cobra.Command{
|
|
|
|
Use: "set-identity-url",
|
|
|
|
Short: "Set the identity url",
|
|
|
|
Long: `Set the identity url.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
url := args[0]
|
2023-09-20 04:05:44 +03:00
|
|
|
request := messages.SetIdentityURLRequest{}
|
2023-07-17 04:23:26 +03:00
|
|
|
request.Value = url
|
|
|
|
|
2023-08-21 14:52:06 +03:00
|
|
|
result, err := commandClient.SendToAgent(request)
|
2023-07-17 04:23:26 +03:00
|
|
|
if err != nil {
|
2023-09-11 23:45:01 +03:00
|
|
|
handleSendToAgentError(err)
|
2023-07-17 04:23:26 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch result.(type) {
|
2023-09-20 04:05:44 +03:00
|
|
|
case messages.ActionResponse:
|
|
|
|
if result.(messages.ActionResponse).Success {
|
2023-07-17 04:23:26 +03:00
|
|
|
println("Done")
|
|
|
|
} else {
|
2023-09-20 04:05:44 +03:00
|
|
|
println("Setting identity url failed: " + result.(messages.ActionResponse).Message)
|
2023-07-17 04:23:26 +03:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
println("Wrong IPC response type")
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-09-11 16:39:19 +03:00
|
|
|
var setNotificationsURLCmd = &cobra.Command{
|
|
|
|
Use: "set-notifications-url",
|
|
|
|
Short: "Set the notifications url",
|
|
|
|
Long: `Set the notifications url.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
url := args[0]
|
2023-09-20 04:05:44 +03:00
|
|
|
request := messages.SetNotificationsURLRequest{}
|
2023-09-11 16:39:19 +03:00
|
|
|
request.Value = url
|
|
|
|
|
|
|
|
result, err := commandClient.SendToAgent(request)
|
|
|
|
if err != nil {
|
2023-09-11 23:45:01 +03:00
|
|
|
handleSendToAgentError(err)
|
2023-09-11 16:39:19 +03:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch result.(type) {
|
2023-09-20 04:05:44 +03:00
|
|
|
case messages.ActionResponse:
|
|
|
|
if result.(messages.ActionResponse).Success {
|
2023-09-11 16:39:19 +03:00
|
|
|
println("Done")
|
|
|
|
} else {
|
2023-09-20 04:05:44 +03:00
|
|
|
println("Setting notifications url failed: " + result.(messages.ActionResponse).Message)
|
2023-09-11 16:39:19 +03:00
|
|
|
}
|
|
|
|
default:
|
|
|
|
println("Wrong IPC response type")
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2024-01-04 23:53:38 +03:00
|
|
|
var setApiClientIDCmd = &cobra.Command{
|
|
|
|
Use: "set-api-client-id",
|
|
|
|
Short: "Set the api client id",
|
|
|
|
Long: `Set the api client id.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
id := args[0]
|
|
|
|
request := messages.SetClientIDRequest{}
|
|
|
|
request.Value = id
|
|
|
|
|
|
|
|
result, err := commandClient.SendToAgent(request)
|
|
|
|
if err != nil {
|
|
|
|
handleSendToAgentError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch result.(type) {
|
|
|
|
case messages.ActionResponse:
|
|
|
|
if result.(messages.ActionResponse).Success {
|
|
|
|
println("Done")
|
|
|
|
} else {
|
|
|
|
println("Setting api client id failed: " + result.(messages.ActionResponse).Message)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
println("Wrong IPC response type")
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
var setApiSecretCmd = &cobra.Command{
|
|
|
|
Use: "set-api-client-secret",
|
|
|
|
Short: "Set the api secret",
|
|
|
|
Long: `Set the api secret.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if len(args) == 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
secret := args[0]
|
|
|
|
request := messages.SetClientSecretRequest{}
|
|
|
|
request.Value = secret
|
|
|
|
|
|
|
|
result, err := commandClient.SendToAgent(request)
|
|
|
|
if err != nil {
|
|
|
|
handleSendToAgentError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch result.(type) {
|
|
|
|
case messages.ActionResponse:
|
|
|
|
if result.(messages.ActionResponse).Success {
|
|
|
|
println("Done")
|
|
|
|
} else {
|
|
|
|
println("Setting api secret failed: " + result.(messages.ActionResponse).Message)
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
println("Wrong IPC response type")
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-12-30 20:53:01 +03:00
|
|
|
var getRuntimeConfigCmd = &cobra.Command{
|
|
|
|
Use: "get-runtime-config",
|
|
|
|
Short: "Get the runtime config",
|
|
|
|
Long: `Get the runtime config.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
request := messages.GetRuntimeConfigRequest{}
|
|
|
|
|
|
|
|
result, err := commandClient.SendToAgent(request)
|
|
|
|
if err != nil {
|
|
|
|
handleSendToAgentError(err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
switch result := result.(type) {
|
|
|
|
case messages.GetRuntimeConfigResponse:
|
|
|
|
fmt.Println("{")
|
|
|
|
fmt.Println(" \"useMemguard\": " + fmt.Sprintf("%t", result.UseMemguard) + ",")
|
|
|
|
fmt.Println(" \"SSHAgentSocketPath\": \"" + result.SSHAgentSocketPath + "\",")
|
|
|
|
fmt.Println(" \"goldwardenSocketPath\": \"" + result.GoldwardenSocketPath + "\"")
|
|
|
|
fmt.Println("}")
|
|
|
|
default:
|
|
|
|
println("Wrong IPC response type")
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-07-17 04:23:26 +03:00
|
|
|
var configCmd = &cobra.Command{
|
|
|
|
Use: "config",
|
|
|
|
Short: "Manage the configuration",
|
|
|
|
Long: `Manage the configuration.`,
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(configCmd)
|
|
|
|
configCmd.AddCommand(setApiUrlCmd)
|
|
|
|
configCmd.AddCommand(setIdentityURLCmd)
|
2023-09-11 16:39:19 +03:00
|
|
|
configCmd.AddCommand(setNotificationsURLCmd)
|
2023-12-30 20:53:01 +03:00
|
|
|
configCmd.AddCommand(getRuntimeConfigCmd)
|
2024-01-04 23:53:38 +03:00
|
|
|
configCmd.AddCommand(setApiClientIDCmd)
|
|
|
|
configCmd.AddCommand(setApiSecretCmd)
|
2023-07-17 04:23:26 +03:00
|
|
|
}
|