consul/testing/deployer/sprawl/internal/secrets/store.go

75 lines
1.5 KiB
Go
Raw Normal View History

[COMPLIANCE] License changes (#18443) * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Adding explicit MPL license for sub-package This directory and its subdirectories (packages) contain files licensed with the MPLv2 `LICENSE` file in this directory and are intentionally licensed separately from the BSL `LICENSE` file at the root of this repository. * Updating the license from MPL to Business Source License Going forward, this project will be licensed under the Business Source License v1.1. Please see our blog post for more details at <Blog URL>, FAQ at www.hashicorp.com/licensing-faq, and details of the license at www.hashicorp.com/bsl. * add missing license headers * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 * Update copyright file headers to BUSL-1.1 --------- Co-authored-by: hashicorp-copywrite[bot] <110428419+hashicorp-copywrite[bot]@users.noreply.github.com>
2023-08-11 13:12:13 +00:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
package secrets
import (
"net/url"
"strings"
"github.com/hashicorp/consul/testing/deployer/topology"
)
type Store struct {
m map[string]string
}
const (
GossipKey = "gossip"
BootstrapToken = "bootstrap-token"
AgentRecovery = "agent-recovery"
CAPEM = "ca-pem"
)
func (s *Store) SaveGeneric(cluster, name, value string) {
s.save(encode(cluster, "generic", name), value)
}
func (s *Store) ReadGeneric(cluster, name string) string {
return s.read(encode(cluster, "generic", name))
}
func (s *Store) SaveAgentToken(cluster string, nid topology.NodeID, value string) {
s.save(encode(cluster, "agent", nid.String()), value)
}
func (s *Store) ReadAgentToken(cluster string, nid topology.NodeID) string {
return s.read(encode(cluster, "agent", nid.String()))
}
func (s *Store) SaveServiceToken(cluster string, sid topology.ServiceID, value string) {
s.save(encode(cluster, "service", sid.String()), value)
}
func (s *Store) ReadServiceToken(cluster string, sid topology.ServiceID) string {
return s.read(encode(cluster, "service", sid.String()))
}
func (s *Store) save(key, value string) {
if s.m == nil {
s.m = make(map[string]string)
}
s.m[key] = value
}
func (s *Store) read(key string) string {
if s.m == nil {
return ""
}
v, ok := s.m[key]
if !ok {
return ""
}
return v
}
func encode(parts ...string) string {
var out []string
for _, p := range parts {
out = append(out, url.QueryEscape(p))
}
return strings.Join(out, "/")
}