mirror of
https://github.com/datarhei/core.git
synced 2025-10-05 16:07:07 +08:00
Set default IAM domain if none provided
This commit is contained in:
@@ -32,6 +32,10 @@ func (a *policyAdapter) LoadPolicy(model model.Model) error {
|
|||||||
domains := map[string]struct{}{}
|
domains := map[string]struct{}{}
|
||||||
|
|
||||||
for _, p := range policies.Policies {
|
for _, p := range policies.Policies {
|
||||||
|
if len(p.Domain) == 0 {
|
||||||
|
p.Domain = "$none"
|
||||||
|
}
|
||||||
|
|
||||||
rule := []string{
|
rule := []string{
|
||||||
p.Name,
|
p.Name,
|
||||||
p.Domain,
|
p.Domain,
|
||||||
|
@@ -434,6 +434,10 @@ func (s *store) addIdentity(cmd CommandAddIdentity) error {
|
|||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
|
if cmd.Identity.Name == "$anon" {
|
||||||
|
return fmt.Errorf("the identity with the name '%s' can't be created", cmd.Identity.Name)
|
||||||
|
}
|
||||||
|
|
||||||
_, ok := s.data.Users.Users[cmd.Identity.Name]
|
_, ok := s.data.Users.Users[cmd.Identity.Name]
|
||||||
if ok {
|
if ok {
|
||||||
return fmt.Errorf("the identity with the name '%s' already exists", cmd.Identity.Name)
|
return fmt.Errorf("the identity with the name '%s' already exists", cmd.Identity.Name)
|
||||||
@@ -449,6 +453,10 @@ func (s *store) updateIdentity(cmd CommandUpdateIdentity) error {
|
|||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
|
if cmd.Name == "$anon" {
|
||||||
|
return fmt.Errorf("the identity with the name '%s' can't be updated", cmd.Name)
|
||||||
|
}
|
||||||
|
|
||||||
_, ok := s.data.Users.Users[cmd.Name]
|
_, ok := s.data.Users.Users[cmd.Name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Name)
|
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Name)
|
||||||
@@ -495,9 +503,20 @@ func (s *store) setPolicies(cmd CommandSetPolicies) error {
|
|||||||
s.lock.Lock()
|
s.lock.Lock()
|
||||||
defer s.lock.Unlock()
|
defer s.lock.Unlock()
|
||||||
|
|
||||||
|
if cmd.Name != "$anon" {
|
||||||
if _, ok := s.data.Users.Users[cmd.Name]; !ok {
|
if _, ok := s.data.Users.Users[cmd.Name]; !ok {
|
||||||
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Name)
|
return fmt.Errorf("the identity with the name '%s' doesn't exist", cmd.Name)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for i, p := range cmd.Policies {
|
||||||
|
if len(p.Domain) != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
p.Domain = "$none"
|
||||||
|
cmd.Policies[i] = p
|
||||||
|
}
|
||||||
|
|
||||||
delete(s.data.Policies.Policies, cmd.Name)
|
delete(s.data.Policies.Policies, cmd.Name)
|
||||||
s.data.Policies.Policies[cmd.Name] = cmd.Policies
|
s.data.Policies.Policies[cmd.Name] = cmd.Policies
|
||||||
|
Reference in New Issue
Block a user