Linting fixes

This commit is contained in:
Juan Font Alonso 2022-11-04 00:23:20 +01:00
parent 825e88311e
commit c70f5696dc
2 changed files with 15 additions and 16 deletions

View File

@ -1,15 +1,14 @@
package integration package integration
import ( import (
"crypto/tls"
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"net/url" "net/url"
"strings" "strings"
"testing" "testing"
"time"
"log"
) )
type AuthWebFlowScenario struct { type AuthWebFlowScenario struct {
@ -127,7 +126,6 @@ func (s *AuthWebFlowScenario) runTailscaleUp(
if err != nil { if err != nil {
log.Printf("failed to register client: %s", err) log.Printf("failed to register client: %s", err)
} }
}(client) }(client)
} }
namespace.joinWaitGroup.Wait() namespace.joinWaitGroup.Wait()
@ -143,10 +141,9 @@ func (s *AuthWebFlowScenario) runHeadscaleRegister(namespaceStr string, loginURL
loginURL.Host = fmt.Sprintf("%s:8080", s.Headscale().GetIP()) loginURL.Host = fmt.Sprintf("%s:8080", s.Headscale().GetIP())
loginURL.Scheme = "http" loginURL.Scheme = "http"
insecureTransport := &http.Transport{ httpClient := &http.Client{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, Timeout: time.Second * 10,
} }
httpClient := &http.Client{Transport: insecureTransport}
resp, err := httpClient.Get(loginURL.String()) resp, err := httpClient.Get(loginURL.String())
if err != nil { if err != nil {
@ -158,21 +155,23 @@ func (s *AuthWebFlowScenario) runHeadscaleRegister(namespaceStr string, loginURL
return err return err
} }
defer resp.Body.Close()
// see api.go HTML template // see api.go HTML template
code := strings.Split(string(body), "</code>")[0] code := strings.Split(string(body), "</code>")[0]
key := strings.Split(code, "key ")[1] key := strings.Split(code, "key ")[1]
if headscale, ok := s.controlServers["headscale"]; ok { if headscale, ok := s.controlServers["headscale"]; ok {
_, err = headscale.Execute([]string{ _, err = headscale.Execute([]string{"headscale", "-n", namespaceStr, "nodes", "register", "--key", key})
"headscale", "-n", namespaceStr, "nodes", "register", "--key", key})
if err != nil { if err != nil {
log.Printf("failed to register node: %s", err) log.Printf("failed to register node: %s", err)
return err return err
} }
log.Printf("registered node %s", key) log.Printf("registered node %s", key)
return nil return nil
} }
return fmt.Errorf("failed to find headscale: %w", errNoHeadscaleAvailable) return fmt.Errorf("failed to find headscale: %w", errNoHeadscaleAvailable)
} }

View File

@ -23,10 +23,9 @@ const (
) )
var ( var (
errTailscalePingFailed = errors.New("ping failed") errTailscalePingFailed = errors.New("ping failed")
errTailscaleNotLoggedIn = errors.New("tailscale not logged in") errTailscaleNotLoggedIn = errors.New("tailscale not logged in")
errTailscaleWrongPeerCount = errors.New("wrong peer count") errTailscaleWrongPeerCount = errors.New("wrong peer count")
errTailscaleCannotUpWithoutAuthkey = errors.New("cannot up without authkey")
) )
type TailscaleInContainer struct { type TailscaleInContainer struct {
@ -176,14 +175,15 @@ func (t *TailscaleInContainer) UpWithLoginURL(
urlStr = strings.TrimSpace(urlStr) urlStr = strings.TrimSpace(urlStr)
// parse URL // parse URL
loginUrl, err := url.Parse(urlStr) loginURL, err := url.Parse(urlStr)
if err != nil { if err != nil {
log.Printf("Could not parse login URL: %s", err) log.Printf("Could not parse login URL: %s", err)
log.Printf("Original join command result: %s", stderr) log.Printf("Original join command result: %s", stderr)
return nil, err return nil, err
} }
return loginUrl, nil return loginURL, nil
} }
func (t *TailscaleInContainer) IPs() ([]netip.Addr, error) { func (t *TailscaleInContainer) IPs() ([]netip.Addr, error) {