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