mirror of
https://github.com/juanfont/headscale.git
synced 2026-01-23 02:24:10 +00:00
all: apply additional wsl_v5 whitespace fixes
This commit is contained in:
parent
58b532ae3c
commit
3b59a91112
13 changed files with 43 additions and 3 deletions
|
|
@ -743,7 +743,8 @@ func extractContainerArtifacts(ctx context.Context, cli *client.Client, containe
|
|||
|
||||
// Extract tar files for headscale containers only
|
||||
if strings.HasPrefix(containerName, "hs-") {
|
||||
if err := extractContainerFiles(ctx, cli, containerID, containerName, logsDir, verbose); err != nil {
|
||||
err := extractContainerFiles(ctx, cli, containerID, containerName, logsDir, verbose)
|
||||
if err != nil {
|
||||
if verbose {
|
||||
log.Printf("Warning: failed to extract files from %s: %v", containerName, err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -321,6 +321,7 @@ func checkRequiredFiles() DoctorResult {
|
|||
|
||||
for _, file := range requiredFiles {
|
||||
cmd := exec.CommandContext(context.Background(), "test", "-e", file)
|
||||
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
missingFiles = append(missingFiles, file)
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@ func (sc *StatsCollector) collectStatsForContainer(ctx context.Context, containe
|
|||
return
|
||||
default:
|
||||
var stats container.StatsResponse
|
||||
|
||||
err := decoder.Decode(&stats)
|
||||
if err != nil {
|
||||
// EOF is expected when container stops or stream ends
|
||||
|
|
|
|||
|
|
@ -108,6 +108,7 @@ func NewHeadscaleDatabase(
|
|||
if err != nil {
|
||||
return fmt.Errorf("automigrating types.PreAuthKey: %w", err)
|
||||
}
|
||||
|
||||
err = tx.AutoMigrate(&types.Node{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("automigrating types.Node: %w", err)
|
||||
|
|
|
|||
|
|
@ -286,6 +286,7 @@ func RenameNode(tx *gorm.DB,
|
|||
|
||||
// Check if the new name is unique
|
||||
var count int64
|
||||
|
||||
err = tx.Model(&types.Node{}).Where("given_name = ? AND id != ?", newName, nodeID).Count(&count).Error
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to check name uniqueness: %w", err)
|
||||
|
|
@ -497,6 +498,7 @@ func generateGivenName(suppliedName string, randomSuffix bool) (string, error) {
|
|||
|
||||
func isUniqueName(tx *gorm.DB, name string) (bool, error) {
|
||||
nodes := types.Nodes{}
|
||||
|
||||
err := tx.
|
||||
Where("given_name = ?", name).Find(&nodes).Error
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -165,6 +165,7 @@ func ListUsers(tx *gorm.DB, where ...*types.User) ([]types.User, error) {
|
|||
}
|
||||
|
||||
users := []types.User{}
|
||||
|
||||
err := tx.Where(user).Find(&users).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
|
|
@ -417,6 +417,7 @@ type DERPVerifyTransport struct {
|
|||
|
||||
func (t *DERPVerifyTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
|
||||
err := t.handleVerifyRequest(req, buf)
|
||||
if err != nil {
|
||||
log.Error().Caller().Err(err).Msg("Failed to handle client verify request: ")
|
||||
|
|
|
|||
|
|
@ -154,6 +154,7 @@ func (h *Headscale) KeyHandler(
|
|||
}
|
||||
|
||||
writer.Header().Set("Content-Type", "application/json")
|
||||
|
||||
err := json.NewEncoder(writer).Encode(resp)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("failed to encode key response")
|
||||
|
|
|
|||
|
|
@ -212,6 +212,7 @@ func (p Prefix) MarshalJSON() ([]byte, error) {
|
|||
|
||||
func (u *Username) UnmarshalJSON(b []byte) error {
|
||||
*u = Username(strings.Trim(string(b), `"`))
|
||||
|
||||
err := u.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -307,6 +308,7 @@ func (g Group) Validate() error {
|
|||
|
||||
func (g *Group) UnmarshalJSON(b []byte) error {
|
||||
*g = Group(strings.Trim(string(b), `"`))
|
||||
|
||||
err := g.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -373,6 +375,7 @@ func (t Tag) Validate() error {
|
|||
|
||||
func (t *Tag) UnmarshalJSON(b []byte) error {
|
||||
*t = Tag(strings.Trim(string(b), `"`))
|
||||
|
||||
err := t.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -424,6 +427,7 @@ func (h Host) Validate() error {
|
|||
|
||||
func (h *Host) UnmarshalJSON(b []byte) error {
|
||||
*h = Host(strings.Trim(string(b), `"`))
|
||||
|
||||
err := h.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -586,6 +590,7 @@ func (ag AutoGroup) Validate() error {
|
|||
|
||||
func (ag *AutoGroup) UnmarshalJSON(b []byte) error {
|
||||
*ag = AutoGroup(strings.Trim(string(b), `"`))
|
||||
|
||||
err := ag.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -674,6 +679,7 @@ type AliasWithPorts struct {
|
|||
|
||||
func (ve *AliasWithPorts) UnmarshalJSON(b []byte) error {
|
||||
var v any
|
||||
|
||||
err := json.Unmarshal(b, &v)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -1055,6 +1061,7 @@ func (g Groups) Contains(group *Group) error {
|
|||
func (g *Groups) UnmarshalJSON(b []byte) error {
|
||||
// First unmarshal as a generic map to validate group names first
|
||||
var rawMap map[string]any
|
||||
|
||||
err := json.Unmarshal(b, &rawMap)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -1063,6 +1070,7 @@ func (g *Groups) UnmarshalJSON(b []byte) error {
|
|||
// Validate group names first before checking data types
|
||||
for key := range rawMap {
|
||||
group := Group(key)
|
||||
|
||||
err := group.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -1103,6 +1111,7 @@ func (g *Groups) UnmarshalJSON(b []byte) error {
|
|||
|
||||
for _, u := range value {
|
||||
username := Username(u)
|
||||
|
||||
err := username.Validate()
|
||||
if err != nil {
|
||||
if isGroup(u) {
|
||||
|
|
@ -1126,6 +1135,7 @@ type Hosts map[Host]Prefix
|
|||
|
||||
func (h *Hosts) UnmarshalJSON(b []byte) error {
|
||||
var rawHosts map[string]string
|
||||
|
||||
err := json.Unmarshal(b, &rawHosts, policyJSONOpts...)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -1135,12 +1145,14 @@ func (h *Hosts) UnmarshalJSON(b []byte) error {
|
|||
|
||||
for key, value := range rawHosts {
|
||||
host := Host(key)
|
||||
|
||||
err := host.Validate()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var prefix Prefix
|
||||
|
||||
err = prefix.parseString(value)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: hostname %q value %q", ErrInvalidIPAddress, key, value)
|
||||
|
|
@ -1758,11 +1770,13 @@ func (p *Policy) validate() error {
|
|||
}
|
||||
case *Group:
|
||||
g := src
|
||||
if err := p.Groups.Contains(g); err != nil {
|
||||
err := p.Groups.Contains(g)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
case *Tag:
|
||||
tagOwner := src
|
||||
|
||||
err := p.TagOwners.Contains(tagOwner)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
@ -1793,11 +1807,13 @@ func (p *Policy) validate() error {
|
|||
}
|
||||
case *Group:
|
||||
g := dst.Alias.(*Group)
|
||||
if err := p.Groups.Contains(g); err != nil {
|
||||
err := p.Groups.Contains(g)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
case *Tag:
|
||||
tagOwner := dst.Alias.(*Tag)
|
||||
|
||||
err := p.TagOwners.Contains(tagOwner)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
@ -1816,6 +1832,7 @@ func (p *Policy) validate() error {
|
|||
for _, user := range ssh.Users {
|
||||
if strings.HasPrefix(string(user), "autogroup:") {
|
||||
maybeAuto := AutoGroup(user)
|
||||
|
||||
err := validateAutogroupForSSHUser(&maybeAuto)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
@ -1842,12 +1859,14 @@ func (p *Policy) validate() error {
|
|||
}
|
||||
case *Group:
|
||||
g := src
|
||||
|
||||
err := p.Groups.Contains(g)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
case *Tag:
|
||||
tagOwner := src
|
||||
|
||||
err := p.TagOwners.Contains(tagOwner)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
@ -1859,6 +1878,7 @@ func (p *Policy) validate() error {
|
|||
switch dst := dst.(type) {
|
||||
case *AutoGroup:
|
||||
ag := dst
|
||||
|
||||
err := validateAutogroupSupported(ag)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
@ -1872,6 +1892,7 @@ func (p *Policy) validate() error {
|
|||
}
|
||||
case *Tag:
|
||||
tagOwner := dst
|
||||
|
||||
err := p.TagOwners.Contains(tagOwner)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
@ -1885,6 +1906,7 @@ func (p *Policy) validate() error {
|
|||
switch tagOwner := tagOwner.(type) {
|
||||
case *Group:
|
||||
g := tagOwner
|
||||
|
||||
err := p.Groups.Contains(g)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
@ -1911,12 +1933,14 @@ func (p *Policy) validate() error {
|
|||
switch approver := approver.(type) {
|
||||
case *Group:
|
||||
g := approver
|
||||
|
||||
err := p.Groups.Contains(g)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
case *Tag:
|
||||
tagOwner := approver
|
||||
|
||||
err := p.TagOwners.Contains(tagOwner)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
@ -1929,12 +1953,14 @@ func (p *Policy) validate() error {
|
|||
switch approver := approver.(type) {
|
||||
case *Group:
|
||||
g := approver
|
||||
|
||||
err := p.Groups.Contains(g)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
case *Tag:
|
||||
tagOwner := approver
|
||||
|
||||
err := p.TagOwners.Contains(tagOwner)
|
||||
if err != nil {
|
||||
errs = append(errs, err)
|
||||
|
|
|
|||
|
|
@ -573,6 +573,7 @@ func (node *Node) ApplyHostnameFromHostInfo(hostInfo *tailcfg.Hostinfo) {
|
|||
}
|
||||
|
||||
newHostname := strings.ToLower(hostInfo.Hostname)
|
||||
|
||||
err := util.ValidateHostname(newHostname)
|
||||
if err != nil {
|
||||
log.Warn().
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ func TestUnmarshallOIDCClaims(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var got OIDCClaims
|
||||
|
||||
err := json.Unmarshal([]byte(tt.jsonstr), &got)
|
||||
if err != nil {
|
||||
t.Errorf("UnmarshallOIDCClaims() error = %v", err)
|
||||
|
|
@ -483,6 +484,7 @@ func TestOIDCClaimsJSONToUser(t *testing.T) {
|
|||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
var got OIDCClaims
|
||||
|
||||
err := json.Unmarshal([]byte(tt.jsonstr), &got)
|
||||
if err != nil {
|
||||
t.Errorf("TestOIDCClaimsJSONToUser() error = %v", err)
|
||||
|
|
|
|||
|
|
@ -323,6 +323,7 @@ func EnsureHostname(hostinfo *tailcfg.Hostinfo, machineKey, nodeKey string) stri
|
|||
}
|
||||
|
||||
lowercased := strings.ToLower(hostinfo.Hostname)
|
||||
|
||||
err := ValidateHostname(lowercased)
|
||||
if err == nil {
|
||||
return lowercased
|
||||
|
|
|
|||
|
|
@ -109,6 +109,7 @@ func DERPVerify(
|
|||
defer c.Close()
|
||||
|
||||
var result error
|
||||
|
||||
err := c.Connect(t.Context())
|
||||
if err != nil {
|
||||
result = fmt.Errorf("client Connect: %w", err)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue