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

View File

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