Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent possible duplicate ECS services. #884

Merged
merged 11 commits into from
Jun 17, 2016
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

**Bugs**

* Fixed a bug where multiple duplicate ECS services could be created by the CloudFormation backend, when using the `Custom::ECSService` resource [#884](https://github.com/remind101/empire/pull/884).

**Performance**

**Security**
Expand Down
5 changes: 4 additions & 1 deletion docs/cloudformation.json
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,10 @@
},

"CustomResourcesQueue": {
"Type": "AWS::SQS::Queue"
"Type": "AWS::SQS::Queue",
"Properties": {
"VisibilityTimeout": "1800"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems really long - you handle de-duping requests here as well, right? Otherwise we could see things being re-submitted 30 minutes later after a crash or something. In the case where de-duping is handled, what's the idea behind making this so long? Would 5 minutes be sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good point. Probably the best thing to do would be to leave the default, and then use the ChangeMessageVisibility api call to increase it when needed.

I'll revert the current change for now, since the de-duping is sufficient to fix the current issue.

}
},

"CustomResourcesQueuePolicy": {
Expand Down
29 changes: 29 additions & 0 deletions pkg/base62/base62.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Package base62 implements conversion to and from base62. Useful for url shorteners.
package base62
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was stripped from an internal project.


// characters used for conversion
const alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

// converts number to base62
func Encode(number uint64) string {
if number == 0 {
return string(alphabet[0])
}

chars := make([]byte, 0)

length := uint64(len(alphabet))

for number > 0 {
result := number / length
remainder := number % length
chars = append(chars, alphabet[remainder])
number = result
}

for i, j := 0, len(chars)-1; i < j; i, j = i+1, j-1 {
chars[i], chars[j] = chars[j], chars[i]
}

return string(chars)
}
24 changes: 24 additions & 0 deletions pkg/base62/base62_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package base62

import "testing"

func Test_Encode(t *testing.T) {
tests := []struct {
Input uint64
Expected string
}{
{1024, "gw"},
{512347, "29hF"},
{5369806, "mwVM"},
{2147483647, "2lkCB1"},
{0xFFFFFFFFFFFFFFFF, "lYGhA16ahyf"}, // Max uint64
}

for i, test := range tests {
e := Encode(test.Input)

if e != test.Expected {
t.Errorf("%v: Got %v, want %v", i, e, test.Expected)
}
}
}
21 changes: 21 additions & 0 deletions pkg/hashstructure/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Mitchell Hashimoto

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
62 changes: 62 additions & 0 deletions pkg/hashstructure/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# hashstructure [![GoDoc](https://godoc.org/github.com/mitchellh/hashstructure?status.svg)](https://godoc.org/github.com/mitchellh/hashstructure)

hashstructure is a Go library for creating a unique hash value
for arbitrary values in Go.

This can be used to key values in a hash (for use in a map, set, etc.)
that are complex. The most common use case is comparing two values without
sending data across the network, caching values locally (de-dup), and so on.

## Features

* Hash any arbitrary Go value, including complex types.

* Tag a struct field to ignore it and not affect the hash value.

* Tag a slice type struct field to treat it as a set where ordering
doesn't affect the hash code but the field itself is still taken into
account to create the hash value.

* Optionally specify a custom hash function to optimize for speed, collision
avoidance for your data set, etc.

## Installation

Standard `go get`:

```
$ go get github.com/mitchellh/hashstructure
```

## Usage & Example

For usage and examples see the [Godoc](http://godoc.org/github.com/mitchellh/hashstructure).

A quick code example is shown below:

```go
type ComplexStruct struct {
Name string
Age uint
Metadata map[string]interface{}
}

v := ComplexStruct{
Name: "mitchellh",
Age: 64,
Metadata: map[string]interface{}{
"car": true,
"location": "California",
"siblings": []string{"Bob", "John"},
},
}

hash, err := hashstructure.Hash(v, nil)
if err != nil {
panic(err)
}

fmt.Printf("%d", hash)
// Output:
// 2307517237273902113
```
Loading