Skip to content

Commit

Permalink
update dynamodb client
Browse files Browse the repository at this point in the history
  • Loading branch information
kelseyhightower committed Feb 18, 2016
1 parent abba746 commit 5a5e762
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
29 changes: 14 additions & 15 deletions backends/dynamodb/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package dynamodb
import (
"os"

"github.com/awslabs/aws-sdk-go/aws"
"github.com/awslabs/aws-sdk-go/aws/credentials"
"github.com/awslabs/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/kelseyhightower/confd/log"
)

Expand All @@ -23,7 +23,6 @@ func NewDynamoDBClient(table string) (*Client, error) {
creds := credentials.NewChainCredentials(
[]credentials.Provider{
&credentials.EnvProvider{},
&credentials.EC2RoleProvider{},
})
_, err := creds.Get()
if err != nil {
Expand All @@ -32,11 +31,14 @@ func NewDynamoDBClient(table string) (*Client, error) {
var c *aws.Config
if os.Getenv("DYNAMODB_LOCAL") != "" {
log.Debug("DYNAMODB_LOCAL is set")
c = &aws.Config{Endpoint: "http://localhost:8000"}
endpoint := "http://localhost:8000"
c = &aws.Config{
Endpoint: &endpoint,
}
} else {
c = nil
}
d := dynamodb.New(c)
d := dynamodb.New(nil, c)
// Check if the table exists
_, err = d.DescribeTable(&dynamodb.DescribeTableInput{TableName: &table})
if err != nil {
Expand All @@ -50,18 +52,15 @@ func (c *Client) GetValues(keys []string) (map[string]string, error) {
vars := make(map[string]string)
for _, key := range keys {
// Check if we can find the single item
g, err := c.client.GetItem(&dynamodb.GetItemInput{
Key: &map[string]*dynamodb.AttributeValue{
"key": &dynamodb.AttributeValue{S: aws.String(key)},
},
TableName: &c.table})

m := make(map[string]*dynamodb.AttributeValue)
m["key"] = &dynamodb.AttributeValue{S: aws.String(key)}
g, err := c.client.GetItem(&dynamodb.GetItemInput{Key: m, TableName: &c.table})
if err != nil {
return vars, err
}

if g.Item != nil {
if val, ok := (*(g.Item))["value"]; ok {
if val, ok := g.Item["value"]; ok {
vars[key] = *val.S
continue
}
Expand All @@ -70,7 +69,7 @@ func (c *Client) GetValues(keys []string) (map[string]string, error) {
// Check for nested keys
q, err := c.client.Scan(
&dynamodb.ScanInput{
ScanFilter: &map[string]*dynamodb.Condition{
ScanFilter: map[string]*dynamodb.Condition{
"key": &dynamodb.Condition{
AttributeValueList: []*dynamodb.AttributeValue{
&dynamodb.AttributeValue{S: aws.String(key)}},
Expand All @@ -85,7 +84,7 @@ func (c *Client) GetValues(keys []string) (map[string]string, error) {
}

for _, i := range q.Items {
item := *i
item := i
if val, ok := item["value"]; ok {
vars[*item["key"].S] = *val.S
continue
Expand Down
3 changes: 2 additions & 1 deletion build
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash

echo "Building confd..."
gb build all
mkdir -p bin
go build -o bin/confd .
2 changes: 1 addition & 1 deletion test
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env bash

echo "Running tests..."
gb test
go test

0 comments on commit 5a5e762

Please sign in to comment.