github.com/minio/console@v1.3.0/api/admin_arns.go (about)

     1  // This file is part of MinIO Console Server
     2  // Copyright (c) 2021 MinIO, Inc.
     3  //
     4  // This program is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Affero General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // This program is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  // GNU Affero General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Affero General Public License
    15  // along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package api
    18  
    19  import (
    20  	"context"
    21  
    22  	systemApi "github.com/minio/console/api/operations/system"
    23  
    24  	"github.com/go-openapi/runtime/middleware"
    25  	"github.com/minio/console/api/operations"
    26  	"github.com/minio/console/models"
    27  )
    28  
    29  func registerAdminArnsHandlers(api *operations.ConsoleAPI) {
    30  	// return a list of arns
    31  	api.SystemArnListHandler = systemApi.ArnListHandlerFunc(func(params systemApi.ArnListParams, session *models.Principal) middleware.Responder {
    32  		arnsResp, err := getArnsResponse(session, params)
    33  		if err != nil {
    34  			return systemApi.NewArnListDefault(err.Code).WithPayload(err.APIError)
    35  		}
    36  		return systemApi.NewArnListOK().WithPayload(arnsResp)
    37  	})
    38  }
    39  
    40  // getArns invokes admin info and returns a list of arns
    41  func getArns(ctx context.Context, client MinioAdmin) (*models.ArnsResponse, error) {
    42  	serverInfo, err := client.serverInfo(ctx)
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  	// build response
    47  	return &models.ArnsResponse{
    48  		Arns: serverInfo.SQSARN,
    49  	}, nil
    50  }
    51  
    52  // getArnsResponse returns a list of active arns in the instance
    53  func getArnsResponse(session *models.Principal, params systemApi.ArnListParams) (*models.ArnsResponse, *CodedAPIError) {
    54  	ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
    55  	defer cancel()
    56  	mAdmin, err := NewMinioAdminClient(params.HTTPRequest.Context(), session)
    57  	if err != nil {
    58  		return nil, ErrorWithContext(ctx, err)
    59  	}
    60  	// create a minioClient interface implementation
    61  	// defining the client to be used
    62  	adminClient := AdminClient{Client: mAdmin}
    63  
    64  	// serialize output
    65  	arnsList, err := getArns(ctx, adminClient)
    66  	if err != nil {
    67  		return nil, ErrorWithContext(ctx, err)
    68  	}
    69  	return arnsList, nil
    70  }