Skip to content

Commit

Permalink
simplify duplicated code
Browse files Browse the repository at this point in the history
  • Loading branch information
shinebayar-g committed Nov 2, 2021
1 parent 0bf41e8 commit 10247c0
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,19 +120,9 @@ func main() {
for {
select {
case msg := <-messages:
if msg.Type == "container" && msg.Action == "start" {
if ufwManaged := msg.Actor.Attributes["UFW_MANAGED"]; isUfwManaged(ufwManaged) {
container, err := cli.ContainerInspect(ctx, msg.ID)
if err != nil {
fmt.Println("ufw-docker-automated: Couldn't inspect container:", err)
continue
}
ch <- ufwEvent{container, msg}
}
}
// We cannot get container network details once it's stopped, So
// we're deleting ufw rules as soon as container receives stop signal before it's stopped.
if msg.Type == "container" && msg.Action == "kill" {
if msg.Type == "container" && (msg.Action == "start" || msg.Action == "kill") {
if ufwManaged := msg.Actor.Attributes["UFW_MANAGED"]; isUfwManaged(ufwManaged) {
container, err := cli.ContainerInspect(ctx, msg.ID)
if err != nil {
Expand Down

0 comments on commit 10247c0

Please sign in to comment.