Skip to content

Commit

Permalink
refactor: put logic in discoverBootstrapURLs
Browse files Browse the repository at this point in the history
- if user gave us URL, use it
- else if user gave us lease file, use it
- else try to fecth from network manager via dbus

Signed-off-by: Boris Glimcher <[email protected]>
  • Loading branch information
glimchb committed Jul 22, 2024
1 parent 28c2e14 commit e94853b
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions sztp-agent/pkg/secureagent/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,9 @@ func (a *Agent) RunCommandDaemon() error {

func (a *Agent) performBootstrapSequence() error {
var err error
if a.GetBootstrapURL() == "" {
err = a.discoverBootstrapURLs()
if err != nil {
return err
}
err = a.discoverBootstrapURLs()
if err != nil {
return err
}
err = a.doRequestBootstrapServerOnboardingInfo()
if err != nil {
Expand Down Expand Up @@ -91,6 +89,32 @@ func (a *Agent) performBootstrapSequence() error {
}

func (a *Agent) discoverBootstrapURLs() error {
log.Println("[INFO] Discovering the Bootstrap URL")
// TODO: rename to a.InputBootstrapURL
if a.BootstrapURL != "" {
log.Println("[INFO] User gave us the Bootstrap URL: " + a.BootstrapURL)
a.SetBootstrapURL(a.BootstrapURL)
log.Println("[INFO] Bootstrap URL retrieved successfully: " + a.GetBootstrapURL())
return nil
}
if a.DhcpLeaseFile != "" {
log.Println("[INFO] User gave us the DHCP Lease File: " + a.DhcpLeaseFile)
urls, err := getBootstrapURLsViaLeaseFile(a.DhcpLeaseFile, SZTP_REDIRECT_URL)
if err != nil {
return err
}
a.SetBootstrapURL(urls[0])
log.Println("[INFO] Bootstrap URL retrieved successfully: " + a.GetBootstrapURL())
return nil
}
log.Println("[INFO] User gave us nothing, discover the Bootstrap URL from Netwrok Manager via dbus")
// TODO: fetch the Bootstrap URL from Netwrok Manager via dbus in the future
log.Println("[INFO] Bootstrap URL retrieved successfully: " + a.GetBootstrapURL())
return nil
}

// TODO: move this function into DHCP package folder
func (a *Agent) getBootstrapURLsViaLeaseFile() error {
log.Println("[INFO] Get the Bootstrap URL from DHCP client")
var line string
if _, err := os.Stat(a.DhcpLeaseFile); err == nil {
Expand Down

0 comments on commit e94853b

Please sign in to comment.