2016-10-03 03:14:35 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
2017-03-15 15:55:30 +00:00
|
|
|
"context"
|
2018-05-04 01:01:57 +00:00
|
|
|
"encoding/json"
|
2016-10-03 03:14:35 +00:00
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
func decodeDeleteLabelRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
2018-05-04 18:05:55 +00:00
|
|
|
name, err := nameFromRequest(r, "name")
|
2016-10-03 03:14:35 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req deleteLabelRequest
|
2018-05-04 18:05:55 +00:00
|
|
|
req.Name = name
|
2016-10-03 03:14:35 +00:00
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2018-06-25 20:56:59 +00:00
|
|
|
func decodeDeleteLabelByIDRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req deleteLabelByIDRequest
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
2016-10-03 03:14:35 +00:00
|
|
|
func decodeGetLabelRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var req getLabelRequest
|
|
|
|
req.ID = id
|
|
|
|
return req, nil
|
|
|
|
}
|
2016-10-13 18:21:47 +00:00
|
|
|
|
|
|
|
func decodeListLabelsRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
opt, err := listOptionsFromRequest(r)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return listLabelsRequest{ListOptions: opt}, nil
|
|
|
|
}
|
2018-05-04 01:01:57 +00:00
|
|
|
|
2020-03-30 02:19:54 +00:00
|
|
|
func decodeListHostsInLabelRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-02-18 20:52:43 +00:00
|
|
|
|
|
|
|
hopt, err := hostListOptionsFromRequest(r)
|
2020-03-30 02:19:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-02-18 20:52:43 +00:00
|
|
|
|
|
|
|
return listHostsInLabelRequest{ID: id, ListOptions: hopt}, nil
|
2020-03-30 02:19:54 +00:00
|
|
|
}
|
|
|
|
|
2018-05-04 01:01:57 +00:00
|
|
|
func decodeApplyLabelSpecsRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req applyLabelSpecsRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
|
|
|
|
}
|
2018-06-18 17:09:08 +00:00
|
|
|
|
|
|
|
func decodeCreateLabelRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req createLabelRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req.payload); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return req, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func decodeModifyLabelRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
id, err := idFromRequest(r, "id")
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var resp modifyLabelRequest
|
|
|
|
err = json.NewDecoder(r.Body).Decode(&resp.payload)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
resp.ID = id
|
|
|
|
return resp, nil
|
|
|
|
}
|