本文整理汇总了Golang中github.com/hashicorp/consul-template/dependency.ParseVaultSecret函数的典型用法代码示例。如果您正苦于以下问题:Golang ParseVaultSecret函数的具体用法?Golang ParseVaultSecret怎么用?Golang ParseVaultSecret使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ParseVaultSecret函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestVaultFunc_missingData
func TestVaultFunc_missingData(t *testing.T) {
d, err := dep.ParseVaultSecret("secret/foo/bar")
if err != nil {
t.Fatal(err)
}
brain := NewBrain()
used := make(map[string]dep.Dependency)
missing := make(map[string]dep.Dependency)
f := vaultFunc(brain, used, missing)
result, err := f("secret/foo/bar")
if err != nil {
t.Fatal(err)
}
expected := &dep.Secret{}
if !reflect.DeepEqual(result, expected) {
t.Errorf("expected %#v to be %#v", result, expected)
}
if _, ok := used[d.HashCode()]; !ok {
t.Errorf("expected dep to be used")
}
if _, ok := missing[d.HashCode()]; !ok {
t.Errorf("expected dep to be missing")
}
}
开发者ID:necroscope,项目名称:consul-template,代码行数:31,代码来源:template_functions_test.go
示例2: vaultFunc
// vaultFunc returns or accumulates secret dependencies.
func vaultFunc(brain *Brain,
used, missing map[string]dep.Dependency) func(string) (*dep.Secret, error) {
return func(s string) (*dep.Secret, error) {
result := &dep.Secret{}
if len(s) == 0 {
return result, nil
}
d, err := dep.ParseVaultSecret(s)
if err != nil {
return result, nil
}
addDependency(used, d)
if value, ok := brain.Recall(d); ok {
result = value.(*dep.Secret)
return result, nil
}
addDependency(missing, d)
return result, nil
}
}
开发者ID:hashbrowncipher,项目名称:consul-template,代码行数:27,代码来源:template_functions.go
示例3: TestVaultFunc_hasData
func TestVaultFunc_hasData(t *testing.T) {
d, err := dep.ParseVaultSecret("secret/foo/bar")
if err != nil {
t.Fatal(err)
}
data := &dep.Secret{
LeaseID: "abcd1234",
LeaseDuration: 120,
Renewable: true,
Data: map[string]interface{}{"zip": "zap"},
}
brain := NewBrain()
brain.Remember(d, data)
used := make(map[string]dep.Dependency)
missing := make(map[string]dep.Dependency)
f := vaultFunc(brain, used, missing)
result, err := f("secret/foo/bar")
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(result, data) {
t.Errorf("expected %#v to be %#v", result, data)
}
if len(missing) != 0 {
t.Errorf("expected missing to have 0 elements, but had %d", len(missing))
}
if _, ok := used[d.HashCode()]; !ok {
t.Errorf("expected dep to be used")
}
}
开发者ID:necroscope,项目名称:consul-template,代码行数:37,代码来源:template_functions_test.go
示例4: TestExecute_renders
//.........这里部分代码省略.........
Tags: []string{"release", "production"},
},
&dep.HealthService{
Node: "node3",
Address: "9.10.11.12",
Tags: []string{"production"},
},
})
d, err = dep.ParseHealthServices("webapp", "any")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, []*dep.HealthService{
&dep.HealthService{Node: "node1", Address: "1.2.3.4"},
&dep.HealthService{Node: "node2", Address: "5.6.7.8"},
})
d, err = dep.ParseCatalogServices("")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, []*dep.CatalogService{
&dep.CatalogService{
Name: "service1",
Tags: []string{"production"},
},
&dep.CatalogService{
Name: "service2",
Tags: []string{"release", "production"},
},
})
d, err = dep.ParseVaultSecret("secret/foo/bar")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, &dep.Secret{
LeaseID: "abcd1234",
LeaseDuration: 120,
Renewable: true,
Data: map[string]interface{}{"zip": "zap"},
})
if err := os.Setenv("foo", "bar"); err != nil {
t.Fatal(err)
}
d, err = dep.ParseFile("/path/to/json/file")
if err != nil {
t.Fatal(err)
}
brain.Remember(d, `{"foo": "bar"}`)
if err := os.Setenv("json", `{"foo": "bar"}`); err != nil {
t.Fatal(err)
}
_, _, result, err := tmpl.Execute(brain)
if err != nil {
t.Fatal(err)
}
expected := []byte(`
API Functions
-------------
开发者ID:necroscope,项目名称:consul-template,代码行数:67,代码来源:template_test.go
示例5: init
// init creates the Runner's underlying data structures and returns an error if
// any problems occur.
func (r *Runner) init() error {
// Ensure we have defaults
config := DefaultConfig()
config.Merge(r.config)
r.config = config
// Print the final config for debugging
result, err := json.MarshalIndent(r.config, "", " ")
if err != nil {
return err
}
log.Printf("[DEBUG] (runner) final config (tokens suppressed):\n\n%s\n\n",
result)
// Setup the kill signal
signal, err := signals.Parse(r.config.KillSignal)
if err != nil {
return errors.Wrap(err, "runner")
}
r.killSignal = signal
// Create the clientset
clients, err := newClientSet(r.config)
if err != nil {
return fmt.Errorf("runner: %s", err)
}
// Create the watcher
watcher, err := newWatcher(r.config, clients, r.once)
if err != nil {
return fmt.Errorf("runner: %s", err)
}
r.watcher = watcher
r.data = make(map[string]interface{})
r.configPrefixMap = make(map[string]*ConfigPrefix)
r.inStream = os.Stdin
r.outStream = os.Stdout
r.errStream = os.Stderr
r.ErrCh = make(chan error)
r.DoneCh = make(chan struct{})
r.ExitCh = make(chan int, 1)
// Parse and add consul dependencies
for _, p := range r.config.Prefixes {
d, err := dep.ParseStoreKeyPrefix(p.Path)
if err != nil {
return err
}
r.dependencies = append(r.dependencies, d)
r.configPrefixMap[d.HashCode()] = p
}
// Parse and add vault dependencies - it is important that this come after
// consul, because consul should never be permitted to overwrite values from
// vault; that would expose a security hole since access to consul is
// typically less controlled than access to vault.
for _, s := range r.config.Secrets {
log.Printf("looking at vault %s", s.Path)
d, err := dep.ParseVaultSecret(s.Path)
if err != nil {
return err
}
r.dependencies = append(r.dependencies, d)
r.configPrefixMap[d.HashCode()] = s
}
return nil
}
开发者ID:hashicorp,项目名称:envconsul,代码行数:73,代码来源:runner.go
注:本文中的github.com/hashicorp/consul-template/dependency.ParseVaultSecret函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论