chore: last cleanup

This commit is contained in:
Julian Sommer
2026-07-01 14:30:23 +10:00
parent 4c1f7864f8
commit 88f043027c
5 changed files with 20 additions and 45 deletions
+3 -2
View File
@@ -293,8 +293,9 @@ func respondWithSystemTerminateError(msg *nats.Msg, errMsg string) {
// string if subject does not start with prefix. Helper kept local to avoid
// touching utils for a one-liner.
func splitSubjectTail(subject, prefix string) string {
if len(subject) <= len(prefix) || subject[:len(prefix)] != prefix {
tail, ok := strings.CutPrefix(subject, prefix)
if !ok {
return ""
}
return subject[len(prefix):]
return tail
}
+3 -3
View File
@@ -11,6 +11,7 @@ import (
"log/slog"
"maps"
"net/http"
"strings"
"sync"
"time"
@@ -295,11 +296,10 @@ func (fs *FormationServer) validateToken(r *http.Request) error {
return fmt.Errorf("missing Authorization header")
}
const prefix = "Bearer "
if len(auth) < len(prefix) || auth[:len(prefix)] != prefix {
token, ok := strings.CutPrefix(auth, "Bearer ")
if !ok {
return fmt.Errorf("invalid Authorization header format")
}
token := auth[len(prefix):]
if subtle.ConstantTimeCompare([]byte(token), []byte(fs.joinToken)) != 1 {
return fmt.Errorf("invalid join token")
+5 -4
View File
@@ -2,6 +2,7 @@ package handlers_ecs
import (
"fmt"
"strings"
"time"
"github.com/mulgadc/spinifex/spinifex/handlers/ecs/bus"
@@ -66,11 +67,11 @@ func serviceTaskGroup(name string) string {
// serviceNameFromGroup returns the service name encoded in a task group, or ""
// when the group is not a service group.
func serviceNameFromGroup(group string) string {
const p = "service:"
if len(group) > len(p) && group[:len(p)] == p {
return group[len(p):]
name, ok := strings.CutPrefix(group, "service:")
if !ok {
return ""
}
return ""
return name
}
// ClusterRecord is the persisted cluster meta at ClusterMetaKey.
+3 -12
View File
@@ -239,21 +239,12 @@ func (s *IAMServiceImpl) RemoveUserFromGroup(accountID string, input *iam.Remove
// Operate purely on the membership reference so a dangling pointer to an
// already-deleted group is still cleanable; never fetch the group here.
found := false
remaining := make([]string, 0, len(user.Groups))
for _, name := range user.Groups {
if name == groupName {
found = true
} else {
remaining = append(remaining, name)
}
}
if !found {
idx := slices.Index(user.Groups, groupName)
if idx < 0 {
return nil, errors.New(awserrors.ErrorIAMNoSuchEntity)
}
user.Groups = remaining
user.Groups = slices.Delete(user.Groups, idx, idx+1)
userData, err := json.Marshal(user)
if err != nil {
return nil, fmt.Errorf("marshal user: %w", err)
+6 -24
View File
@@ -529,22 +529,13 @@ func (s *IAMServiceImpl) DeleteAccessKey(accountID string, input *iam.DeleteAcce
return nil, err
}
found := false
remaining := make([]string, 0, len(user.AccessKeys))
for _, keyID := range user.AccessKeys {
if keyID == accessKeyID {
found = true
} else {
remaining = append(remaining, keyID)
}
}
if !found {
idx := slices.Index(user.AccessKeys, accessKeyID)
if idx < 0 {
return nil, errors.New(awserrors.ErrorIAMNoSuchEntity)
}
// Update user record first to avoid orphaning the reference on crash.
user.AccessKeys = remaining
user.AccessKeys = slices.Delete(user.AccessKeys, idx, idx+1)
userData, err := json.Marshal(user)
if err != nil {
return nil, fmt.Errorf("marshal user: %w", err)
@@ -1239,21 +1230,12 @@ func (s *IAMServiceImpl) DetachUserPolicy(accountID string, input *iam.DetachUse
return nil, err
}
found := false
remaining := make([]string, 0, len(user.AttachedPolicies))
for _, arn := range user.AttachedPolicies {
if arn == policyARN {
found = true
} else {
remaining = append(remaining, arn)
}
}
if !found {
idx := slices.Index(user.AttachedPolicies, policyARN)
if idx < 0 {
return nil, errors.New(awserrors.ErrorIAMNoSuchEntity)
}
user.AttachedPolicies = remaining
user.AttachedPolicies = slices.Delete(user.AttachedPolicies, idx, idx+1)
userData, err := json.Marshal(user)
if err != nil {
return nil, fmt.Errorf("marshal user: %w", err)