mirror of
https://github.com/k8sgpt-ai/k8sgpt.git
synced 2025-09-17 15:52:50 +00:00
feat: rework auth commands (#438)
* feat: rename "auth new" to "auth add" This change allows to be more consistent with the rest of the code Signed-off-by: Matthis Holleville <matthish29@gmail.com> * feat: rework "auth remove" to be more consistent with other remove commands like "filters remove" Signed-off-by: Matthis Holleville <matthish29@gmail.com> * feat: update documentation Signed-off-by: Matthis Holleville <matthish29@gmail.com> --------- Signed-off-by: Matthis Holleville <matthish29@gmail.com>
This commit is contained in:
12
README.md
12
README.md
@@ -121,7 +121,7 @@ _This mode of operation is ideal for continuous monitoring of your cluster and c
|
|||||||
|
|
||||||
* Currently the default AI provider is OpenAI, you will need to generate an API key from [OpenAI](https://openai.com)
|
* Currently the default AI provider is OpenAI, you will need to generate an API key from [OpenAI](https://openai.com)
|
||||||
* You can do this by running `k8sgpt generate` to open a browser link to generate it
|
* You can do this by running `k8sgpt generate` to open a browser link to generate it
|
||||||
* Run `k8sgpt auth new` to set it in k8sgpt.
|
* Run `k8sgpt auth add` to set it in k8sgpt.
|
||||||
* You can provide the password directly using the `--password` flag.
|
* You can provide the password directly using the `--password` flag.
|
||||||
* Run `k8sgpt filters` to manage the active filters used by the analyzer. By default, all filters are executed during analysis.
|
* Run `k8sgpt filters` to manage the active filters used by the analyzer. By default, all filters are executed during analysis.
|
||||||
* Run `k8sgpt analyze` to run a scan.
|
* Run `k8sgpt analyze` to run a scan.
|
||||||
@@ -161,7 +161,7 @@ _Run a scan with the default analyzers_
|
|||||||
|
|
||||||
```
|
```
|
||||||
k8sgpt generate
|
k8sgpt generate
|
||||||
k8sgpt auth new
|
k8sgpt auth add
|
||||||
k8sgpt analyze --explain
|
k8sgpt analyze --explain
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ k8sgpt auth list
|
|||||||
_Remove configured backends_
|
_Remove configured backends_
|
||||||
|
|
||||||
```
|
```
|
||||||
k8sgpt auth remove --backend $MY_BACKEND
|
k8sgpt auth remove $MY_BACKEND1,$MY_BACKEND2..
|
||||||
```
|
```
|
||||||
|
|
||||||
_List integrations_
|
_List integrations_
|
||||||
@@ -318,7 +318,7 @@ To authenticate with k8sgpt, you will need the Azure OpenAI endpoint of your ten
|
|||||||
### Run k8sgpt
|
### Run k8sgpt
|
||||||
To run k8sgpt, run `k8sgpt auth` with the `azureopenai` backend:
|
To run k8sgpt, run `k8sgpt auth` with the `azureopenai` backend:
|
||||||
```
|
```
|
||||||
k8sgpt auth new --backend azureopenai --baseurl https://<your Azure OpenAI endpoint> --engine <deployment_name> --model <model_name>
|
k8sgpt auth add --backend azureopenai --baseurl https://<your Azure OpenAI endpoint> --engine <deployment_name> --model <model_name>
|
||||||
```
|
```
|
||||||
Lastly, enter your Azure API key, after the prompt.
|
Lastly, enter your Azure API key, after the prompt.
|
||||||
|
|
||||||
@@ -343,10 +343,10 @@ To start the API server, follow the instruction in [LocalAI](https://github.com/
|
|||||||
|
|
||||||
### Run k8sgpt
|
### Run k8sgpt
|
||||||
|
|
||||||
To run k8sgpt, run `k8sgpt auth new` with the `localai` backend:
|
To run k8sgpt, run `k8sgpt auth add` with the `localai` backend:
|
||||||
|
|
||||||
```
|
```
|
||||||
k8sgpt auth new --backend localai --model <model_name> --baseurl http://localhost:8080/v1
|
k8sgpt auth add --backend localai --model <model_name> --baseurl http://localhost:8080/v1
|
||||||
```
|
```
|
||||||
|
|
||||||
Now you can analyze with the `localai` backend:
|
Now you can analyze with the `localai` backend:
|
||||||
|
@@ -26,8 +26,8 @@ import (
|
|||||||
"golang.org/x/term"
|
"golang.org/x/term"
|
||||||
)
|
)
|
||||||
|
|
||||||
var newCmd = &cobra.Command{
|
var addCmd = &cobra.Command{
|
||||||
Use: "new",
|
Use: "add",
|
||||||
Short: "Configure new provider",
|
Short: "Configure new provider",
|
||||||
Long: "The new command allows to configure a new backend AI provider",
|
Long: "The new command allows to configure a new backend AI provider",
|
||||||
PreRun: func(cmd *cobra.Command, args []string) {
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
@@ -107,20 +107,20 @@ var newCmd = &cobra.Command{
|
|||||||
color.Green("%s added to the AI backend provider list", backend)
|
color.Green("%s added to the AI backend provider list", backend)
|
||||||
} else {
|
} else {
|
||||||
// provider with same name exists, update provider info
|
// provider with same name exists, update provider info
|
||||||
color.Yellow("Provider with same name already exists, use update command to modify an existing provider configuration")
|
color.Yellow("Provider with same name already exists.")
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
// add flag for backend
|
// add flag for backend
|
||||||
newCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider")
|
addCmd.Flags().StringVarP(&backend, "backend", "b", "openai", "Backend AI provider")
|
||||||
// add flag for model
|
// add flag for model
|
||||||
newCmd.Flags().StringVarP(&model, "model", "m", "gpt-3.5-turbo", "Backend AI model")
|
addCmd.Flags().StringVarP(&model, "model", "m", "gpt-3.5-turbo", "Backend AI model")
|
||||||
// add flag for password
|
// add flag for password
|
||||||
newCmd.Flags().StringVarP(&password, "password", "p", "", "Backend AI password")
|
addCmd.Flags().StringVarP(&password, "password", "p", "", "Backend AI password")
|
||||||
// add flag for url
|
// add flag for url
|
||||||
newCmd.Flags().StringVarP(&baseURL, "baseurl", "u", "", "URL AI provider, (e.g `http://localhost:8080/v1`)")
|
addCmd.Flags().StringVarP(&baseURL, "baseurl", "u", "", "URL AI provider, (e.g `http://localhost:8080/v1`)")
|
||||||
// add flag for azure open ai engine/deployment name
|
// add flag for azure open ai engine/deployment name
|
||||||
newCmd.Flags().StringVarP(&engine, "engine", "e", "", "Azure AI deployment name")
|
addCmd.Flags().StringVarP(&engine, "engine", "e", "", "Azure AI deployment name")
|
||||||
}
|
}
|
@@ -45,7 +45,7 @@ func init() {
|
|||||||
// add subcommand to list backends
|
// add subcommand to list backends
|
||||||
AuthCmd.AddCommand(listCmd)
|
AuthCmd.AddCommand(listCmd)
|
||||||
// add subcommand to create new backend provider
|
// add subcommand to create new backend provider
|
||||||
AuthCmd.AddCommand(newCmd)
|
AuthCmd.AddCommand(addCmd)
|
||||||
// add subcommand to remove new backend provider
|
// add subcommand to remove new backend provider
|
||||||
AuthCmd.AddCommand(removeCmd)
|
AuthCmd.AddCommand(removeCmd)
|
||||||
// add subcommand to set default backend provider
|
// add subcommand to set default backend provider
|
||||||
|
@@ -15,6 +15,7 @@ package auth
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -22,32 +23,38 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var removeCmd = &cobra.Command{
|
var removeCmd = &cobra.Command{
|
||||||
Use: "remove",
|
Use: "remove [backend(s)]",
|
||||||
Short: "Remove a provider",
|
Short: "Remove a provider",
|
||||||
Long: "The command to remove an AI backend provider",
|
Long: "The command to remove an AI backend provider",
|
||||||
|
Args: cobra.ExactArgs(1),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
inputBackends := strings.Split(args[0], ",")
|
||||||
err := viper.UnmarshalKey("ai", &configAI)
|
err := viper.UnmarshalKey("ai", &configAI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
color.Red("Error: %v", err)
|
color.Red("Error: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if backend == "" {
|
if len(inputBackends) == 0 {
|
||||||
color.Red("Error: --backend option must be set.")
|
color.Red("Error: backend must be set.")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
foundBackend := false
|
for _, b := range inputBackends {
|
||||||
for i, provider := range configAI.Providers {
|
foundBackend := false
|
||||||
if backend == provider.Name {
|
for i, provider := range configAI.Providers {
|
||||||
foundBackend = true
|
if b == provider.Name {
|
||||||
configAI.Providers = append(configAI.Providers[:i], configAI.Providers[i+1:]...)
|
foundBackend = true
|
||||||
break
|
configAI.Providers = append(configAI.Providers[:i], configAI.Providers[i+1:]...)
|
||||||
|
color.Green("%s deleted to the AI backend provider list", b)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
if !foundBackend {
|
||||||
if !foundBackend {
|
color.Red("Error: %s does not exist in configuration file. Please use k8sgpt auth new.", backend)
|
||||||
color.Red("Error: %s does not exist in configuration file. Please use k8sgpt auth new.", backend)
|
os.Exit(1)
|
||||||
os.Exit(1)
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
viper.Set("ai", configAI)
|
viper.Set("ai", configAI)
|
||||||
if err := viper.WriteConfig(); err != nil {
|
if err := viper.WriteConfig(); err != nil {
|
||||||
@@ -58,7 +65,4 @@ var removeCmd = &cobra.Command{
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {}
|
||||||
// add flag for backend
|
|
||||||
removeCmd.Flags().StringVarP(&backend, "backend", "b", "", "Backend AI provider")
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user