2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2016-10-19 22:06:23 +00:00
|
|
|
package fingerprint
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul-template/signals"
|
2018-09-16 00:48:59 +00:00
|
|
|
log "github.com/hashicorp/go-hclog"
|
2016-10-19 22:06:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// SignalFingerprint is used to fingerprint the available signals
|
|
|
|
type SignalFingerprint struct {
|
|
|
|
StaticFingerprinter
|
2018-09-16 00:48:59 +00:00
|
|
|
logger log.Logger
|
2016-10-19 22:06:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewSignalFingerprint is used to create a Signal fingerprint
|
2018-09-16 00:48:59 +00:00
|
|
|
func NewSignalFingerprint(logger log.Logger) Fingerprint {
|
|
|
|
f := &SignalFingerprint{logger: logger.Named("signals")}
|
2016-10-19 22:06:23 +00:00
|
|
|
return f
|
|
|
|
}
|
|
|
|
|
2018-12-01 16:10:39 +00:00
|
|
|
func (f *SignalFingerprint) Fingerprint(req *FingerprintRequest, resp *FingerprintResponse) error {
|
2016-10-19 22:06:23 +00:00
|
|
|
// Build the list of available signals
|
|
|
|
sigs := make([]string, 0, len(signals.SignalLookup))
|
|
|
|
for signal := range signals.SignalLookup {
|
|
|
|
sigs = append(sigs, signal)
|
|
|
|
}
|
|
|
|
|
2018-01-26 16:21:07 +00:00
|
|
|
resp.AddAttribute("os.signals", strings.Join(sigs, ","))
|
2018-01-31 22:03:55 +00:00
|
|
|
resp.Detected = true
|
2018-01-24 14:09:53 +00:00
|
|
|
return nil
|
2016-10-19 22:06:23 +00:00
|
|
|
}
|