本文整理匯總了Golang中github.com/mitchellh/packer/helper/config.Decode函數的典型用法代碼示例。如果您正苦於以下問題:Golang Decode函數的具體用法?Golang Decode怎麽用?Golang Decode使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Decode函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestCoreBuild_templatePath
func TestCoreBuild_templatePath(t *testing.T) {
config := TestCoreConfig(t)
testCoreTemplate(t, config, fixtureDir("build-template-path.json"))
b := TestBuilder(t, config, "test")
core := TestCore(t, config)
expected, _ := filepath.Abs("./test-fixtures")
build, err := core.Build("test")
if err != nil {
t.Fatalf("err: %s", err)
}
if _, err := build.Prepare(); err != nil {
t.Fatalf("err: %s", err)
}
// Interpolate the config
var result map[string]interface{}
err = configHelper.Decode(&result, nil, b.PrepareConfig...)
if err != nil {
t.Fatalf("err: %s", err)
}
if result["value"] != expected {
t.Fatalf("bad: %#v", result)
}
}
示例2: Configure
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
// Accumulate any errors
errs := new(packer.MultiError)
if p.config.Template == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Template must be set"))
}
if p.config.Output == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Output must be set"))
}
log.Printf("Configure(): template:%s output:%s", p.config.Template, p.config.Output)
if len(errs.Errors) > 0 {
return errs
}
return nil
}
示例3: Prepare
func (p *Provisioner) Prepare(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{
"execute_command",
},
},
}, raws...)
if err != nil {
return err
}
if p.config.RestartCommand == "" {
p.config.RestartCommand = DefaultRestartCommand
}
if p.config.RestartCheckCommand == "" {
p.config.RestartCheckCommand = DefaultRestartCheckCommand
}
if p.config.RestartTimeout == 0 {
p.config.RestartTimeout = 5 * time.Minute
}
return nil
}
示例4: TestCoreBuild_buildTypeVar
func TestCoreBuild_buildTypeVar(t *testing.T) {
config := TestCoreConfig(t)
testCoreTemplate(t, config, fixtureDir("build-var-build-type.json"))
b := TestBuilder(t, config, "test")
core := TestCore(t, config)
b.ArtifactId = "hello"
build, err := core.Build("test")
if err != nil {
t.Fatalf("err: %s", err)
}
if _, err := build.Prepare(); err != nil {
t.Fatalf("err: %s", err)
}
// Interpolate the config
var result map[string]interface{}
err = configHelper.Decode(&result, nil, b.PrepareConfig...)
if err != nil {
t.Fatalf("err: %s", err)
}
if result["value"] != "test" {
t.Fatalf("bad: %#v", result)
}
}
示例5: Configure
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
}, raws...)
if err != nil {
return err
}
errs := &packer.MultiError{}
// required configuration
templates := map[string]*string{
"path": &p.config.Path,
"manifest": &p.config.ManifestPath,
"box_name": &p.config.BoxName,
"box_dir": &p.config.BoxDir,
"version": &p.config.Version,
}
for key, ptr := range templates {
if *ptr == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("vagrant-path %s must be set", key))
}
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
示例6: Configure
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
// Defaults
if p.config.RemoveEthernet == "" {
p.config.RemoveEthernet = "false"
}
if p.config.RemoveFloppy == "" {
p.config.RemoveFloppy = "false"
}
if p.config.RemoveOpticalDrive == "" {
p.config.RemoveOpticalDrive = "false"
}
if p.config.VirtualHardwareVer == "" {
p.config.VirtualHardwareVer = "10"
}
// Accumulate any errors
errs := new(packer.MultiError)
if _, err := exec.LookPath("ovftool"); err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("ovftool not found: %s", err))
}
// First define all our templatable parameters that are _required_
templates := map[string]*string{
"datacenter": &p.config.Datacenter,
"host": &p.config.Host,
"password": &p.config.Password,
"username": &p.config.Username,
"datastore": &p.config.Datastore,
"vm_folder": &p.config.VMFolder,
}
for key, ptr := range templates {
if *ptr == "" {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("%s must be set", key))
}
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
示例7: Configure
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
if p.config.ChecksumTypes == nil {
p.config.ChecksumTypes = []string{"md5"}
}
if p.config.OutputPath == "" {
p.config.OutputPath = "packer_{{.BuildName}}_{{.BuilderType}}" + ".checksum"
}
errs := new(packer.MultiError)
if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error parsing target template: %s", err))
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
示例8: Prepare
func (p *Provisioner) Prepare(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
if p.config.Direction == "" {
p.config.Direction = "upload"
}
var errs *packer.MultiError
if p.config.Direction != "download" && p.config.Direction != "upload" {
errs = packer.MultiErrorAppend(errs,
errors.New("Direction must be one of: download, upload."))
}
if p.config.Destination == "" {
errs = packer.MultiErrorAppend(errs,
errors.New("Destination must be specified."))
}
if errs != nil && len(errs.Errors) > 0 {
return errs
}
return nil
}
示例9: NewConfig
func NewConfig(raws ...interface{}) (*Config, []string, error) {
c := new(Config)
warnings := []string{}
err := config.Decode(c, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return nil, warnings, err
}
var errs *packer.MultiError
if c.Target == "" {
errs = packer.MultiErrorAppend(errs, ErrTargetRequired)
}
if c.Content == "" && c.Source == "" {
warnings = append(warnings, "Both source file and contents are blank; target will have no content")
}
if c.Content != "" && c.Source != "" {
errs = packer.MultiErrorAppend(errs, ErrContentSourceConflict)
}
if errs != nil && len(errs.Errors) > 0 {
return nil, warnings, errs
}
return c, warnings, nil
}
示例10: Prepare
func (p *Provisioner) Prepare(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
var errs *packer.MultiError
if _, err := os.Stat(p.config.Source); err != nil {
errs = packer.MultiErrorAppend(errs,
fmt.Errorf("Bad source '%s': %s", p.config.Source, err))
}
if p.config.Destination == "" {
errs = packer.MultiErrorAppend(errs,
errors.New("Destination must be specified."))
}
if errs != nil && len(errs.Errors) > 0 {
return errs
}
return nil
}
示例11: Configure
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
if err != nil {
return err
}
errs := &packer.MultiError{}
errs = packer.MultiErrorAppend(errs, p.config.AccessConfig.Prepare(&p.config.ctx)...)
// required configuration
templates := map[string]*string{
"region": &p.config.Region,
"bucket": &p.config.Bucket,
"manifest": &p.config.ManifestPath,
"box_name": &p.config.BoxName,
"box_dir": &p.config.BoxDir,
"version": &p.config.Version,
}
// Template process
for key, ptr := range templates {
if *ptr == "" {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("%s must be set", key))
}
*ptr, err = interpolate.Render(*ptr, &p.config.ctx)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", key, err))
}
}
// setup the s3 bucket
auth, err := aws.GetAuth(p.config.AccessConfig.AccessKey, p.config.AccessConfig.SecretKey)
if err != nil {
errs = packer.MultiErrorAppend(errs, err)
}
// determine region
region, valid := aws.Regions[p.config.Region]
if valid {
p.s3 = s3.New(auth, region).Bucket(p.config.Bucket)
} else {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid region specified: %s", p.config.Region))
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
示例12: Configure
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{"output"},
},
}, raws...)
if err != nil {
return err
}
errs := new(packer.MultiError)
// required configuration
templates := map[string]*string{
"region": &p.config.Region,
"bucket": &p.config.Bucket,
"manifest": &p.config.ManifestPath,
"box_name": &p.config.BoxName,
"box_dir": &p.config.BoxDir,
"version": &p.config.Version,
}
for key, ptr := range templates {
if *ptr == "" {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("vagrant-s3 %s must be set", key))
}
}
// Template process
for key, ptr := range templates {
if err = interpolate.Validate(*ptr, &p.config.ctx); err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error parsing %s template: %s", key, err))
}
}
auth, err := aws.GetAuth(p.config.AccessKey, p.config.SecretKey)
if err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Unable to create Aws Authentication. Try providing keys 'access_key_id' and 'secret_key'"))
}
// determine region
region, valid := aws.Regions[p.config.Region]
if valid {
p.s3 = s3.New(auth, region).Bucket(p.config.Bucket)
} else {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("Invalid region specified: %s", p.config.Region))
}
if p.config.ACL == "" {
p.config.ACL = "public-read"
}
if len(errs.Errors) > 0 {
return errs
}
return nil
}
示例13: newConfig
func newConfig(raws ...interface{}) (*Config, []string, error) {
var c Config
err := config.Decode(&c, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: c.ctx,
}, raws...)
if err != nil {
return nil, nil, err
}
provideDefaultValues(&c)
setRuntimeValues(&c)
err = setSshValues(&c)
if err != nil {
return nil, nil, err
}
var errs *packer.MultiError
errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(c.ctx)...)
assertRequiredParametersSet(&c, errs)
if errs != nil && len(errs.Errors) > 0 {
return nil, nil, errs
}
return &c, nil, nil
}
示例14: Prepare
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs := &multierror.Error{}
err := config.Decode(&b.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &b.config.ctx,
}, raws...)
if err != nil {
errs = multierror.Append(errs, err)
}
if b.config.Comm.SSHUsername == "" {
b.config.Comm.SSHUsername = "root"
}
errs = multierror.Append(errs, b.config.AccessConfig.Prepare(&b.config.ctx)...)
errs = multierror.Append(errs, b.config.SourceMachineConfig.Prepare(&b.config.ctx)...)
errs = multierror.Append(errs, b.config.Comm.Prepare(&b.config.ctx)...)
errs = multierror.Append(errs, b.config.TargetImageConfig.Prepare(&b.config.ctx)...)
if b.config.Comm.SSHPrivateKey == "" {
b.config.Comm.SSHPrivateKey = b.config.KeyMaterial
}
return nil, errs.ErrorOrNil()
}
示例15: Configure
func (p *PostProcessor) Configure(raws ...interface{}) error {
err := config.Decode(&p.config, &config.DecodeOpts{
Interpolate: true,
InterpolateContext: &p.config.ctx,
InterpolateFilter: &interpolate.RenderFilter{
Exclude: []string{},
},
}, raws...)
errs := new(packer.MultiError)
// If there is no explicit number of Go threads to use, then set it
if os.Getenv("GOMAXPROCS") == "" {
runtime.GOMAXPROCS(runtime.NumCPU())
}
if p.config.OutputPath == "" {
p.config.OutputPath = "packer_{{.BuildName}}_{{.Provider}}"
}
if err = interpolate.Validate(p.config.OutputPath, &p.config.ctx); err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error parsing target template: %s", err))
}
templates := map[string]*string{
"output": &p.config.OutputPath,
}
if p.config.CompressionLevel > pgzip.BestCompression {
p.config.CompressionLevel = pgzip.BestCompression
}
// Technically 0 means "don't compress" but I don't know how to
// differentiate between "user entered zero" and "user entered nothing".
// Also, why bother creating a compressed file with zero compression?
if p.config.CompressionLevel == -1 || p.config.CompressionLevel == 0 {
p.config.CompressionLevel = pgzip.DefaultCompression
}
for key, ptr := range templates {
if *ptr == "" {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("%s must be set", key))
}
*ptr, err = interpolate.Render(p.config.OutputPath, &p.config.ctx)
if err != nil {
errs = packer.MultiErrorAppend(
errs, fmt.Errorf("Error processing %s: %s", key, err))
}
}
p.config.detectFromFilename()
if len(errs.Errors) > 0 {
return errs
}
return nil
}