mirror of
https://github.com/grafana/grafana.git
synced 2025-07-29 22:57:16 +08:00

Back-end: * update alerting module * update GetSecretKeysForContactPointType to extract secret fields from nested options * Update RemoveSecretsForContactPoint to support complex settings * update PostableGrafanaReceiverToEmbeddedContactPoint to support nested secrets * update Integration to support nested settings in models.Integration * make sigv4 fields optional Front-end: * add UI support for encrypted subform fields * allow emptying nested secure fields * Omit non touched secure fields in POST payload when saving a contact point * Use SecretInput from grafana-ui instead of the new EncryptedInput * use produce from immer * rename mapClone * rename sliceClone * Don't use produce from immer as we need to delete the fileds afterwards --------- Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com> Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com> Co-authored-by: Matt Jacobson <matthew.jacobson@grafana.com>
56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package models
|
|
|
|
import (
|
|
"encoding/binary"
|
|
"fmt"
|
|
"hash"
|
|
"hash/fnv"
|
|
"math"
|
|
"unsafe"
|
|
)
|
|
|
|
// fingerprint is a wrapper for hash.Hash64 that adds utility methods to simplify hash calculation of structs
|
|
type fingerprint struct {
|
|
h hash.Hash64
|
|
}
|
|
|
|
// creates a fingerprint that is backed by 64bit FNV-1a hash
|
|
func newFingerprint() fingerprint {
|
|
return fingerprint{h: fnv.New64a()}
|
|
}
|
|
|
|
func (f fingerprint) String() string {
|
|
return fmt.Sprintf("%016x", f.h.Sum64())
|
|
}
|
|
|
|
func (f fingerprint) writeBytes(b []byte) {
|
|
_, _ = f.h.Write(b)
|
|
// add a byte sequence that cannot happen in UTF-8 strings.
|
|
_, _ = f.h.Write([]byte{255})
|
|
}
|
|
|
|
func (f fingerprint) writeString(s string) {
|
|
if len(s) == 0 {
|
|
f.writeBytes(nil)
|
|
return
|
|
}
|
|
// #nosec G103
|
|
// avoid allocation when converting string to byte slice
|
|
f.writeBytes(unsafe.Slice(unsafe.StringData(s), len(s)))
|
|
}
|
|
|
|
func (f fingerprint) writeFloat64(num float64) {
|
|
bits := math.Float64bits(num)
|
|
bytes := make([]byte, 8)
|
|
binary.LittleEndian.PutUint64(bytes, bits)
|
|
f.writeBytes(bytes)
|
|
}
|
|
|
|
func (f fingerprint) writeBool(b bool) {
|
|
if b {
|
|
f.writeBytes([]byte{1})
|
|
} else {
|
|
f.writeBytes([]byte{0})
|
|
}
|
|
}
|