github.com/hernad/nomad@v1.6.112/nomad/regions_endpoint.go (about)

     1  // Copyright (c) HashiCorp, Inc.
     2  // SPDX-License-Identifier: MPL-2.0
     3  
     4  package nomad
     5  
     6  import (
     7  	"github.com/hashicorp/go-hclog"
     8  
     9  	"github.com/hernad/nomad/nomad/structs"
    10  )
    11  
    12  // Region is used to query and list the known regions
    13  type Region struct {
    14  	srv    *Server
    15  	ctx    *RPCContext
    16  	logger hclog.Logger
    17  }
    18  
    19  func NewRegionEndpoint(srv *Server, ctx *RPCContext) *Region {
    20  	return &Region{srv: srv, ctx: ctx, logger: srv.logger.Named("region")}
    21  }
    22  
    23  // List is used to list all of the known regions. No leader forwarding is
    24  // required for this endpoint because memberlist is used to populate the
    25  // peers list we read from.
    26  func (r *Region) List(args *structs.GenericRequest, reply *[]string) error {
    27  	// note: we're intentionally throwing away any auth error here and only
    28  	// authenticate so that we can measure rate metrics
    29  	r.srv.Authenticate(r.ctx, args)
    30  	r.srv.MeasureRPCRate("region", structs.RateMetricList, args)
    31  
    32  	*reply = r.srv.Regions()
    33  	return nil
    34  }