github.com/choria-io/go-choria@v0.28.1-0.20240416190746-b3bf9c7d5a45/server/discovery/discovery.go (about)

     1  // Copyright (c) 2017-2021, R.I. Pienaar and the Choria Project contributors
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package discovery
     6  
     7  import (
     8  	"encoding/json"
     9  
    10  	"github.com/sirupsen/logrus"
    11  
    12  	"github.com/choria-io/go-choria/config"
    13  	"github.com/choria-io/go-choria/protocol"
    14  	"github.com/choria-io/go-choria/providers/data/ddl"
    15  )
    16  
    17  type ServerInfoSource interface {
    18  	Classes() []string
    19  	Facts() json.RawMessage
    20  	Identity() string
    21  	KnownAgents() []string
    22  	DataFuncMap() (ddl.FuncMap, error)
    23  }
    24  
    25  // Manager manages the full discovery life cycle
    26  type Manager struct {
    27  	cfg *config.Config
    28  	si  ServerInfoSource
    29  	log *logrus.Entry
    30  }
    31  
    32  // New creates a new discovery Manager
    33  func New(cfg *config.Config, si ServerInfoSource, logger *logrus.Entry) *Manager {
    34  	return &Manager{
    35  		cfg: cfg,
    36  		si:  si,
    37  		log: logger.WithFields(logrus.Fields{"subsystem": "discovery"}),
    38  	}
    39  }
    40  
    41  // ShouldProcess checks all filters against methods for filtering and returns boolean if it matches
    42  func (mgr *Manager) ShouldProcess(request protocol.Request) bool {
    43  	filter, _ := request.Filter()
    44  
    45  	return filter.MatchServerRequest(request, mgr.si, mgr.log.WithField("request", request.RequestID()))
    46  }