diff --git a/client/request.go b/client/request.go index a99690a12..e2cf03a87 100644 --- a/client/request.go +++ b/client/request.go @@ -66,6 +66,15 @@ func (client *APIClient) post(ctx context.Context, path string, query url.Values return client.sendRequest(ctx, "POST", path, query, body, headers) } +func (client *APIClient) put(ctx context.Context, path string, query url.Values, obj interface{}, headers map[string][]string) (*Response, error) { + body, err := objectToJSONStream(obj) + if err != nil { + return nil, err + } + + return client.sendRequest(ctx, "PUT", path, query, body, headers) +} + func (client *APIClient) postRawData(ctx context.Context, path string, query url.Values, data io.Reader, headers map[string][]string) (*Response, error) { return client.sendRequest(ctx, "POST", path, query, data, headers) } diff --git a/client/task_update.go b/client/task_update.go new file mode 100644 index 000000000..2ca4fd6aa --- /dev/null +++ b/client/task_update.go @@ -0,0 +1,34 @@ +/* + * Copyright The Dragonfly Authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package client + +import ( + "context" + + "github.com/dragonflyoss/Dragonfly/apis/types" +) + +// TaskUpdate updates a task in supernode. +func (client *APIClient) TaskUpdate(ctx context.Context, id string, config *types.TaskUpdateRequest) error { + resp, err := client.put(ctx, "/tasks/"+id, nil, config, nil) + if err != nil { + return err + } + + ensureCloseReader(resp) + return nil +}