builder/amazon/common: AccessConfig for standard access config

This commit is contained in:
Mitchell Hashimoto 2013-07-16 13:08:19 +09:00
parent 980841b6c0
commit 5aced3f339
3 changed files with 24 additions and 5 deletions

View File

@ -0,0 +1,21 @@
package common
import (
"github.com/mitchellh/goamz/aws"
)
// AccessConfig is for common configuration related to AWS access
type AccessConfig struct {
AccessKey string `mapstructure:"access_key"`
SecretKey string `mapstructure:"secret_key"`
}
// Auth returns a valid aws.Auth object for access to AWS services, or
// an error if the authentication couldn't be resolved.
func (c *AccessConfig) Auth() (aws.Auth, error) {
return aws.GetAuth(c.AccessKey, c.SecretKey)
}
func (c *AccessConfig) Validate() []error {
return nil
}

View File

@ -11,6 +11,7 @@ import (
"github.com/mitchellh/goamz/aws" "github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/ec2" "github.com/mitchellh/goamz/ec2"
"github.com/mitchellh/multistep" "github.com/mitchellh/multistep"
awscommon "github.com/mitchellh/packer/builder/amazon/common"
"github.com/mitchellh/packer/builder/common" "github.com/mitchellh/packer/builder/common"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
"log" "log"
@ -22,9 +23,7 @@ import (
const BuilderId = "mitchellh.amazonebs" const BuilderId = "mitchellh.amazonebs"
type config struct { type config struct {
// Access information awscommon.AccessConfig `mapstructure:",squash"`
AccessKey string `mapstructure:"access_key"`
SecretKey string `mapstructure:"secret_key"`
// Information for the source instance // Information for the source instance
Region string Region string
@ -123,7 +122,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
panic("region not found") panic("region not found")
} }
auth, err := aws.GetAuth(b.config.AccessKey, b.config.SecretKey) auth, err := b.config.AccessConfig.Auth()
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -12,4 +12,3 @@ func TestBuilder_ImplementsBuilder(t *testing.T) {
t.Fatalf("Builder should be a builder") t.Fatalf("Builder should be a builder")
} }
} }