mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-19 14:11:04 +08:00
Go: default public key (#16265)
### What problem does this PR solve? Provider default public key for CLI ### Type of change - [x] Refactoring Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -38,6 +38,7 @@ type APIServerConfig struct {
|
||||
UserName *string `yaml:"user_name"`
|
||||
UserPassword *string `yaml:"password"`
|
||||
ApiToken *string `yaml:"api_token"`
|
||||
KeyFile *string `yaml:"key_file"`
|
||||
IP string
|
||||
Port int
|
||||
}
|
||||
@@ -86,6 +87,7 @@ type AdminModeConfig struct {
|
||||
AdminPort int
|
||||
AdminName *string
|
||||
AdminPassword *string
|
||||
KeyFile *string
|
||||
//AdminCommand *string
|
||||
}
|
||||
|
||||
@@ -217,6 +219,11 @@ func ParseArgs(args []string) (*CommandLineConfig, error) {
|
||||
}
|
||||
i++
|
||||
}
|
||||
case "-k", "--key":
|
||||
if i+1 < len(args) && !strings.HasPrefix(args[i+1], "-") {
|
||||
defaultApiServerConfig.KeyFile = &args[i+1]
|
||||
i++
|
||||
}
|
||||
default:
|
||||
// Non-flag argument (command)
|
||||
if !strings.HasPrefix(arg, "-") {
|
||||
@@ -333,6 +340,11 @@ func ParseArgs(args []string) (*CommandLineConfig, error) {
|
||||
AdminConfig.AdminName = &args[i+1]
|
||||
i++
|
||||
}
|
||||
case "-k", "--key":
|
||||
if i+1 < len(args) && !strings.HasPrefix(args[i+1], "-") {
|
||||
AdminConfig.KeyFile = &args[i+1]
|
||||
i++
|
||||
}
|
||||
case "-p", "--password":
|
||||
if i+1 < len(args) && !strings.HasPrefix(args[i+1], "-") {
|
||||
AdminConfig.AdminPassword = &args[i+1]
|
||||
@@ -853,6 +865,27 @@ func (c *CLI) VerifyAuth(username, password string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func (c *CLI) GetPublicKeyPEM() ([]byte, error) {
|
||||
|
||||
var publicKeyFile *string = nil
|
||||
switch c.Config.CLIMode {
|
||||
case AdminMode:
|
||||
publicKeyFile = c.Config.AdminClientConfig.KeyFile
|
||||
case APIMode:
|
||||
publicKeyFile = c.Config.APIClientConfig.APIServerMap[c.Config.APIClientConfig.CurrentAPIServer].KeyFile
|
||||
}
|
||||
if publicKeyFile == nil {
|
||||
result := "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEArq9XTUSeYr2+N1h3Afl/\nz8Dse/2yD0ZGrKwx+EEEcdsBLca9Ynmx3nIB5obmLlSfmskLpBo0UACBmB5rEjBp\n2Q2f3AG3Hjd4B+gNCG6BDaawuDlgANIhGnaTLrIqWrrcm4EMzJOnAOI1fgzJRsOO\nUEfaS318Eq9OVO3apEyCCt0lOQK6PuksduOjVxtltDav+guVAA068NrPYmRNabVK\nRNLJpL8w4D44sfth5RvZ3q9t+6RTArpEtc5sh5ChzvqPOzKGMXW83C95TxmXqpbK\n6olN4RevSfVjEAgCydH6HN6OhtOQEcnrU97r9H0iZOWwbw3pVrZiUkuRD1R56Wzs\n2wIDAQAB\n-----END PUBLIC KEY-----"
|
||||
return []byte(result), nil
|
||||
}
|
||||
|
||||
publicKeyPEM, err := os.ReadFile(*publicKeyFile)
|
||||
if err != nil {
|
||||
return []byte(""), fmt.Errorf("failed to read public key: %w", err)
|
||||
}
|
||||
return publicKeyPEM, nil
|
||||
}
|
||||
|
||||
// printSearchHelp prints help for the search command
|
||||
func printSearchHelp() {
|
||||
help := `Search command usage: search <query> [path] [-n number]
|
||||
|
||||
Reference in New Issue
Block a user