Skip to content

Commit

Permalink
Embed keygen form (#231)
Browse files Browse the repository at this point in the history
* embed keygen form

* Added additional tests

* Updated generation responses, fixed router subscription

* added html template
  • Loading branch information
sarge authored and kelindar committed May 23, 2019
1 parent 9c5e9ec commit 8c23cb4
Show file tree
Hide file tree
Showing 11 changed files with 709 additions and 31 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
debug
*.log
*.sst
*.html
build/*
*.log
*.bat
Expand Down
5 changes: 4 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/emitter-io/address v1.0.0
github.com/emitter-io/config v1.0.0
github.com/emitter-io/stats v1.0.1
github.com/golang/protobuf v1.3.1 // indirect
github.com/golang/snappy v0.0.1
github.com/gorilla/websocket v1.4.0
github.com/kelindar/binary v1.0.1
Expand All @@ -18,6 +19,8 @@ require (
github.com/klauspost/cpuid v1.2.0 // indirect
github.com/pkg/errors v0.0.0-20181008045315-2233dee583dc // indirect
github.com/prometheus/client_golang v0.9.2
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414 // indirect
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd // indirect
github.com/stretchr/objx v0.1.1 // indirect
github.com/stretchr/testify v1.3.0
github.com/tidwall/btree v0.0.0-20170113224114-9876f1454cf0 // indirect
Expand All @@ -30,6 +33,6 @@ require (
github.com/tidwall/tinyqueue v0.0.0-20180302190814-1e39f5511563 // indirect
github.com/valyala/fasthttp v1.2.0
github.com/weaveworks/mesh v0.0.0-20190204141226-512bdb7b3cb7
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284
gopkg.in/alexcesaro/statsd.v2 v2.0.0
)
15 changes: 13 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ github.com/emitter-io/stats v1.0.1/go.mod h1:4hKrGsT8bS+kMlTNsCyY1r2j8Jsq25U1+Jp
github.com/go-ini/ini v1.39.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.1 h1:YF8+flBXS5eO826T4nzqPrxfhQThhXl0YzfuUPu4SBg=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db h1:woRePGFeVFfLKN/pOkfl+p/TAqKOfFu+7KPlMVpok/w=
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
Expand Down Expand Up @@ -65,6 +67,10 @@ github.com/prometheus/common v0.0.0-20181126121408-4724e9255275 h1:PnBWHBf+6L0jO
github.com/prometheus/common v0.0.0-20181126121408-4724e9255275/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nLJdBg+pBmGgkJlSaKC2KaQmTCk1XDtE=
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414 h1:IYVb70m/qpJGjyZV2S4qbdSDnsMl+w9nsQ2iQedf1HI=
github.com/shurcooL/httpfs v0.0.0-20181222201310-74dc9339e414/go.mod h1:ZY1cvUeJuFPAdZ/B6v7RHavJWZn2YPVFQ1OSXhCGOkg=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd h1:ug7PpSOB5RBPK1Kg6qskGBoP3Vnj/aNYFTznWvlkGo0=
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd/go.mod h1:TrYk7fJVaAttu97ZZKrO9UbRa8izdowaMIZcxYMbVaw=
github.com/stretchr/objx v0.0.0-20180825064932-ef50b0de2877 h1:Uk9JZ6L7yGoJ0V/gy05d5cSnPGf4bEP7AN1DeEJuX4E=
github.com/stretchr/objx v0.0.0-20180825064932-ef50b0de2877/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down Expand Up @@ -101,15 +107,20 @@ github.com/weaveworks/mesh v0.0.0-20190204141226-512bdb7b3cb7/go.mod h1:mcON9Ws1
golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e h1:IzypfodbhbnViNUO/MEh0FzCUooG97cIGfdggUrUSyU=
golang.org/x/crypto v0.0.0-20181015023909-0c41d7ab0a0e/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734 h1:p/H982KKEjUnLJkM3tt/LemDnOc1GiZL5FCVlORJ5zo=
golang.org/x/crypto v0.0.0-20190426145343-a29dc8fdc734/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284 h1:rlLehGeYg6jfoyz/eDqDU1iRXLKfR42nnNh57ytKEWo=
golang.org/x/crypto v0.0.0-20190506204251-e1dfcc566284/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180911220305-26e67e76b6c3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f h1:Bl/8QSvNqXvPGPGXa2z5xUTmV7VDcZyvRZ+QQXkXTZQ=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
Expand Down
184 changes: 184 additions & 0 deletions internal/broker/assets.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions internal/broker/assets/keygen.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" crossorigin="anonymous">
<style>
pre { border: none; padding: 5px; background-color: transparent}
.string { color: #d35400; }
.number { color: #8e44ad; }
.boolean { color: #27ae60; }
.null { color: #c0392b; }
.key { color: #2980b9; }
</style>
</head>
<body>
<div class="container" id="content">
<div class="row">
<form method="post">
<div class="col-md-offset-2 col-md-8">
<h3>Key Generation</h3>
<div class="well">
<div class="form-group">
<label for="keygenKey">Secret Key</label>
<input type="text" class="form-control" name="key" value="{{.Key}}" required="true" placeholder="[Required] Your secret key">
</div>
<div class="form-group">
<label for="keygenChannel">Target Channel</label>
<input type="text" class="form-control" name="channel" value="{{.Channel}}" required="true" placeholder="[Required] The target channel to secure with the key">
</div>
<div class="form-group">
<label for="keygenTtl">Time-To-Live</label>
<input type="number" class="form-control" name="ttl" value={{.TTL}} placeholder="Number of seconds after which the key will expire">
</div>
<div class="form-group">
<label>Security Access</label>
<div class="checkbox"><label><input name="sub" {{ isChecked .Sub }} type="checkbox"> Allow <b>read</b> (subscribe) from the channel</label></div>
<div class="checkbox"><label><input name="pub" {{ isChecked .Pub }} type="checkbox"> Allow <b>write</b> (publish) to the channel</label></div>
<div class="checkbox"><label><input name="store" {{ isChecked .Store }} type="checkbox"> Allow <b>store</b> messages into the channel store</label></div>
<div class="checkbox"><label><input name="load" {{ isChecked .Load }} type="checkbox"> Allow <b>load</b> messages from the channel store</label></div>
<div class="checkbox"><label><input name="presence" {{ isChecked .Presence }} type="checkbox"> Allow <b>presence</b> querying </label></div>
<div class="checkbox"><label><input name="extend" {{ isChecked .Extend }} type="checkbox"> Allow <b>extending</b> for private sub-channels</label></div>
</div>

<div class="form-group">
<button id="keygen" type="submit" class="btn btn-default">Generate Key</button>
</div>
<pre id="keygenResponse">{{.Response}}</pre>
</div>
</div>

</form>
</div>
</div>
</body>
</html>
23 changes: 23 additions & 0 deletions internal/broker/generate/assets_gen.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// +build ignore

package main

import (
"log"
"net/http"

"github.com/shurcooL/vfsgen"
)

func main() {

var fs http.FileSystem = http.Dir("./internal/broker/assets")

err := vfsgen.Generate(fs, vfsgen.Options{
Filename: "./internal/broker/assets.go",
PackageName: "broker",
})
if err != nil {
log.Fatalln(err)
}
}
Loading

0 comments on commit 8c23cb4

Please sign in to comment.