Skip to content

Commit

Permalink
Return actors instead of strings. Closes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
abedra committed Oct 21, 2015
1 parent a1185ed commit b5a2f73
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 27 deletions.
7 changes: 4 additions & 3 deletions actor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,17 @@ import (

type Actor struct {
Id string
Reason string
Whitelisted bool
Blacklisted bool
Marked bool
GeoIP *geoip.GeoIPRecord
}

type Summary struct {
Blacklisted []string
Whitelisted []string
Marked []string
Blacklisted []Actor
Whitelisted []Actor
Marked []Actor
}

func geoipLookup(configuration *Configuration, actor string) *geoip.GeoIPRecord {
Expand Down
2 changes: 1 addition & 1 deletion blacklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func BlacklistHandler(configuration *Configuration, response http.ResponseWriter

connection := connect(configuration.Redis.Host, configuration.Redis.Port)

blacklisted := replyToArray(connection.Cmd("KEYS", "*:repsheet:ip:blacklisted"))
blacklisted := replyToActors(configuration, connection.Cmd("KEYS", "*:repsheet:ip:blacklisted"))
templates, _ := template.ParseFiles(configuration.TemplateFor("layout"), configuration.TemplateFor("blacklist"))
summary := Summary{Blacklisted: blacklisted}
templates.ExecuteTemplate(response, "layout", Page{Summary: summary, Active: "blacklist"})
Expand Down
6 changes: 3 additions & 3 deletions dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ func DashboardHandler(configuration *Configuration, response http.ResponseWriter

connection := connect(configuration.Redis.Host, configuration.Redis.Port)

blacklisted := replyToArray(connection.Cmd("KEYS", "*:repsheet:ip:blacklisted"))
whitelisted := replyToArray(connection.Cmd("KEYS", "*:repsheet:ip:whitelisted"))
marked := replyToArray(connection.Cmd("KEYS", "*:repsheet:ip:marked"))
blacklisted := replyToActors(configuration, connection.Cmd("KEYS", "*:repsheet:ip:blacklisted"))
whitelisted := replyToActors(configuration, connection.Cmd("KEYS", "*:repsheet:ip:whitelisted"))
marked := replyToActors(configuration, connection.Cmd("KEYS", "*:repsheet:ip:marked"))
templates, _ := template.ParseFiles(configuration.TemplateFor("layout"), configuration.TemplateFor("dashboard"))
summary := Summary{Blacklisted: blacklisted, Whitelisted: whitelisted, Marked: marked}
templates.ExecuteTemplate(response, "layout", Page{Summary: summary, Active: "dashboard"})
Expand Down
2 changes: 1 addition & 1 deletion marklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func MarklistHandler(configuration *Configuration, response http.ResponseWriter,

connection := connect(configuration.Redis.Host, configuration.Redis.Port)

marked := replyToArray(connection.Cmd("KEYS", "*:repsheet:ip:marked"))
marked := replyToActors(configuration, connection.Cmd("KEYS", "*:repsheet:ip:marked"))
templates, _ := template.ParseFiles(configuration.TemplateFor("layout"), configuration.TemplateFor("marklist"))
summary := Summary{Marked: marked}
templates.ExecuteTemplate(response, "layout", Page{Summary: summary, Active: "marklist"})
Expand Down
13 changes: 13 additions & 0 deletions redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,16 @@ func replyToArray(reply *redis.Reply) []string {

return results
}

func replyToActors(configuration *Configuration, reply *redis.Reply) []Actor {
var actors []Actor
connection := connect(configuration.Redis.Host, configuration.Redis.Port)
for i := 0; i < len(reply.Elems); i++ {
actor, _ := reply.Elems[i].Str()
reason := connection.Cmd("GET", actor)
reasonString, _ := reason.Str()
actors = append(actors, Actor{Id: strings.Split(actor, ":")[0], Reason: reasonString})
}

return actors
}
6 changes: 3 additions & 3 deletions templates/blacklist.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ <h3>All Blacklisted Actors</h3>
<tbody>
{{range .Summary.Blacklisted}}
<tr>
<td>{{.}}</td>
<td>placeholder</td>
<td><a href="/actors/{{.}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
<td>{{.Id}}</td>
<td>{{.Reason}}</td>
<td><a href="/actors/{{.Id}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
</tr>
{{ end }}
</tbody>
Expand Down
12 changes: 6 additions & 6 deletions templates/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ <h3>Blacklisted Actors</h3>
<tbody>
{{range .Summary.Blacklisted}}
<tr>
<td>{{.}}</td>
<td><a href="actors/{{.}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
<td>{{.Id}}</td>
<td><a href="actors/{{.Id}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
</tr>
{{end}}
</tbody>
Expand Down Expand Up @@ -98,8 +98,8 @@ <h3>Marked Actors</h3>
<tbody>
{{range .Summary.Marked}}
<tr>
<td>{{.}}</td>
<td><a href="actors/{{.}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
<td>{{.Id}}</td>
<td><a href="actors/{{.Id}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
</tr>
{{ end }}
</tbody>
Expand Down Expand Up @@ -131,8 +131,8 @@ <h3>Whitelisted Actors</h3>
<tbody>
{{range .Summary.Whitelisted}}
<tr>
<td>{{.}}</td>
<td><a href="actors/{{.}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
<td>{{.Id}}</td>
<td><a href="actors/{{.Id}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
</tr>
{{end}}
</tbody>
Expand Down
6 changes: 3 additions & 3 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -75,21 +75,21 @@ <h3 class="logo-head">Repsheet Visualizer</h3>
</li>

<li {{if eq .Active "blacklist"}} class="active" {{end}}>
<a href="blacklist">
<a href="/blacklist">
<i class="fa fa-ban"></i>
Blacklist
</a>
</li>

<li {{if eq .Active "marklist"}} class="active" {{end}}>
<a href="marklist">
<a href="/marklist">
<i class="fa fa-gavel"></i>
Marklist
</a>
</li>

<li {{if eq .Active "whitelist"}} class="active" {{end}}>
<a href="whitelist">
<a href="/whitelist">
<i class="fa fa-thumbs-o-up"></i>
Whitelist
</a>
Expand Down
6 changes: 3 additions & 3 deletions templates/marklist.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ <h3>All Marked Actors</h3>
<tbody>
{{range .Summary.Marked}}
<tr>
<td>{{.}}</td>
<td>placeholder</td>
<td><a href="/actors/{{.}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
<td>{{.Id}}</td>
<td>{{.Reason}}</td>
<td><a href="/actors/{{.Id}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
</tr>
{{ end }}
</tbody>
Expand Down
6 changes: 3 additions & 3 deletions templates/whitelist.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ <h3>All Whitelisted Actors</h3>
<tbody>
{{range .Summary.Whitelisted}}
<tr>
<td>{{.}}</td>
<td>placeholder</td>
<td><a href="/actors/{{.}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
<td>{{.Id}}</td>
<td>{{.Reason}}</td>
<td><a href="/actors/{{.Id}}" class="btn btn-xs btn-tertiary">View &nbsp;&nbsp;<i class="fa fa-chevron-right"></i></a></td>
</tr>
{{ end }}
</tbody>
Expand Down
2 changes: 1 addition & 1 deletion whitelist.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func WhitelistHandler(configuration *Configuration, response http.ResponseWriter

connection := connect(configuration.Redis.Host, configuration.Redis.Port)

whitelisted := replyToArray(connection.Cmd("KEYS", "*:repsheet:ip:whitelisted"))
whitelisted := replyToActors(configuration, connection.Cmd("KEYS", "*:repsheet:ip:whitelisted"))
templates, _ := template.ParseFiles(configuration.TemplateFor("layout"), configuration.TemplateFor("whitelist"))
summary := Summary{Whitelisted: whitelisted}
templates.ExecuteTemplate(response, "layout", Page{Summary: summary, Active: "whitelist"})
Expand Down

0 comments on commit b5a2f73

Please sign in to comment.