1
0
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:
Juan Carlos Mejías Rodríguez 2019-09-09 00:16:14 -04:00
parent ca14cf6f5e
commit 49eb081130

View File

@ -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
}