49 lines
1.5 KiB
Go
49 lines
1.5 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var kmdCmd = &cobra.Command{
|
|
Use: "kmd",
|
|
Short: "Komodo management commands",
|
|
Long: `Commands for interacting directly with the Komodo Core API.`,
|
|
}
|
|
|
|
var kmdConfigureCmd = &cobra.Command{
|
|
Use: "configure [flags]",
|
|
Short: "Configure Komodo Core API credentials",
|
|
Long: `Saves the Komodo URL to ~/.kmanage.yaml and securely stores the API Key and API Secret in the OS keyring.`,
|
|
Example: ` kmanage kmd configure --url https://kmd.example.com --key K_..._K --secret S_..._S`,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
url, _ := cmd.Flags().GetString("url")
|
|
key, _ := cmd.Flags().GetString("key")
|
|
secret, _ := cmd.Flags().GetString("secret")
|
|
|
|
if url == "" || key == "" || secret == "" {
|
|
_ = cmd.Help()
|
|
fmt.Fprintln(os.Stderr)
|
|
return fmt.Errorf("❌ Error: The flags '--url', '--key', and '--secret' are all required")
|
|
}
|
|
|
|
if err := SaveKomodoConfig(url, key, secret); err != nil {
|
|
return fmt.Errorf("failed to save Komodo configuration: %w", err)
|
|
}
|
|
|
|
fmt.Println("✅ Komodo configuration successfully saved (credentials stored in OS keyring).")
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.AddCommand(kmdCmd)
|
|
kmdCmd.AddCommand(kmdConfigureCmd)
|
|
|
|
kmdConfigureCmd.Flags().StringP("url", "u", "", "Komodo API Base URL (e.g. https://kmd.example.com)")
|
|
kmdConfigureCmd.Flags().StringP("key", "k", "", "Komodo API Key (required)")
|
|
kmdConfigureCmd.Flags().StringP("secret", "s", "", "Komodo API Secret (required)")
|
|
}
|