-
Notifications
You must be signed in to change notification settings - Fork 109
Expand file tree
/
Copy pathinventory.go
More file actions
92 lines (79 loc) · 3.17 KB
/
inventory.go
File metadata and controls
92 lines (79 loc) · 3.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// Copyright (c) 2015-2025 MinIO, Inc.
//
// This file is part of MinIO Object Storage stack
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package madmin
import (
"context"
"encoding/json"
"fmt"
"net/http"
)
// InventoryJobControlStatus represents the status of an inventory job control operation
type InventoryJobControlStatus string
const (
InventoryJobStatusCanceled InventoryJobControlStatus = "canceled"
InventoryJobStatusSuspended InventoryJobControlStatus = "suspended"
InventoryJobStatusResumed InventoryJobControlStatus = "resumed"
)
// InventoryJobControlResponse represents the response from inventory job control operations
type InventoryJobControlResponse struct {
Status InventoryJobControlStatus `json:"status"`
Bucket string `json:"bucket"`
InventoryID string `json:"inventoryId"`
Message string `json:"message,omitempty"`
}
// CancelInventoryJob cancels a running inventory job
func (adm *AdminClient) CancelInventoryJob(ctx context.Context, bucket, inventoryID string) (*InventoryJobControlResponse, error) {
return adm.controlInventoryJob(ctx, bucket, inventoryID, "cancel")
}
// SuspendInventoryJob suspends a running inventory job
func (adm *AdminClient) SuspendInventoryJob(ctx context.Context, bucket, inventoryID string) (*InventoryJobControlResponse, error) {
return adm.controlInventoryJob(ctx, bucket, inventoryID, "suspend")
}
// ResumeInventoryJob resumes a suspended inventory job
func (adm *AdminClient) ResumeInventoryJob(ctx context.Context, bucket, inventoryID string) (*InventoryJobControlResponse, error) {
return adm.controlInventoryJob(ctx, bucket, inventoryID, "resume")
}
// controlInventoryJob is the common function for all inventory job control operations
func (adm *AdminClient) controlInventoryJob(ctx context.Context, bucket, inventoryID, action string) (*InventoryJobControlResponse, error) {
if bucket == "" {
return nil, fmt.Errorf("bucket name cannot be empty")
}
if inventoryID == "" {
return nil, fmt.Errorf("inventory ID cannot be empty")
}
resp, err := adm.executeMethod(ctx, http.MethodPost,
requestData{
relPath: adminAPIPrefix + fmt.Sprintf("/inventory/%s/%s/%s", bucket, inventoryID, action),
},
)
if err != nil {
return nil, err
}
defer closeResponse(resp)
if resp.StatusCode != http.StatusOK {
return nil, httpRespToErrorResponse(resp)
}
// Decode the response
var result InventoryJobControlResponse
dec := json.NewDecoder(resp.Body)
if err = dec.Decode(&result); err != nil {
return nil, err
}
return &result, nil
}