github.com/minio/console@v1.3.0/api/admin_nodes.go (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2022 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 "github.com/go-openapi/runtime/middleware" 23 "github.com/minio/console/api/operations" 24 systemApi "github.com/minio/console/api/operations/system" 25 "github.com/minio/console/models" 26 ) 27 28 func registerNodesHandler(api *operations.ConsoleAPI) { 29 api.SystemListNodesHandler = systemApi.ListNodesHandlerFunc(func(params systemApi.ListNodesParams, session *models.Principal) middleware.Responder { 30 listNodesResponse, err := getListNodesResponse(session, params) 31 if err != nil { 32 return systemApi.NewListNodesDefault(err.Code).WithPayload(err.APIError) 33 } 34 return systemApi.NewListNodesOK().WithPayload(listNodesResponse) 35 }) 36 } 37 38 // getListNodesResponse returns a list of available node endpoints . 39 func getListNodesResponse(session *models.Principal, params systemApi.ListNodesParams) ([]string, *CodedAPIError) { 40 ctx, cancel := context.WithCancel(params.HTTPRequest.Context()) 41 defer cancel() 42 mAdmin, err := NewMinioAdminClient(params.HTTPRequest.Context(), session) 43 if err != nil { 44 return nil, ErrorWithContext(ctx, err) 45 } 46 var nodeList []string 47 48 adminResources, _ := mAdmin.ServerInfo(ctx) 49 50 for _, n := range adminResources.Servers { 51 nodeList = append(nodeList, n.Endpoint) 52 } 53 54 return nodeList, nil 55 }