2018-06-11 13:13:19 +00:00
|
|
|
package endpointgroups
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2018-09-10 10:01:38 +00:00
|
|
|
httperror "github.com/portainer/libhttp/error"
|
|
|
|
"github.com/portainer/libhttp/response"
|
2019-03-21 01:20:14 +00:00
|
|
|
"github.com/portainer/portainer/api/http/security"
|
2018-06-11 13:13:19 +00:00
|
|
|
)
|
|
|
|
|
2021-02-23 03:21:39 +00:00
|
|
|
// @id EndpointGroupList
|
2021-09-20 00:14:22 +00:00
|
|
|
// @summary List Environment(Endpoint) groups
|
|
|
|
// @description List all environment(endpoint) groups based on the current user authorizations. Will
|
|
|
|
// @description return all environment(endpoint) groups if using an administrator account otherwise it will
|
|
|
|
// @description only return authorized environment(endpoint) groups.
|
2021-02-23 03:21:39 +00:00
|
|
|
// @description **Access policy**: restricted
|
|
|
|
// @tags endpoint_groups
|
2021-11-30 02:31:16 +00:00
|
|
|
// @security ApiKeyAuth
|
2021-02-23 03:21:39 +00:00
|
|
|
// @security jwt
|
|
|
|
// @produce json
|
2021-09-20 00:14:22 +00:00
|
|
|
// @success 200 {array} portainer.EndpointGroup "Environment(Endpoint) group"
|
2021-02-23 03:21:39 +00:00
|
|
|
// @failure 500 "Server error"
|
|
|
|
// @router /endpoint_groups [get]
|
2018-06-11 13:13:19 +00:00
|
|
|
func (handler *Handler) endpointGroupList(w http.ResponseWriter, r *http.Request) *httperror.HandlerError {
|
2020-05-20 05:23:15 +00:00
|
|
|
endpointGroups, err := handler.DataStore.EndpointGroup().EndpointGroups()
|
2018-06-11 13:13:19 +00:00
|
|
|
if err != nil {
|
2022-09-14 23:42:39 +00:00
|
|
|
return httperror.InternalServerError("Unable to retrieve environment groups from the database", err)
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
securityContext, err := security.RetrieveRestrictedRequestContext(r)
|
|
|
|
if err != nil {
|
2022-09-14 23:42:39 +00:00
|
|
|
return httperror.InternalServerError("Unable to retrieve info from request context", err)
|
2018-06-11 13:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
endpointGroups = security.FilterEndpointGroups(endpointGroups, securityContext)
|
|
|
|
return response.JSON(w, endpointGroups)
|
|
|
|
}
|