2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2020-10-06 18:24:05 +00:00
|
|
|
package consul
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) getSystemMetadata(key string) (string, error) {
|
|
|
|
_, entry, err := s.fsm.State().SystemMetadataGet(nil, key)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
return "", nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return entry.Value, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) setSystemMetadataKey(key, val string) error {
|
|
|
|
args := &structs.SystemMetadataRequest{
|
|
|
|
Op: structs.SystemMetadataUpsert,
|
|
|
|
Entry: &structs.SystemMetadataEntry{Key: key, Value: val},
|
|
|
|
}
|
|
|
|
|
2022-03-17 23:02:26 +00:00
|
|
|
// TODO(rpc-metrics-improv): Double check request name here
|
|
|
|
_, err := s.leaderRaftApply("SystemMetadata.Upsert", structs.SystemMetadataRequestType, args)
|
|
|
|
|
2021-04-08 22:58:15 +00:00
|
|
|
return err
|
2020-10-06 18:24:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) deleteSystemMetadataKey(key string) error {
|
|
|
|
args := &structs.SystemMetadataRequest{
|
|
|
|
Op: structs.SystemMetadataDelete,
|
|
|
|
Entry: &structs.SystemMetadataEntry{Key: key},
|
|
|
|
}
|
|
|
|
|
2022-03-17 23:02:26 +00:00
|
|
|
// TODO(rpc-metrics-improv): Double check request name here
|
|
|
|
_, err := s.leaderRaftApply("SystemMetadata.Delete", structs.SystemMetadataRequestType, args)
|
|
|
|
|
2021-04-08 22:58:15 +00:00
|
|
|
return err
|
2020-10-06 18:24:05 +00:00
|
|
|
}
|