Skip to content

Commit

Permalink
move to aclFile
Browse files Browse the repository at this point in the history
  • Loading branch information
ncode committed Apr 18, 2024
1 parent 90176b5 commit 282916f
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions pkg/aclmanager/aclmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type AclManager struct {
RedisClient *redis.Client
primary atomic.Bool
nodes map[string]int
aclfile bool
aclFile bool
}

// New creates a new AclManager
Expand All @@ -51,7 +51,7 @@ func New(addr string, username string, password string, aclfile bool) *AclManage
Password: password,
RedisClient: redisClient,
nodes: make(map[string]int),
aclfile: aclfile,
aclFile: aclfile,
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ func (a *AclManager) Primary(ctx context.Context) (primary *AclManager, err erro

for address, function := range a.nodes {
if function == Primary {
return New(address, a.Username, a.Password, a.aclfile), err
return New(address, a.Username, a.Password, a.aclFile), err
}
}

Expand Down Expand Up @@ -166,21 +166,21 @@ func listAcls(ctx context.Context, client *redis.Client) (acls []string, err err
return acls, nil
}

// saveAclFile call the redis command ACL SAVE to save the acls to the aclfile
// saveAclFile call the redis command ACL SAVE to save the acls to the aclFile
func saveAclFile(ctx context.Context, client *redis.Client) error {
slog.Debug("Saving acls to aclfile")
slog.Debug("Saving acls to aclFile")
if err := client.Do(ctx, "ACL", "SAVE").Err(); err != nil {
return fmt.Errorf("error saving acls to aclfile: %v", err)
return fmt.Errorf("error saving acls to aclFile: %v", err)
}

return nil
}

// loadAclFile call the redis command ACL LOAD to load the acls from the aclfile
// loadAclFile call the redis command ACL LOAD to load the acls from the aclFile
func loadAclFile(ctx context.Context, client *redis.Client) error {
slog.Debug("Loading acls from aclfile")
slog.Debug("Loading acls from aclFile")
if err := client.Do(ctx, "ACL", "LOAD").Err(); err != nil {
return fmt.Errorf("error loading acls from aclfile: %v", err)
return fmt.Errorf("error loading acls from aclFile: %v", err)
}

return nil
Expand All @@ -198,10 +198,10 @@ func (a *AclManager) SyncAcls(ctx context.Context, primary *AclManager) (updated
return nil, nil, fmt.Errorf("error listing source acls: %v", err)
}

if a.aclfile {
if a.aclFile {
err = saveAclFile(ctx, primary.RedisClient)
if err != nil {
return nil, nil, fmt.Errorf("error saving primary acls to aclfile: %v", err)
return nil, nil, fmt.Errorf("error saving primary acls to aclFile: %v", err)
}
}

Expand Down Expand Up @@ -251,14 +251,14 @@ func (a *AclManager) SyncAcls(ctx context.Context, primary *AclManager) (updated
updated = append(updated, username)
}

if a.aclfile {
if a.aclFile {
err = saveAclFile(ctx, a.RedisClient)
if err != nil {
return nil, nil, fmt.Errorf("error saving acls to aclfile: %v", err)
return nil, nil, fmt.Errorf("error saving acls to aclFile: %v", err)
}
err = loadAclFile(ctx, a.RedisClient)
if err != nil {
return nil, nil, fmt.Errorf("error loading synced acls from aclfile: %v", err)
return nil, nil, fmt.Errorf("error loading synced acls from aclFile: %v", err)
}
}

Expand Down

0 comments on commit 282916f

Please sign in to comment.