mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-11-20 00:01:06 +00:00
* feat(mcp): add 1Panel MCP and enhance MCP credential management * feat(i18n): implement MCP document localization and remove legacy code
38 lines
849 B
Go
38 lines
849 B
Go
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/1Panel-dev/1Panel/core/app/dto"
|
|
contract "github.com/1Panel-dev/1Panel/core/utils/mcp"
|
|
)
|
|
|
|
func encodeMCPIPs(entries []string) string {
|
|
data, _ := json.Marshal(entries)
|
|
if entries == nil {
|
|
return "[]"
|
|
}
|
|
return string(data)
|
|
}
|
|
func normalizeMCPAccessSettings(req *dto.MCPRuntimeSettings) error {
|
|
entries, err := contract.NormalizeAllowedIPs(req.AllowedIPs)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
switch req.AccessPolicy {
|
|
case "inherit", "all":
|
|
if len(entries) != 0 {
|
|
return errors.New("independent MCP IP entries require restricted policy")
|
|
}
|
|
case "restricted":
|
|
if len(entries) == 0 {
|
|
return errors.New("MCP restricted policy requires at least one IP or CIDR")
|
|
}
|
|
default:
|
|
return errors.New("invalid MCP access policy")
|
|
}
|
|
req.AllowedIPs = entries
|
|
return nil
|
|
}
|