Skip to content

Commit

Permalink
Fix bug in SetUserGroupMembership which results in always throwing an…
Browse files Browse the repository at this point in the history
… error
  • Loading branch information
NHAS committed Jun 5, 2024
1 parent 9552441 commit e270437
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 4 deletions.
7 changes: 7 additions & 0 deletions commands/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,13 @@ func clusterState(noIptables bool, errorChan chan<- error) func(string) {
errorChan <- fmt.Errorf("to write witness data when cluster is healthy: %v", err)
return
}

err = data.SetVersion()
if err != nil {
errorChan <- fmt.Errorf("to write version data when cluster is healthy: %v", err)
return
}

}

wasDead = false
Expand Down
15 changes: 15 additions & 0 deletions internal/data/clustering.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,21 @@ func IsWitness(idHex string) (bool, error) {
return isDrained.Count != 0, nil
}

func GetVersion(idHex string) (string, error) {
_, err := strconv.ParseUint(idHex, 16, 64)
if err != nil {
return "", fmt.Errorf("bad member ID arg (%v), expecting ID in Hex", err)
}

return getString(path.Join(NodeInfo, idHex, "version"))
}

func SetVersion() error {
d, _ := json.Marshal(config.Version)
_, err := etcd.Put(context.Background(), path.Join(NodeInfo, GetServerID().String(), "version"), string(d))
return err
}

func SetDrained(idHex string, on bool) error {

isWitness, err := IsWitness(idHex)
Expand Down
6 changes: 5 additions & 1 deletion internal/data/groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,9 @@ func SetUserGroupMembership(username string, newGroups []string) error {
return string(userGroups), nil
})

return fmt.Errorf("failed to update group membership: %s", err)
if err != nil {
return fmt.Errorf("failed to update group membership: %v", err)
}

return nil
}
2 changes: 1 addition & 1 deletion internal/router/statemachine.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func deviceChanges(_ string, current, previous data.Device, et data.EventType) e
}

if current.Authorised.IsZero() {
reasons = append(reasons, "admin action")
reasons = append(reasons, "session terminated")
}

err := Deauthenticate(current.Address)
Expand Down
5 changes: 3 additions & 2 deletions ui/clustering.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ type MembershipDTO struct {
IsDrained bool
IsWitness bool

Ping string
Status string
Version string
Ping string
Status string
}

func clusterMembersUI(w http.ResponseWriter, r *http.Request) {
Expand Down
8 changes: 8 additions & 0 deletions ui/templates/cluster/members.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ <h5 class="font-weight-bold text-truncate">{{if
{{.ID}}
</div>
</div>
<div class="row mb-1">
<div class="col-4">
Version:
</div>
<div class="col text-left">
{{.Version}}
</div>
</div>
<div class="row mb-1">
<div class="col-4">
Role:
Expand Down

0 comments on commit e270437

Please sign in to comment.