mirror of
https://github.com/minio/minio.git
synced 2025-11-09 13:39:46 -05:00
fix: change policies API to return and take struct (#9181)
This allows for order guarantees in returned values can be consumed safely by the caller to avoid any additional parsing and validation. Fixes #9171
This commit is contained in:
@@ -71,7 +71,7 @@ __Parameters__
|
||||
## 2. Service operations
|
||||
|
||||
<a name="ServiceStatus"></a>
|
||||
### ServiceStatus() (ServiceStatusMetadata, error)
|
||||
### ServiceStatus(ctx context.Context) (ServiceStatusMetadata, error)
|
||||
Fetch service status, replies disk space used, backend type and total disks offline/online (applicable in distributed mode).
|
||||
|
||||
| Param | Type | Description |
|
||||
@@ -89,7 +89,7 @@ Fetch service status, replies disk space used, backend type and total disks offl
|
||||
|
||||
```go
|
||||
|
||||
st, err := madmClnt.ServiceStatus()
|
||||
st, err := madmClnt.ServiceStatus(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -98,14 +98,14 @@ Fetch service status, replies disk space used, backend type and total disks offl
|
||||
```
|
||||
|
||||
<a name="ServiceRestart"></a>
|
||||
### ServiceRestart() error
|
||||
### ServiceRestart(ctx context.Context) error
|
||||
Sends a service action restart command to MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
```go
|
||||
// To restart the service, restarts all servers in the cluster.
|
||||
err := madmClnt.ServiceRestart()
|
||||
err := madmClnt.ServiceRestart(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -113,14 +113,14 @@ Sends a service action restart command to MinIO server.
|
||||
```
|
||||
|
||||
<a name="ServiceStop"></a>
|
||||
### ServiceStop() error
|
||||
### ServiceStop(ctx context.Context) error
|
||||
Sends a service action stop command to MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
```go
|
||||
// To stop the service, stops all servers in the cluster.
|
||||
err := madmClnt.ServiceStop()
|
||||
err := madmClnt.ServiceStop(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -128,7 +128,7 @@ Sends a service action stop command to MinIO server.
|
||||
```
|
||||
|
||||
<a name="ServiceTrace"></a>
|
||||
### ServiceTrace(allTrace bool, doneCh <-chan struct{}) <-chan TraceInfo
|
||||
### ServiceTrace(ctx context.Context, allTrace bool, doneCh <-chan struct{}) <-chan TraceInfo
|
||||
Enable HTTP request tracing on all nodes in a MinIO cluster
|
||||
|
||||
__Example__
|
||||
@@ -139,7 +139,7 @@ __Example__
|
||||
// listen to all trace including internal API calls
|
||||
allTrace := true
|
||||
// Start listening on all trace activity.
|
||||
traceCh := madmClnt.ServiceTrace(allTrace, doneCh)
|
||||
traceCh := madmClnt.ServiceTrace(context.Background(), allTrace, doneCh)
|
||||
for traceInfo := range traceCh {
|
||||
fmt.Println(traceInfo.String())
|
||||
}
|
||||
@@ -148,7 +148,7 @@ __Example__
|
||||
## 3. Info operations
|
||||
|
||||
<a name="ServerInfo"></a>
|
||||
### ServerInfo() ([]ServerInfo, error)
|
||||
### ServerInfo(ctx context.Context) ([]ServerInfo, error)
|
||||
Fetches information for all cluster nodes, such as server properties, storage information, network statistics, etc.
|
||||
|
||||
| Param | Type | Description |
|
||||
@@ -199,7 +199,7 @@ Fetches information for all cluster nodes, such as server properties, storage in
|
||||
|
||||
```go
|
||||
|
||||
serversInfo, err := madmClnt.ServerInfo()
|
||||
serversInfo, err := madmClnt.ServerInfo(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -211,7 +211,7 @@ Fetches information for all cluster nodes, such as server properties, storage in
|
||||
```
|
||||
|
||||
<a name="ServerDrivesPerfInfo"></a>
|
||||
### ServerDrivesPerfInfo() ([]ServerDrivesPerfInfo, error)
|
||||
### ServerDrivesPerfInfo(ctx context.Context) ([]ServerDrivesPerfInfo, error)
|
||||
|
||||
Fetches drive performance information for all cluster nodes.
|
||||
|
||||
@@ -229,7 +229,7 @@ Fetches drive performance information for all cluster nodes.
|
||||
| `disk.Performance.ReadSpeed` | _float64_ | Read speed on above path in Bytes/s. |
|
||||
|
||||
<a name="ServerCPULoadInfo"></a>
|
||||
### ServerCPULoadInfo() ([]ServerCPULoadInfo, error)
|
||||
### ServerCPULoadInfo(ctx context.Context) ([]ServerCPULoadInfo, error)
|
||||
|
||||
Fetches CPU utilization for all cluster nodes.
|
||||
|
||||
@@ -247,7 +247,7 @@ Fetches CPU utilization for all cluster nodes.
|
||||
| `cpu.Load.Error` | _string_ | Error (if any) encountered while accessing the CPU info |
|
||||
|
||||
<a name="ServerMemUsageInfo"></a>
|
||||
### ServerMemUsageInfo() ([]ServerMemUsageInfo, error)
|
||||
### ServerMemUsageInfo(ctx context.Context) ([]ServerMemUsageInfo, error)
|
||||
|
||||
Fetches Mem utilization for all cluster nodes.
|
||||
|
||||
@@ -263,7 +263,7 @@ Fetches Mem utilization for all cluster nodes.
|
||||
| `mem.Usage.Error` | _string_ | Error (if any) encountered while accessing the CPU info |
|
||||
|
||||
<a name="NetPerfInfo"></a>
|
||||
### NetPerfInfo(int size) (map[string][]NetPerfInfo, error)
|
||||
### NetPerfInfo(ctx context.Context, int size) (map[string][]NetPerfInfo, error)
|
||||
|
||||
Fetches network performance of all cluster nodes using given sized payload. Returned value is a map containing each node indexed list of performance of other nodes.
|
||||
|
||||
@@ -275,7 +275,7 @@ Fetches network performance of all cluster nodes using given sized payload. Retu
|
||||
|
||||
|
||||
<a name="ServerCPUHardwareInfo"></a>
|
||||
### ServerCPUHardwareInfo() ([]ServerCPUHardwareInfo, error)
|
||||
### ServerCPUHardwareInfo(ctx context.Context) ([]ServerCPUHardwareInfo, error)
|
||||
|
||||
Fetches hardware information of CPU.
|
||||
|
||||
@@ -302,7 +302,7 @@ Fetches hardware information of CPU.
|
||||
| `CPUInfo.Microcode` | _string_ | Micro codes |
|
||||
|
||||
<a name="ServerNetworkHardwareInfo"></a>
|
||||
### ServerNetworkHardwareInfo() ([]ServerNetworkHardwareInfo, error)
|
||||
### ServerNetworkHardwareInfo(ctx context.Context) ([]ServerNetworkHardwareInfo, error)
|
||||
|
||||
Fetches hardware information of CPU.
|
||||
|
||||
@@ -321,7 +321,7 @@ Fetches hardware information of CPU.
|
||||
| `NetworkInfo.Flags` | _uint32_ | e.g., FlagUp, FlagLoopback, FlagMulticast |
|
||||
|
||||
<a name="StorageInfo"></a>
|
||||
### StorageInfo() (StorageInfo, error)
|
||||
### StorageInfo(ctx context.Context) (StorageInfo, error)
|
||||
|
||||
Fetches Storage information for all cluster nodes.
|
||||
|
||||
@@ -347,7 +347,7 @@ __Example__
|
||||
|
||||
```go
|
||||
|
||||
storageInfo, err := madmClnt.StorageInfo()
|
||||
storageInfo, err := madmClnt.StorageInfo(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -359,7 +359,7 @@ __Example__
|
||||
## 5. Heal operations
|
||||
|
||||
<a name="Heal"></a>
|
||||
### Heal(bucket, prefix string, healOpts HealOpts, clientToken string, forceStart bool, forceStop bool) (start HealStartSuccess, status HealTaskStatus, err error)
|
||||
### Heal(ctx context.Context, bucket, prefix string, healOpts HealOpts, clientToken string, forceStart bool, forceStop bool) (start HealStartSuccess, status HealTaskStatus, err error)
|
||||
|
||||
Start a heal sequence that scans data under given (possible empty)
|
||||
`bucket` and `prefix`. The `recursive` bool turns on recursive
|
||||
@@ -384,7 +384,7 @@ __Example__
|
||||
}
|
||||
forceStart := false
|
||||
forceStop := false
|
||||
healPath, err := madmClnt.Heal("", "", opts, "", forceStart, forceStop)
|
||||
healPath, err := madmClnt.Heal(context.Background(), "", "", opts, "", forceStart, forceStop)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -424,13 +424,13 @@ __Example__
|
||||
## 6. Config operations
|
||||
|
||||
<a name="GetConfig"></a>
|
||||
### GetConfig() ([]byte, error)
|
||||
### GetConfig(ctx context.Context) ([]byte, error)
|
||||
Get current `config.json` of a MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
configBytes, err := madmClnt.GetConfig()
|
||||
configBytes, err := madmClnt.GetConfig(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalf("failed due to: %v", err)
|
||||
}
|
||||
@@ -447,14 +447,14 @@ __Example__
|
||||
|
||||
|
||||
<a name="SetConfig"></a>
|
||||
### SetConfig(config io.Reader) error
|
||||
### SetConfig(ctx context.Context, config io.Reader) error
|
||||
Set a new `config.json` for a MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
config := bytes.NewReader([]byte(`config.json contents go here`))
|
||||
if err := madmClnt.SetConfig(config); err != nil {
|
||||
if err := madmClnt.SetConfig(context.Background(), config); err != nil {
|
||||
log.Fatalf("failed due to: %v", err)
|
||||
}
|
||||
log.Println("SetConfig was successful")
|
||||
@@ -463,13 +463,13 @@ __Example__
|
||||
## 7. Top operations
|
||||
|
||||
<a name="TopLocks"></a>
|
||||
### TopLocks() (LockEntries, error)
|
||||
### TopLocks(ctx context.Context) (LockEntries, error)
|
||||
Get the oldest locks from MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
locks, err := madmClnt.TopLocks()
|
||||
locks, err := madmClnt.TopLocks(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalf("failed due to: %v", err)
|
||||
}
|
||||
@@ -485,51 +485,54 @@ __Example__
|
||||
## 8. IAM operations
|
||||
|
||||
<a name="AddCannedPolicy"></a>
|
||||
### AddCannedPolicy(policyName string, policy string) error
|
||||
### AddCannedPolicy(ctx context.Context, policyName string, policy *iampolicy.Policy) error
|
||||
Create a new canned policy on MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
```
|
||||
policy := `{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Resource": ["arn:aws:s3:::my-bucketname/*"],"Sid": ""}]}`
|
||||
policy, err := iampolicy.ParseConfig(strings.NewReader(`{"Version": "2012-10-17","Statement": [{"Action": ["s3:GetObject"],"Effect": "Allow","Resource": ["arn:aws:s3:::my-bucketname/*"],"Sid": ""}]}`))
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
if err = madmClnt.AddCannedPolicy("get-only", policy); err != nil {
|
||||
if err = madmClnt.AddCannedPolicy(context.Background(), "get-only", policy); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
```
|
||||
|
||||
<a name="AddUser"></a>
|
||||
### AddUser(user string, secret string) error
|
||||
### AddUser(ctx context.Context, user string, secret string) error
|
||||
Add a new user on a MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
if err = madmClnt.AddUser("newuser", "newstrongpassword"); err != nil {
|
||||
if err = madmClnt.AddUser(context.Background(), "newuser", "newstrongpassword"); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
```
|
||||
|
||||
<a name="SetUserPolicy"></a>
|
||||
### SetUserPolicy(user string, policyName string) error
|
||||
### SetUserPolicy(ctx context.Context, user string, policyName string) error
|
||||
Enable a canned policy `get-only` for a given user on MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
if err = madmClnt.SetUserPolicy("newuser", "get-only"); err != nil {
|
||||
if err = madmClnt.SetUserPolicy(context.Background(), "newuser", "get-only"); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
```
|
||||
|
||||
<a name="ListUsers"></a>
|
||||
### ListUsers() (map[string]UserInfo, error)
|
||||
### ListUsers(ctx context.Context) (map[string]UserInfo, error)
|
||||
Lists all users on MinIO server.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
users, err := madmClnt.ListUsers();
|
||||
users, err := madmClnt.ListUsers(context.Background());
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -541,7 +544,7 @@ __Example__
|
||||
## 9. Misc operations
|
||||
|
||||
<a name="ServerUpdate"></a>
|
||||
### ServerUpdate(updateURL string) (ServerUpdateStatus, error)
|
||||
### ServerUpdate(ctx context.Context, updateURL string) (ServerUpdateStatus, error)
|
||||
Sends a update command to MinIO server, to update MinIO server to latest release. In distributed setup it updates all servers atomically.
|
||||
|
||||
__Example__
|
||||
@@ -549,7 +552,7 @@ Sends a update command to MinIO server, to update MinIO server to latest release
|
||||
```go
|
||||
// Updates all servers and restarts all the servers in the cluster.
|
||||
// optionally takes an updateURL, which is used to update the binary.
|
||||
us, err := madmClnt.ServerUpdate(updateURL)
|
||||
us, err := madmClnt.ServerUpdate(context.Background(), updateURL)
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -559,13 +562,13 @@ Sends a update command to MinIO server, to update MinIO server to latest release
|
||||
```
|
||||
|
||||
<a name="StartProfiling"></a>
|
||||
### StartProfiling(profiler string) error
|
||||
### StartProfiling(ctx context.Context, profiler string) error
|
||||
Ask all nodes to start profiling using the specified profiler mode
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
startProfilingResults, err = madmClnt.StartProfiling("cpu")
|
||||
startProfilingResults, err = madmClnt.StartProfiling(context.Background(), "cpu")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -580,13 +583,13 @@ __Example__
|
||||
```
|
||||
|
||||
<a name="DownloadProfilingData"></a>
|
||||
### DownloadProfilingData() ([]byte, error)
|
||||
### DownloadProfilingData(ctx context.Context) ([]byte, error)
|
||||
Download profiling data of all nodes in a zip format.
|
||||
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
profilingData, err := madmClnt.DownloadProfilingData()
|
||||
profilingData, err := madmClnt.DownloadProfilingData(context.Background())
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
@@ -614,7 +617,7 @@ __Example__
|
||||
## 11. KMS
|
||||
|
||||
<a name="GetKeyStatus"></a>
|
||||
### GetKeyStatus(keyID string) (*KMSKeyStatus, error)
|
||||
### GetKeyStatus(ctx context.Context, keyID string) (*KMSKeyStatus, error)
|
||||
Requests status information about one particular KMS master key
|
||||
from a MinIO server. The keyID is optional and the server will
|
||||
use the default master key (configured via `MINIO_KMS_VAULT_KEY_NAME`
|
||||
@@ -623,7 +626,7 @@ or `MINIO_KMS_MASTER_KEY`) if the keyID is empty.
|
||||
__Example__
|
||||
|
||||
``` go
|
||||
keyInfo, err := madmClnt.GetKeyStatus("my-minio-key")
|
||||
keyInfo, err := madmClnt.GetKeyStatus(context.Background(), "my-minio-key")
|
||||
if err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
|
||||
// GetConfig - returns the config.json of a minio setup, incoming data is encrypted.
|
||||
func (adm *AdminClient) GetConfig(ctx context.Context) ([]byte, error) {
|
||||
// Execute GET on /minio/admin/v2/config to get config of a setup.
|
||||
// Execute GET on /minio/admin/v3/config to get config of a setup.
|
||||
resp, err := adm.executeMethod(ctx,
|
||||
http.MethodGet,
|
||||
requestData{relPath: adminAPIPrefix + "/config"})
|
||||
@@ -66,7 +66,7 @@ func (adm *AdminClient) SetConfig(ctx context.Context, config io.Reader) (err er
|
||||
content: econfigBytes,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/config to set config.
|
||||
// Execute PUT on /minio/admin/v3/config to set config.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
|
||||
@@ -59,7 +59,7 @@ func (adm *AdminClient) HelpConfigKV(ctx context.Context, subSys, key string, en
|
||||
queryValues: v,
|
||||
}
|
||||
|
||||
// Execute GET on /minio/admin/v2/help-config-kv
|
||||
// Execute GET on /minio/admin/v3/help-config-kv
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||
if err != nil {
|
||||
return Help{}, err
|
||||
|
||||
@@ -37,7 +37,7 @@ func (adm *AdminClient) ClearConfigHistoryKV(ctx context.Context, restoreID stri
|
||||
queryValues: v,
|
||||
}
|
||||
|
||||
// Execute DELETE on /minio/admin/v2/clear-config-history-kv
|
||||
// Execute DELETE on /minio/admin/v3/clear-config-history-kv
|
||||
resp, err := adm.executeMethod(ctx, http.MethodDelete, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -62,7 +62,7 @@ func (adm *AdminClient) RestoreConfigHistoryKV(ctx context.Context, restoreID st
|
||||
queryValues: v,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/set-config-kv to set config key/value.
|
||||
// Execute PUT on /minio/admin/v3/set-config-kv to set config key/value.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -98,7 +98,7 @@ func (adm *AdminClient) ListConfigHistoryKV(ctx context.Context, count int) ([]C
|
||||
v := url.Values{}
|
||||
v.Set("count", strconv.Itoa(count))
|
||||
|
||||
// Execute GET on /minio/admin/v2/list-config-history-kv
|
||||
// Execute GET on /minio/admin/v3/list-config-history-kv
|
||||
resp, err := adm.executeMethod(ctx,
|
||||
http.MethodGet,
|
||||
requestData{
|
||||
|
||||
@@ -35,7 +35,7 @@ func (adm *AdminClient) DelConfigKV(ctx context.Context, k string) (err error) {
|
||||
content: econfigBytes,
|
||||
}
|
||||
|
||||
// Execute DELETE on /minio/admin/v2/del-config-kv to delete config key.
|
||||
// Execute DELETE on /minio/admin/v3/del-config-kv to delete config key.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodDelete, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -62,7 +62,7 @@ func (adm *AdminClient) SetConfigKV(ctx context.Context, kv string) (err error)
|
||||
content: econfigBytes,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/set-config-kv to set config key/value.
|
||||
// Execute PUT on /minio/admin/v3/set-config-kv to set config key/value.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -82,7 +82,7 @@ func (adm *AdminClient) GetConfigKV(ctx context.Context, key string) (Targets, e
|
||||
v := url.Values{}
|
||||
v.Set("key", key)
|
||||
|
||||
// Execute GET on /minio/admin/v2/get-config-kv?key={key} to get value of key.
|
||||
// Execute GET on /minio/admin/v3/get-config-kv?key={key} to get value of key.
|
||||
resp, err := adm.executeMethod(ctx,
|
||||
http.MethodGet,
|
||||
requestData{
|
||||
|
||||
@@ -46,7 +46,7 @@ func (adm *AdminClient) UpdateGroupMembers(ctx context.Context, g GroupAddRemove
|
||||
content: data,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/update-group-members
|
||||
// Execute PUT on /minio/admin/v3/update-group-members
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
|
||||
@@ -25,9 +25,9 @@ import (
|
||||
|
||||
// GetKeyStatus requests status information about the key referenced by keyID
|
||||
// from the KMS connected to a MinIO by performing a Admin-API request.
|
||||
// It basically hits the `/minio/admin/v2/kms/key/status` API endpoint.
|
||||
// It basically hits the `/minio/admin/v3/kms/key/status` API endpoint.
|
||||
func (adm *AdminClient) GetKeyStatus(ctx context.Context, keyID string) (*KMSKeyStatus, error) {
|
||||
// GET /minio/admin/v2/kms/key/status?key-id=<keyID>
|
||||
// GET /minio/admin/v3/kms/key/status?key-id=<keyID>
|
||||
qv := url.Values{}
|
||||
qv.Set("key-id", keyID)
|
||||
reqData := requestData{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* MinIO Cloud Storage, (C) 2018 MinIO, Inc.
|
||||
* MinIO Cloud Storage, (C) 2018-2020 MinIO, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,10 +23,12 @@ import (
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
)
|
||||
|
||||
// InfoCannedPolicy - expand canned policy into JSON structure.
|
||||
func (adm *AdminClient) InfoCannedPolicy(ctx context.Context, policyName string) ([]byte, error) {
|
||||
func (adm *AdminClient) InfoCannedPolicy(ctx context.Context, policyName string) (*iampolicy.Policy, error) {
|
||||
queryValues := url.Values{}
|
||||
queryValues.Set("name", policyName)
|
||||
|
||||
@@ -35,7 +37,7 @@ func (adm *AdminClient) InfoCannedPolicy(ctx context.Context, policyName string)
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute GET on /minio/admin/v2/info-canned-policy
|
||||
// Execute GET on /minio/admin/v3/info-canned-policy
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -47,16 +49,16 @@ func (adm *AdminClient) InfoCannedPolicy(ctx context.Context, policyName string)
|
||||
return nil, httpRespToErrorResponse(resp)
|
||||
}
|
||||
|
||||
return ioutil.ReadAll(resp.Body)
|
||||
return iampolicy.ParseConfig(resp.Body)
|
||||
}
|
||||
|
||||
// ListCannedPolicies - list all configured canned policies.
|
||||
func (adm *AdminClient) ListCannedPolicies(ctx context.Context) (map[string][]byte, error) {
|
||||
func (adm *AdminClient) ListCannedPolicies(ctx context.Context) (map[string]*iampolicy.Policy, error) {
|
||||
reqData := requestData{
|
||||
relPath: adminAPIPrefix + "/list-canned-policies",
|
||||
}
|
||||
|
||||
// Execute GET on /minio/admin/v2/list-canned-policies
|
||||
// Execute GET on /minio/admin/v3/list-canned-policies
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -73,7 +75,7 @@ func (adm *AdminClient) ListCannedPolicies(ctx context.Context) (map[string][]by
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var policies = make(map[string][]byte)
|
||||
var policies = make(map[string]*iampolicy.Policy)
|
||||
if err = json.Unmarshal(respBytes, &policies); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -91,7 +93,7 @@ func (adm *AdminClient) RemoveCannedPolicy(ctx context.Context, policyName strin
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute DELETE on /minio/admin/v2/remove-canned-policy to remove policy.
|
||||
// Execute DELETE on /minio/admin/v3/remove-canned-policy to remove policy.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodDelete, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -107,17 +109,26 @@ func (adm *AdminClient) RemoveCannedPolicy(ctx context.Context, policyName strin
|
||||
}
|
||||
|
||||
// AddCannedPolicy - adds a policy for a canned.
|
||||
func (adm *AdminClient) AddCannedPolicy(ctx context.Context, policyName, policy string) error {
|
||||
func (adm *AdminClient) AddCannedPolicy(ctx context.Context, policyName string, policy *iampolicy.Policy) error {
|
||||
if policy == nil {
|
||||
return ErrInvalidArgument("policy input cannot be empty")
|
||||
}
|
||||
|
||||
buf, err := json.Marshal(policy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
queryValues := url.Values{}
|
||||
queryValues.Set("name", policyName)
|
||||
|
||||
reqData := requestData{
|
||||
relPath: adminAPIPrefix + "/add-canned-policy",
|
||||
queryValues: queryValues,
|
||||
content: []byte(policy),
|
||||
content: buf,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/add-canned-policy to set policy.
|
||||
// Execute PUT on /minio/admin/v3/add-canned-policy to set policy.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -148,7 +159,7 @@ func (adm *AdminClient) SetPolicy(ctx context.Context, policyName, entityName st
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/set-user-or-group-policy to set policy.
|
||||
// Execute PUT on /minio/admin/v3/set-user-or-group-policy to set policy.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
|
||||
@@ -55,7 +55,7 @@ func (l LockEntries) Swap(i, j int) {
|
||||
|
||||
// TopLocks - returns the oldest locks in a minio setup.
|
||||
func (adm *AdminClient) TopLocks(ctx context.Context) (LockEntries, error) {
|
||||
// Execute GET on /minio/admin/v2/top/locks
|
||||
// Execute GET on /minio/admin/v3/top/locks
|
||||
// to get the oldest locks in a minio setup.
|
||||
resp, err := adm.executeMethod(ctx,
|
||||
http.MethodGet,
|
||||
|
||||
@@ -54,7 +54,7 @@ func (adm *AdminClient) RemoveUser(ctx context.Context, accessKey string) error
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute DELETE on /minio/admin/v2/remove-user to remove a user.
|
||||
// Execute DELETE on /minio/admin/v3/remove-user to remove a user.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodDelete, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -75,7 +75,7 @@ func (adm *AdminClient) ListUsers(ctx context.Context) (map[string]UserInfo, err
|
||||
relPath: adminAPIPrefix + "/list-users",
|
||||
}
|
||||
|
||||
// Execute GET on /minio/admin/v2/list-users
|
||||
// Execute GET on /minio/admin/v3/list-users
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -110,7 +110,7 @@ func (adm *AdminClient) GetUserInfo(ctx context.Context, name string) (u UserInf
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute GET on /minio/admin/v2/user-info
|
||||
// Execute GET on /minio/admin/v3/user-info
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -166,7 +166,7 @@ func (adm *AdminClient) SetUser(ctx context.Context, accessKey, secretKey string
|
||||
content: econfigBytes,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/add-user to set a user.
|
||||
// Execute PUT on /minio/admin/v3/add-user to set a user.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -197,7 +197,7 @@ func (adm *AdminClient) SetUserStatus(ctx context.Context, accessKey string, sta
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/set-user-status to set status.
|
||||
// Execute PUT on /minio/admin/v3/set-user-status to set status.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
|
||||
defer closeResponse(resp)
|
||||
@@ -249,7 +249,7 @@ func (adm *AdminClient) AddServiceAccount(ctx context.Context, parentUser string
|
||||
content: econfigBytes,
|
||||
}
|
||||
|
||||
// Execute PUT on /minio/admin/v2/add-service-account to set a user.
|
||||
// Execute PUT on /minio/admin/v3/add-service-account to set a user.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodPut, reqData)
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
@@ -287,7 +287,7 @@ func (adm *AdminClient) GetServiceAccount(ctx context.Context, serviceAccountAcc
|
||||
queryValues: queryValues,
|
||||
}
|
||||
|
||||
// Execute GET on /minio/admin/v2/get-service-account to set a user.
|
||||
// Execute GET on /minio/admin/v3/get-service-account to set a user.
|
||||
resp, err := adm.executeMethod(ctx, http.MethodGet, reqData)
|
||||
defer closeResponse(resp)
|
||||
if err != nil {
|
||||
|
||||
@@ -30,10 +30,11 @@ import (
|
||||
"github.com/minio/minio-go/v6/pkg/s3utils"
|
||||
)
|
||||
|
||||
// AdminAPIVersion - admin api version used in the request.
|
||||
const (
|
||||
// AdminAPIVersion - admin api version used in the request.
|
||||
AdminAPIVersion = "v2"
|
||||
adminAPIPrefix = "/" + AdminAPIVersion
|
||||
AdminAPIVersion = "v3"
|
||||
AdminAPIVersionV2 = "v2"
|
||||
adminAPIPrefix = "/" + AdminAPIVersion
|
||||
)
|
||||
|
||||
// sum256 calculate sha256 sum for an input byte array.
|
||||
|
||||
Reference in New Issue
Block a user