mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-25 10:18:59 +02:00
feat(agent): add optional StreamPort to agent creation API
- Introduced `StreamPort` field in `NewAgentRequest` for agent configuration. - Implemented default behavior for `StreamPort` to be `Port + 1` if not specified. - Added validation to ensure `StreamPort` is within the valid range (1-65535).
This commit is contained in:
@@ -16,6 +16,7 @@ type NewAgentRequest struct {
|
|||||||
Name string `json:"name" binding:"required"`
|
Name string `json:"name" binding:"required"`
|
||||||
Host string `json:"host" binding:"required"`
|
Host string `json:"host" binding:"required"`
|
||||||
Port int `json:"port" binding:"required,min=1,max=65535"`
|
Port int `json:"port" binding:"required,min=1,max=65535"`
|
||||||
|
StreamPort int `json:"stream_port" binding:"omitempty,min=1,max=65535"`
|
||||||
Type string `json:"type" binding:"required,oneof=docker system"`
|
Type string `json:"type" binding:"required,oneof=docker system"`
|
||||||
Nightly bool `json:"nightly" binding:"omitempty"`
|
Nightly bool `json:"nightly" binding:"omitempty"`
|
||||||
ContainerRuntime agent.ContainerRuntime `json:"container_runtime" binding:"omitempty,oneof=docker podman" default:"docker"`
|
ContainerRuntime agent.ContainerRuntime `json:"container_runtime" binding:"omitempty,oneof=docker podman" default:"docker"`
|
||||||
@@ -68,9 +69,18 @@ func Create(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if request.StreamPort <= 0 {
|
||||||
|
request.StreamPort = request.Port + 1
|
||||||
|
if request.StreamPort > 65535 {
|
||||||
|
c.JSON(http.StatusBadRequest, apitypes.Error("stream port is out of range"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var cfg agent.Generator = &agent.AgentEnvConfig{
|
var cfg agent.Generator = &agent.AgentEnvConfig{
|
||||||
Name: request.Name,
|
Name: request.Name,
|
||||||
Port: request.Port,
|
Port: request.Port,
|
||||||
|
StreamPort: request.StreamPort,
|
||||||
CACert: ca.String(),
|
CACert: ca.String(),
|
||||||
SSLCert: srv.String(),
|
SSLCert: srv.String(),
|
||||||
ContainerRuntime: request.ContainerRuntime,
|
ContainerRuntime: request.ContainerRuntime,
|
||||||
|
|||||||
Reference in New Issue
Block a user