Style changes

This commit is contained in:
Alex 2020-11-13 12:55:32 +01:00
parent 4367e4a232
commit e4b5c67be0
3 changed files with 16 additions and 16 deletions

View file

@ -298,7 +298,7 @@ func (server *Server) init() error {
} }
base_attributes[suffix_dn[0].Type] = []string{suffix_dn[0].Value} base_attributes[suffix_dn[0].Type] = []string{suffix_dn[0].Value}
err = server.addElements(server.config.Suffix, base_attributes) err = server.putAttributes(server.config.Suffix, base_attributes)
if err != nil { if err != nil {
return err return err
} }
@ -324,7 +324,7 @@ func (server *Server) init() error {
ATTR_ENTRYUUID: []string{genUuid()}, ATTR_ENTRYUUID: []string{genUuid()},
} }
err = server.addElements(admin_dn, admin_attributes) err = server.putAttributes(admin_dn, admin_attributes)
if err != nil { if err != nil {
return err return err
} }
@ -338,7 +338,7 @@ func (server *Server) init() error {
return nil return nil
} }
func (server *Server) addElements(dn string, attrs Entry) error { func (server *Server) putAttributes(dn string, attrs Entry) error {
prefix, err := dnToConsul(dn) prefix, err := dnToConsul(dn)
if err != nil { if err != nil {
return err return err
@ -364,7 +364,7 @@ func (server *Server) addElements(dn string, attrs Entry) error {
return err return err
} }
} else { } else {
json, err := json.Marshal(values) json, err := json.MarshalIndent(values, "", " ")
if err != nil { if err != nil {
return err return err
} }

View file

@ -13,8 +13,8 @@ func (server *Server) memberOfAdd(member string, group string) {
} }
// Return early if group is already in memberOf // Return early if group is already in memberOf
for _, mb := range memberGroups { for _, g := range memberGroups {
if mb == group { if g == group {
server.logger.Warnf("Inconsistency detected, %s was memberOf %s at a time when it didn't exist! (not an issue anymore)", server.logger.Warnf("Inconsistency detected, %s was memberOf %s at a time when it didn't exist! (not an issue anymore)",
member, group) member, group)
return return
@ -23,7 +23,7 @@ func (server *Server) memberOfAdd(member string, group string) {
// Add group to memberOf // Add group to memberOf
memberGroups = append(memberGroups, group) memberGroups = append(memberGroups, group)
err = server.addElements(member, Entry{ err = server.putAttributes(member, Entry{
ATTR_MEMBEROF: memberGroups, ATTR_MEMBEROF: memberGroups,
}) })
if err != nil { if err != nil {
@ -41,9 +41,9 @@ func (server *Server) memberOfRemove(member string, group string) {
// Filter out group // Filter out group
newMemberOf := []string{} newMemberOf := []string{}
for _, mb := range memberOf { for _, g := range memberOf {
if mb != group { if g != group {
newMemberOf = append(newMemberOf, mb) newMemberOf = append(newMemberOf, g)
} }
} }
@ -55,7 +55,7 @@ func (server *Server) memberOfRemove(member string, group string) {
} }
// Update value of memberOf // Update value of memberOf
err = server.addElements(member, Entry{ err = server.putAttributes(member, Entry{
ATTR_MEMBEROF: newMemberOf, ATTR_MEMBEROF: newMemberOf,
}) })
if err != nil { if err != nil {
@ -105,7 +105,7 @@ func (server *Server) memberOfResync() error {
} }
if len(keepMember) != len(member) { if len(keepMember) != len(member) {
server.logger.Warnf("Writing new member list for %s", dn) server.logger.Warnf("Writing new member list for %s", dn)
err = server.addElements(dn, Entry{ err = server.putAttributes(dn, Entry{
ATTR_MEMBER: keepMember, ATTR_MEMBER: keepMember,
}) })
if err != nil { if err != nil {
@ -134,7 +134,7 @@ func (server *Server) memberOfResync() error {
if different { if different {
server.logger.Warnf("Fixing memberOf for %s (%d -> %d)", server.logger.Warnf("Fixing memberOf for %s (%d -> %d)",
dn, len(prevMemberOf), len(newMemberOfV)) dn, len(prevMemberOf), len(newMemberOfV))
err = server.addElements(dn, Entry{ err = server.putAttributes(dn, Entry{
ATTR_MEMBEROF: newMemberOfV, ATTR_MEMBEROF: newMemberOfV,
}) })
if err != nil { if err != nil {

View file

@ -134,7 +134,7 @@ func (server *Server) handleAddInternal(state *State, r *message.AddRequest) (in
entry[dnSplit[0].Type] = []string{dnSplit[0].Value} entry[dnSplit[0].Type] = []string{dnSplit[0].Value}
// Add our item in the DB // Add our item in the DB
err = server.addElements(dn, entry) err = server.putAttributes(dn, entry)
if err != nil { if err != nil {
return ldap.LDAPResultOperationsError, err return ldap.LDAPResultOperationsError, err
} }
@ -239,7 +239,7 @@ func (server *Server) handleDeleteInternal(state *State, r *message.DelRequest)
} }
} }
err = server.addElements(group, Entry{ err = server.putAttributes(group, Entry{
ATTR_MEMBER: newMembers, ATTR_MEMBER: newMembers,
}) })
if err != nil { if err != nil {
@ -455,7 +455,7 @@ func (server *Server) handleModifyInternal(state *State, r *message.ModifyReques
entry[ATTR_MODIFYTIMESTAMP] = []string{genTimestamp()} entry[ATTR_MODIFYTIMESTAMP] = []string{genTimestamp()}
// Save the edited values // Save the edited values
err = server.addElements(dn, entry) err = server.putAttributes(dn, entry)
if err != nil { if err != nil {
return ldap.LDAPResultOperationsError, err return ldap.LDAPResultOperationsError, err
} }