Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions restapi/admin_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@ func getListConfigResponse(session *models.Principal) (*models.ListConfigRespons
}

// getConfig gets the key values for a defined configuration
func getConfig(client MinioAdmin, name string) ([]*models.ConfigurationKV, error) {
ctx := context.Background()

func getConfig(ctx context.Context, client MinioAdmin, name string) ([]*models.ConfigurationKV, error) {
configKeysHelp, err := client.helpConfigKV(ctx, name, "", false)
if err != nil {
return nil, err
Expand All @@ -125,6 +123,7 @@ func getConfig(client MinioAdmin, name string) ([]*models.ConfigurationKV, error

// getConfigResponse performs getConfig() and serializes it to the handler's output
func getConfigResponse(session *models.Principal, params admin_api.ConfigInfoParams) (*models.Configuration, *models.Error) {
ctx := context.Background()
mAdmin, err := newMAdminClient(session)
if err != nil {
return nil, prepareError(err)
Expand All @@ -133,7 +132,7 @@ func getConfigResponse(session *models.Principal, params admin_api.ConfigInfoPar
// defining the client to be used
adminClient := adminClient{client: mAdmin}

configkv, err := getConfig(adminClient, params.Name)
configkv, err := getConfig(ctx, adminClient, params.Name)
if err != nil {
return nil, prepareError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion restapi/admin_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ func Test_getConfig(t *testing.T) {
for _, tt := range tests {
tt.mock()
t.Run(tt.name, func(t *testing.T) {
got, err := getConfig(tt.args.client, tt.args.name)
got, err := getConfig(context.Background(), tt.args.client, tt.args.name)
if (err != nil) != tt.wantErr {
t.Errorf("getConfig() error = %v, wantErr %v", err, tt.wantErr)
return
Expand Down
1 change: 1 addition & 0 deletions restapi/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var (
errorGenericUnauthorized = errors.New("unauthorized")
errorGenericForbidden = errors.New("forbidden")
errorGenericNotFound = errors.New("not found")
errConnectingToMinio = errors.New("unable to connect to MinIO instance")
// Explicit error messages
errorInvalidErasureCodingValue = errors.New("invalid Erasure Coding Value")
errorUnableToGetTenantUsage = errors.New("unable to get tenant usage")
Expand Down
20 changes: 12 additions & 8 deletions restapi/user_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"log"
"net/http"
"time"

"github.com/go-openapi/runtime"
"github.com/go-openapi/runtime/middleware"
Expand Down Expand Up @@ -97,9 +98,9 @@ func login(credentials ConsoleCredentials, actions []string) (*string, error) {
return &token, nil
}

func getConfiguredRegionForLogin(client MinioAdmin) (string, error) {
func getConfiguredRegionForLogin(ctx context.Context, client MinioAdmin) (string, error) {
location := ""
configuration, err := getConfig(client, "region")
configuration, err := getConfig(ctx, client, "region")
if err != nil {
log.Println("error obtaining MinIO region:", err)
return location, errorGeneric
Expand All @@ -113,17 +114,18 @@ func getConfiguredRegionForLogin(client MinioAdmin) (string, error) {

// getLoginResponse performs login() and serializes it to the handler's output
func getLoginResponse(lr *models.LoginRequest) (*models.LoginResponse, *models.Error) {
ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
mAdmin, err := newSuperMAdminClient()
if err != nil {
return nil, prepareError(err, errorGeneric)
}
adminClient := adminClient{client: mAdmin}
// obtain the configured MinIO region
// need it for user authentication
location, err := getConfiguredRegionForLogin(adminClient)
location, err := getConfiguredRegionForLogin(ctx, adminClient)
if err != nil {
return nil, prepareError(err, errorGeneric)
return nil, prepareError(err, errConnectingToMinio)
}
creds, err := newConsoleCredentials(*lr.AccessKey, *lr.SecretKey, location)
if err != nil {
Expand Down Expand Up @@ -158,7 +160,8 @@ func getLoginResponse(lr *models.LoginRequest) (*models.LoginResponse, *models.E

// getLoginDetailsResponse returns information regarding the Console authentication mechanism.
func getLoginDetailsResponse() (*models.LoginDetails, *models.Error) {
ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
loginStrategy := models.LoginDetailsLoginStrategyForm
redirectURL := ""
if acl.GetOperatorMode() {
Expand Down Expand Up @@ -191,7 +194,8 @@ func loginOauth2Auth(ctx context.Context, provider *auth.IdentityProvider, code,
}

func getLoginOauth2AuthResponse(lr *models.LoginOauth2AuthRequest) (*models.LoginResponse, *models.Error) {
ctx := context.Background()
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
defer cancel()
if oauth2.IsIdpEnabled() {
// initialize new oauth2 client
oauth2Client, err := oauth2.NewOauth2ProviderClient(ctx, nil)
Expand All @@ -214,7 +218,7 @@ func getLoginOauth2AuthResponse(lr *models.LoginOauth2AuthRequest) (*models.Logi
secretKey := utils.RandomCharString(32)
// obtain the configured MinIO region
// need it for user authentication
location, err := getConfiguredRegionForLogin(adminClient)
location, err := getConfiguredRegionForLogin(ctx, adminClient)
if err != nil {
return nil, prepareError(err)
}
Expand Down
2 changes: 1 addition & 1 deletion restapi/user_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func Test_getConfiguredRegion(t *testing.T) {
for _, tt := range tests {
tt.mock()
t.Run(tt.name, func(t *testing.T) {
if got, _ := getConfiguredRegionForLogin(tt.args.client); got != tt.want {
if got, _ := getConfiguredRegionForLogin(context.Background(), tt.args.client); got != tt.want {
t.Errorf("getConfiguredRegionForLogin() = %v, want %v", got, tt.want)
}
})
Expand Down