2022-11-27 14:17:30 +08:00
|
|
|
package functions
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/gravitl/netmaker/models"
|
|
|
|
)
|
|
|
|
|
2022-11-28 20:36:46 +08:00
|
|
|
// HasAdmin - check if server has an admin user
|
2022-11-27 14:17:30 +08:00
|
|
|
func HasAdmin() *bool {
|
|
|
|
return request[bool](http.MethodGet, "/api/users/adm/hasadmin", nil)
|
|
|
|
}
|
|
|
|
|
2022-11-28 20:36:46 +08:00
|
|
|
// CreateUser - create a user
|
2022-11-27 14:17:30 +08:00
|
|
|
func CreateUser(payload *models.User) *models.User {
|
|
|
|
return request[models.User](http.MethodPost, "/api/users/"+payload.UserName, payload)
|
|
|
|
}
|
|
|
|
|
2022-11-28 20:36:46 +08:00
|
|
|
// UpdateUser - update a user
|
2022-11-28 19:12:36 +08:00
|
|
|
func UpdateUser(payload *models.User) *models.User {
|
|
|
|
return request[models.User](http.MethodPut, "/api/users/networks/"+payload.UserName, payload)
|
|
|
|
}
|
|
|
|
|
2022-11-28 20:36:46 +08:00
|
|
|
// DeleteUser - delete a user
|
2022-11-28 19:12:36 +08:00
|
|
|
func DeleteUser(username string) *string {
|
|
|
|
return request[string](http.MethodDelete, "/api/users/"+username, nil)
|
|
|
|
}
|
|
|
|
|
2022-11-28 20:36:46 +08:00
|
|
|
// GetUser - fetch a single user
|
2022-11-28 19:12:36 +08:00
|
|
|
func GetUser(username string) *models.User {
|
|
|
|
return request[models.User](http.MethodGet, "/api/users/"+username, nil)
|
|
|
|
}
|
|
|
|
|
2022-11-28 20:36:46 +08:00
|
|
|
// ListUsers - fetch all users
|
2022-11-27 14:17:30 +08:00
|
|
|
func ListUsers() *[]models.ReturnUser {
|
|
|
|
return request[[]models.ReturnUser](http.MethodGet, "/api/users", nil)
|
|
|
|
}
|