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

     1  // Copyright (c) 2021, R.I. Pienaar and the Choria Project contributors
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package registration
     6  
     7  import (
     8  	"bytes"
     9  	"compress/gzip"
    10  	"encoding/json"
    11  
    12  	"github.com/choria-io/go-choria/aagent"
    13  	"github.com/choria-io/go-choria/build"
    14  	"github.com/choria-io/go-choria/providers/data/ddl"
    15  	"github.com/choria-io/go-choria/server/agents"
    16  	"github.com/choria-io/go-choria/statistics"
    17  )
    18  
    19  type ServerInfoSource interface {
    20  	Classes() []string
    21  	Facts() json.RawMessage
    22  	Identity() string
    23  	KnownAgents() []string
    24  	DataFuncMap() (ddl.FuncMap, error)
    25  	Status() *statistics.InstanceStatus
    26  	AgentMetadata(agent string) (agents.Metadata, bool)
    27  	BuildInfo() *build.Info
    28  	MachinesStatus() ([]aagent.MachineState, error)
    29  }
    30  
    31  func compress(data []byte) ([]byte, error) {
    32  	var b bytes.Buffer
    33  
    34  	gz := gzip.NewWriter(&b)
    35  
    36  	_, err := gz.Write(data)
    37  	if err != nil {
    38  		return []byte{}, err
    39  	}
    40  
    41  	err = gz.Flush()
    42  	if err != nil {
    43  		return []byte{}, err
    44  	}
    45  
    46  	err = gz.Close()
    47  	if err != nil {
    48  		return []byte{}, err
    49  	}
    50  
    51  	return b.Bytes(), nil
    52  }