initialize the s3 lock path in one place

This commit is contained in:
James Bardin 2017-03-30 13:36:54 -04:00
parent 6980e14191
commit 54aa466b74
1 changed files with 8 additions and 5 deletions

View File

@ -113,8 +113,7 @@ func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) {
return "", nil return "", nil
} }
stateName := fmt.Sprintf("%s/%s", c.bucketName, c.path) info.Path = c.lockPath()
info.Path = stateName
if info.ID == "" { if info.ID == "" {
lockID, err := uuid.GenerateUUID() lockID, err := uuid.GenerateUUID()
@ -127,7 +126,7 @@ func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) {
putParams := &dynamodb.PutItemInput{ putParams := &dynamodb.PutItemInput{
Item: map[string]*dynamodb.AttributeValue{ Item: map[string]*dynamodb.AttributeValue{
"LockID": {S: aws.String(stateName)}, "LockID": {S: aws.String(c.lockPath())},
"Info": {S: aws.String(string(info.Marshal()))}, "Info": {S: aws.String(string(info.Marshal()))},
}, },
TableName: aws.String(c.lockTable), TableName: aws.String(c.lockTable),
@ -153,7 +152,7 @@ func (c *RemoteClient) Lock(info *state.LockInfo) (string, error) {
func (c *RemoteClient) getLockInfo() (*state.LockInfo, error) { func (c *RemoteClient) getLockInfo() (*state.LockInfo, error) {
getParams := &dynamodb.GetItemInput{ getParams := &dynamodb.GetItemInput{
Key: map[string]*dynamodb.AttributeValue{ Key: map[string]*dynamodb.AttributeValue{
"LockID": {S: aws.String(fmt.Sprintf("%s/%s", c.bucketName, c.path))}, "LockID": {S: aws.String(c.lockPath())},
}, },
ProjectionExpression: aws.String("LockID, Info"), ProjectionExpression: aws.String("LockID, Info"),
TableName: aws.String(c.lockTable), TableName: aws.String(c.lockTable),
@ -202,7 +201,7 @@ func (c *RemoteClient) Unlock(id string) error {
params := &dynamodb.DeleteItemInput{ params := &dynamodb.DeleteItemInput{
Key: map[string]*dynamodb.AttributeValue{ Key: map[string]*dynamodb.AttributeValue{
"LockID": {S: aws.String(fmt.Sprintf("%s/%s", c.bucketName, c.path))}, "LockID": {S: aws.String(c.lockPath())},
}, },
TableName: aws.String(c.lockTable), TableName: aws.String(c.lockTable),
} }
@ -214,3 +213,7 @@ func (c *RemoteClient) Unlock(id string) error {
} }
return nil return nil
} }
func (c *RemoteClient) lockPath() string {
return fmt.Sprintf("%s/%s", c.bucketName, c.path)
}