-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CreatedAt and UpdatedAt field to IAM user
- Loading branch information
1 parent
f31cb8e
commit 92f2f6d
Showing
27 changed files
with
3,912 additions
and
3,145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package store | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
func (s *store) addIdentity(cmd CommandAddIdentity) error { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
err := s.data.Users.userlist.Add(cmd.Identity) | ||
if err != nil { | ||
return fmt.Errorf("the identity with the name '%s' already exists", cmd.Identity.Name) | ||
} | ||
|
||
now := time.Now() | ||
|
||
s.data.Users.UpdatedAt = now | ||
|
||
cmd.Identity.CreatedAt = now | ||
cmd.Identity.UpdatedAt = now | ||
s.data.Users.Users[cmd.Identity.Name] = cmd.Identity | ||
|
||
return nil | ||
} | ||
|
||
func (s *store) updateIdentity(cmd CommandUpdateIdentity) error { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
if cmd.Name == "$anon" { | ||
return fmt.Errorf("the identity with the name '%s' can't be updated", cmd.Name) | ||
} | ||
|
||
oldUser, err := s.data.Users.userlist.Get(cmd.Name) | ||
if err != nil { | ||
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Name) | ||
} | ||
|
||
o, ok := s.data.Users.Users[oldUser.Name] | ||
if !ok { | ||
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Name) | ||
} | ||
|
||
err = s.data.Users.userlist.Update(cmd.Name, cmd.Identity) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
user, err := s.data.Users.userlist.Get(cmd.Identity.Name) | ||
if err != nil { | ||
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Identity.Name) | ||
} | ||
|
||
now := time.Now() | ||
|
||
user.CreatedAt = o.CreatedAt | ||
user.UpdatedAt = now | ||
|
||
s.data.Users.UpdatedAt = now | ||
delete(s.data.Users.Users, oldUser.Name) | ||
s.data.Users.Users[user.Name] = user | ||
|
||
s.data.Policies.UpdatedAt = now | ||
policies := s.data.Policies.Policies[oldUser.Name] | ||
delete(s.data.Policies.Policies, oldUser.Name) | ||
s.data.Policies.Policies[user.Name] = policies | ||
|
||
return nil | ||
} | ||
|
||
func (s *store) removeIdentity(cmd CommandRemoveIdentity) error { | ||
s.lock.Lock() | ||
defer s.lock.Unlock() | ||
|
||
user, err := s.data.Users.userlist.Get(cmd.Name) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
s.data.Users.userlist.Delete(user.Name) | ||
|
||
delete(s.data.Users.Users, user.Name) | ||
s.data.Users.UpdatedAt = time.Now() | ||
delete(s.data.Policies.Policies, user.Name) | ||
s.data.Policies.UpdatedAt = time.Now() | ||
|
||
return nil | ||
} | ||
|
||
func (s *store) ListUsers() Users { | ||
s.lock.RLock() | ||
defer s.lock.RUnlock() | ||
|
||
u := Users{ | ||
UpdatedAt: s.data.Users.UpdatedAt, | ||
} | ||
|
||
for _, user := range s.data.Users.Users { | ||
u.Users = append(u.Users, user) | ||
} | ||
|
||
return u | ||
} | ||
|
||
func (s *store) GetUser(name string) Users { | ||
s.lock.RLock() | ||
defer s.lock.RUnlock() | ||
|
||
u := Users{ | ||
UpdatedAt: s.data.Users.UpdatedAt, | ||
} | ||
|
||
user, err := s.data.Users.userlist.Get(name) | ||
if err != nil { | ||
return u | ||
} | ||
|
||
u.UpdatedAt = user.UpdatedAt | ||
|
||
if user, ok := s.data.Users.Users[user.Name]; ok { | ||
u.Users = append(u.Users, user) | ||
} | ||
|
||
return u | ||
} |
Oops, something went wrong.