forked from tsuru/tsuru
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read groups from oauth provider and allow roles to groups
- Loading branch information
Showing
24 changed files
with
562 additions
and
19 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
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,57 @@ | ||
// Copyright 2020 tsuru authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package auth | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
"github.com/tsuru/tsuru/permission" | ||
"github.com/tsuru/tsuru/storage" | ||
authTypes "github.com/tsuru/tsuru/types/auth" | ||
) | ||
|
||
var ( | ||
_ authTypes.GroupService = &groupService{} | ||
|
||
errGroupNameEmpty = errors.New("group name cannot be empty") | ||
) | ||
|
||
func GroupService() (authTypes.GroupService, error) { | ||
dbDriver, err := storage.GetCurrentDbDriver() | ||
if err != nil { | ||
dbDriver, err = storage.GetDefaultDbDriver() | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return &groupService{ | ||
storage: dbDriver.AuthGroupStorage, | ||
}, nil | ||
} | ||
|
||
type groupService struct { | ||
storage authTypes.GroupStorage | ||
} | ||
|
||
func (s *groupService) List(filter []string) ([]authTypes.Group, error) { | ||
return s.storage.List(filter) | ||
} | ||
|
||
func (s *groupService) AddRole(name, roleName, contextValue string) error { | ||
if name == "" { | ||
return errGroupNameEmpty | ||
} | ||
_, err := permission.FindRole(roleName) | ||
if err != nil { | ||
return err | ||
} | ||
return s.storage.AddRole(name, roleName, contextValue) | ||
} | ||
|
||
func (s *groupService) RemoveRole(name, roleName, contextValue string) error { | ||
if name == "" { | ||
return errGroupNameEmpty | ||
} | ||
return s.storage.RemoveRole(name, roleName, contextValue) | ||
} |
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
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
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
Oops, something went wrong.