2018-06-11 15:13:19 +02:00
package endpointgroups
import (
"net/http"
2018-09-10 12:01:38 +02:00
httperror "github.com/portainer/libhttp/error"
"github.com/portainer/libhttp/request"
"github.com/portainer/libhttp/response"
2021-02-23 05:21:39 +02:00
portainer "github.com/portainer/portainer/api"
2020-07-08 00:57:52 +03:00
"github.com/portainer/portainer/api/bolt/errors"
2018-06-11 15:13:19 +02:00
)
2021-09-20 12:14:22 +12:00
// @summary Inspect an Environment(Endpoint) group
// @description Retrieve details abont an environment(endpoint) group.
2021-02-23 05:21:39 +02:00
// @description **Access policy**: administrator
// @tags endpoint_groups
2021-11-30 15:31:16 +13:00
// @security ApiKeyAuth
2021-02-23 05:21:39 +02:00
// @security jwt
// @accept json
// @produce json
2021-09-20 12:14:22 +12:00
// @param id path int true "Environment(Endpoint) group identifier"
2021-02-23 05:21:39 +02:00
// @success 200 {object} portainer.EndpointGroup "Success"
// @failure 400 "Invalid request"
// @failure 404 "EndpointGroup not found"
// @failure 500 "Server error"
2021-09-13 15:42:53 +12:00
// @router /endpoint_groups/{id} [get]
2018-06-11 15:13:19 +02:00
func ( handler * Handler ) endpointGroupInspect ( w http . ResponseWriter , r * http . Request ) * httperror . HandlerError {
endpointGroupID , err := request . RetrieveNumericRouteVariableValue ( r , "id" )
if err != nil {
2021-09-08 20:42:17 +12:00
return & httperror . HandlerError { http . StatusBadRequest , "Invalid environment group identifier route variable" , err }
2018-06-11 15:13:19 +02:00
}
2020-05-20 17:23:15 +12:00
endpointGroup , err := handler . DataStore . EndpointGroup ( ) . EndpointGroup ( portainer . EndpointGroupID ( endpointGroupID ) )
2020-07-08 00:57:52 +03:00
if err == errors . ErrObjectNotFound {
2021-09-08 20:42:17 +12:00
return & httperror . HandlerError { http . StatusNotFound , "Unable to find an environment group with the specified identifier inside the database" , err }
2018-06-11 15:13:19 +02:00
} else if err != nil {
2021-09-08 20:42:17 +12:00
return & httperror . HandlerError { http . StatusInternalServerError , "Unable to find an environment group with the specified identifier inside the database" , err }
2018-06-11 15:13:19 +02:00
}
return response . JSON ( w , endpointGroup )
}