move to madmin-go/, pkg/ packages (#765)
This commit is contained in:
@@ -21,7 +21,7 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
asrt "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/console/restapi/operations"
|
||||
madmin "github.com/minio/minio/pkg/madmin"
|
||||
madmin "github.com/minio/madmin-go"
|
||||
|
||||
"github.com/minio/console/restapi/operations/admin_api"
|
||||
)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
@@ -29,9 +28,22 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/minio/cmd/config"
|
||||
"github.com/minio/minio/pkg/event/target"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
)
|
||||
|
||||
const (
|
||||
NotifyPostgresSubSys = "notify_postgres"
|
||||
PostgresFormat = "format"
|
||||
PostgresConnectionString = "connection_string"
|
||||
PostgresTable = "table"
|
||||
PostgresHost = "host"
|
||||
PostgresPort = "port"
|
||||
PostgresUsername = "username"
|
||||
PostgresPassword = "password"
|
||||
PostgresDatabase = "database"
|
||||
PostgresQueueDir = "queue_dir"
|
||||
PostgresQueueLimit = "queue_limit"
|
||||
PostgresMaxOpenConnections = "max_open_connections"
|
||||
)
|
||||
|
||||
// assigning mock at runtime instead of compile time
|
||||
@@ -345,65 +357,48 @@ func Test_getConfig(t *testing.T) {
|
||||
name: "notify_postgres",
|
||||
},
|
||||
mock: func() {
|
||||
cfg := config.Config{}
|
||||
cfg["notify_postgres"] = make(map[string]config.KVS)
|
||||
cfg["notify_postgres"]["_"] = config.KVS{
|
||||
{
|
||||
Key: target.PostgresConnectionString,
|
||||
Value: "host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresTable,
|
||||
Value: "bucketevents",
|
||||
},
|
||||
}
|
||||
|
||||
var buf = &bytes.Buffer{}
|
||||
cw := config.NewConfigWriteTo(cfg, "notify_postgres:_")
|
||||
cw.WriteTo(buf)
|
||||
|
||||
// mock function response from getConfig()
|
||||
minioGetConfigKVMock = func(key string) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
return []byte(`notify_postgres:_ connection_string="host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable" table=bucketevents`), nil
|
||||
}
|
||||
|
||||
configListMock := []madmin.HelpKV{
|
||||
{
|
||||
Key: target.PostgresConnectionString,
|
||||
Key: PostgresConnectionString,
|
||||
Description: `Postgres server connection-string e.g. "host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable"`,
|
||||
Type: "string",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresTable,
|
||||
Key: PostgresTable,
|
||||
Description: "DB table name to store/update events, table is auto-created",
|
||||
Type: "string",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresFormat,
|
||||
Key: PostgresFormat,
|
||||
Description: "desc",
|
||||
Type: "namespace*|access",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresQueueDir,
|
||||
Key: PostgresQueueDir,
|
||||
Description: "des",
|
||||
Optional: true,
|
||||
Type: "path",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresQueueLimit,
|
||||
Key: PostgresQueueLimit,
|
||||
Description: "desc",
|
||||
Optional: true,
|
||||
Type: "number",
|
||||
},
|
||||
{
|
||||
Key: config.Comment,
|
||||
Description: config.DefaultComment,
|
||||
Key: madmin.CommentKey,
|
||||
Description: "",
|
||||
Optional: true,
|
||||
Type: "sentence",
|
||||
},
|
||||
}
|
||||
mockConfigList := madmin.Help{
|
||||
SubSys: config.NotifyPostgresSubSys,
|
||||
SubSys: NotifyPostgresSubSys,
|
||||
Description: "publish bucket notifications to Postgres databases",
|
||||
MultipleTargets: true,
|
||||
KeysHelp: configListMock,
|
||||
@@ -415,11 +410,11 @@ func Test_getConfig(t *testing.T) {
|
||||
},
|
||||
want: []*models.ConfigurationKV{
|
||||
{
|
||||
Key: target.PostgresConnectionString,
|
||||
Key: PostgresConnectionString,
|
||||
Value: "host=localhost dbname=minio_events user=postgres password=password port=5432 sslmode=disable",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresTable,
|
||||
Key: PostgresTable,
|
||||
Value: "bucketevents",
|
||||
},
|
||||
},
|
||||
@@ -429,59 +424,51 @@ func Test_getConfig(t *testing.T) {
|
||||
name: "valid config, but server returned empty",
|
||||
args: args{
|
||||
client: client,
|
||||
name: "notify_postgres",
|
||||
name: NotifyPostgresSubSys,
|
||||
},
|
||||
mock: func() {
|
||||
cfg := config.Config{}
|
||||
cfg["notify_postgres"] = make(map[string]config.KVS)
|
||||
cfg["notify_postgres"]["_"] = config.KVS{}
|
||||
|
||||
var buf = &bytes.Buffer{}
|
||||
cw := config.NewConfigWriteTo(cfg, "notify_postgres:_")
|
||||
cw.WriteTo(buf)
|
||||
|
||||
// mock function response from getConfig()
|
||||
minioGetConfigKVMock = func(key string) ([]byte, error) {
|
||||
return buf.Bytes(), nil
|
||||
return []byte(`notify_postgres:_`), nil
|
||||
}
|
||||
|
||||
configListMock := []madmin.HelpKV{
|
||||
{
|
||||
Key: target.PostgresConnectionString,
|
||||
Key: PostgresConnectionString,
|
||||
Description: `Postgres server connection-string e.g. "host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable"`,
|
||||
Type: "string",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresTable,
|
||||
Key: PostgresTable,
|
||||
Description: "DB table name to store/update events, table is auto-created",
|
||||
Type: "string",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresFormat,
|
||||
Key: PostgresFormat,
|
||||
Description: "desc",
|
||||
Type: "namespace*|access",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresQueueDir,
|
||||
Key: PostgresQueueDir,
|
||||
Description: "des",
|
||||
Optional: true,
|
||||
Type: "path",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresQueueLimit,
|
||||
Key: PostgresQueueLimit,
|
||||
Description: "desc",
|
||||
Optional: true,
|
||||
Type: "number",
|
||||
},
|
||||
{
|
||||
Key: config.Comment,
|
||||
Description: config.DefaultComment,
|
||||
Key: madmin.CommentKey,
|
||||
Description: "optionally add a comment to this setting",
|
||||
Optional: true,
|
||||
Type: "sentence",
|
||||
},
|
||||
}
|
||||
mockConfigList := madmin.Help{
|
||||
SubSys: config.NotifyPostgresSubSys,
|
||||
SubSys: NotifyPostgresSubSys,
|
||||
Description: "publish bucket notifications to Postgres databases",
|
||||
MultipleTargets: true,
|
||||
KeysHelp: configListMock,
|
||||
@@ -512,41 +499,41 @@ func Test_getConfig(t *testing.T) {
|
||||
|
||||
configListMock := []madmin.HelpKV{
|
||||
{
|
||||
Key: target.PostgresConnectionString,
|
||||
Key: PostgresConnectionString,
|
||||
Description: `Postgres server connection-string e.g. "host=localhost port=5432 dbname=minio_events user=postgres password=password sslmode=disable"`,
|
||||
Type: "string",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresTable,
|
||||
Key: PostgresTable,
|
||||
Description: "DB table name to store/update events, table is auto-created",
|
||||
Type: "string",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresFormat,
|
||||
Key: PostgresFormat,
|
||||
Description: "desc",
|
||||
Type: "namespace*|access",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresQueueDir,
|
||||
Key: PostgresQueueDir,
|
||||
Description: "des",
|
||||
Optional: true,
|
||||
Type: "path",
|
||||
},
|
||||
{
|
||||
Key: target.PostgresQueueLimit,
|
||||
Key: PostgresQueueLimit,
|
||||
Description: "desc",
|
||||
Optional: true,
|
||||
Type: "number",
|
||||
},
|
||||
{
|
||||
Key: config.Comment,
|
||||
Description: config.DefaultComment,
|
||||
Key: madmin.CommentKey,
|
||||
Description: "optionally add a comment to this setting",
|
||||
Optional: true,
|
||||
Type: "sentence",
|
||||
},
|
||||
}
|
||||
mockConfigList := madmin.Help{
|
||||
SubSys: config.NotifyPostgresSubSys,
|
||||
SubSys: NotifyPostgresSubSys,
|
||||
Description: "publish bucket notifications to Postgres databases",
|
||||
MultipleTargets: true,
|
||||
KeysHelp: configListMock,
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
)
|
||||
|
||||
const logTimeFormat string = "15:04:05 MST 01/02/2006"
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/minio/console/restapi/operations"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
|
||||
"github.com/minio/console/restapi/operations/admin_api"
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"errors"
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
)
|
||||
|
||||
// An alias of string to represent the health color code of an object
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
madmin "github.com/minio/minio/pkg/madmin"
|
||||
madmin "github.com/minio/madmin-go"
|
||||
)
|
||||
|
||||
// startHealthInfo starts fetching mc.ServerHealthInfo and
|
||||
@@ -43,7 +43,7 @@ func startHealthInfo(ctx context.Context, conn WSConn, client MinioAdmin, deadli
|
||||
madmin.HealthDataTypeMinioInfo,
|
||||
madmin.HealthDataTypeMinioConfig,
|
||||
madmin.HealthDataTypeSysCPU,
|
||||
madmin.HealthDataTypeSysDiskHw,
|
||||
madmin.HealthDataTypeSysDriveHw,
|
||||
madmin.HealthDataTypeSysDocker,
|
||||
madmin.HealthDataTypeSysOsInfo,
|
||||
madmin.HealthDataTypeSysLoad,
|
||||
@@ -52,35 +52,20 @@ func startHealthInfo(ctx context.Context, conn WSConn, client MinioAdmin, deadli
|
||||
madmin.HealthDataTypeSysProcess,
|
||||
}
|
||||
|
||||
healthChan := client.serverHealthInfo(ctx, healthDataTypes, *deadline)
|
||||
// wait for events to occur
|
||||
for {
|
||||
select {
|
||||
// return if context ends
|
||||
case <-ctx.Done():
|
||||
return nil
|
||||
case adminHealthInfo, ok := <-healthChan:
|
||||
// zero value returned because the channel is closed and empty
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if adminHealthInfo.Error != "" {
|
||||
return errors.New(adminHealthInfo.Error)
|
||||
}
|
||||
// Serialize message to be sent
|
||||
bytes, err := json.Marshal(adminHealthInfo)
|
||||
if err != nil {
|
||||
log.Println("error on json.Marshal:", err)
|
||||
return err
|
||||
}
|
||||
// Send Message through websocket connection
|
||||
err = conn.writeMessage(websocket.TextMessage, bytes)
|
||||
if err != nil {
|
||||
log.Println("error writeMessage:", err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
healthInfo, _, err := client.serverHealthInfo(ctx, healthDataTypes, *deadline)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Serialize message to be sent
|
||||
bytes, err := json.Marshal(healthInfo)
|
||||
if err != nil {
|
||||
log.Println("error on json.Marshal:", err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Send Message through websocket connection
|
||||
return conn.writeMessage(websocket.TextMessage, bytes)
|
||||
}
|
||||
|
||||
// getHealthInfoOptionsFromReq gets duration for startHealthInfo request
|
||||
|
||||
@@ -24,14 +24,14 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
madmin "github.com/minio/minio/pkg/madmin"
|
||||
madmin "github.com/minio/madmin-go"
|
||||
)
|
||||
|
||||
// assigning mock at runtime instead of compile time
|
||||
var minioServerHealthInfoMock func(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) <-chan madmin.HealthInfo
|
||||
var minioServerHealthInfoMock func(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) (interface{}, string, error)
|
||||
|
||||
// mock function serverHealthInfo
|
||||
func (ac adminClientMock) serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) <-chan madmin.HealthInfo {
|
||||
func (ac adminClientMock) serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) (interface{}, string, error) {
|
||||
return minioServerHealthInfoMock(ctx, healthDataTypes, deadline)
|
||||
}
|
||||
|
||||
@@ -58,16 +58,16 @@ func Test_serverHealthInfo(t *testing.T) {
|
||||
args: args{
|
||||
deadline: deadlineDuration,
|
||||
mockMessages: []madmin.HealthInfo{
|
||||
madmin.HealthInfo{
|
||||
{
|
||||
Perf: madmin.PerfInfo{
|
||||
NetParallel: madmin.ServerNetHealthInfo{
|
||||
NetParallel: madmin.NetPerfInfo{
|
||||
Addr: "someaddress",
|
||||
},
|
||||
},
|
||||
},
|
||||
madmin.HealthInfo{
|
||||
{
|
||||
Perf: madmin.PerfInfo{
|
||||
NetParallel: madmin.ServerNetHealthInfo{
|
||||
NetParallel: madmin.NetPerfInfo{
|
||||
Addr: "otheraddress",
|
||||
},
|
||||
},
|
||||
@@ -90,9 +90,9 @@ func Test_serverHealthInfo(t *testing.T) {
|
||||
args: args{
|
||||
deadline: deadlineDuration,
|
||||
mockMessages: []madmin.HealthInfo{
|
||||
madmin.HealthInfo{
|
||||
{
|
||||
Perf: madmin.PerfInfo{
|
||||
NetParallel: madmin.ServerNetHealthInfo{
|
||||
NetParallel: madmin.NetPerfInfo{
|
||||
Addr: "address",
|
||||
},
|
||||
},
|
||||
@@ -115,9 +115,9 @@ func Test_serverHealthInfo(t *testing.T) {
|
||||
args: args{
|
||||
deadline: deadlineDuration,
|
||||
mockMessages: []madmin.HealthInfo{
|
||||
madmin.HealthInfo{
|
||||
{
|
||||
Perf: madmin.PerfInfo{
|
||||
NetParallel: madmin.ServerNetHealthInfo{
|
||||
NetParallel: madmin.NetPerfInfo{
|
||||
Addr: "address",
|
||||
},
|
||||
},
|
||||
@@ -139,7 +139,7 @@ func Test_serverHealthInfo(t *testing.T) {
|
||||
args: args{
|
||||
deadline: deadlineDuration,
|
||||
mockMessages: []madmin.HealthInfo{
|
||||
madmin.HealthInfo{
|
||||
{
|
||||
Error: "error on healthInfo",
|
||||
},
|
||||
},
|
||||
@@ -152,23 +152,19 @@ func Test_serverHealthInfo(t *testing.T) {
|
||||
|
||||
},
|
||||
},
|
||||
wantError: errors.New("error on healthInfo"),
|
||||
wantError: nil,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
tt := tt
|
||||
t.Run(tt.test, func(t *testing.T) {
|
||||
// make testReceiver channel
|
||||
testReceiver = make(chan madmin.HealthInfo, len(tt.args.mockMessages))
|
||||
// mock function same for all tests, changes mockMessages
|
||||
minioServerHealthInfoMock = func(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) <-chan madmin.HealthInfo {
|
||||
respChan := make(chan madmin.HealthInfo)
|
||||
go func(ch chan madmin.HealthInfo) {
|
||||
defer close(ch)
|
||||
for _, info := range tt.args.mockMessages {
|
||||
ch <- info
|
||||
}
|
||||
}(respChan)
|
||||
return respChan
|
||||
minioServerHealthInfoMock = func(ctx context.Context, healthDataTypes []madmin.HealthDataType,
|
||||
deadline time.Duration) (interface{}, string, error) {
|
||||
info := tt.args.mockMessages[0]
|
||||
return info, madmin.HealthInfoVersion, nil
|
||||
}
|
||||
connWriteMessageMock = tt.args.wsWriteMock
|
||||
err := startHealthInfo(ctx, mockWSConn, client, &deadlineDuration)
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
asrt "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ func Test_MaxAllocatableMemory(t *testing.T) {
|
||||
},
|
||||
Spec: corev1.NodeSpec{
|
||||
Taints: []corev1.Taint{
|
||||
corev1.Taint{
|
||||
{
|
||||
Key: "node.kubernetes.io/unreachable",
|
||||
Effect: corev1.TaintEffectNoSchedule,
|
||||
},
|
||||
@@ -161,7 +161,7 @@ func Test_MaxAllocatableMemory(t *testing.T) {
|
||||
},
|
||||
Spec: corev1.NodeSpec{
|
||||
Taints: []corev1.Taint{
|
||||
corev1.Taint{
|
||||
{
|
||||
Key: "node.kubernetes.io/unreachable",
|
||||
Effect: corev1.TaintEffectNoExecute,
|
||||
},
|
||||
@@ -180,7 +180,7 @@ func Test_MaxAllocatableMemory(t *testing.T) {
|
||||
},
|
||||
Spec: corev1.NodeSpec{
|
||||
Taints: []corev1.Taint{
|
||||
corev1.Taint{
|
||||
{
|
||||
Key: "node.kubernetes.io/unreachable",
|
||||
Effect: corev1.TaintEffectPreferNoSchedule,
|
||||
},
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/console/restapi/operations"
|
||||
"github.com/minio/console/restapi/operations/admin_api"
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
)
|
||||
|
||||
func registersPoliciesHandler(api *operations.ConsoleAPI) {
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import (
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/console/restapi/operations"
|
||||
"github.com/minio/console/restapi/operations/admin_api"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
)
|
||||
|
||||
func registerProfilingHandler(api *operations.ConsoleAPI) {
|
||||
|
||||
@@ -25,7 +25,7 @@ import (
|
||||
"errors"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -30,9 +30,8 @@ import (
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/console/restapi/operations"
|
||||
"github.com/minio/console/restapi/operations/user_api"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/minio-go/v7/pkg/replication"
|
||||
"github.com/minio/minio/pkg/auth"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
)
|
||||
|
||||
type RemoteBucketResult struct {
|
||||
@@ -248,7 +247,7 @@ func addRemoteBucket(ctx context.Context, client MinioAdmin, params models.Creat
|
||||
}
|
||||
host = host + ":" + strconv.Itoa(port)
|
||||
}
|
||||
creds := &auth.Credentials{AccessKey: accessKey, SecretKey: secretKey}
|
||||
creds := &madmin.Credentials{AccessKey: accessKey, SecretKey: secretKey}
|
||||
remoteBucket := &madmin.BucketTarget{
|
||||
TargetBucket: *params.TargetBucket,
|
||||
Secure: secure,
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import (
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
"github.com/minio/console/cluster"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/go-openapi/swag"
|
||||
|
||||
@@ -19,7 +19,7 @@ package restapi
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
)
|
||||
|
||||
// Define a mock struct of Admin Client interface implementation
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"encoding/base64"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/minio/console/models"
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/console/restapi/operations/admin_api"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
)
|
||||
|
||||
// shortTraceMsg Short trace record
|
||||
|
||||
@@ -22,8 +22,7 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
trace "github.com/minio/minio/pkg/trace"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
@@ -57,7 +56,7 @@ func TestAdminTrace(t *testing.T) {
|
||||
lines := make([]int, testStreamSize)
|
||||
// mocking sending 5 lines of info
|
||||
for range lines {
|
||||
info := trace.Info{
|
||||
info := madmin.TraceInfo{
|
||||
FuncName: textToReceive,
|
||||
}
|
||||
ch <- madmin.ServiceTraceInfo{Trace: info}
|
||||
@@ -109,7 +108,7 @@ func TestAdminTrace(t *testing.T) {
|
||||
lines := make([]int, 2)
|
||||
// mocking sending 5 lines of info
|
||||
for range lines {
|
||||
info := trace.Info{
|
||||
info := madmin.TraceInfo{
|
||||
NodeName: "test",
|
||||
}
|
||||
ch <- madmin.ServiceTraceInfo{Trace: info}
|
||||
|
||||
@@ -17,26 +17,27 @@
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
"strings"
|
||||
|
||||
"github.com/go-openapi/errors"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/console/restapi/operations"
|
||||
"github.com/minio/console/restapi/operations/admin_api"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"github.com/minio/madmin-go"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
)
|
||||
|
||||
const Allow = 1
|
||||
const Deny = -1
|
||||
const Unknown = 0
|
||||
// Policy evaluated constants
|
||||
const (
|
||||
Unknown = 0
|
||||
Allow = 1
|
||||
Deny = -1
|
||||
)
|
||||
|
||||
func registerUsersHandlers(api *operations.ConsoleAPI) {
|
||||
// List Users
|
||||
|
||||
@@ -19,16 +19,13 @@ package restapi
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/minio/madmin-go"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
asrt "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -17,19 +17,21 @@
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/console/pkg"
|
||||
"github.com/minio/madmin-go"
|
||||
mcCmd "github.com/minio/mc/cmd"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
mauth "github.com/minio/minio/pkg/auth"
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
)
|
||||
|
||||
const globalAppName = "MinIO Console"
|
||||
@@ -93,7 +95,7 @@ type MinioAdmin interface {
|
||||
heal(ctx context.Context, bucket, prefix string, healOpts madmin.HealOpts, clientToken string,
|
||||
forceStart, forceStop bool) (healStart madmin.HealStartSuccess, healTaskStatus madmin.HealTaskStatus, err error)
|
||||
// Service Accounts
|
||||
addServiceAccount(ctx context.Context, policy *iampolicy.Policy) (mauth.Credentials, error)
|
||||
addServiceAccount(ctx context.Context, policy *iampolicy.Policy) (madmin.Credentials, error)
|
||||
listServiceAccounts(ctx context.Context, user string) (madmin.ListServiceAccountsResp, error)
|
||||
deleteServiceAccount(ctx context.Context, serviceAccount string) error
|
||||
// Remote Buckets
|
||||
@@ -104,7 +106,7 @@ type MinioAdmin interface {
|
||||
// Account password management
|
||||
changePassword(ctx context.Context, accessKey, secretKey string) error
|
||||
|
||||
serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) <-chan madmin.HealthInfo
|
||||
serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) (interface{}, string, error)
|
||||
// List Tiers
|
||||
listTiers(ctx context.Context) ([]*madmin.TierConfig, error)
|
||||
// Add Tier
|
||||
@@ -172,12 +174,28 @@ func (ac adminClient) setGroupStatus(ctx context.Context, group string, status m
|
||||
|
||||
// implements madmin.ListCannedPolicies()
|
||||
func (ac adminClient) listPolicies(ctx context.Context) (map[string]*iampolicy.Policy, error) {
|
||||
return ac.client.ListCannedPolicies(ctx)
|
||||
policyMap, err := ac.client.ListCannedPolicies(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policies := make(map[string]*iampolicy.Policy, len(policyMap))
|
||||
for k, v := range policyMap {
|
||||
p, err := iampolicy.ParseConfig(bytes.NewReader(v))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
policies[k] = p
|
||||
}
|
||||
return policies, nil
|
||||
}
|
||||
|
||||
// implements madmin.ListCannedPolicies()
|
||||
func (ac adminClient) getPolicy(ctx context.Context, name string) (*iampolicy.Policy, error) {
|
||||
return ac.client.InfoCannedPolicy(ctx, name)
|
||||
praw, err := ac.client.InfoCannedPolicy(ctx, name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return iampolicy.ParseConfig(bytes.NewReader(praw))
|
||||
}
|
||||
|
||||
// implements madmin.RemoveCannedPolicy()
|
||||
@@ -187,7 +205,11 @@ func (ac adminClient) removePolicy(ctx context.Context, name string) error {
|
||||
|
||||
// implements madmin.AddCannedPolicy()
|
||||
func (ac adminClient) addPolicy(ctx context.Context, name string, policy *iampolicy.Policy) error {
|
||||
return ac.client.AddCannedPolicy(ctx, name, policy)
|
||||
buf, err := json.Marshal(policy)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ac.client.AddCannedPolicy(ctx, name, buf)
|
||||
}
|
||||
|
||||
// implements madmin.SetPolicy()
|
||||
@@ -249,10 +271,13 @@ func (ac adminClient) getLogs(ctx context.Context, node string, lineCnt int, log
|
||||
}
|
||||
|
||||
// implements madmin.AddServiceAccount()
|
||||
func (ac adminClient) addServiceAccount(ctx context.Context, policy *iampolicy.Policy) (mauth.Credentials, error) {
|
||||
// TODO: Fix this
|
||||
func (ac adminClient) addServiceAccount(ctx context.Context, policy *iampolicy.Policy) (madmin.Credentials, error) {
|
||||
buf, err := json.Marshal(policy)
|
||||
if err != nil {
|
||||
return madmin.Credentials{}, err
|
||||
}
|
||||
return ac.client.AddServiceAccount(ctx, madmin.AddServiceAccountReq{
|
||||
Policy: policy,
|
||||
Policy: buf,
|
||||
TargetUser: "",
|
||||
AccessKey: "",
|
||||
SecretKey: "",
|
||||
@@ -316,8 +341,37 @@ func (ac adminClient) getBucketQuota(ctx context.Context, bucket string) (madmin
|
||||
}
|
||||
|
||||
// serverHealthInfo implements mc.ServerHealthInfo - Connect to a minio server and call Health Info Management API
|
||||
func (ac adminClient) serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) <-chan madmin.HealthInfo {
|
||||
return ac.client.ServerHealthInfo(ctx, healthDataTypes, deadline)
|
||||
func (ac adminClient) serverHealthInfo(ctx context.Context, healthDataTypes []madmin.HealthDataType, deadline time.Duration) (interface{}, string, error) {
|
||||
resp, version, err := ac.client.ServerHealthInfo(ctx, healthDataTypes, deadline)
|
||||
if err != nil {
|
||||
return nil, version, err
|
||||
}
|
||||
|
||||
var healthInfo interface{}
|
||||
|
||||
decoder := json.NewDecoder(resp.Body)
|
||||
switch version {
|
||||
case madmin.HealthInfoVersion0:
|
||||
for {
|
||||
var info madmin.HealthInfoV0
|
||||
err = decoder.Decode(&info)
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return nil, version, err
|
||||
}
|
||||
|
||||
healthInfo = mcCmd.MapHealthInfoToV1(info, nil)
|
||||
}
|
||||
case madmin.HealthInfoVersion:
|
||||
for {
|
||||
var info madmin.HealthInfo
|
||||
if err != nil && !errors.Is(err, io.EOF) {
|
||||
return nil, version, err
|
||||
}
|
||||
|
||||
healthInfo = info
|
||||
}
|
||||
}
|
||||
return healthInfo, version, nil
|
||||
}
|
||||
|
||||
// implements madmin.listTiers()
|
||||
|
||||
@@ -25,8 +25,8 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/minio/minio/pkg/certs"
|
||||
"github.com/minio/minio/pkg/env"
|
||||
"github.com/minio/pkg/certs"
|
||||
"github.com/minio/pkg/env"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
k8sErrors "k8s.io/apimachinery/pkg/api/errors"
|
||||
)
|
||||
|
||||
|
||||
@@ -24,7 +24,7 @@ import (
|
||||
)
|
||||
|
||||
func prepareSTSClientTransport(insecure bool) *http.Transport {
|
||||
// This takes github.com/minio/minio/pkg/madmin/transport.go as an example
|
||||
// This takes github.com/minio/madmin-go/transport.go as an example
|
||||
//
|
||||
// DefaultTransport - this default transport is similar to
|
||||
// http.DefaultTransport but with additional param DisableCompression
|
||||
|
||||
@@ -21,7 +21,7 @@ import (
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
"errors"
|
||||
"testing"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
)
|
||||
|
||||
@@ -26,7 +26,7 @@ import (
|
||||
"github.com/minio/console/restapi/operations"
|
||||
"github.com/minio/console/restapi/operations/user_api"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
|
||||
"github.com/minio/console/models"
|
||||
)
|
||||
|
||||
@@ -36,7 +36,7 @@ import (
|
||||
"github.com/minio/console/restapi/operations"
|
||||
"github.com/minio/console/restapi/operations/user_api"
|
||||
"github.com/minio/minio-go/v7/pkg/policy"
|
||||
minioIAMPolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
minioIAMPolicy "github.com/minio/pkg/iam/policy"
|
||||
)
|
||||
|
||||
func registerBucketsHandlers(api *operations.ConsoleAPI) {
|
||||
|
||||
@@ -27,10 +27,10 @@ import (
|
||||
|
||||
"github.com/go-openapi/swag"
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/madmin-go"
|
||||
"github.com/minio/mc/pkg/probe"
|
||||
"github.com/minio/minio-go/v7"
|
||||
"github.com/minio/minio-go/v7/pkg/sse"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package restapi
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"log"
|
||||
"net/http"
|
||||
@@ -24,7 +25,7 @@ import (
|
||||
|
||||
"github.com/minio/minio-go/v7/pkg/credentials"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
|
||||
"github.com/go-openapi/runtime"
|
||||
"github.com/go-openapi/runtime/middleware"
|
||||
@@ -109,7 +110,7 @@ func getAccountPolicy(ctx context.Context, client MinioAdmin) (*iampolicy.Policy
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &accountInfo.Policy, err
|
||||
return iampolicy.ParseConfig(bytes.NewReader(accountInfo.Policy))
|
||||
}
|
||||
|
||||
// getConsoleCredentials will return consoleCredentials interface including the associated policy of the current account
|
||||
|
||||
@@ -22,9 +22,9 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
|
||||
"github.com/minio/console/pkg/auth"
|
||||
|
||||
|
||||
@@ -130,13 +130,13 @@ func Test_listObjects(t *testing.T) {
|
||||
go func(objectStatCh chan<- minio.ObjectInfo) {
|
||||
defer close(objectStatCh)
|
||||
for _, bucket := range []minio.ObjectInfo{
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj1",
|
||||
LastModified: t1,
|
||||
Size: int64(1024),
|
||||
ContentType: "content",
|
||||
},
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj2",
|
||||
LastModified: t1,
|
||||
Size: int64(512),
|
||||
@@ -168,7 +168,7 @@ func Test_listObjects(t *testing.T) {
|
||||
},
|
||||
},
|
||||
expectedResp: []*models.BucketObject{
|
||||
&models.BucketObject{
|
||||
{
|
||||
Name: "obj1",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(1024),
|
||||
@@ -179,7 +179,7 @@ func Test_listObjects(t *testing.T) {
|
||||
Tags: map[string]string{
|
||||
"tag1": "value1",
|
||||
},
|
||||
}, &models.BucketObject{
|
||||
}, {
|
||||
Name: "obj2",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(512),
|
||||
@@ -240,13 +240,13 @@ func Test_listObjects(t *testing.T) {
|
||||
go func(objectStatCh chan<- minio.ObjectInfo) {
|
||||
defer close(objectStatCh)
|
||||
for _, bucket := range []minio.ObjectInfo{
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj2",
|
||||
LastModified: t1,
|
||||
Size: int64(512),
|
||||
ContentType: "content",
|
||||
},
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Err: errors.New("error here"),
|
||||
},
|
||||
} {
|
||||
@@ -291,14 +291,14 @@ func Test_listObjects(t *testing.T) {
|
||||
go func(objectStatCh chan<- minio.ObjectInfo) {
|
||||
defer close(objectStatCh)
|
||||
for _, bucket := range []minio.ObjectInfo{
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj1",
|
||||
LastModified: t1,
|
||||
Size: int64(1024),
|
||||
ContentType: "content",
|
||||
IsDeleteMarker: true,
|
||||
},
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj2",
|
||||
LastModified: t1,
|
||||
Size: int64(512),
|
||||
@@ -330,13 +330,13 @@ func Test_listObjects(t *testing.T) {
|
||||
},
|
||||
},
|
||||
expectedResp: []*models.BucketObject{
|
||||
&models.BucketObject{
|
||||
{
|
||||
Name: "obj1",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(1024),
|
||||
ContentType: "content",
|
||||
IsDeleteMarker: true,
|
||||
}, &models.BucketObject{
|
||||
}, {
|
||||
Name: "obj2",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(512),
|
||||
@@ -366,7 +366,7 @@ func Test_listObjects(t *testing.T) {
|
||||
go func(objectStatCh chan<- minio.ObjectInfo) {
|
||||
defer close(objectStatCh)
|
||||
for _, bucket := range []minio.ObjectInfo{
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj1",
|
||||
LastModified: t1,
|
||||
Size: int64(1024),
|
||||
@@ -389,7 +389,7 @@ func Test_listObjects(t *testing.T) {
|
||||
},
|
||||
},
|
||||
expectedResp: []*models.BucketObject{
|
||||
&models.BucketObject{
|
||||
{
|
||||
Name: "obj1",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(1024),
|
||||
@@ -413,13 +413,13 @@ func Test_listObjects(t *testing.T) {
|
||||
go func(objectStatCh chan<- minio.ObjectInfo) {
|
||||
defer close(objectStatCh)
|
||||
for _, bucket := range []minio.ObjectInfo{
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj1",
|
||||
LastModified: t1,
|
||||
Size: int64(1024),
|
||||
ContentType: "content",
|
||||
},
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj2",
|
||||
LastModified: t1,
|
||||
Size: int64(512),
|
||||
@@ -451,12 +451,12 @@ func Test_listObjects(t *testing.T) {
|
||||
},
|
||||
},
|
||||
expectedResp: []*models.BucketObject{
|
||||
&models.BucketObject{
|
||||
{
|
||||
Name: "obj1",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(1024),
|
||||
ContentType: "content",
|
||||
}, &models.BucketObject{
|
||||
}, {
|
||||
Name: "obj2",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(512),
|
||||
@@ -480,13 +480,13 @@ func Test_listObjects(t *testing.T) {
|
||||
go func(objectStatCh chan<- minio.ObjectInfo) {
|
||||
defer close(objectStatCh)
|
||||
for _, bucket := range []minio.ObjectInfo{
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj1",
|
||||
LastModified: t1,
|
||||
Size: int64(1024),
|
||||
ContentType: "content",
|
||||
},
|
||||
minio.ObjectInfo{
|
||||
{
|
||||
Key: "obj2",
|
||||
LastModified: t1,
|
||||
Size: int64(512),
|
||||
@@ -518,12 +518,12 @@ func Test_listObjects(t *testing.T) {
|
||||
},
|
||||
},
|
||||
expectedResp: []*models.BucketObject{
|
||||
&models.BucketObject{
|
||||
{
|
||||
Name: "obj1",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(1024),
|
||||
ContentType: "content",
|
||||
}, &models.BucketObject{
|
||||
}, {
|
||||
Name: "obj2",
|
||||
LastModified: t1.Format(time.RFC3339),
|
||||
Size: int64(512),
|
||||
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
"github.com/minio/console/models"
|
||||
"github.com/minio/console/restapi/operations"
|
||||
"github.com/minio/console/restapi/operations/user_api"
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
)
|
||||
|
||||
func registerServiceAccountsHandlers(api *operations.ConsoleAPI) {
|
||||
|
||||
@@ -23,19 +23,18 @@ import (
|
||||
|
||||
"errors"
|
||||
|
||||
"github.com/minio/minio/pkg/auth"
|
||||
iampolicy "github.com/minio/minio/pkg/iam/policy"
|
||||
"github.com/minio/minio/pkg/madmin"
|
||||
"github.com/minio/madmin-go"
|
||||
iampolicy "github.com/minio/pkg/iam/policy"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// assigning mock at runtime instead of compile time
|
||||
var minioAddServiceAccountMock func(ctx context.Context, policy *iampolicy.Policy) (auth.Credentials, error)
|
||||
var minioAddServiceAccountMock func(ctx context.Context, policy *iampolicy.Policy) (madmin.Credentials, error)
|
||||
var minioListServiceAccountsMock func(ctx context.Context, user string) (madmin.ListServiceAccountsResp, error)
|
||||
var minioDeleteServiceAccountMock func(ctx context.Context, serviceAccount string) error
|
||||
|
||||
// mock function of AddServiceAccount()
|
||||
func (ac adminClientMock) addServiceAccount(ctx context.Context, policy *iampolicy.Policy) (auth.Credentials, error) {
|
||||
func (ac adminClientMock) addServiceAccount(ctx context.Context, policy *iampolicy.Policy) (madmin.Credentials, error) {
|
||||
return minioAddServiceAccountMock(ctx, policy)
|
||||
}
|
||||
|
||||
@@ -57,11 +56,11 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
// Test-1: createServiceAccount create a service account by assigning it a policy
|
||||
ctx := context.Background()
|
||||
policyDefinition := "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\",\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::bucket1/*\"]}]}"
|
||||
mockResponse := auth.Credentials{
|
||||
mockResponse := madmin.Credentials{
|
||||
AccessKey: "minio",
|
||||
SecretKey: "minio123",
|
||||
}
|
||||
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy) (auth.Credentials, error) {
|
||||
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy) (madmin.Credentials, error) {
|
||||
return mockResponse, nil
|
||||
}
|
||||
saCreds, err := createServiceAccount(ctx, client, policyDefinition)
|
||||
@@ -73,11 +72,11 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
|
||||
// Test-2: if an invalid policy is assigned to the service account, this will raise an error
|
||||
policyDefinition = "invalid policy"
|
||||
mockResponse = auth.Credentials{
|
||||
mockResponse = madmin.Credentials{
|
||||
AccessKey: "minio",
|
||||
SecretKey: "minio123",
|
||||
}
|
||||
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy) (auth.Credentials, error) {
|
||||
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy) (madmin.Credentials, error) {
|
||||
return mockResponse, nil
|
||||
}
|
||||
saCreds, err = createServiceAccount(ctx, client, policyDefinition)
|
||||
@@ -85,12 +84,12 @@ func TestAddServiceAccount(t *testing.T) {
|
||||
|
||||
// Test-3: if an error occurs on server while creating service account (valid policy), handle it
|
||||
policyDefinition = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Action\":[\"s3:GetBucketLocation\",\"s3:GetObject\",\"s3:ListAllMyBuckets\"],\"Resource\":[\"arn:aws:s3:::bucket1/*\"]}]}"
|
||||
mockResponse = auth.Credentials{
|
||||
mockResponse = madmin.Credentials{
|
||||
AccessKey: "minio",
|
||||
SecretKey: "minio123",
|
||||
}
|
||||
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy) (auth.Credentials, error) {
|
||||
return auth.Credentials{}, errors.New("error")
|
||||
minioAddServiceAccountMock = func(ctx context.Context, policy *iampolicy.Policy) (madmin.Credentials, error) {
|
||||
return madmin.Credentials{}, errors.New("error")
|
||||
}
|
||||
_, err = createServiceAccount(ctx, client, policyDefinition)
|
||||
if assert.Error(err) {
|
||||
|
||||
Reference in New Issue
Block a user