2015-03-20 16:59:48 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2015-08-06 16:26:41 +00:00
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2015-08-06 16:37:08 +00:00
|
|
|
"github.com/aws/aws-sdk-go/aws/credentials"
|
2015-08-06 16:26:41 +00:00
|
|
|
"github.com/aws/aws-sdk-go/service/iam"
|
2015-03-20 16:59:48 +00:00
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
)
|
|
|
|
|
|
|
|
func clientIAM(s logical.Storage) (*iam.IAM, error) {
|
2015-04-19 05:21:31 +00:00
|
|
|
entry, err := s.Get("config/root")
|
2015-03-20 16:59:48 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if entry == nil {
|
|
|
|
return nil, fmt.Errorf(
|
|
|
|
"root credentials haven't been configured. Please configure\n" +
|
2015-04-19 05:21:31 +00:00
|
|
|
"them at the 'config/root' endpoint")
|
2015-03-20 16:59:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var config rootConfig
|
|
|
|
if err := entry.DecodeJSON(&config); err != nil {
|
|
|
|
return nil, fmt.Errorf("error reading root configuration: %s", err)
|
|
|
|
}
|
|
|
|
|
2015-08-06 16:37:08 +00:00
|
|
|
creds := credentials.NewStaticCredentials(config.AccessKey, config.SecretKey, "")
|
|
|
|
awsConfig := &aws.Config{
|
|
|
|
Credentials: creds,
|
|
|
|
Region: aws.String(config.Region),
|
|
|
|
}
|
|
|
|
return iam.New(awsConfig), nil
|
2015-03-20 16:59:48 +00:00
|
|
|
}
|