You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
consul/testing/deployer/sprawl/internal/secrets/store.go

85 lines
1.8 KiB

[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>
1 year ago
// 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()))
}
// Deprecated: SaveWorkloadToken
func (s *Store) SaveServiceToken(cluster string, wid topology.ID, value string) {
s.SaveWorkloadToken(cluster, wid, value)
}
func (s *Store) SaveWorkloadToken(cluster string, wid topology.ID, value string) {
s.save(encode(cluster, "workload", wid.String()), value)
}
// Deprecated: ReadWorkloadToken
func (s *Store) ReadServiceToken(cluster string, wid topology.ID) string {
return s.ReadWorkloadToken(cluster, wid)
}
func (s *Store) ReadWorkloadToken(cluster string, wid topology.ID) string {
return s.read(encode(cluster, "workload", wid.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, "/")
}