本文整理汇总了Golang中github.com/hashicorp/nomad/nomad/structs.Task.Vault方法的典型用法代码示例。如果您正苦于以下问题:Golang Task.Vault方法的具体用法?Golang Task.Vault怎么用?Golang Task.Vault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hashicorp/nomad/nomad/structs.Task
的用法示例。
在下文中一共展示了Task.Vault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseTasks
//.........这里部分代码省略.........
// Instantiate a driver to validate the configuration
d, err := driver.NewDriver(
t.Driver,
driver.NewEmptyDriverContext(),
)
if err != nil {
return multierror.Prefix(err,
fmt.Sprintf("'%s', config ->", n))
}
if err := d.Validate(t.Config); err != nil {
return multierror.Prefix(err,
fmt.Sprintf("'%s', config ->", n))
}
}
// Parse constraints
if o := listVal.Filter("constraint"); len(o.Items) > 0 {
if err := parseConstraints(&t.Constraints, o); err != nil {
return multierror.Prefix(err, fmt.Sprintf(
"'%s', constraint ->", n))
}
}
// Parse out meta fields. These are in HCL as a list so we need
// to iterate over them and merge them.
if metaO := listVal.Filter("meta"); len(metaO.Items) > 0 {
for _, o := range metaO.Elem().Items {
var m map[string]interface{}
if err := hcl.DecodeObject(&m, o.Val); err != nil {
return err
}
if err := mapstructure.WeakDecode(m, &t.Meta); err != nil {
return err
}
}
}
// If we have resources, then parse that
if o := listVal.Filter("resources"); len(o.Items) > 0 {
var r structs.Resources
if err := parseResources(&r, o); err != nil {
return multierror.Prefix(err, fmt.Sprintf("'%s',", n))
}
t.Resources = &r
}
// If we have logs then parse that
logConfig := structs.DefaultLogConfig()
if o := listVal.Filter("logs"); len(o.Items) > 0 {
if len(o.Items) > 1 {
return fmt.Errorf("only one logs block is allowed in a Task. Number of logs block found: %d", len(o.Items))
}
var m map[string]interface{}
logsBlock := o.Items[0]
// Check for invalid keys
valid := []string{
"max_files",
"max_file_size",
}
if err := checkHCLKeys(logsBlock.Val, valid); err != nil {
return multierror.Prefix(err, fmt.Sprintf("'%s', logs ->", n))
}
if err := hcl.DecodeObject(&m, logsBlock.Val); err != nil {
return err
}
if err := mapstructure.WeakDecode(m, &logConfig); err != nil {
return err
}
}
t.LogConfig = logConfig
// Parse artifacts
if o := listVal.Filter("artifact"); len(o.Items) > 0 {
if err := parseArtifacts(&t.Artifacts, o); err != nil {
return multierror.Prefix(err, fmt.Sprintf("'%s', artifact ->", n))
}
}
// If we have a vault block, then parse that
if o := listVal.Filter("vault"); len(o.Items) > 0 {
var v structs.Vault
if err := parseVault(&v, o); err != nil {
return multierror.Prefix(err, fmt.Sprintf("'%s', vault ->", n))
}
t.Vault = &v
}
*result = append(*result, &t)
}
return nil
}