2023-03-28 23:48:58 +01:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 09:12:13 -04:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 23:48:58 +01:00
|
|
|
|
2022-07-15 15:03:40 -05:00
|
|
|
package pbpeerstream
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
2023-02-17 16:14:46 -05:00
|
|
|
pbservice "github.com/hashicorp/consul/proto/private/pbservice"
|
2022-07-15 15:03:40 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// CheckServiceNodesToStruct converts the contained CheckServiceNodes to their structs equivalent.
|
|
|
|
func (s *ExportedService) CheckServiceNodesToStruct() ([]structs.CheckServiceNode, error) {
|
|
|
|
if s == nil {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
resp := make([]structs.CheckServiceNode, 0, len(s.Nodes))
|
|
|
|
for _, pb := range s.Nodes {
|
|
|
|
instance, err := pbservice.CheckServiceNodeToStructs(pb)
|
|
|
|
if err != nil {
|
|
|
|
return resp, fmt.Errorf("failed to convert instance: %w", err)
|
|
|
|
}
|
|
|
|
resp = append(resp, *instance)
|
|
|
|
}
|
|
|
|
return resp, nil
|
|
|
|
}
|
2022-09-29 15:37:19 -04:00
|
|
|
|
|
|
|
func ExportedServiceListFromStruct(e *structs.ExportedServiceList) *ExportedServiceList {
|
|
|
|
services := make([]string, 0, len(e.Services))
|
|
|
|
|
|
|
|
for _, s := range e.Services {
|
|
|
|
services = append(services, s.String())
|
|
|
|
}
|
|
|
|
|
|
|
|
return &ExportedServiceList{
|
|
|
|
Services: services,
|
|
|
|
}
|
|
|
|
}
|