27 lines
524 B
Go
27 lines
524 B
Go
package ids
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/monlet/agent/internal/config"
|
|
)
|
|
|
|
func ResolveAgentID(configured, hostname string) (string, error) {
|
|
if configured != "" {
|
|
id := strings.TrimSpace(configured)
|
|
if err := config.ValidateID("agent_id", id); err != nil {
|
|
return "", err
|
|
}
|
|
return id, nil
|
|
}
|
|
id := strings.TrimSpace(hostname)
|
|
if id == "" {
|
|
return "", fmt.Errorf("hostname is empty")
|
|
}
|
|
if err := config.ValidateID("hostname as agent_id", id); err != nil {
|
|
return "", err
|
|
}
|
|
return id, nil
|
|
}
|