mirror of
https://gitlab.com/psuapp/psu.git
synced 2024-08-30 18:12:34 +00:00
Add function to get user by its name
This commit is contained in:
parent
ca14cf6f5e
commit
49eb081130
@ -18,6 +18,7 @@ const (
|
||||
ErrEndpointGroupNotFound = Error("Endpoint group not found")
|
||||
ErrSeveralEndpointsAvailable = Error("Several endpoints available")
|
||||
ErrNoEndpointsAvailable = Error("No endpoints available")
|
||||
ErrUserNotFound = Error("User not found")
|
||||
)
|
||||
|
||||
const (
|
||||
@ -215,3 +216,28 @@ func repr(t reflect.Type, margin, beforeMargin string) (r string) {
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetUserByName returns an user by its name from the list of all users
|
||||
func GetUserByName(name string) (user portainer.User, err error) {
|
||||
portainerClient, err := GetClient()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Get users list
|
||||
users, err := portainerClient.UserList()
|
||||
|
||||
// Find user
|
||||
for _, listUser := range users {
|
||||
if listUser.Username == name {
|
||||
// User found
|
||||
user = listUser
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// User not found
|
||||
err = ErrUserNotFound
|
||||
|
||||
return
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user