Compare commits
No commits in common. "Xe/feat/eclier" and "Xe/feat/twirp" have entirely different histories.
Xe/feat/ec
...
Xe/feat/tw
|
@ -1,2 +0,0 @@
|
|||
/bin
|
||||
/.git
|
13
Dockerfile
13
Dockerfile
|
@ -1,13 +0,0 @@
|
|||
FROM xena/go-mini:1.9.2
|
||||
|
||||
ENV CGO_ENABLED=0
|
||||
ENV PATH=$PATH:/root/go/bin
|
||||
|
||||
RUN apk add --no-cache git protobuf \
|
||||
&& go download
|
||||
|
||||
COPY . /root/go/src/git.xeserv.us/xena/route
|
||||
|
||||
RUN cd /root/go/src/git.xeserv.us/xena/route \
|
||||
&& go run ./cmd/mage/main.go -v tools generate build \
|
||||
&& rm -rf /root/go/pkg /root/go/bin
|
|
@ -1,24 +1,6 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ThomasRooney/gexpect"
|
||||
packages = ["."]
|
||||
revision = "5482f03509440585d13d8f648989e05903001842"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/eclier"
|
||||
packages = ["."]
|
||||
revision = "3cde6c5f47044f4875c4b7fe6b12e4e6000608ea"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/gluanetrc"
|
||||
packages = ["."]
|
||||
revision = "af26c7928995089c19896bcc5d0f8ba48a7930a9"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/gopreload"
|
||||
|
@ -43,10 +25,7 @@
|
|||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/x"
|
||||
packages = [
|
||||
"tools/glue/libs/gluaexpect",
|
||||
"tools/glue/libs/gluasimplebox"
|
||||
]
|
||||
packages = ["tools/svc/credentials/jwt"]
|
||||
revision = "860ea0dedb8beb93b60717510eabca2ef5ffe150"
|
||||
|
||||
[[projects]]
|
||||
|
@ -70,12 +49,6 @@
|
|||
revision = "5f10fee965225ac1eecdc234c09daf5cd9e7f7b6"
|
||||
version = "v1.2.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ailncode/gluaxmlpath"
|
||||
packages = ["."]
|
||||
revision = "6ce478ecb4a60c4fc8929838e0b21b7fb7ca7440"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/alecthomas/template"
|
||||
|
@ -193,18 +166,6 @@
|
|||
revision = "7cd7992b3bc86f920394f8de92c13900da1a46b7"
|
||||
version = "v3.2.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluahttp"
|
||||
packages = ["."]
|
||||
revision = "b4bfe0c50fea948dcbf3966e120996d6607bbd89"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluaurl"
|
||||
packages = ["."]
|
||||
revision = "31cbb9bef199454415879f2e6d609d1136d60cad"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/coreos/bbolt"
|
||||
packages = ["."]
|
||||
|
@ -235,24 +196,12 @@
|
|||
packages = ["."]
|
||||
revision = "fcd59fca7456889be7f2ad4515b7612fd6acef31"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/gchaincl/dotsql"
|
||||
packages = ["."]
|
||||
revision = "5487b6a5fc12870425fc14d9e05a3fabddd91d7e"
|
||||
version = "v0.1.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/go-ini/ini"
|
||||
packages = ["."]
|
||||
revision = "32e4c1e6bc4e7d0d8451aa6b75200d19e37a536a"
|
||||
version = "v1.32.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/go-serve/bindatafs"
|
||||
packages = ["."]
|
||||
revision = "1f30d36183f010db5e83986b3554c1a1d9f32d47"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/golang/protobuf"
|
||||
|
@ -364,7 +313,7 @@
|
|||
"hcldec",
|
||||
"hclparse"
|
||||
]
|
||||
revision = "613331e829930a2321c1de7227c9483d9c76c3f4"
|
||||
revision = "83451bb547db5e521b21cdf02fc0018c5790f6d5"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
|
@ -411,12 +360,6 @@
|
|||
packages = ["."]
|
||||
revision = "683f49123a33db61abfb241b7ac5e4af4dc54d55"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/howeyc/gopass"
|
||||
packages = ["."]
|
||||
revision = "bf9dde6d0d2c004a008c27aaee91170c786f6db8"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/jmespath/go-jmespath"
|
||||
packages = ["."]
|
||||
|
@ -443,12 +386,6 @@
|
|||
packages = ["."]
|
||||
revision = "ae77be60afb1dcacde03767a8c37337fad28ac14"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kballard/go-shellquote"
|
||||
packages = ["."]
|
||||
revision = "cd60e84ee657ff3dc51de0b4f55dd299a3e136f2"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/klauspost/cpuid"
|
||||
packages = ["."]
|
||||
|
@ -461,75 +398,18 @@
|
|||
revision = "6bb6130ff6a76a904c1841707d65603aec9cc288"
|
||||
version = "v1.6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaenv"
|
||||
packages = ["."]
|
||||
revision = "2888db6bbe38923d59c42e443895875cc8ce0820"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluafs"
|
||||
packages = ["."]
|
||||
revision = "01391ed2d7ab89dc80157605b073403f960aa223"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaquestion"
|
||||
packages = ["."]
|
||||
revision = "311437c29ba54d027ad2af383661725ae2bfdcdc"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluassh"
|
||||
packages = ["."]
|
||||
revision = "2a7bd48d7568de8230c87ac1ef4a4c481e45814d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluatemplate"
|
||||
packages = ["."]
|
||||
revision = "d9e2c9d6b00f069a9da377a9ac529c827c1c7d71"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluayaml"
|
||||
packages = ["."]
|
||||
revision = "6fe413d49d73d785510ecf1529991ab0573e96c7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kr/fs"
|
||||
packages = ["."]
|
||||
revision = "2788f0dbd16903de03cb8186e5c7d97b69ad387b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kr/pretty"
|
||||
packages = ["."]
|
||||
revision = "cfb55aafdaf3ec08f0db22699ab822c50091b1c4"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/kr/pty"
|
||||
packages = ["."]
|
||||
revision = "282ce0e5322c82529687d609ee670fac7c7d917c"
|
||||
version = "v1.1.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kr/text"
|
||||
packages = ["."]
|
||||
revision = "7cafcd837844e784b526369c9bce262804aebc60"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/lib/pq"
|
||||
packages = [
|
||||
".",
|
||||
"oid"
|
||||
]
|
||||
revision = "27ea5d92de30060e7121ddd543fe14e9a327e0cc"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/lucas-clemente/aes12"
|
||||
|
@ -580,18 +460,6 @@
|
|||
revision = "ab3ca2f6f85577d7ec82e0a6df721147a2e737f9"
|
||||
version = "v2.0.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattes/migrate"
|
||||
packages = [
|
||||
".",
|
||||
"database",
|
||||
"database/postgres",
|
||||
"source",
|
||||
"source/go-bindata"
|
||||
]
|
||||
revision = "035c07716cd373d88456ec4d701402df52584cb4"
|
||||
version = "v3.0.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-isatty"
|
||||
packages = ["."]
|
||||
|
@ -676,30 +544,12 @@
|
|||
packages = ["."]
|
||||
revision = "96aac992fc8b1a4c83841a6c3e7178d20d989625"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluaflag"
|
||||
packages = ["."]
|
||||
revision = "078088de689148194436293886e8e39809167332"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluash"
|
||||
packages = ["."]
|
||||
revision = "e145c563986f0b91f740a758a84bca46c163aec7"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pkg/errors"
|
||||
packages = ["."]
|
||||
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
|
||||
version = "v0.8.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pkg/sftp"
|
||||
packages = ["."]
|
||||
revision = "f6a9258a0f570c3a76681b897b6ded57cb0dfa88"
|
||||
version = "1.2.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/posener/complete"
|
||||
packages = [
|
||||
|
@ -774,35 +624,6 @@
|
|||
revision = "ebec7ef2574b42a7088cd7751176483e0a27d458"
|
||||
version = "v1.0.6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yookoala/realpath"
|
||||
packages = ["."]
|
||||
revision = "d19ef9c409d9817c1e685775e53d361b03eabbc8"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gluamapper"
|
||||
packages = ["."]
|
||||
revision = "d836955830e75240d46ce9f0e6d148d94f2e1d3a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gluare"
|
||||
packages = ["."]
|
||||
revision = "d7c94f1a80ede93a621ed100866e6d4745ca8c22"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gopher-lua"
|
||||
packages = [
|
||||
".",
|
||||
"ast",
|
||||
"parse",
|
||||
"pm"
|
||||
]
|
||||
revision = "7d7bc8747e3f614c5c587729a341fe7d8903cdb8"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/zclconf/go-cty"
|
||||
|
@ -833,10 +654,7 @@
|
|||
"blowfish",
|
||||
"cast5",
|
||||
"curve25519",
|
||||
"ed25519",
|
||||
"ed25519/internal/edwards25519",
|
||||
"hkdf",
|
||||
"internal/chacha20",
|
||||
"nacl/secretbox",
|
||||
"openpgp",
|
||||
"openpgp/armor",
|
||||
|
@ -848,9 +666,6 @@
|
|||
"poly1305",
|
||||
"salsa20",
|
||||
"salsa20/salsa",
|
||||
"ssh",
|
||||
"ssh/agent",
|
||||
"ssh/terminal",
|
||||
"tea",
|
||||
"twofish",
|
||||
"xtea"
|
||||
|
@ -880,10 +695,7 @@
|
|||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
packages = [
|
||||
"unix",
|
||||
"windows"
|
||||
]
|
||||
packages = ["unix"]
|
||||
revision = "2c42eef0765b9837fbdab12011af7830f55f88f0"
|
||||
|
||||
[[projects]]
|
||||
|
@ -907,15 +719,6 @@
|
|||
]
|
||||
revision = "e19ae1496984b1c655b8044a65c0300a3c878dd3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/tools"
|
||||
packages = [
|
||||
"godoc/vfs",
|
||||
"godoc/vfs/httpfs"
|
||||
]
|
||||
revision = "99037e3760ed7d9c772c980caee42b17779b80ce"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "google.golang.org/genproto"
|
||||
|
@ -959,39 +762,9 @@
|
|||
revision = "947dcec5ba9c011838740e680966fd7087a71d0d"
|
||||
version = "v2.2.6"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/xmlpath.v2"
|
||||
packages = ["."]
|
||||
revision = "860cbeca3ebcc600db0b213c0e83ad6ce91f5739"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/yaml.v2"
|
||||
packages = ["."]
|
||||
revision = "d670f9405373e636a5a2765eea47fac0c9bc91a4"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "layeh.com/asar"
|
||||
packages = ["."]
|
||||
revision = "0ec214a4ae0d21fa761591e8cb8f0bbf162ef3e5"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-json"
|
||||
packages = ["."]
|
||||
revision = "1aab82196e3b418b56866938f28b6a693f2c6b18"
|
||||
|
||||
[[projects]]
|
||||
name = "layeh.com/gopher-luar"
|
||||
packages = ["."]
|
||||
revision = "7b2b96926970546e504881ee7364c1127508eb4e"
|
||||
version = "v1.0.2"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "d000c14171581755a2ee37649cb969d019d9c197928028a87e83e3ec729421aa"
|
||||
inputs-digest = "51866d1bd0089290b4562a563c65db61b4973e66be0e14297f0680059dbdf138"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
||||
|
|
|
@ -19,9 +19,6 @@
|
|||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/eclier"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
$goVer = "1.9.2"
|
||||
$repoPath = "git.xeserv.us/xena/route"
|
||||
|
||||
from "xena/go-mini:#{$goVer}"
|
||||
|
||||
run "go#{$goVer} download"
|
||||
|
||||
[
|
||||
"vendor",
|
||||
"internal",
|
||||
"proto",
|
||||
"cmd",
|
||||
].each { |x| copy x+"/", "/root/go/src/#{$repoPath}/#{x}" }
|
||||
|
||||
run "apk --no-cache add build-base"
|
||||
run "go#{$goVer} build -v #{$repoPath}/cmd/... && go#{$goVer} install -v #{$repoPath}/cmd/..."
|
||||
run "apk del build-base"
|
||||
|
||||
[
|
||||
"route-cli",
|
||||
"routed",
|
||||
"route-httpagent",
|
||||
].each { |x| run "cp /root/go/bin/#{x} /usr/local/bin/#{x}" }
|
||||
|
||||
tag "xena/route:thick"
|
||||
|
||||
run "apk del go#{$goVer} && rm -rf /root/sdk /root/go"
|
||||
flatten
|
||||
|
||||
tag "xena/route:latest"
|
|
@ -1,69 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
"github.com/kr/pretty"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
var (
|
||||
hits *atomic.Int64
|
||||
)
|
||||
|
||||
func init() {
|
||||
hits = atomic.NewInt64(0)
|
||||
}
|
||||
|
||||
func demoServerHandler(msg string) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintln(w, "Route is go!")
|
||||
fmt.Fprintf(w, "%s\n", pretty.Sprintf("%s", r.Header))
|
||||
hn, _ := os.Hostname()
|
||||
fmt.Fprintf(w, "message: %s\n", msg)
|
||||
fmt.Fprintf(w, "Served by %s running %s\n", hn, runtime.GOOS)
|
||||
fmt.Fprintf(w, "Hit count: %d", hits.Inc())
|
||||
|
||||
ip := r.Header.Get("X-Remote-Ip")
|
||||
if ip != "" {
|
||||
log.Printf("Hit from %s: %s", ip, r.RequestURI)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func demoServer(ctx context.Context, args []string) error {
|
||||
fs := flag.NewFlagSet("server", flag.ContinueOnError)
|
||||
|
||||
addr := fs.String("addr", ":9090", "http address to listen on")
|
||||
msg := fs.String("msg", "now here's a little lesson in trickery...", "custom message to add to each page render")
|
||||
|
||||
err := fs.Parse(args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
hs := &http.Server{
|
||||
Addr: *addr,
|
||||
Handler: demoServerHandler(*msg),
|
||||
}
|
||||
|
||||
go hs.ListenAndServe()
|
||||
|
||||
log.Printf("listening on %s", *addr)
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
sctx := context.Background()
|
||||
hs.Shutdown(sctx)
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,124 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"git.xeserv.us/xena/route/internal/gluaroute"
|
||||
edata "git.xeserv.us/xena/route/proto/eclier"
|
||||
"github.com/Xe/eclier"
|
||||
"github.com/Xe/gluanetrc"
|
||||
"github.com/Xe/x/tools/glue/libs/gluaexpect"
|
||||
"github.com/Xe/x/tools/glue/libs/gluasimplebox"
|
||||
"github.com/ailncode/gluaxmlpath"
|
||||
"github.com/cjoudrey/gluahttp"
|
||||
"github.com/cjoudrey/gluaurl"
|
||||
"github.com/go-serve/bindatafs"
|
||||
"github.com/kohkimakimoto/gluaenv"
|
||||
"github.com/kohkimakimoto/gluafs"
|
||||
"github.com/kohkimakimoto/gluaquestion"
|
||||
"github.com/kohkimakimoto/gluassh"
|
||||
"github.com/kohkimakimoto/gluatemplate"
|
||||
"github.com/kohkimakimoto/gluayaml"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"github.com/otm/gluaflag"
|
||||
"github.com/otm/gluash"
|
||||
"github.com/yuin/gluare"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
"golang.org/x/tools/godoc/vfs/httpfs"
|
||||
json "layeh.com/gopher-json"
|
||||
)
|
||||
|
||||
var hDir string
|
||||
var cfgHome *string
|
||||
var netrcFile *string
|
||||
var defaultServer *string
|
||||
|
||||
func init() {
|
||||
dir, err := homedir.Dir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
hDir = dir
|
||||
|
||||
cfgHome = flag.String("home", filepath.Join(hDir, ".construct"), "construct's home directory")
|
||||
netrcFile = flag.String("netrc", filepath.Join(hDir, ".netrc"), "location of netrc file to use for authentication")
|
||||
defaultServer = flag.String("default-server", "https://api.route.xeserv.us:7268", "api server to connect to")
|
||||
|
||||
log.SetFlags(log.LstdFlags | log.Llongfile)
|
||||
}
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
pluginLoc := filepath.Join(*cfgHome, "plugins")
|
||||
scriptsLoc := filepath.Join(*cfgHome, "local", "scripts")
|
||||
|
||||
os.MkdirAll(pluginLoc, 0755)
|
||||
os.MkdirAll(scriptsLoc, 0755)
|
||||
|
||||
if _, err := os.Stat(*netrcFile); err != nil {
|
||||
log.Printf("creating netrc file...")
|
||||
fout, err := os.Create(*netrcFile)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fout.Close()
|
||||
}
|
||||
|
||||
efs := bindatafs.New("core://", edata.Asset, edata.AssetDir, edata.AssetInfo)
|
||||
|
||||
opts := []eclier.RouterOption{
|
||||
eclier.WithGluaCreationHook(preload),
|
||||
eclier.WithScriptHome(scriptsLoc),
|
||||
eclier.WithFilesystem("/bindata:core/", httpfs.New(efs)),
|
||||
}
|
||||
|
||||
err := filepath.Walk(pluginLoc, func(path string, info os.FileInfo, err error) error {
|
||||
if info.IsDir() {
|
||||
opts = append(opts, eclier.WithScriptHome(info.Name()))
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
r, err := eclier.NewRouter(opts...)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
r.AddCommand(eclier.NewBuiltinCommand("server", "spawns a http server for testing", "[-addr host:port|-msg \"some message\"]", demoServer))
|
||||
|
||||
r.Run(ctx, flag.Args())
|
||||
}
|
||||
|
||||
func preload(L *lua.LState) {
|
||||
L.PreloadModule("re", gluare.Loader)
|
||||
L.PreloadModule("sh", gluash.Loader)
|
||||
L.PreloadModule("fs", gluafs.Loader)
|
||||
L.PreloadModule("env", gluaenv.Loader)
|
||||
L.PreloadModule("yaml", gluayaml.Loader)
|
||||
L.PreloadModule("question", gluaquestion.Loader)
|
||||
L.PreloadModule("ssh", gluassh.Loader)
|
||||
L.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{}).Loader)
|
||||
L.PreloadModule("flag", gluaflag.Loader)
|
||||
L.PreloadModule("template", gluatemplate.Loader)
|
||||
L.PreloadModule("url", gluaurl.Loader)
|
||||
gluaexpect.Preload(L)
|
||||
gluasimplebox.Preload(L)
|
||||
gluaxmlpath.Preload(L)
|
||||
json.Preload(L)
|
||||
gluanetrc.Preload(L)
|
||||
gluaroute.Preload(L)
|
||||
}
|
|
@ -170,13 +170,7 @@ retry_netrc:
|
|||
|
||||
tBody := uuid.New()
|
||||
|
||||
tok := database.Token{
|
||||
Body: uuid.New(),
|
||||
Owner: *tokenGenerateUsername,
|
||||
Scopes: *tokenGenerateScopes,
|
||||
}
|
||||
|
||||
_, err = db.Tokens().Put(context.Background(), tok)
|
||||
_, err = db.PutToken(context.Background(), tBody, *tokenGenerateUsername, *tokenGenerateScopes)
|
||||
if err != nil {
|
||||
ln.FatalErr(ctx, err, ln.Action("add newly created token to database"))
|
||||
}
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"git.xeserv.us/xena/route/internal/database/dmigrations"
|
||||
"github.com/caarlos0/env"
|
||||
"github.com/mattes/migrate"
|
||||
_ "github.com/mattes/migrate/database/postgres"
|
||||
bindata "github.com/mattes/migrate/source/go-bindata"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
DatabaseURL string `env:"DATABASE_URL,required"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
var cfg config
|
||||
err := env.Parse(&cfg)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
s := bindata.Resource(dmigrations.AssetNames(),
|
||||
func(name string) ([]byte, error) {
|
||||
return dmigrations.Asset(name)
|
||||
})
|
||||
|
||||
d, err := bindata.WithInstance(s)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
m, err := migrate.NewWithSourceInstance("go-bindata", d, cfg.DatabaseURL)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = m.Up()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -60,7 +60,7 @@ func (s *Server) makeTwirpHooks() *twirp.ServerHooks {
|
|||
|
||||
tok := ck.Value
|
||||
|
||||
t, err := s.db.Tokens().Get(ctx, tok)
|
||||
t, err := s.db.GetToken(ctx, tok)
|
||||
if err != nil {
|
||||
return ctx, err
|
||||
}
|
||||
|
@ -94,13 +94,6 @@ func (s *Server) makeTwirpHooks() *twirp.ServerHooks {
|
|||
"twirp_error_msg": e.Msg(),
|
||||
})
|
||||
|
||||
tr, ok := trace.FromContext(ctx)
|
||||
if !ok {
|
||||
return ctx
|
||||
}
|
||||
|
||||
tr.SetError()
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
|
@ -115,12 +108,6 @@ func (s *Server) getAuth(ctx context.Context, operation, scope string) (database
|
|||
|
||||
ok = false
|
||||
for _, sc := range t.Scopes {
|
||||
// the "admin" scope is implicitly allowed for everything.
|
||||
if sc == "admin" {
|
||||
ok = true
|
||||
break
|
||||
}
|
||||
|
||||
if sc == scope {
|
||||
ok = true
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"git.xeserv.us/xena/route/internal/database"
|
||||
"git.xeserv.us/xena/route/internal/elfs"
|
||||
proto "git.xeserv.us/xena/route/proto"
|
||||
"github.com/Xe/ln"
|
||||
|
@ -25,7 +24,7 @@ func (r *Route) Get(ctx context.Context, req *proto.GetRouteRequest) (*proto.Rou
|
|||
return nil, handleError(ctx, clitok, err, ln.F{"action": "Route.Get_getAuth"})
|
||||
}
|
||||
|
||||
val, err := r.db.Routes().Get(ctx, req.Id)
|
||||
val, err := r.db.GetRoute(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "get single route from database", "id": req.Id})
|
||||
}
|
||||
|
@ -44,7 +43,7 @@ func (r *Route) GetAll(ctx context.Context, req *proto.Nil) (*proto.GetAllRoutes
|
|||
return nil, handleError(ctx, clitok, err, ln.F{"action": "Route.GetAll_getAuth"})
|
||||
}
|
||||
|
||||
routes, err := r.db.Routes().GetAll(ctx, clitok.Owner)
|
||||
routes, err := r.db.GetAllRoutes(ctx, clitok.Owner)
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "get all routes for user from database"})
|
||||
}
|
||||
|
@ -71,18 +70,12 @@ func (r *Route) Put(ctx context.Context, rt *proto.Route) (*proto.Route, error)
|
|||
rt.Host = elfs.MakeName() + r.cfg.DomainSuffix
|
||||
}
|
||||
|
||||
rr := database.Route{
|
||||
ID: rt.Id,
|
||||
Hostname: rt.Host,
|
||||
Creator: clitok.Owner,
|
||||
}
|
||||
|
||||
drt, err := r.db.Routes().Put(ctx, rr)
|
||||
drt, err := r.db.PutRoute(ctx, rt.Host, clitok.Owner)
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "put route to database"})
|
||||
}
|
||||
|
||||
ln.Log(ctx, drt, ln.Action("put route to database"))
|
||||
ln.Log(ctx, drt, ln.Action("created new route"))
|
||||
|
||||
return drt.AsProto(), nil
|
||||
}
|
||||
|
@ -93,7 +86,7 @@ func (r *Route) Delete(ctx context.Context, rt *proto.Route) (*proto.Nil, error)
|
|||
return nil, handleError(ctx, clitok, err, ln.F{"action": "Route.Delete_getAuth"})
|
||||
}
|
||||
|
||||
drt, err := r.db.Routes().Get(ctx, rt.Host)
|
||||
drt, err := r.db.GetRoute(ctx, rt.Host)
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "fetch route from database", "host": rt.Host})
|
||||
}
|
||||
|
@ -102,7 +95,7 @@ func (r *Route) Delete(ctx context.Context, rt *proto.Route) (*proto.Nil, error)
|
|||
return nil, handleError(ctx, clitok, ErrNotAuthorized, ln.F{"action": "user not authorized to delete this route", "host": rt.Host})
|
||||
}
|
||||
|
||||
_, err = r.db.Routes().Delete(ctx, database.Route{ID: rt.Id})
|
||||
err = r.db.DeleteRoute(ctx, rt.Id)
|
||||
f := drt.F()
|
||||
f["action"] = "delete route from database"
|
||||
if err != nil {
|
||||
|
|
|
@ -16,7 +16,7 @@ var (
|
|||
)
|
||||
|
||||
func (s *storageWrapper) HasToken(token string) (string, []string, error) {
|
||||
t, err := s.Storage.Tokens().GetBody(context.Background(), token)
|
||||
t, err := s.Storage.GetToken(context.Background(), token)
|
||||
if err != nil {
|
||||
return "", nil, err
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ func (s *storageWrapper) HasToken(token string) (string, []string, error) {
|
|||
}
|
||||
|
||||
func (s *storageWrapper) HasRoute(domain string) (string, error) {
|
||||
r, err := s.Storage.Routes().GetHost(context.Background(), domain)
|
||||
r, err := s.Storage.GetRouteHost(context.Background(), domain)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.xeserv.us/xena/route/internal/database"
|
||||
proto "git.xeserv.us/xena/route/proto"
|
||||
"github.com/Xe/ln"
|
||||
"github.com/Xe/uuid"
|
||||
|
@ -32,7 +29,7 @@ func (t *Token) Get(ctx context.Context, req *proto.GetTokenRequest) (*proto.Tok
|
|||
return nil, status.Errorf(codes.InvalidArgument, "must specify ID")
|
||||
}
|
||||
|
||||
dbt, err := t.db.Tokens().Get(ctx, req.Id)
|
||||
dbt, err := t.db.GetTokenID(ctx, req.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -50,7 +47,7 @@ func (t *Token) GetAll(ctx context.Context, req *proto.Nil) (*proto.TokenSet, er
|
|||
return nil, handleError(ctx, clitok, err, ln.F{"action": "Token.GetAll_getAuth"})
|
||||
}
|
||||
|
||||
toks, err := t.db.Tokens().GetAll(ctx, clitok.Owner)
|
||||
toks, err := t.db.GetTokensForOwner(ctx, clitok.Owner)
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "Token.GetAll_db.GetTokensForOwner"})
|
||||
}
|
||||
|
@ -72,13 +69,7 @@ func (t *Token) Put(ctx context.Context, tok *proto.Token) (*proto.Token, error)
|
|||
return nil, handleError(ctx, clitok, err, ln.F{"action": "not authorized"})
|
||||
}
|
||||
|
||||
dtok := database.Token{
|
||||
ID: uuid.New(),
|
||||
Owner: clitok.Owner,
|
||||
Scopes: tok.Scopes,
|
||||
}
|
||||
|
||||
dbt, err := t.db.Tokens().Put(ctx, dtok)
|
||||
dbt, err := t.db.PutToken(ctx, uuid.New(), clitok.Owner, tok.Scopes)
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "put token into database", "scopes": tok.Scopes})
|
||||
}
|
||||
|
@ -94,7 +85,7 @@ func (t *Token) Delete(ctx context.Context, tok *proto.Token) (*proto.Nil, error
|
|||
return nil, handleError(ctx, clitok, err, ln.F{"action": "not authorized"})
|
||||
}
|
||||
|
||||
_, err = t.db.Tokens().Delete(ctx, tok.Id)
|
||||
err = t.db.DeleteToken(ctx, tok.Id)
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "delete token from database", "token_id": tok.Id})
|
||||
}
|
||||
|
@ -105,5 +96,17 @@ func (t *Token) Delete(ctx context.Context, tok *proto.Token) (*proto.Nil, error
|
|||
}
|
||||
|
||||
func (t *Token) Deactivate(ctx context.Context, tok *proto.Token) (*proto.Nil, error) {
|
||||
return nil, errors.New("not implemented")
|
||||
clitok, err := t.getAuth(ctx, "deactivate single token", "token:deactivate")
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "not authorized"})
|
||||
}
|
||||
|
||||
err = t.db.DeactivateToken(ctx, tok.Id)
|
||||
if err != nil {
|
||||
return nil, handleError(ctx, clitok, err, ln.F{"action": "deactivate token in database", "token_id": tok.Id})
|
||||
}
|
||||
|
||||
ln.Log(ctx, clitok, ln.Action("deactivated token"), ln.F{"token_id": tok.Id})
|
||||
|
||||
return &proto.Nil{}, nil
|
||||
}
|
||||
|
|
|
@ -29,22 +29,6 @@ var (
|
|||
type BoltDBStorage struct {
|
||||
db *storm.DB
|
||||
sb *simplebox.SimpleBox
|
||||
|
||||
cs *boltCertificateStorage
|
||||
rs *boltRouteStorage
|
||||
ts *boltTokenStorage
|
||||
}
|
||||
|
||||
type boltCertificateStorage struct {
|
||||
*BoltDBStorage
|
||||
}
|
||||
|
||||
type boltRouteStorage struct {
|
||||
*BoltDBStorage
|
||||
}
|
||||
|
||||
type boltTokenStorage struct {
|
||||
*BoltDBStorage
|
||||
}
|
||||
|
||||
// NewBoltStorage creates a new Storage instance backed by BoltDB + Storm.
|
||||
|
@ -59,43 +43,24 @@ func NewBoltStorage(path string, key *[32]byte) (Storage, error) {
|
|||
sb: simplebox.NewFromSecretKey(key),
|
||||
}
|
||||
|
||||
b.cs = &boltCertificateStorage{b}
|
||||
b.rs = &boltRouteStorage{b}
|
||||
b.ts = &boltTokenStorage{b}
|
||||
|
||||
return b, nil
|
||||
return Storage(b), nil
|
||||
}
|
||||
|
||||
// Certs gets the certificate storage interface.
|
||||
func (b *BoltDBStorage) Certs() Certs { return b.cs }
|
||||
|
||||
// Routes gets the route storage interface.
|
||||
func (b *BoltDBStorage) Routes() Routes { return b.rs }
|
||||
|
||||
// Tokens gets the token storage interface.
|
||||
func (b *BoltDBStorage) Tokens() Tokens { return b.ts }
|
||||
|
||||
// Close cleans up resources for this Storage.
|
||||
func (b *BoltDBStorage) Close() error { return b.db.Close() }
|
||||
|
||||
// interface compliance
|
||||
var (
|
||||
_ Storage = &BoltDBStorage{}
|
||||
_ Certs = &boltCertificateStorage{}
|
||||
_ Routes = &boltRouteStorage{}
|
||||
_ Tokens = &boltTokenStorage{}
|
||||
)
|
||||
|
||||
func (b *boltRouteStorage) Get(ctx context.Context, id string) (Route, error) {
|
||||
func (b *BoltDBStorage) GetRoute(ctx context.Context, id string) (Route, error) {
|
||||
return b.getRouteBy(ctx, "ID", id)
|
||||
}
|
||||
|
||||
func (b *boltRouteStorage) GetHost(ctx context.Context, id string) (Route, error) {
|
||||
func (b *BoltDBStorage) GetRouteHost(ctx context.Context, id string) (Route, error) {
|
||||
return b.getRouteBy(ctx, "Hostname", id)
|
||||
}
|
||||
|
||||
// getRouteBy gets a single route out of the database by a given field data.
|
||||
func (b *boltRouteStorage) getRouteBy(ctx context.Context, match, val string) (Route, error) {
|
||||
func (b *BoltDBStorage) getRouteBy(ctx context.Context, match, val string) (Route, error) {
|
||||
r := Route{}
|
||||
err := b.db.One(match, val, &r)
|
||||
if err != nil {
|
||||
|
@ -114,17 +79,19 @@ func (b *boltRouteStorage) getRouteBy(ctx context.Context, match, val string) (R
|
|||
return r, nil
|
||||
}
|
||||
|
||||
// GetAll gets all routes out of the database for a given user by username.
|
||||
func (b *boltRouteStorage) GetAll(ctx context.Context, user string) ([]Route, error) {
|
||||
// GetAllRoutes gets all routes out of the database for a given user by username.
|
||||
func (b *BoltDBStorage) GetAllRoutes(ctx context.Context, user string) ([]Route, error) {
|
||||
rs := []Route{}
|
||||
err := b.db.All(&rs)
|
||||
return rs, err
|
||||
}
|
||||
|
||||
// Put creates a new route in the database.
|
||||
func (b *boltRouteStorage) Put(ctx context.Context, r Route) (Route, error) {
|
||||
if r.ID == "" {
|
||||
r.ID = uuid.New()
|
||||
// PutRoute creates a new route in the database.
|
||||
func (b *BoltDBStorage) PutRoute(ctx context.Context, domain, creator string) (Route, error) {
|
||||
r := Route{
|
||||
ID: uuid.New(),
|
||||
Creator: creator,
|
||||
Hostname: domain,
|
||||
}
|
||||
|
||||
err := b.db.Save(&r)
|
||||
|
@ -138,30 +105,30 @@ func (b *boltRouteStorage) Put(ctx context.Context, r Route) (Route, error) {
|
|||
return r, err
|
||||
}
|
||||
|
||||
// Delete removes a route from the database.
|
||||
func (b *boltRouteStorage) Delete(ctx context.Context, inp Route) (Route, error) {
|
||||
// DeleteRoute removes a route from the database.
|
||||
func (b *BoltDBStorage) DeleteRoute(ctx context.Context, id string) error {
|
||||
r := Route{}
|
||||
err := b.db.One("ID", inp.ID, &r)
|
||||
err := b.db.One("ID", id, &r)
|
||||
if err != nil {
|
||||
return r, err
|
||||
return err
|
||||
}
|
||||
defer b.db.Commit()
|
||||
|
||||
ln.Log(ctx, r, ln.Action("route deleted from database"))
|
||||
|
||||
return r, b.db.DeleteStruct(&r)
|
||||
return b.db.DeleteStruct(&r)
|
||||
}
|
||||
|
||||
// GetBody fetches a token from the database. This is mainly used in validation
|
||||
// GetToken fetches a token from the database. This is mainly used in validation
|
||||
// of tokens.
|
||||
func (b *boltTokenStorage) GetBody(ctx context.Context, token string) (Token, error) {
|
||||
func (b *BoltDBStorage) GetToken(ctx context.Context, token string) (Token, error) {
|
||||
t := Token{}
|
||||
err := b.db.One("Body", token, &t)
|
||||
return t, err
|
||||
}
|
||||
|
||||
// Get fetches a token by a given token ID.
|
||||
func (b *boltTokenStorage) Get(ctx context.Context, id string) (Token, error) {
|
||||
// GetTokenID fetches a token by a given token ID.
|
||||
func (b *BoltDBStorage) GetTokenID(ctx context.Context, id string) (Token, error) {
|
||||
t := Token{}
|
||||
err := b.db.One("ID", id, &t)
|
||||
if err != nil {
|
||||
|
@ -176,20 +143,23 @@ func (b *boltTokenStorage) Get(ctx context.Context, id string) (Token, error) {
|
|||
return t, nil
|
||||
}
|
||||
|
||||
// GetAll fetches all of the tokens owned by a given owner.
|
||||
func (b *boltTokenStorage) GetAll(ctx context.Context, owner string) ([]Token, error) {
|
||||
// GetTokensForOwner fetches all of the tokens owned by a given owner.
|
||||
func (b *BoltDBStorage) GetTokensForOwner(ctx context.Context, owner string) ([]Token, error) {
|
||||
ts := []Token{}
|
||||
err := b.db.Find("Owner", owner, &ts)
|
||||
return ts, err
|
||||
}
|
||||
|
||||
// Put adds a new token to the database.
|
||||
func (b *boltTokenStorage) Put(ctx context.Context, t Token) (Token, error) {
|
||||
if t.ID == "" {
|
||||
t.ID = uuid.New()
|
||||
t.CreatedAt = time.Now()
|
||||
t.Active = true
|
||||
t.Body = uuid.New()
|
||||
// PutToken adds a new token to the database.
|
||||
func (b *BoltDBStorage) PutToken(ctx context.Context, token, owner string, scopes []string) (Token, error) {
|
||||
t := Token{
|
||||
ID: uuid.New(),
|
||||
Body: token,
|
||||
Owner: owner,
|
||||
Scopes: scopes,
|
||||
|
||||
CreatedAt: time.Now(),
|
||||
Active: true,
|
||||
}
|
||||
|
||||
err := b.db.Save(&t)
|
||||
|
@ -203,53 +173,38 @@ func (b *boltTokenStorage) Put(ctx context.Context, t Token) (Token, error) {
|
|||
return t, nil
|
||||
}
|
||||
|
||||
// Delete removes a token from the database.
|
||||
func (b *boltTokenStorage) Delete(ctx context.Context, id string) (Token, error) {
|
||||
// DeleteToken removes a token from the database.
|
||||
func (b *BoltDBStorage) DeleteToken(ctx context.Context, id string) error {
|
||||
t := Token{}
|
||||
err := b.db.One("ID", id, &t)
|
||||
if err != nil {
|
||||
return t, err
|
||||
return err
|
||||
}
|
||||
|
||||
ln.Log(ctx, t, ln.Action("token deleted from database"))
|
||||
|
||||
return t, b.db.DeleteStruct(&t)
|
||||
return b.db.DeleteStruct(&t)
|
||||
}
|
||||
|
||||
// DeleteExpired deletes all expired tokens.
|
||||
func (b *boltTokenStorage) DeleteExpired(ctx context.Context) error {
|
||||
return errors.New("not implemented")
|
||||
}
|
||||
|
||||
// GetAll fetches all certificates and returns their DECRYPTED BODIES to the caller.
|
||||
// This is intended for usage in migration tools only.
|
||||
func (b *boltCertificateStorage) GetAll(ctx context.Context) ([]CachedCert, error) {
|
||||
var cc []CachedCert
|
||||
err := b.db.All(&cc)
|
||||
// DeactivateToken de-activates a token in the database. This should be used
|
||||
// instead of deletion in many cases.
|
||||
func (b *BoltDBStorage) DeactivateToken(ctx context.Context, id string) error {
|
||||
t := Token{}
|
||||
err := b.db.One("ID", id, &t)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
defer b.db.Commit()
|
||||
|
||||
var result []CachedCert
|
||||
t.Active = false
|
||||
|
||||
for _, c := range cc {
|
||||
r := CachedCert{
|
||||
Key: c.Key,
|
||||
}
|
||||
ln.Log(ctx, t, ln.Action("token deactivated"))
|
||||
|
||||
r.Body, err = b.sb.Decrypt(c.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result = append(result, r)
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return b.db.Save(&t)
|
||||
}
|
||||
|
||||
// Get fetches a TLS certificate from the database.
|
||||
func (b *boltCertificateStorage) Get(ctx context.Context, key string) ([]byte, error) {
|
||||
// GetCert fetches a TLS certificate from the database.
|
||||
func (b *BoltDBStorage) GetCert(ctx context.Context, key string) ([]byte, error) {
|
||||
cc := CachedCert{}
|
||||
err := b.db.One("Key", key, &cc)
|
||||
if err != nil {
|
||||
|
@ -258,26 +213,33 @@ func (b *boltCertificateStorage) Get(ctx context.Context, key string) ([]byte, e
|
|||
|
||||
var body []byte
|
||||
|
||||
if b.sb == nil {
|
||||
return nil, ErrCantDecryptCert
|
||||
}
|
||||
switch cc.CryptoLevel {
|
||||
case CryptoLevelNone:
|
||||
body = cc.Body
|
||||
case CryptoLevelSecretbox:
|
||||
if b.sb == nil {
|
||||
return nil, ErrCantDecryptCert
|
||||
}
|
||||
|
||||
body, err = b.sb.Decrypt(cc.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
body, err = b.sb.Decrypt(cc.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return body, nil
|
||||
}
|
||||
|
||||
// Put adds a new TLS certificate to the database.
|
||||
func (b *boltCertificateStorage) Put(ctx context.Context, key string, data []byte) error {
|
||||
// PutCert adds a new TLS certificate to the database.
|
||||
func (b *BoltDBStorage) PutCert(ctx context.Context, key string, data []byte) error {
|
||||
cc := CachedCert{
|
||||
Key: key,
|
||||
Body: data,
|
||||
Key: key,
|
||||
CryptoLevel: CryptoLevelNone,
|
||||
Body: data,
|
||||
}
|
||||
|
||||
if b.sb != nil {
|
||||
cc.CryptoLevel = CryptoLevelSecretbox
|
||||
cc.Body = b.sb.Encrypt(data)
|
||||
}
|
||||
|
||||
|
@ -288,8 +250,8 @@ func (b *boltCertificateStorage) Put(ctx context.Context, key string, data []byt
|
|||
return b.db.Save(&cc)
|
||||
}
|
||||
|
||||
// Delete removes a certificate from the database.
|
||||
func (b *boltCertificateStorage) Delete(ctx context.Context, key string) error {
|
||||
// DeleteCert removes a certificate from the database.
|
||||
func (b *BoltDBStorage) DeleteCert(ctx context.Context, key string) error {
|
||||
cc := CachedCert{}
|
||||
err := b.db.One("Key", key, &cc)
|
||||
if err != nil {
|
||||
|
@ -302,3 +264,8 @@ func (b *boltCertificateStorage) Delete(ctx context.Context, key string) error {
|
|||
|
||||
return b.db.DeleteStruct(&cc)
|
||||
}
|
||||
|
||||
// Close ...
|
||||
func (b *BoltDBStorage) Close() error {
|
||||
return b.db.Close()
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/asdine/storm"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
"golang.org/x/net/context"
|
||||
|
@ -12,17 +14,29 @@ import (
|
|||
// to implement certificate decryption, as that will be handled in the layer
|
||||
// above this DAO.
|
||||
type Certs interface {
|
||||
io.Closer
|
||||
autocert.Cache
|
||||
|
||||
GetAll(ctx context.Context) ([]CachedCert, error)
|
||||
}
|
||||
|
||||
// CryptoLevel indicates what form of cryptography the certificate is stored
|
||||
// with.
|
||||
type CryptoLevel int
|
||||
|
||||
// Crypto levels / strategies defined
|
||||
const (
|
||||
// NOTE: this is defined for debugging / testing usage only
|
||||
CryptoLevelNone CryptoLevel = iota
|
||||
|
||||
// Use the global set of secretbox keys
|
||||
CryptoLevelSecretbox
|
||||
)
|
||||
|
||||
// CachedCert is an individual cached certificate in the database.
|
||||
type CachedCert struct {
|
||||
Key string `storm:"id"`
|
||||
|
||||
// Encrypted data
|
||||
Body []byte // above as a byte slice
|
||||
Key string `storm:"id"`
|
||||
CryptoLevel CryptoLevel
|
||||
// PEM-encoded bytes with the above crypto level as a filter.
|
||||
Body []byte
|
||||
}
|
||||
|
||||
type storageManager struct {
|
||||
|
@ -30,24 +44,24 @@ type storageManager struct {
|
|||
}
|
||||
|
||||
func (s *storageManager) Get(ctx context.Context, key string) ([]byte, error) {
|
||||
data, err := s.Certs().Get(ctx, key)
|
||||
data, err := s.GetCert(ctx, key)
|
||||
if err != nil {
|
||||
if err == storm.ErrNotFound {
|
||||
return nil, autocert.ErrCacheMiss
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return data, nil
|
||||
}
|
||||
|
||||
func (s *storageManager) Put(ctx context.Context, key string, data []byte) error {
|
||||
return s.Certs().Put(ctx, key, data)
|
||||
return s.PutCert(ctx, key, data)
|
||||
}
|
||||
|
||||
func (s *storageManager) Delete(ctx context.Context, key string) error {
|
||||
return s.Certs().Delete(ctx, key)
|
||||
return s.DeleteCert(ctx, key)
|
||||
}
|
||||
|
||||
// Cache creates an autocert.Cache from a Storage instance.
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/Xe/uuid"
|
||||
)
|
||||
|
||||
const (
|
||||
cryptoKey = `I7EzBRcoFtbW6RuqKdFjxYTHC_bpQLPJO3zyS2R-sf8=`
|
||||
certNameBase = "cert."
|
||||
certValue = "hunter2"
|
||||
)
|
||||
|
||||
func testCerts(ctx context.Context, t *testing.T, c Certs) {
|
||||
cn := certNameBase + uuid.New()
|
||||
|
||||
t.Run("put", func(t *testing.T) {
|
||||
data := certValue + uuid.New()
|
||||
|
||||
err := c.Put(ctx, cn, []byte(data))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
data2, err := c.Get(ctx, cn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if data != string(data2) {
|
||||
t.Fatalf("expected data to be %q, got %q", data, string(data2))
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("get", func(t *testing.T) {
|
||||
_, err := c.Get(ctx, cn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("delete", func(t *testing.T) {
|
||||
err := c.Delete(ctx, cn)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = c.Get(ctx, cn)
|
||||
if err == nil {
|
||||
t.Fatal("able to fetch a deleted item")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBoltDBCertStorage(t *testing.T) {
|
||||
st, p, ctx, cancel := newTestBoltStorage(t)
|
||||
defer os.RemoveAll(p)
|
||||
defer st.Close()
|
||||
defer cancel()
|
||||
|
||||
testCerts(ctx, t, st.Certs())
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.xeserv.us/xena/route/internal/routecrypto"
|
||||
"github.com/Xe/uuid"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func newTestBoltStorage(t *testing.T) (Storage, string, context.Context, context.CancelFunc) {
|
||||
k, err := routecrypto.ParseKey(cryptoKey)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
p := uuid.New()
|
||||
|
||||
st, err := NewBoltStorage(p, k)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
return st, p, ctx, cancel
|
||||
}
|
||||
|
||||
func newTestPostgresStorage(t *testing.T, url string) (Storage, context.Context, context.CancelFunc) {
|
||||
k, err := routecrypto.ParseKey(cryptoKey)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
st, err := NewPostgresStorage(url, k)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
return st, ctx, cancel
|
||||
}
|
|
@ -1,373 +0,0 @@
|
|||
// Code generated by go-bindata.
|
||||
// sources:
|
||||
// 1513981282_certificates.down.sql
|
||||
// 1513981282_certificates.up.sql
|
||||
// 1513981599_routes.down.sql
|
||||
// 1513981599_routes.up.sql
|
||||
// 1513982254_tokens.down.sql
|
||||
// 1513982254_tokens.up.sql
|
||||
// postgres.sql
|
||||
// DO NOT EDIT!
|
||||
|
||||
package dmigrations
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
clErr := gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
if clErr != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
type asset struct {
|
||||
bytes []byte
|
||||
info os.FileInfo
|
||||
}
|
||||
|
||||
type bindataFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
func (fi bindataFileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
func (fi bindataFileInfo) Size() int64 {
|
||||
return fi.size
|
||||
}
|
||||
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||
return fi.mode
|
||||
}
|
||||
func (fi bindataFileInfo) ModTime() time.Time {
|
||||
return fi.modTime
|
||||
}
|
||||
func (fi bindataFileInfo) IsDir() bool {
|
||||
return false
|
||||
}
|
||||
func (fi bindataFileInfo) Sys() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var __1513981282_certificatesDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\xf0\xf4\x73\x71\x8d\x50\x70\x4e\x2d\x2a\xc9\x4c\xcb\x4c\x4e\x2c\x49\x2d\x8e\x4f\xc9\xcf\x4d\xcc\xcc\xb3\xe6\x02\xcb\x87\x38\x3a\xf9\xb8\xa2\xc8\x5b\x73\x01\x02\x00\x00\xff\xff\xb8\xef\x1e\x9f\x39\x00\x00\x00")
|
||||
|
||||
func _1513981282_certificatesDownSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__1513981282_certificatesDownSql,
|
||||
"1513981282_certificates.down.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _1513981282_certificatesDownSql() (*asset, error) {
|
||||
bytes, err := _1513981282_certificatesDownSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1513981282_certificates.down.sql", size: 57, mode: os.FileMode(420), modTime: time.Unix(1516564385, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __1513981282_certificatesUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x90\x31\x4f\xc3\x30\x10\x85\x77\xff\x8a\xa7\x4e\x89\x04\x03\x48\xb0\x74\x72\x93\xab\xb0\x48\xec\x92\xd8\x90\x4e\x91\x95\x18\xe4\xa1\x2d\x4a\x9c\xfe\x7e\x44\x1a\x02\x61\x40\x78\xf3\xe9\x7b\xf7\x9d\x5e\x52\x10\xd7\x04\xaa\x34\xc9\x52\x28\x09\xb1\x85\x54\x1a\x54\x89\x52\x97\x58\x0d\x83\x6f\xaf\x4f\x7d\xff\xbe\x5a\x33\x36\xc1\x9a\x6f\x32\xfa\x05\x26\xae\x0b\xfe\xd5\x37\x36\xb8\x9e\x01\x11\x7c\x8b\xaf\x67\x8c\x48\xe7\xcf\xae\x10\x39\x2f\xf6\x78\xa4\x3d\x52\xda\x72\x93\x69\x7c\x4a\xea\x37\x77\x74\x9d\x0d\xae\x3e\xdf\x1c\x9a\x28\x66\xc0\x15\xda\xd3\xc1\xfa\xe3\x98\x7b\xe6\x45\xf2\xc0\x8b\xe8\xf6\xee\x3e\x1e\xc5\xd2\x64\xd9\x05\xb2\xc1\x4e\xcb\x35\x55\x7a\x36\x2d\xa0\xa6\x73\x36\xb8\xb6\xb6\x01\x5a\xe4\x54\x6a\x9e\xef\x7e\x42\xf3\x2d\x52\xbd\x4c\x72\xd7\xfa\x29\xf1\xef\x88\x6d\x82\x3f\xbb\xd1\xbe\x51\x2a\x23\x2e\x97\xa7\xcc\x91\xd0\x0d\x8e\x01\xf1\x77\xa9\x46\x8a\x27\x43\x10\x32\xa5\xea\x8f\x6e\xeb\xa9\x12\x25\x17\x63\x44\x97\x79\xbc\x66\x1f\x01\x00\x00\xff\xff\xcf\x95\x0a\x45\xd2\x01\x00\x00")
|
||||
|
||||
func _1513981282_certificatesUpSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__1513981282_certificatesUpSql,
|
||||
"1513981282_certificates.up.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _1513981282_certificatesUpSql() (*asset, error) {
|
||||
bytes, err := _1513981282_certificatesUpSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1513981282_certificates.up.sql", size: 466, mode: os.FileMode(420), modTime: time.Unix(1516564385, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __1513981599_routesDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\x08\x71\x74\xf2\x71\x55\x08\xca\x2f\x2d\x49\x2d\xb6\xe6\x02\x04\x00\x00\xff\xff\xf9\xea\x76\x2b\x13\x00\x00\x00")
|
||||
|
||||
func _1513981599_routesDownSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__1513981599_routesDownSql,
|
||||
"1513981599_routes.down.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _1513981599_routesDownSql() (*asset, error) {
|
||||
bytes, err := _1513981599_routesDownSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1513981599_routes.down.sql", size: 19, mode: os.FileMode(420), modTime: time.Unix(1516564385, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __1513981599_routesUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8c\x90\x3f\x6f\x83\x30\x14\xc4\x77\x7f\x8a\x53\x26\x90\xda\xa1\xa9\xda\x25\x93\x13\x5e\x54\xab\x60\x52\x63\xb7\x64\x42\x08\xac\x96\x21\x50\x81\xc9\xe7\xaf\xa0\x40\xff\x0e\xf1\xe6\xa7\xdf\xdd\x7b\x77\x3b\x45\x5c\x13\x28\xd5\x24\x13\x11\x4b\x88\x3d\x64\xac\x41\xa9\x48\x74\x82\x55\xdf\x57\xe5\x75\xd3\x75\xef\xab\x0d\x63\x13\xac\xf9\x36\xa4\x5f\xa0\x6a\x7a\x67\x3b\x06\x78\xa8\x4a\xcc\xcf\x18\x11\x2c\x9f\x83\x12\x11\x57\x47\x3c\xd2\x11\x01\xed\xb9\x09\x35\x06\xfb\xec\xd5\xd6\xb6\xcd\x9d\xcd\xce\x37\xa7\xc2\xf3\x19\x70\x85\xa2\xb5\xb9\x6b\xda\x41\xf7\xcc\xd5\xee\x81\x2b\xef\x76\xed\x63\x5c\x29\x4d\x18\x8e\xd0\x5b\xd3\xb9\x3a\x3f\xd9\x6f\xd0\xfa\xee\xde\xff\x09\x8d\x4e\xb6\xcc\x72\x07\x2d\x22\x4a\x34\x8f\x0e\x83\xed\x0c\x2d\xb7\xc8\xf8\x65\x5a\x6e\xcb\x6a\x52\x5c\x2c\xc9\x0b\x57\x9d\xed\x98\x73\x1b\xc7\x21\x71\xf9\x19\xfa\x8f\xc4\xb5\xbd\x65\x80\xff\x55\xa7\x91\xe2\xc9\x10\x84\x0c\x28\xfd\xb7\xd5\x6c\xc9\xd9\xd4\xd3\x08\xde\x3c\xf3\x37\xec\x23\x00\x00\xff\xff\x28\x30\xd1\x48\xc4\x01\x00\x00")
|
||||
|
||||
func _1513981599_routesUpSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__1513981599_routesUpSql,
|
||||
"1513981599_routes.up.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _1513981599_routesUpSql() (*asset, error) {
|
||||
bytes, err := _1513981599_routesUpSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1513981599_routes.up.sql", size: 452, mode: os.FileMode(420), modTime: time.Unix(1516564385, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __1513982254_tokensDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\xf0\xf4\x73\x71\x8d\x50\x08\xc9\xcf\x4e\xcd\x2b\x8e\x4f\xca\x4f\xa9\xb4\xe6\xe2\x02\x4b\x84\x38\x3a\xf9\xb8\x42\x25\xac\xb9\x00\x01\x00\x00\xff\xff\x35\x06\x52\x0d\x2c\x00\x00\x00")
|
||||
|
||||
func _1513982254_tokensDownSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__1513982254_tokensDownSql,
|
||||
"1513982254_tokens.down.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _1513982254_tokensDownSql() (*asset, error) {
|
||||
bytes, err := _1513982254_tokensDownSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1513982254_tokens.down.sql", size: 44, mode: os.FileMode(420), modTime: time.Unix(1516564385, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var __1513982254_tokensUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x74\x90\x4f\x4b\xc3\x40\x10\xc5\xef\xfb\x29\x86\x9e\x12\xd0\x83\x15\xbd\xf4\xb4\x6d\xa7\xb8\x98\x6e\x6a\x32\xab\x29\x22\x21\x26\x83\x04\xb1\x1b\xb2\x49\xd1\x6f\x2f\x5d\x62\x6c\xfd\xb3\xb7\x07\xbf\xfd\xbd\xe1\x2d\x12\x94\x84\x80\x19\xa1\x4e\x55\xac\x41\xad\x40\xc7\x04\x98\xa9\x94\x52\x98\xf4\x7d\x5d\x9d\x5b\xe7\x9a\xc9\x4c\x88\x01\x26\x39\x8f\xf0\x07\x48\xf6\x95\x77\x4e\x00\x04\x50\x57\xf0\xf5\x8c\x51\xcb\x31\x6c\x12\xb5\x96\xc9\x16\x6e\x71\x0b\x4b\x5c\x49\x13\x11\x1c\xf4\xf9\x0b\xef\xb8\x2d\x3a\xce\xf7\x17\x6f\x65\x10\x0a\x80\x33\x78\xb6\xd5\xc7\xf0\xef\x5e\x26\x8b\x1b\x99\x04\xd3\xab\xeb\xd0\x57\x6a\x13\x45\x1e\x2a\x5b\x2e\x3a\xdb\x1e\x43\x97\xd3\x10\x4e\x21\x57\xda\x86\x9d\x37\x11\x66\xf4\xf8\x34\x68\x7f\x9b\xb8\xca\x8b\x0e\x48\xad\x31\x25\xb9\xde\x1c\x43\xe3\xc1\x3a\x7e\x18\x2e\xe4\xf7\xa6\x6e\xd9\xfd\xfb\xc5\x43\x45\xd9\xd5\x7b\xf6\x7d\xf3\x38\x8e\x50\xea\xd3\xf2\xd1\xdb\xb5\x3d\x0b\x80\xf0\x7b\x65\xa3\xd5\x9d\x41\x50\x7a\x89\xd9\x9f\x63\xe7\x7e\x23\xbb\x1b\x22\x04\x87\x1c\xce\xc4\x67\x00\x00\x00\xff\xff\x43\x54\xbb\x34\xd3\x01\x00\x00")
|
||||
|
||||
func _1513982254_tokensUpSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
__1513982254_tokensUpSql,
|
||||
"1513982254_tokens.up.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func _1513982254_tokensUpSql() (*asset, error) {
|
||||
bytes, err := _1513982254_tokensUpSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "1513982254_tokens.up.sql", size: 467, mode: os.FileMode(420), modTime: time.Unix(1516564385, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _postgresSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xb4\x94\x4f\x8b\xea\x30\x14\xc5\xf7\xfd\x14\x77\x67\x85\x66\xf1\x56\x0f\xde\xe3\x21\xa2\x79\x4c\xa1\x2a\xd4\xce\xcc\x52\x62\x73\x9d\x09\x53\x1b\x49\xa2\x8c\xdf\x7e\x48\x5b\x35\xd1\xfa\x87\xa1\x03\x5d\x94\x40\xce\xf9\xdd\x73\x4f\x4b\x08\x94\x6c\x8d\x7f\x40\x94\x1a\x95\x21\x39\x2a\x23\x56\x22\x67\x06\x83\x78\x3a\xa7\x69\x06\xf1\x34\x9b\xc1\xe8\x74\xae\x43\x2e\xd7\x4c\x94\x11\x70\x66\x58\x1f\x5e\x86\xc9\x33\x9d\x43\x38\x88\x60\xd0\xff\x1b\x04\x47\xc9\x95\x28\x39\x91\x25\x7a\xa2\x73\x9a\xd0\x51\x06\x82\x47\xe0\xca\x44\x90\x2b\x64\x06\xf9\x82\x99\x08\x90\x8b\xc3\x2b\xcb\x8d\xd8\x21\xfc\x4f\x67\x13\x0f\x02\x5e\x9f\x68\x4a\x1b\x0d\xf8\x07\x03\x48\xe2\x49\x9c\xc1\x2f\x07\x40\xe1\x5a\xee\xf0\x02\x61\x4c\x13\x9a\xd1\xef\x49\xbe\xa1\x21\xac\x28\x5c\x3d\xdd\xd9\x4c\x8e\x4f\xb3\x0e\x25\xb7\x67\x8b\x48\xed\x89\x0e\x2b\x65\xa9\x22\x78\x97\xda\xd8\x2b\x67\x7b\x68\x5b\x43\x25\x46\x96\x7b\x22\xb8\x8b\x7c\x21\xf5\x10\x77\xcd\xd1\x44\x26\xf8\x95\xb8\x2e\xbd\xad\x49\xc7\xee\x87\x9b\xb7\x18\xec\xce\x2a\x06\x4d\x56\x52\x91\xad\x46\xd5\x31\x45\x23\x61\x21\x1c\x73\x8e\x05\x1a\x3c\x45\xe0\x95\xaf\x2d\xc3\xe1\x74\x7c\xbb\x81\x4d\x33\x8c\xfc\xc0\xd2\x6b\x46\x66\x4f\x74\xb8\x94\x7c\xef\x0c\xa4\x73\xb9\x41\x1d\x01\x7e\x6e\x84\x42\xbd\x60\xc6\x6f\x4a\xfd\xf4\xcf\x2a\x6e\x79\x6b\x07\x27\xa4\x2b\xca\x5e\x50\x47\x17\x3f\xa9\x9a\xed\x5e\x5b\x3c\x67\x5b\x16\xeb\xf8\x13\x04\x56\xe7\xce\x07\x5e\x31\xb4\x97\xa5\x2b\x8a\xf6\xc6\x38\x3f\xad\x7a\x03\x6e\x63\x1e\xcb\xb1\x91\xa8\x21\x78\x33\xca\x75\x9d\x13\x2c\x10\x10\xa5\x41\xb5\x63\x05\xf4\x7e\x03\x67\x7b\xdd\x0b\xbe\x02\x00\x00\xff\xff\x49\x2d\x7b\x8a\x23\x06\x00\x00")
|
||||
|
||||
func postgresSqlBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_postgresSql,
|
||||
"postgres.sql",
|
||||
)
|
||||
}
|
||||
|
||||
func postgresSql() (*asset, error) {
|
||||
bytes, err := postgresSqlBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "postgres.sql", size: 1571, mode: os.FileMode(420), modTime: time.Unix(1516571679, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.bytes, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
|
||||
// MustAsset is like Asset but panics when Asset would return an error.
|
||||
// It simplifies safe initialization of global variables.
|
||||
func MustAsset(name string) []byte {
|
||||
a, err := Asset(name)
|
||||
if err != nil {
|
||||
panic("asset: Asset(" + name + "): " + err.Error())
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// AssetInfo loads and returns the asset info for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func AssetInfo(name string) (os.FileInfo, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.info, nil
|
||||
}
|
||||
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||
}
|
||||
|
||||
// AssetNames returns the names of the assets.
|
||||
func AssetNames() []string {
|
||||
names := make([]string, 0, len(_bindata))
|
||||
for name := range _bindata {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"1513981282_certificates.down.sql": _1513981282_certificatesDownSql,
|
||||
"1513981282_certificates.up.sql": _1513981282_certificatesUpSql,
|
||||
"1513981599_routes.down.sql": _1513981599_routesDownSql,
|
||||
"1513981599_routes.up.sql": _1513981599_routesUpSql,
|
||||
"1513982254_tokens.down.sql": _1513982254_tokensDownSql,
|
||||
"1513982254_tokens.up.sql": _1513982254_tokensUpSql,
|
||||
"postgres.sql": postgresSql,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
// directory embedded in the file by go-bindata.
|
||||
// For example if you run go-bindata on data/... and data contains the
|
||||
// following hierarchy:
|
||||
// data/
|
||||
// foo.txt
|
||||
// img/
|
||||
// a.png
|
||||
// b.png
|
||||
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||
// AssetDir("") will return []string{"data"}.
|
||||
func AssetDir(name string) ([]string, error) {
|
||||
node := _bintree
|
||||
if len(name) != 0 {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
pathList := strings.Split(cannonicalName, "/")
|
||||
for _, p := range pathList {
|
||||
node = node.Children[p]
|
||||
if node == nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.Func != nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
rv := make([]string, 0, len(node.Children))
|
||||
for childName := range node.Children {
|
||||
rv = append(rv, childName)
|
||||
}
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
type bintree struct {
|
||||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"1513981282_certificates.down.sql": &bintree{_1513981282_certificatesDownSql, map[string]*bintree{}},
|
||||
"1513981282_certificates.up.sql": &bintree{_1513981282_certificatesUpSql, map[string]*bintree{}},
|
||||
"1513981599_routes.down.sql": &bintree{_1513981599_routesDownSql, map[string]*bintree{}},
|
||||
"1513981599_routes.up.sql": &bintree{_1513981599_routesUpSql, map[string]*bintree{}},
|
||||
"1513982254_tokens.down.sql": &bintree{_1513982254_tokensDownSql, map[string]*bintree{}},
|
||||
"1513982254_tokens.up.sql": &bintree{_1513982254_tokensUpSql, map[string]*bintree{}},
|
||||
"postgres.sql": &bintree{postgresSql, map[string]*bintree{}},
|
||||
}}
|
||||
|
||||
// RestoreAsset restores an asset under the given directory
|
||||
func RestoreAsset(dir, name string) error {
|
||||
data, err := Asset(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := AssetInfo(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RestoreAssets restores an asset under the given directory recursively
|
||||
func RestoreAssets(dir, name string) error {
|
||||
children, err := AssetDir(name)
|
||||
// File
|
||||
if err != nil {
|
||||
return RestoreAsset(dir, name)
|
||||
}
|
||||
// Dir
|
||||
for _, child := range children {
|
||||
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _filePath(dir, name string) string {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
DROP INDEX Certificates_domain;
|
||||
DROP TABLE Certificates;
|
|
@ -1,12 +0,0 @@
|
|||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Certificates
|
||||
( id UUID PRIMARY KEY DEFAULT uuid_generate_v1mc()
|
||||
, domain VARCHAR(256) NOT NULL
|
||||
, data TEXT NOT NULL
|
||||
, created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
, edited_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
, active BOOLEAN NOT NULL DEFAULT true
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS Certificates_domain ON Certificates (domain);
|
|
@ -1 +0,0 @@
|
|||
DROP TABLE Routes;
|
|
@ -1,12 +0,0 @@
|
|||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Routes
|
||||
( id UUID PRIMARY KEY DEFAULT uuid_generate_v1mc()
|
||||
, creator VARCHAR(32) NOT NULL
|
||||
, hostname VARCHAR(256) NOT NULL
|
||||
, created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
, edited_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
, active BOOLEAN NOT NULL DEFAULT true
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS Routes_hostname on Routes (hostname);
|
|
@ -1,3 +0,0 @@
|
|||
DROP INDEX Tokens_body;
|
||||
|
||||
DROP TABLE Tokens;
|
|
@ -1,13 +0,0 @@
|
|||
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
|
||||
|
||||
CREATE TABLE IF NOT EXISTS Tokens
|
||||
( id UUID PRIMARY KEY DEFAULT uuid_generate_v1mc()
|
||||
, body VARCHAR(256) NOT NULL
|
||||
, creator VARCHAR(32) NOT NULL
|
||||
, scopes TEXT[] NOT NULL
|
||||
, created_at TIMESTAMP NOT NULL DEFAULT NOW()
|
||||
, expires_at TIMESTAMP NOT NULL
|
||||
, active BOOLEAN NOT NULL DEFAULT true
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS Tokens_body on Tokens (body);
|
|
@ -1,42 +0,0 @@
|
|||
-- name: insert-certificate
|
||||
INSERT INTO Certificates(domain, data) VALUES ($1, $2);
|
||||
|
||||
-- name: find-one-certificate
|
||||
SELECT id, domain, data, created_at, edited_at, active FROM Certificates WHERE domain = $1 LIMIT 1;
|
||||
|
||||
-- name: remove-one-certificate
|
||||
DELETE FROM Certificates WHERE domain = $1 LIMIT 1;
|
||||
|
||||
-- name: get-all-certificates
|
||||
SELECT id, domain, data, created_at, edited_at, active FROM Certificates;
|
||||
|
||||
-- name: insert-route
|
||||
INSERT INTO Routes(creator, hostname) VALUES ($1, $2);
|
||||
|
||||
-- name: find-one-route-by-id
|
||||
SELECT id, creator, hostname, created_at, edited_at, active FROM Routes WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: find-one-route-by-host
|
||||
SELECT id, creator, hostname, created_at, edited_at, active FROM Routes WHERE hostname = $1 LIMIT 1;
|
||||
|
||||
-- name: find-all-routes-for-user
|
||||
SELECT id, creator, hostname, created_at, edited_at, active FROM Routes WHERE creator = $1;
|
||||
|
||||
-- name: delete-one-route
|
||||
DELETE FROM Routes WHERE id = $1 AND domain = $2 LIMIT 1;
|
||||
|
||||
-- name: insert-token
|
||||
INSERT INTO Tokens(body, creator, scopes, expires_at) VALUES ($1, $2, $3, $4);
|
||||
|
||||
-- name: get-one-token
|
||||
SELECT id, body, creator, scopes, created_at, expires_at, active FROM Tokens WHERE id = $1 LIMIT 1;
|
||||
|
||||
-- name: get-one-token-by-body
|
||||
SELECT id, body, creator, scopes, created_at, expires_at, active FROM Tokens WHERE body = $1 LIMIT 1;
|
||||
|
||||
-- name: get-all-tokens-for-user
|
||||
SELECT id, body, creator, scopes, created_at, expires_at, active FROM Tokens WHERE creator = $1;
|
||||
|
||||
-- name: remove-one-token
|
||||
DELETE FROM Tokens WHERE id = $1 LIMIT 1;
|
||||
|
|
@ -1,178 +0,0 @@
|
|||
// +build ignore
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"database/sql"
|
||||
"log"
|
||||
|
||||
"git.xeserv.us/xena/route/internal/database/dmigrations"
|
||||
"github.com/Xe/uuid"
|
||||
"github.com/brandur/simplebox"
|
||||
"github.com/gchaincl/dotsql"
|
||||
_ "github.com/lib/pq"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type PostgresStorage struct {
|
||||
ds *dotsql.DotSql
|
||||
db *sql.DB
|
||||
sb *simplebox.SimpleBox
|
||||
|
||||
//cs *postgresCertificateStorage
|
||||
rs *postgresRouteStorage
|
||||
//ts *postgresTokenStorage
|
||||
}
|
||||
|
||||
type postgresCertificateStorage struct {
|
||||
*PostgresStorage
|
||||
}
|
||||
|
||||
type postgresRouteStorage struct {
|
||||
*PostgresStorage
|
||||
}
|
||||
|
||||
type postgresTokenStorage struct {
|
||||
*PostgresStorage
|
||||
}
|
||||
|
||||
// NewPostgresStorage creates a new Storage instance backed by postgres at the
|
||||
// given URL.
|
||||
func NewPostgresStorage(url string, key *[32]byte) (Storage, error) {
|
||||
db, err := sql.Open("postgres", url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
data, err := dmigrations.Asset("postgres.sql")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf := bytes.NewBuffer(data)
|
||||
|
||||
ds, err := dotsql.Load(buf)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for k := range ds.QueryMap() {
|
||||
log.Printf("preparing %s", k)
|
||||
stmt, err := ds.Prepare(db, k)
|
||||
if err != nil {
|
||||
db.Close()
|
||||
return nil, err
|
||||
}
|
||||
defer stmt.Close()
|
||||
}
|
||||
|
||||
p := &PostgresStorage{
|
||||
db: db,
|
||||
ds: ds,
|
||||
sb: simplebox.NewFromSecretKey(key),
|
||||
}
|
||||
|
||||
//p.cs = &postgresCertificateStorage{p}
|
||||
p.rs = &postgresRouteStorage{p}
|
||||
//p.ts = &postgresTokenStorage{p}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// Certs gets the certificate storage interface.
|
||||
func (p *PostgresStorage) Certs() Certs { return nil }
|
||||
|
||||
// Routes gets the route storage interface.
|
||||
func (p *PostgresStorage) Routes() Routes { return p.rs }
|
||||
|
||||
// Tokens gets the token storage interface.
|
||||
func (p *PostgresStorage) Tokens() Tokens { return nil }
|
||||
|
||||
// Close cleans up resources for this Storage.
|
||||
func (p *PostgresStorage) Close() error { return p.db.Close() }
|
||||
|
||||
// interface compliance
|
||||
var (
|
||||
_ Storage = &PostgresStorage{}
|
||||
//_ Certs = &postgresCertificateStorage{}
|
||||
_ Routes = &postgresRouteStorage{}
|
||||
//_ Tokens = &postgresTokenStorage{}
|
||||
)
|
||||
|
||||
func (p *postgresRouteStorage) getRouteInner(ctx context.Context, arg string, kind string) (Route, error) {
|
||||
r, err := p.ds.QueryRow(p.db, kind, arg)
|
||||
if err != nil {
|
||||
return Route{}, err
|
||||
}
|
||||
|
||||
rt := Route{}
|
||||
|
||||
err = (&rt).Scan(r)
|
||||
if err != nil {
|
||||
return Route{}, err
|
||||
}
|
||||
|
||||
return rt, nil
|
||||
}
|
||||
|
||||
func (p *postgresRouteStorage) Get(ctx context.Context, id string) (Route, error) {
|
||||
return p.getRouteInner(ctx, id, "find-one-route-by-id")
|
||||
}
|
||||
|
||||
func (p *postgresRouteStorage) GetHost(ctx context.Context, host string) (Route, error) {
|
||||
return p.getRouteInner(ctx, host, "find-one-route-by-host")
|
||||
}
|
||||
|
||||
func (p *postgresRouteStorage) GetAll(ctx context.Context, user string) ([]Route, error) {
|
||||
var result []Route
|
||||
|
||||
rows, err := p.ds.Query(p.db, "find-all-routes-for-user", user)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer rows.Close()
|
||||
for rows.Next() {
|
||||
rt := &Route{}
|
||||
|
||||
if err := rt.Scan(rows); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
result = append(result, *rt)
|
||||
}
|
||||
|
||||
if err := rows.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (p *postgresRouteStorage) Put(ctx context.Context, r Route) (Route, error) {
|
||||
if r.ID == "" {
|
||||
r.ID = uuid.New()
|
||||
}
|
||||
|
||||
_, err := p.ds.Exec(p.db, "insert-route", r.ID, r.Hostname)
|
||||
if err != nil {
|
||||
return Route{}, err
|
||||
}
|
||||
|
||||
return p.Get(ctx, r.ID)
|
||||
}
|
||||
|
||||
func (p *postgresRouteStorage) Delete(ctx context.Context, r Route) (Route, error) {
|
||||
rt, err := p.Get(ctx, r.ID)
|
||||
if err != nil {
|
||||
return Route{}, err
|
||||
}
|
||||
|
||||
_, err = p.ds.Exec(p.db, "delete-one-route", rt.ID, rt.Hostname)
|
||||
if err != nil {
|
||||
return Route{}, err
|
||||
}
|
||||
|
||||
return rt, nil
|
||||
}
|
|
@ -2,7 +2,6 @@ package database
|
|||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
proto "git.xeserv.us/xena/route/proto"
|
||||
"github.com/Xe/ln"
|
||||
|
@ -27,10 +26,6 @@ type Route struct {
|
|||
ID string `storm:"id"`
|
||||
Creator string
|
||||
Hostname string `storm:"unique"`
|
||||
|
||||
CreatedAt time.Time
|
||||
EditedAt time.Time
|
||||
Active bool
|
||||
}
|
||||
|
||||
// F https://godoc.org/github.com/Xe/ln#F
|
||||
|
@ -42,10 +37,6 @@ func (r Route) F() ln.F {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *Route) Scan(row Scanner) error {
|
||||
return row.Scan(&r.ID, &r.Creator, &r.Hostname, &r.CreatedAt, &r.EditedAt, &r.Active)
|
||||
}
|
||||
|
||||
// AsProto converts this into a protobuf Route.
|
||||
func (r Route) AsProto() *proto.Route {
|
||||
return &proto.Route{
|
||||
|
|
|
@ -1,85 +0,0 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/Xe/uuid"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
const (
|
||||
creator = "shachi"
|
||||
hostBase = "shachi.loves."
|
||||
)
|
||||
|
||||
func testRoutes(ctx context.Context, t *testing.T, r Routes) {
|
||||
hostname := hostBase + uuid.New()
|
||||
id := uuid.New()
|
||||
|
||||
t.Run("put", func(t *testing.T) {
|
||||
rt := Route{
|
||||
ID: id,
|
||||
Creator: creator,
|
||||
Hostname: hostname,
|
||||
}
|
||||
|
||||
_, err := r.Put(ctx, rt)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("get", func(t *testing.T) {
|
||||
_, err := r.Get(ctx, id)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("getHost", func(t *testing.T) {
|
||||
_, err := r.GetHost(ctx, hostname)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("getAll", func(t *testing.T) {
|
||||
res, err := r.GetAll(ctx, creator)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(res) == 0 {
|
||||
t.Fatal("didn't get any routes back for shachi")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("delete", func(t *testing.T) {
|
||||
_, err := r.Delete(ctx, Route{ID: id})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = r.Get(ctx, id)
|
||||
if err == nil {
|
||||
t.Fatal("able to fetch a deleted item")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBoltDBRouteStorage(t *testing.T) {
|
||||
st, p, ctx, cancel := newTestBoltStorage(t)
|
||||
defer os.RemoveAll(p)
|
||||
defer st.Close()
|
||||
defer cancel()
|
||||
|
||||
testRoutes(ctx, t, st.Routes())
|
||||
}
|
||||
|
||||
func TestPostgresRouteStorage(t *testing.T) {
|
||||
st, ctx, cancel := newTestPostgresStorage(t, os.Getenv("DATABASE_URL"))
|
||||
defer st.Close()
|
||||
defer cancel()
|
||||
|
||||
testRoutes(ctx, t, st.Routes())
|
||||
}
|
|
@ -1,14 +1,30 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
// Storage is the parent interface for the database backends of route.
|
||||
type Storage interface {
|
||||
Certs() Certs
|
||||
Routes() Routes
|
||||
Tokens() Tokens
|
||||
// routes
|
||||
GetRoute(ctx context.Context, id string) (Route, error)
|
||||
GetRouteHost(ctx context.Context, host string) (Route, error)
|
||||
GetAllRoutes(ctx context.Context, user string) ([]Route, error)
|
||||
PutRoute(ctx context.Context, domain, kind string) (Route, error)
|
||||
DeleteRoute(ctx context.Context, id string) error
|
||||
|
||||
// tokens
|
||||
GetToken(ctx context.Context, token string) (Token, error)
|
||||
GetTokenID(ctx context.Context, id string) (Token, error)
|
||||
GetTokensForOwner(ctx context.Context, owner string) ([]Token, error)
|
||||
PutToken(ctx context.Context, token, owner string, scopes []string) (Token, error)
|
||||
DeleteToken(ctx context.Context, id string) error
|
||||
DeactivateToken(ctx context.Context, id string) error
|
||||
|
||||
// certificates
|
||||
GetCert(ctx context.Context, key string) ([]byte, error)
|
||||
PutCert(ctx context.Context, key string, data []byte) error
|
||||
DeleteCert(ctx context.Context, key string) error
|
||||
|
||||
Close() error
|
||||
}
|
||||
|
||||
type Scanner interface {
|
||||
Scan(...interface{}) error
|
||||
}
|
||||
|
|
|
@ -1,74 +0,0 @@
|
|||
package database
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
func testTokens(ctx context.Context, t *testing.T, tk Tokens) {
|
||||
var (
|
||||
tokenID string
|
||||
tokenBody string
|
||||
)
|
||||
|
||||
t.Run("put", func(t *testing.T) {
|
||||
tok := Token{
|
||||
Owner: creator,
|
||||
}
|
||||
|
||||
tok2, err := tk.Put(ctx, tok)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
tokenID = tok2.ID
|
||||
tokenBody = tok2.Body
|
||||
})
|
||||
|
||||
t.Run("get", func(t *testing.T) {
|
||||
_, err := tk.Get(ctx, tokenID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("getBody", func(t *testing.T) {
|
||||
_, err := tk.GetBody(ctx, tokenBody)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("getAll", func(t *testing.T) {
|
||||
lis, err := tk.GetAll(ctx, creator)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(lis) == 0 {
|
||||
t.Fatal("expected results but got none")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("delete", func(t *testing.T) {
|
||||
_, err := tk.Delete(ctx, tokenID)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
_, err = tk.Get(ctx, tokenID)
|
||||
if err == nil {
|
||||
t.Fatal("can fetch a deleted resource")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestBoltDBTokenStorage(t *testing.T) {
|
||||
st, p, ctx, cancel := newTestBoltStorage(t)
|
||||
defer os.RemoveAll(p)
|
||||
defer st.Close()
|
||||
defer cancel()
|
||||
|
||||
testTokens(ctx, t, st.Tokens())
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package gluaroute
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.xeserv.us/xena/route/proto"
|
||||
"git.xeserv.us/xena/route/proto/route"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
var exports = map[string]lua.LGFunction{
|
||||
"new": newClient,
|
||||
}
|
||||
|
||||
func newClient(L *lua.LState) int {
|
||||
routedURL := L.ToString(1)
|
||||
token := L.ToString(2)
|
||||
|
||||
L.Push(luar.New(L, route.New(routedURL, token, &http.Client{})))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
type client struct {
|
||||
*route.Client
|
||||
}
|
||||
|
||||
type backends struct {
|
||||
proto.Backends
|
||||
}
|
||||
|
||||
type routes struct {
|
||||
proto.Routes
|
||||
}
|
||||
|
||||
type tokens struct {
|
||||
proto.Tokens
|
||||
}
|
||||
|
||||
func Preload(L *lua.LState) {
|
||||
L.PreloadModule("svc", Loader)
|
||||
}
|
||||
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
52
mage.go
52
mage.go
|
@ -12,13 +12,10 @@ import (
|
|||
|
||||
"github.com/jtolds/qod"
|
||||
"github.com/magefile/mage/mg"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
var wd string
|
||||
var arches []string
|
||||
var bins []string
|
||||
var tools []string
|
||||
|
||||
func init() {
|
||||
lwd, err := os.Getwd()
|
||||
|
@ -27,14 +24,6 @@ func init() {
|
|||
wd = lwd
|
||||
|
||||
arches = []string{"amd64", "ppc64", "386", "arm", "arm64"}
|
||||
bins = []string{"route-httpagent", "route-cli", "routed", "terraform-provider-route", "construct"}
|
||||
tools = []string{
|
||||
"github.com/golang/dep/cmd/dep",
|
||||
"github.com/golang/protobuf/protoc-gen-go",
|
||||
"github.com/twitchtv/twirp/protoc-gen-twirp",
|
||||
"github.com/Xe/twirp-codegens/cmd/protoc-gen-twirp_eclier",
|
||||
"github.com/jteeuwen/go-bindata/go-bindata",
|
||||
}
|
||||
}
|
||||
|
||||
const pkgBase = "git.xeserv.us/xena/route/"
|
||||
|
@ -47,7 +36,7 @@ func buildBins(goos, goarch string) {
|
|||
|
||||
os.MkdirAll(filepath.Join(d, goos, goarch), 0777)
|
||||
|
||||
for _, pkg := range bins {
|
||||
for _, pkg := range []string{"route-httpagent", "route-cli", "routed", "terraform-provider-route"} {
|
||||
env := []string{"GOOS=" + goos, "GOARCH=" + goarch}
|
||||
goBuild(ctx, env, filepath.Join(d, goos, goarch), "cmd/"+pkg)
|
||||
goInstall(ctx, env, "cmd/"+pkg)
|
||||
|
@ -61,7 +50,7 @@ func Dep() {
|
|||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
shouldWork(ctx, nil, wd, "dep", "ensure", "-update")
|
||||
shouldWork(ctx, nil, wd, "dep", "ensure")
|
||||
shouldWork(ctx, nil, wd, "dep", "prune")
|
||||
}
|
||||
|
||||
|
@ -73,9 +62,9 @@ func Docker() {
|
|||
ver, err := gitTag()
|
||||
qod.ANE(err)
|
||||
|
||||
shouldWork(ctx, nil, wd, "docker", "build", "-t", "xena/route-core", ".")
|
||||
shouldWork(ctx, nil, wd+"/run", "docker", "build", "-t", "xena/routed:"+ver, "-f", "Dockerfile.routed", ".")
|
||||
shouldWork(ctx, nil, wd+"/run", "docker", "build", "-t", "xena/route-httpagent:"+ver, "-f", "Dockerfile.agent", ".")
|
||||
shouldWork(ctx, nil, wd, "box", "box.rb")
|
||||
shouldWork(ctx, nil, wd, "docker", "tag", "xena/route:latest", "xena/route:"+ver)
|
||||
shouldWork(ctx, nil, wd, "docker", "tag", "xena/route:thick", "xena/route:thick-"+ver)
|
||||
}
|
||||
|
||||
// Linux builds binaries for linux
|
||||
|
@ -99,6 +88,10 @@ func Darwin() {
|
|||
// Build builds the binaries for route and routed.
|
||||
func Build() {
|
||||
buildBins(runtime.GOOS, runtime.GOARCH)
|
||||
|
||||
if runtime.GOOS == "linux" {
|
||||
Plugin()
|
||||
}
|
||||
}
|
||||
|
||||
// Plugin builds all of the plugins for programs wanting to augment themselves with route.
|
||||
|
@ -168,8 +161,14 @@ func Test() {
|
|||
|
||||
// Tools installs all of the needed tools for the project.
|
||||
func Tools(ctx context.Context) {
|
||||
tools := []string{
|
||||
"github.com/golang/dep/cmd/dep",
|
||||
"github.com/golang/protobuf/protoc-gen-go",
|
||||
"github.com/twitchtv/twirp/protoc-gen-twirp",
|
||||
}
|
||||
|
||||
for _, t := range tools {
|
||||
shouldWork(ctx, nil, wd, "go", "get", "-v", "-u", t)
|
||||
shouldWork(ctx, nil, wd, "go", "get", "-u", t)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -177,22 +176,15 @@ func Tools(ctx context.Context) {
|
|||
func Generate(ctx context.Context) {
|
||||
dir := filepath.Join(wd, "proto")
|
||||
|
||||
Tools(ctx)
|
||||
|
||||
shouldWork(ctx, nil, dir, "sh", "./regen.sh")
|
||||
shouldWork(ctx, nil, filepath.Join(dir, "eclier"), "go-bindata", "-pkg", "edata", "-ignore", "bindata.go", ".")
|
||||
}
|
||||
|
||||
// Vars shows the various variables that this magefile uses.
|
||||
func Vars() {
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
|
||||
table.SetHeader([]string{"key", "value"})
|
||||
|
||||
table.Append([]string{"arches", fmt.Sprint(arches)})
|
||||
table.Append([]string{"bins", fmt.Sprint(bins)})
|
||||
table.Append([]string{"goarch", runtime.GOARCH})
|
||||
table.Append([]string{"goos", runtime.GOOS})
|
||||
table.Append([]string{"tools", fmt.Sprint(tools)})
|
||||
table.Append([]string{"wd", wd})
|
||||
|
||||
table.Render()
|
||||
qod.Printlnf("goarch:\t%s", runtime.GOARCH)
|
||||
qod.Printlnf("goos:\t%s", runtime.GOOS)
|
||||
qod.Printlnf("arches:\t%v", arches)
|
||||
qod.Printlnf("wd:\t%s", wd)
|
||||
}
|
||||
|
|
|
@ -4,18 +4,14 @@ package main
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/jtolds/qod"
|
||||
"github.com/kr/fs"
|
||||
"github.com/pkg/errors"
|
||||
"layeh.com/asar"
|
||||
)
|
||||
|
||||
func output(cmd string, args ...string) (string, error) {
|
||||
|
@ -76,32 +72,3 @@ func goBuildPlugin(ctx context.Context, dir, pkgname, fname string) {
|
|||
shouldWork(ctx, nil, dir, "go", "build", "-v", "-buildmode=plugin", "-o="+fname, pkgBase+pkgname)
|
||||
qod.Printlnf("built %s for %s", fname, runtime.GOOS)
|
||||
}
|
||||
|
||||
func asarPack(dir string) (*asar.Entry, error) {
|
||||
b := &asar.Builder{}
|
||||
|
||||
w := fs.Walk(dir)
|
||||
for w.Step() {
|
||||
if err := w.Err(); err != nil {
|
||||
fmt.Printf("walk error: %v\n", err)
|
||||
continue
|
||||
}
|
||||
|
||||
p := w.Path()
|
||||
st := w.Stat()
|
||||
|
||||
if st.IsDir() {
|
||||
w.SkipDir()
|
||||
}
|
||||
|
||||
fin, err := os.Open(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer fin.Close()
|
||||
|
||||
b.Add(filepath.Base(p), fin, st.Size(), asar.FlagNone)
|
||||
}
|
||||
|
||||
return b.Root(), nil
|
||||
}
|
||||
|
|
|
@ -1,465 +0,0 @@
|
|||
// Code generated by go-bindata.
|
||||
// sources:
|
||||
// route_twirp_eclier_backends_kill.lua
|
||||
// route_twirp_eclier_backends_list.lua
|
||||
// route_twirp_eclier_routes_delete.lua
|
||||
// route_twirp_eclier_routes_get.lua
|
||||
// route_twirp_eclier_routes_get_all.lua
|
||||
// route_twirp_eclier_routes_put.lua
|
||||
// route_twirp_eclier_tokens_deactivate.lua
|
||||
// route_twirp_eclier_tokens_delete.lua
|
||||
// route_twirp_eclier_tokens_get.lua
|
||||
// route_twirp_eclier_tokens_get_all.lua
|
||||
// route_twirp_eclier_tokens_put.lua
|
||||
// DO NOT EDIT!
|
||||
|
||||
package edata
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func bindataRead(data []byte, name string) ([]byte, error) {
|
||||
gz, err := gzip.NewReader(bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
_, err = io.Copy(&buf, gz)
|
||||
clErr := gz.Close()
|
||||
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Read %q: %v", name, err)
|
||||
}
|
||||
if clErr != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
type asset struct {
|
||||
bytes []byte
|
||||
info os.FileInfo
|
||||
}
|
||||
|
||||
type bindataFileInfo struct {
|
||||
name string
|
||||
size int64
|
||||
mode os.FileMode
|
||||
modTime time.Time
|
||||
}
|
||||
|
||||
func (fi bindataFileInfo) Name() string {
|
||||
return fi.name
|
||||
}
|
||||
func (fi bindataFileInfo) Size() int64 {
|
||||
return fi.size
|
||||
}
|
||||
func (fi bindataFileInfo) Mode() os.FileMode {
|
||||
return fi.mode
|
||||
}
|
||||
func (fi bindataFileInfo) ModTime() time.Time {
|
||||
return fi.modTime
|
||||
}
|
||||
func (fi bindataFileInfo) IsDir() bool {
|
||||
return false
|
||||
}
|
||||
func (fi bindataFileInfo) Sys() interface{} {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_backends_killLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x5c\x52\x4d\x6b\xdc\x30\x10\xbd\xeb\x57\x3c\x74\xb2\x21\x36\xdb\x43\x2f\x0b\xbe\xb4\xc9\x21\x50\x1a\x28\xe9\xa9\x84\xa2\x95\xc7\xb6\x58\xaf\xe4\xce\x48\x4e\xfa\xef\x8b\xe4\xec\x47\x73\x30\x58\x7a\xef\xcd\x7b\x33\xa3\xa6\xc1\xd7\xd0\x13\x46\xf2\xc4\x26\x52\x8f\xc3\x5f\x2c\x1c\x62\xb0\xcd\x48\xbe\x89\xaf\x8e\x97\xdf\x64\x67\x47\x8c\xf5\x73\xbb\x6b\x77\xf7\x4f\xf8\xfe\xf4\x8c\x87\xfb\xc7\x67\xd5\x34\x90\x90\xd8\xd2\x1e\x1c\x52\xa4\xb6\x48\x95\x12\xcb\x6e\x89\xed\x4a\x7c\x40\x07\x7d\x30\xf6\x48\xbe\x97\xfd\xd1\xcd\xb3\x3e\xa3\x13\xcd\x4b\x46\x1f\xde\xc8\xa6\x48\x82\x13\xc5\x29\xf4\xc8\x24\x04\x0f\x21\x5e\x9d\x25\x9c\xd5\x18\x02\xa3\x04\xc2\x62\xec\xd1\x8c\x84\x37\xca\xa4\x36\x49\xbb\xd9\x9f\xa9\x17\x0f\x93\xe2\x14\x38\xbb\x9c\x8c\x9d\x9c\xa7\xe6\xd2\xa9\xbe\x49\x29\x2e\xf8\x4c\xda\x3a\xbc\x20\x49\xb2\x49\x07\xad\x95\x9a\x83\x35\x33\x86\xd9\x8c\xe8\xc0\xf4\x27\x39\x26\xe8\x7c\xd6\xef\x98\xac\xf6\x16\x92\xd5\x5e\x65\x82\xae\x68\x5b\x4f\xaf\x55\xad\xf2\xe0\xf2\x71\xeb\xe9\xcb\x96\xfa\xb1\x57\x83\xec\x25\xb2\xf3\x63\xa5\x5d\xaf\xef\xa0\xf3\xb7\x9a\x39\x51\x21\x9e\x48\x4a\x22\xc3\x23\x5c\xaf\x6b\xf5\x31\xe8\x20\xfb\xf2\x9b\x2d\x86\xe4\x6d\xcc\x7d\x71\xf2\x95\xe1\xb1\x56\x80\x1b\xb2\xf6\xd7\xa7\x17\x74\x1d\x74\x93\x37\xa0\x11\xf8\xbf\xcb\xf7\xdb\x38\x91\x57\x00\xb0\xb0\xf3\xb1\xba\x56\xae\xcb\x2d\x53\x4c\x9c\x09\xe4\x7b\xa5\x50\x2a\xec\x5e\xd0\xe1\x66\xf5\x0a\xb8\x4e\x4d\xb6\x78\x8b\x61\xa1\x2d\xce\x05\x66\x92\xfc\x10\x64\xb5\x65\x3c\x66\x71\x3f\x7f\x7c\xbb\x43\x0c\x47\xf2\xf5\xfe\xbc\xd3\xaa\x2e\xcf\xa7\x2a\xc5\x6a\xa5\xb2\xf1\xbf\x00\x00\x00\xff\xff\x9b\x1b\x96\x37\xbf\x02\x00\x00")
|
||||
|
||||
func route_twirp_eclier_backends_killLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_backends_killLua,
|
||||
"route_twirp_eclier_backends_kill.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_backends_killLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_backends_killLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_backends_kill.lua", size: 703, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_backends_listLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x52\xc1\x6e\xdb\x3a\x10\xbc\xf3\x2b\x06\x3c\x59\x40\x24\xe4\x1d\xde\x45\x80\x2e\x6d\x72\x28\x50\x34\x40\x9b\x9e\x9a\xa0\xa0\xa9\x95\x4c\x44\x26\xd5\x5d\x52\x49\xff\xbe\x20\x65\xd9\x6e\x81\xf6\x60\xc0\xdc\x99\xd9\x9d\x5d\x4d\x5d\xe3\x7d\xe8\x09\x23\x79\x62\x13\xa9\xc7\xfe\x27\x66\x0e\x31\xd8\x7a\x24\x5f\xc7\x57\xc7\xf3\x77\xb2\x93\x23\xc6\xf2\x7f\x73\xdb\xdc\xde\x3d\xe0\xd3\xc3\x23\xee\xef\x3e\x3c\xaa\xba\x86\x84\xc4\x96\x5a\x70\x48\x91\x9a\x22\x55\x4a\x2c\xbb\x39\x36\x0b\xf1\x1e\x1d\xf4\xde\xd8\x17\xf2\xbd\xb4\x93\x93\xa8\x37\xf4\x40\xd3\x9c\xd1\xfb\x37\xb2\x29\x92\xe0\x48\xf1\x10\x7a\x64\x12\x82\x87\x10\x2f\xce\x12\x36\x35\x86\xc0\x28\x86\x30\x1b\xfb\x62\x46\xc2\x1b\x65\x52\x93\xa4\x59\xc7\x6f\xd4\xf3\x0c\x93\xe2\x21\x70\x9e\x72\x34\xf6\xe0\x3c\xd5\xe7\x4d\xf5\x95\x4b\x71\xc1\x67\xd2\xba\xe1\x19\x49\x92\x87\x74\xd0\x5a\xa9\x29\x58\x33\x61\x98\xcc\x88\x0e\x4c\x3f\x92\x63\x82\xce\x6f\x7d\xc2\x64\xb1\xd7\x90\x2c\xf6\x22\x13\x74\x45\xdb\x78\x7a\xdd\x55\x2a\x1f\x2e\x3f\xd7\x9d\xde\xad\xae\xbf\xd0\x44\x36\x06\x56\x83\xb4\x12\xd9\xf9\x71\xa7\xfb\x70\x34\xce\xeb\x1b\xe8\xfc\x5b\xcc\x94\xa8\x48\x8e\x24\xc5\x9b\xe1\x11\x27\x4e\x75\xad\x4b\x42\xfc\x6f\x55\x61\x54\xea\xcf\x55\x07\x69\xcb\xdf\x6c\x72\x48\xde\xc6\x7c\x19\x4e\x7e\x67\x78\xac\x14\xe0\x86\xac\xfe\xf6\xdf\x33\xba\x0e\xba\xce\xdf\x50\x23\xf0\x6f\xc5\x53\x35\x1e\xc8\x2b\x00\x98\xd9\xf9\xb8\xbb\x74\xae\x4a\x95\x29\x26\xce\x04\xf2\xbd\x52\x28\x1d\x6e\x9f\xd1\xe1\x2a\x3c\x0a\xb8\xdc\x5d\x56\x7b\xb3\x61\xa1\xd5\xce\x19\x66\x92\x1c\x25\x59\x6c\x39\xb0\x99\xdd\xd7\xcf\x1f\x6f\x10\xc3\x0b\xf9\xaa\xdd\x52\xb1\xab\x4a\x00\x77\xa5\x59\x51\xaf\xce\xf4\x5e\xda\xa7\xf8\x14\x35\x9a\x06\x31\x9c\x6e\x98\x7b\x36\x7b\x29\x6e\x37\xde\x96\xe3\xbf\xb1\x4f\x78\x55\xa9\xbc\xd4\xaf\x00\x00\x00\xff\xff\x5b\x4a\x7f\xf6\x5d\x03\x00\x00")
|
||||
|
||||
func route_twirp_eclier_backends_listLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_backends_listLua,
|
||||
"route_twirp_eclier_backends_list.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_backends_listLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_backends_listLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_backends_list.lua", size: 861, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_routes_deleteLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x52\x4f\x6b\xdc\x3e\x10\xbd\xeb\x53\x3c\x74\xb2\x21\x36\xfb\x3b\xfc\x2e\x06\x9f\x9a\x1c\x0a\xa5\x81\x90\x9e\x4a\x28\x8a\x3c\xb6\x45\xbc\x92\x3b\x23\x39\xe9\xb7\x2f\x92\x37\xbb\x9b\x1e\x72\x30\x58\xf3\xde\x9b\x79\xf3\xa7\x69\xf0\x25\x0c\x84\x89\x3c\xb1\x89\x34\xe0\xf9\x0f\x56\x0e\x31\xd8\x66\x22\xdf\xc4\x57\xc7\xeb\x2f\xb2\x8b\x23\xc6\xf6\x7f\x7b\x68\x0f\xb7\xf7\xf8\x7e\xff\x88\xbb\xdb\xaf\x8f\xaa\x69\x20\x21\xb1\xa5\x0e\x1c\x52\xa4\xb6\x48\x95\x12\xcb\x6e\x8d\xed\x46\xfc\x8c\x1e\xba\x60\xd2\x0d\xb4\x50\x24\xfd\x8e\xce\xb4\xac\x19\xbd\x7b\x23\x9b\x71\x1c\x29\xce\x61\xc0\x4e\x43\xf0\x10\xe2\xcd\x59\xda\x73\x0b\xc6\xc0\x28\x86\xb0\x1a\xfb\x62\x26\xc2\x1b\x65\x4a\x9b\xa4\xdd\xcb\xef\xc4\x73\x05\x93\xe2\x1c\x38\xd7\x38\x1a\x3b\x3b\x4f\xcd\xb9\x4f\x7d\xe5\x51\x5c\xf0\x99\xb4\xf7\x77\x46\x92\xe4\x12\x3d\xb4\x56\x6a\x09\xd6\x2c\x18\x17\x33\xa1\x07\xd3\xef\xe4\x98\xa0\xf3\x5b\x9f\x30\xd9\xec\x35\x24\x9b\xbd\xc8\x04\x7d\xd1\xb6\x9e\x5e\xab\x5a\xe5\xb1\xe5\xe7\xde\xd1\x43\xf6\xac\x46\xe9\x24\xb2\xf3\x53\xa5\xdd\xa0\x6f\xa0\xf3\xb7\x99\x25\x51\x21\x1d\x49\x8a\x1b\xc3\x13\xdc\xa0\xeb\x6b\xbe\x65\x32\x31\xf0\xe7\xa2\x77\xd2\x07\xe5\x1c\x24\x7e\x2e\x2b\x8c\x5a\xfd\x3b\x92\x51\xba\xf2\x9b\x9b\x19\x93\xb7\x31\x4f\x90\x93\xaf\x0c\x4f\xb5\x02\xdc\x98\xd5\x3f\xff\x7b\x42\xdf\x43\x37\x79\xd3\x1a\x81\x3f\x04\x4f\xd1\x38\x93\x57\x00\xb0\xb2\xf3\xb1\xba\x64\xae\x4b\x94\x29\x26\xce\x04\xf2\x83\x52\x28\x19\x0e\x4f\xe8\x71\x75\x62\x0a\xb8\xec\x47\x76\x7b\xab\x61\xa1\xdd\xce\x19\x66\x92\x7c\x70\xb2\xd9\xb2\x08\xb3\xba\x1f\x0f\xdf\x6e\x10\xc3\x0b\xf9\xba\xdb\x6f\xa7\xaa\x4f\x67\x5a\x95\x64\xb5\x52\xb9\xf0\xdf\x00\x00\x00\xff\xff\x75\x1a\x14\x61\x27\x03\x00\x00")
|
||||
|
||||
func route_twirp_eclier_routes_deleteLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_routes_deleteLua,
|
||||
"route_twirp_eclier_routes_delete.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_routes_deleteLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_routes_deleteLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_routes_delete.lua", size: 807, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_routes_getLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x52\x4d\x6b\xdc\x30\x10\xbd\xeb\x57\x3c\x74\x5a\x43\x6c\xd2\x43\x2f\x06\x9f\x9a\x50\x0a\xa5\x81\x90\x9e\x9a\x50\x14\x79\x6c\x8b\x38\x92\x33\x92\x9c\xf4\xdf\x97\x91\xdd\xdd\x6d\x21\xf4\xb0\xb0\x9a\xf7\x31\x6f\xc6\x53\xd7\xf8\x14\x7a\xc2\x48\x9e\xd8\x24\xea\xf1\xf8\x0b\x0b\x87\x14\x6c\x3d\x92\xaf\xd3\xab\xe3\xe5\x27\xd9\xd9\x11\x63\xfd\xd8\x5c\x36\x97\x57\x37\xf8\x76\x73\x87\xeb\xab\x2f\x77\xaa\xae\x11\x43\x66\x4b\x2d\x38\xe4\x44\x4d\x91\x2a\x15\x2d\xbb\x25\x35\x2b\xf1\x23\x3a\xe8\x82\xc5\x76\xa4\xa4\xff\x40\x13\xcd\x8b\x40\xd7\x6f\x64\x05\xc4\x33\xa5\x29\xf4\x18\x29\x21\x78\x44\xe2\xd5\x59\xda\x5c\x23\x86\xc0\x28\x51\xb0\x18\xfb\x64\x46\xc2\x1b\x09\xa5\xc9\xb1\xd9\x1a\x6f\xc4\xa3\xbd\xc9\x69\x0a\x2c\x0d\x9e\x8d\x9d\x9c\xa7\xfa\x38\xa1\x3e\x4b\x17\x5d\xf0\x42\xda\x26\x3b\x22\x39\x4a\x8b\x0e\x5a\x2b\x35\x07\x6b\x66\x0c\xb3\x19\xd1\x81\xe9\x25\x3b\x26\x68\x79\xeb\x1d\x8b\xab\x3d\x87\xe2\x6a\x4f\xb2\x88\xae\x68\x1b\x4f\xaf\x87\x4a\xc9\xc2\xe4\xb9\x4d\xf4\x99\xd2\xad\xc4\xbe\xa5\x97\x4c\x31\xa9\x21\xb6\x31\xb1\xf3\xe3\x41\x67\x9f\x23\xf5\xfa\x02\x5a\x7e\xab\x99\x33\x15\xc9\x33\xc5\x92\xcd\xf0\x88\x9d\x53\x9d\xeb\xdc\x7f\x34\x4e\xf8\xff\x8e\x39\xc4\xb6\xfc\x95\x80\x43\xf6\x36\xc9\x56\x38\xfb\x83\xe1\xb1\x52\x80\x1b\x44\xfb\xe3\xc3\x03\xba\x0e\xba\x96\x4f\xa7\x11\xf8\xaf\xe2\x5e\x4d\x13\x79\x05\x00\x0b\x3b\x9f\x0e\x27\xe7\xaa\x54\x99\x52\x66\x21\x90\xef\x95\x42\x71\xb8\x7c\x40\x87\xb3\x83\x51\xc0\x69\xe7\x71\x8b\xb7\x18\x8e\xb4\xc5\x39\xc2\x4c\x51\x2e\x28\xae\xb6\x2c\xd7\x2c\xee\xfb\xed\xd7\x0b\xa4\xf0\x44\xbe\x6a\xb7\x7b\x38\x54\x72\x74\x87\xe2\x54\xa4\x5b\x2c\xed\xfa\xf6\x3e\xdd\x27\x8d\xa6\x41\x0a\xfb\xf2\xc4\xb0\x71\x7d\x89\xba\xf3\x2c\x93\x49\x81\xdf\x23\xef\xf0\xb9\x62\x0a\x31\xbd\x47\x17\xac\xaa\x94\xcc\xfe\x3b\x00\x00\xff\xff\x07\xd9\x95\x3a\x78\x03\x00\x00")
|
||||
|
||||
func route_twirp_eclier_routes_getLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_routes_getLua,
|
||||
"route_twirp_eclier_routes_get.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_routes_getLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_routes_getLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_routes_get.lua", size: 888, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_routes_get_allLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x5c\x52\x4d\x6f\xdd\x20\x10\xbc\xf3\x2b\x46\x9c\x6c\xa9\xb6\x5e\x0f\xbd\x3c\xc9\xa7\x26\x87\x4a\x55\x22\x55\xe9\xa9\x89\x22\xc2\x5b\xdb\x28\x0e\xb8\xcb\xe2\xa4\xff\xbe\x02\xde\x57\x7b\x83\x9d\xd9\xd9\x19\x96\xae\xc3\xd7\x70\x20\x4c\xe4\x89\x8d\xd0\x01\x2f\x7f\xb0\x72\x90\x60\xbb\x89\x7c\x27\xef\x8e\xd7\x67\xb2\x8b\x23\xc6\xf6\xa5\xdf\xf5\xbb\x9b\x7b\xdc\xdd\x3f\xe0\xf6\xe6\xdb\x83\xea\x3a\xc4\x90\xd8\xd2\x1e\x1c\x92\x50\x5f\x5a\x95\x8a\x96\xdd\x2a\xfd\x46\xfc\x82\x01\xba\x60\x71\x3f\x91\x3c\x9b\x65\xd1\x27\x78\xa6\x65\xcd\xf0\xed\x07\xd9\x4c\xc0\x1b\xc9\x1c\x0e\x38\xf2\x10\x3c\x22\xf1\xe6\x2c\x55\xf5\x88\x31\x30\x8a\x25\xac\xc6\xbe\x9a\x89\xf0\x41\x99\xd2\xa7\xd8\x57\x03\x95\x78\x1e\x61\x92\xcc\x81\xf3\x90\x37\x63\x67\xe7\xa9\x3b\x27\xd5\x57\x2e\xa3\x0b\x3e\x93\x6a\xc2\x33\x92\x62\x1e\x31\x40\x6b\xa5\x96\x60\xcd\x82\x71\x31\x13\x06\x30\xfd\x4e\x8e\x09\x3a\xdf\xf5\x11\x8b\x9b\xbd\x86\xe2\x66\x2f\x6d\x11\x43\xe9\xed\x3d\xbd\x37\xad\xca\x0f\x97\xaf\x35\xd1\x9d\x5b\xd4\xff\x23\xc7\xb8\x2f\xc7\x4c\x1e\x93\xb7\x92\x1d\x72\xf2\x8d\xe1\xa9\x55\x80\x1b\x61\x78\xfa\xf5\xf9\x09\xc3\x00\xdd\xe5\xa7\xd4\x08\xfc\x4f\xf1\x58\x95\x99\xbc\x02\x80\x95\x9d\x97\xe6\xa2\xdc\x96\x2a\x93\x24\xce\x04\xf2\x07\xa5\x50\x14\x76\x4f\x18\x70\xb5\x44\x05\x5c\xf2\xc7\x6a\x6f\x35\x1c\xa9\xda\x39\xc3\x4c\x31\x6f\x34\x6e\xb6\x04\x35\xab\xfb\xf9\xe3\xfb\x27\x48\x78\x25\xdf\xee\xeb\x6e\x9a\xf6\xf4\x11\x9a\xa2\x56\xda\xab\xb5\xd3\x47\x79\x94\x47\xd1\xe8\x7b\x48\x88\xc2\xce\x4f\x4d\x16\x3e\xee\xb6\x6d\x55\x76\xfa\x37\x00\x00\xff\xff\xd4\xa1\xe0\x99\xba\x02\x00\x00")
|
||||
|
||||
func route_twirp_eclier_routes_get_allLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_routes_get_allLua,
|
||||
"route_twirp_eclier_routes_get_all.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_routes_get_allLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_routes_get_allLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_routes_get_all.lua", size: 698, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_routes_putLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x52\xcd\x6a\xdc\x3c\x14\xdd\xeb\x29\x0e\x5a\x8d\x21\x36\xf9\x16\xdf\xc6\xe0\x55\x93\x45\xa1\x34\x10\xd2\x55\x13\x8a\x22\x5f\xdb\x22\x8e\xe4\x5e\x49\x4e\xfa\xf6\xe5\xca\xce\xcc\xa4\x90\x2c\x0c\x96\xce\x8f\xce\xfd\xa9\x6b\x7c\x09\x3d\x61\x24\x4f\x6c\x12\xf5\x78\xfc\x83\x85\x43\x0a\xb6\x1e\xc9\xd7\xe9\xc5\xf1\xf2\x8b\xec\xec\x88\xb1\xfe\xdf\x5c\x36\x97\x57\x37\xf8\x7e\x73\x87\xeb\xab\xaf\x77\xaa\xae\x11\x43\x66\x4b\x2d\x38\xe4\x44\x4d\x91\x2a\x15\x2d\xbb\x25\x35\x2b\xf1\x23\x3a\xe8\x82\xc5\x76\xc9\x49\xbf\x41\x13\xcd\x8b\x40\xd7\xaf\x64\x05\xc4\x33\xa5\x29\xf4\x58\x72\x42\xf0\x88\xc4\xab\xb3\xb4\xb9\x46\x0c\x81\x51\xa2\x60\x31\xf6\xc9\x8c\x84\x57\x12\x4a\x93\x63\xb3\x3d\xbc\x11\x8f\xf6\x26\xa7\x29\xb0\x3c\xf0\x6c\xec\xe4\x3c\xd5\xc7\x0a\xf5\x59\xba\xe8\x82\x17\xd2\x56\xd9\x11\xc9\x51\x9e\xe8\xa0\xb5\x52\x73\xb0\x66\xc6\x30\x9b\x11\x1d\x98\x7e\x67\xc7\x04\x2d\x67\xbd\x63\x71\xb5\xe7\x50\x5c\xed\x49\x16\xd1\x15\x6d\xe3\xe9\xe5\x50\x29\x69\x98\x1c\xb7\x8a\x6e\x25\xb3\x1a\x62\x1b\x13\x3b\x3f\x1e\xf4\x14\x62\xd2\x17\xd0\xf2\xad\x66\xce\x54\x68\xcf\x14\x4b\x1e\xc3\x23\x0a\xa3\x3a\xd7\xb8\xfe\x73\x85\xeb\xdf\xf3\x2d\x93\x49\x81\x3f\x17\xbd\x91\x2a\xf5\x6f\x4b\x86\xd8\x96\x5f\x29\x66\xc8\xde\x26\xe9\x20\x67\x7f\x30\x3c\x56\x0a\x70\x83\x18\xfc\xfc\xef\x01\x5d\x07\x5d\xcb\x98\x35\x02\xbf\xbb\xdc\x6f\xd3\x44\x5e\x01\xc0\xc2\xce\xa7\xc3\xc9\xb9\x2a\xb7\x4c\x29\xb3\x10\xc8\xf7\x4a\xa1\x38\x5c\x3e\xa0\xc3\xd9\x72\x29\xe0\x34\x9f\xb8\xc5\x5b\x0c\x47\xda\xe2\x1c\x61\xa6\x28\xdb\x16\x57\x5b\x06\x61\x16\xf7\xe3\xf6\xdb\x05\x52\x78\x22\x5f\xb5\xdb\xee\x1c\x2a\x59\xd0\x43\x71\x2a\xd2\x2d\x96\x76\x7d\x7b\x9f\xee\x93\x46\xd3\x20\x85\xbd\x8d\x62\xd8\xb8\xbe\x44\xdd\x79\x7b\xcf\x3e\x22\xef\xf0\xb9\x42\x86\xf9\x11\x5d\xb0\xaa\x52\x52\xfb\xdf\x00\x00\x00\xff\xff\x86\x08\x46\x8f\xa4\x03\x00\x00")
|
||||
|
||||
func route_twirp_eclier_routes_putLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_routes_putLua,
|
||||
"route_twirp_eclier_routes_put.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_routes_putLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_routes_putLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_routes_put.lua", size: 932, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_tokens_deactivateLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x92\x41\x6f\xdb\x30\x0c\x85\xef\xfa\x15\x0f\x3a\xd9\x40\x6c\x64\x87\x5d\x02\xf8\xb4\xf6\x30\x60\x58\x81\x21\x3b\x0d\xc5\xa0\xc8\xb4\x23\xd4\x91\x3c\x52\x72\xdb\x7f\x3f\x48\xce\x92\x74\x40\x7b\xb3\xc9\xef\x91\x8f\x14\x9b\x06\x5f\x42\x4f\x18\xc9\x13\x9b\x48\x3d\x0e\xaf\x98\x39\xc4\x60\x9b\x91\x7c\x13\x9f\x1d\xcf\xbf\xc9\x4e\x8e\x18\xcb\xe7\x76\xdb\x6e\xef\x1e\xf0\xfd\x61\x8f\xfb\xbb\xaf\x7b\xd5\x34\x90\x90\xd8\xd2\x0e\x1c\x52\xa4\xb6\x48\x95\x12\xcb\x6e\x8e\xed\x42\x7c\x40\x07\x1d\xc3\x13\x79\xd9\xf5\x64\x6c\x74\x8b\x89\xa4\xff\x11\x47\x9a\xe6\x4c\xdc\xbf\x90\x4d\x91\x04\x27\x8a\xc7\xd0\xe3\x8a\x22\x78\x08\xf1\xe2\x2c\x61\xad\x83\x21\x30\x8a\x31\xcc\xc6\x3e\x99\x91\xf0\x42\x19\x69\x93\xb4\xab\x8d\x15\xbc\x74\x31\x29\x1e\x03\xe7\x3e\x27\x63\x8f\xce\x53\x73\x99\x57\xdf\x78\x15\x17\x7c\x86\xd6\x39\x2f\x99\x24\xb9\x45\x07\xad\x95\x9a\x82\x35\x13\x86\xc9\x8c\xe8\xc0\xf4\x27\x39\x26\xe8\xfc\xaf\xcf\x39\x59\xec\x6d\x4a\x16\x7b\x95\x09\xba\xa2\x6d\x3d\x3d\x57\xb5\xca\xeb\xcb\xbf\xeb\x44\xfb\xec\x59\x0d\xb2\x3b\x84\x30\x55\xba\xcc\x4f\x7a\x83\xc1\x4c\x42\x1b\xe8\xc5\x4c\x89\x0a\x79\x22\x29\x96\x0c\x8f\x38\x63\x75\x16\x4a\x64\xe7\xc7\x4a\xbb\x5e\x6f\xa0\xf5\xbb\x1a\xd7\xbf\xe5\x0f\xa1\x7f\xfd\x58\x51\x88\x1b\x8d\x54\x5a\x6c\x98\x49\xde\x97\x9c\xf3\xb5\xfa\x7f\x8d\x83\xec\xca\x67\x5e\xc0\x90\xbc\x8d\x79\xeb\x9c\x7c\x65\x78\xac\x15\xe0\x86\xac\xff\xf5\xe9\x11\x5d\x07\xdd\xe4\x0b\xd1\x08\xfc\x26\x78\x8e\xc6\x23\x79\x05\x00\x33\x3b\x1f\xab\x6b\xe5\xba\x44\x99\x62\xe2\x0c\x90\xef\x95\x42\xa9\xb0\x7d\x44\x87\x9b\xf3\x54\xc0\xf5\x4d\x65\xb5\x37\x1b\x16\x5a\xed\x5c\xd2\x4c\x92\x0f\x55\x16\x5b\x1e\xcf\xcc\xee\xe7\x8f\x6f\x9b\xf5\x22\xeb\xdd\x7a\x6f\x55\x7d\x73\xe2\x55\x29\x58\x2b\x95\x9b\xff\x0d\x00\x00\xff\xff\x41\x42\x7e\x72\x67\x03\x00\x00")
|
||||
|
||||
func route_twirp_eclier_tokens_deactivateLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_tokens_deactivateLua,
|
||||
"route_twirp_eclier_tokens_deactivate.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_tokens_deactivateLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_tokens_deactivateLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_tokens_deactivate.lua", size: 871, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_tokens_deleteLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x52\xc1\x6a\xdc\x30\x10\xbd\xeb\x2b\x1e\x3a\xd9\x10\x9b\xed\xa1\x97\x05\x9f\x9a\x1c\x0a\xa5\x81\xb2\x3d\x95\x50\xb4\xf2\xd8\x2b\xe2\x95\xdc\x19\xc9\x49\xfe\xbe\x48\xde\xee\xba\x85\xf4\x60\xb0\xf4\xde\x9b\x79\x33\x7a\x4d\x83\x4f\xa1\x27\x8c\xe4\x89\x4d\xa4\x1e\xc7\x37\xcc\x1c\x62\xb0\xcd\x48\xbe\x89\x2f\x8e\xe7\x9f\x64\x27\x47\x8c\xe5\x63\xbb\x6b\x77\xf7\x8f\xf8\xfa\x78\xc0\xc3\xfd\xe7\x83\x6a\x1a\x48\x48\x6c\x69\x0f\x0e\x29\x52\x5b\xa4\x4a\x89\x65\x37\xc7\x76\x21\x3e\xa2\x83\x8e\xe1\x99\xbc\xec\x7b\x9a\x28\x92\xfe\x83\x9e\x68\x9a\x33\xfa\xf0\x4a\x36\x45\x12\x9c\x29\x9e\x42\x8f\x95\x86\xe0\x21\xc4\x8b\xb3\x84\x55\x8f\x21\x30\x8a\x21\xcc\xc6\x3e\x9b\x91\xf0\x4a\x99\xd2\x26\x69\xd7\xf6\x2b\xf1\xda\xc1\xa4\x78\x0a\x9c\x7b\x9c\x8d\x3d\x39\x4f\xcd\x75\x4e\xbd\xf1\x28\x2e\xf8\x4c\x5a\xe7\xbb\x22\x49\x72\x8b\x0e\x5a\x2b\x35\x05\x6b\x26\x0c\x93\x19\xd1\x81\xe9\x57\x72\x4c\xd0\xf9\xac\x2f\x98\x2c\x76\x0b\xc9\x62\x6f\x32\x41\x57\xb4\xad\xa7\x97\xaa\x56\x79\x6d\xf9\xb8\x4e\x74\xc8\x9e\xd5\x20\x7b\x89\xec\xfc\x58\x69\xd7\xeb\x3b\xe8\xfc\x2d\x66\x4a\x54\x48\x67\x92\xe2\xc6\xf0\x08\xd7\xeb\x7a\xcb\x3f\x86\xfe\xed\xff\x8a\xc2\xd8\x68\xa4\xd2\x62\xc3\x4c\xf2\xbe\xe4\x82\x17\xd1\x31\x84\xa9\xd2\xc6\x46\xb7\x90\xbe\xc3\x60\x26\xa1\x77\x85\x17\x5a\xad\xfe\x5d\xe3\x20\xfb\xf2\x9b\x17\x30\x24\x6f\x63\xde\x3a\x27\x5f\x19\x1e\x6b\x05\xb8\x21\xeb\x7f\x7c\x78\x42\xd7\x41\x37\x39\x1d\x1a\x81\xff\xba\xbc\xdc\xc6\x13\x79\x05\x00\x33\x3b\x1f\xab\x5b\xe5\xba\xdc\x32\xc5\xc4\x99\x40\xbe\x57\x0a\xa5\xc2\xee\x09\x1d\x36\xb1\x54\xc0\xed\x4d\x65\xb5\x37\x1b\x16\x5a\xed\x5c\x61\x26\xc9\x21\x95\xc5\x96\xc7\x33\xb3\xfb\xfe\xed\xcb\xdd\x9a\xc8\x7a\xbf\xe6\xad\xaa\x2f\xd1\xae\x4a\xb1\x5a\xa9\xdc\xf8\x77\x00\x00\x00\xff\xff\x50\xe4\x70\xe6\x5b\x03\x00\x00")
|
||||
|
||||
func route_twirp_eclier_tokens_deleteLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_tokens_deleteLua,
|
||||
"route_twirp_eclier_tokens_delete.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_tokens_deleteLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_tokens_deleteLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_tokens_delete.lua", size: 859, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_tokens_getLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x92\x41\x6b\xdc\x3e\x10\xc5\xef\xfa\x14\x0f\x9d\x6c\x88\x4d\xfe\x87\xff\xc5\xe0\x53\x13\x4a\xa1\x34\x10\xb6\xa7\x26\x14\xad\x3c\xf6\x8a\x78\x25\x67\x24\x39\xc9\xb7\x2f\x92\xb6\xbb\x6e\x61\x7b\x58\x58\xe9\xfd\xde\xe8\xcd\x78\x9a\x06\x9f\xdc\x40\x98\xc8\x12\xab\x40\x03\xf6\x1f\x58\xd8\x05\xa7\x9b\x89\x6c\x13\xde\x0c\x2f\x3f\x49\xcf\x86\x18\xeb\xff\xed\x6d\x7b\x7b\xf7\x80\x6f\x0f\x3b\xdc\xdf\x7d\xd9\x89\xa6\x81\x77\x91\x35\x75\x60\x17\x03\xb5\xd9\x2a\x84\xd7\x6c\x96\xd0\xae\xc4\x7b\xf4\x90\xc1\xbd\x90\xf5\xdd\x44\x41\xfe\x96\x0e\x34\x2f\x49\xba\x7f\x27\x1d\x03\x79\x1c\x29\x1c\xdc\x80\x89\x02\x9c\x85\x27\x5e\x8d\x26\x14\x27\x46\xc7\xc8\x51\xb0\x28\xfd\xa2\x26\xc2\x3b\x25\xa4\x8d\xbe\x2d\x0f\x17\xf0\x5c\x5e\xc5\x70\x70\x9c\x1e\x38\x2a\x7d\x30\x96\x9a\x73\x87\x72\x93\xce\x1b\x67\x13\x54\x3a\x3b\x2b\xd1\xa7\x27\x7a\x48\x29\xc4\xec\xb4\x9a\x31\xce\x6a\x42\x0f\xa6\xd7\x68\x98\x20\xd3\x59\x9e\x34\xbf\xea\xad\xe4\x57\x7d\xb1\x79\xf4\xd9\xdb\x5a\x7a\xab\x6a\x91\x06\x96\x8e\xa5\xa3\xcf\x14\x76\x29\xf6\x23\xbd\x46\xf2\x41\x8c\xbe\xf3\x81\x8d\x9d\x2a\x69\x06\x79\x03\x99\x7e\xab\x9a\x23\x65\xfc\x48\x3e\xe7\x52\x3c\xc1\x0c\xb2\xde\xf2\xb9\xfd\x7f\x5b\x0a\x52\x8b\xbf\x9b\x1c\x7d\x97\xff\xa6\x78\x63\xb4\x3a\xa4\x99\x70\xb4\x95\xe2\xa9\x16\x80\x19\x93\xfd\xc7\x7f\xcf\xe8\x7b\xc8\x26\x7d\x38\x09\xc7\x7f\x5c\x9e\x6e\xc3\x81\xac\x00\x80\x85\x8d\x0d\xd5\xa5\x72\x9d\x6f\x99\x42\xe4\x04\x90\x1d\x84\x40\xae\x70\xfb\x8c\x1e\x9b\x75\x11\xc0\x65\xe2\xbe\xc4\x5b\x14\x7b\x2a\x71\xce\x32\x93\x4f\xfb\xe3\x57\x9d\x47\xab\x16\xf3\xfd\xf1\xeb\x4d\x69\xb2\xee\xca\x36\x54\x75\x5a\xb9\x2a\x57\xca\xd6\x12\x4b\x9a\xa1\x7b\x0a\x4f\x41\xa2\x6d\x11\xdc\x69\x84\xa9\x60\x6b\x86\x1c\xf5\xc4\xed\xdd\xf0\x71\x8d\x4c\xda\x96\xf5\xda\x2d\xe4\xaf\xd1\x45\xdd\xf2\x4a\x07\xb3\xd2\x35\xbe\xa8\x75\x2d\xd2\xa4\x7e\x05\x00\x00\xff\xff\x6f\x53\x96\xcd\xa4\x03\x00\x00")
|
||||
|
||||
func route_twirp_eclier_tokens_getLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_tokens_getLua,
|
||||
"route_twirp_eclier_tokens_get.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_tokens_getLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_tokens_getLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_tokens_get.lua", size: 932, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_tokens_get_allLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x5c\x52\x4d\x6f\xdd\x20\x10\xbc\xf3\x2b\x46\x9c\x6c\xa9\xb6\x5e\x0f\xbd\x3c\xc9\xa7\x26\x87\x4a\x55\x22\x55\xe9\xa9\x89\x22\xc2\x5b\xdb\x28\x0e\xb8\xcb\xe2\xa4\xff\xbe\x02\xde\x57\x7b\x83\x9d\xd9\xdd\x19\x86\xae\xc3\xd7\x70\x20\x4c\xe4\x89\x8d\xd0\x01\x2f\x7f\xb0\x72\x90\x60\xbb\x89\x7c\x27\xef\x8e\xd7\x67\xb2\x8b\x23\xc6\xf6\xa5\xdf\xf5\xbb\x9b\x7b\xdc\xdd\x3f\xe0\xf6\xe6\xdb\x83\xea\x3a\xc4\x90\xd8\xd2\x1e\x1c\x92\x50\x5f\x5a\x95\x8a\x96\xdd\x2a\xfd\x46\xfc\x82\x01\x5a\xc2\x2b\xf9\xb8\x9f\x48\x9e\xcd\xb2\xe8\x13\x3c\xd3\xb2\x66\xf8\xf6\x83\x6c\x12\x8a\x78\x23\x99\xc3\x01\x47\x1e\x82\x47\x24\xde\x9c\x25\xd4\x09\x18\x03\xa3\x48\xc2\x6a\xec\xab\x99\x08\x1f\x94\x29\x7d\x8a\x7d\x15\x50\x89\xe7\x15\x26\xc9\x1c\x38\x2f\x79\x33\x76\x76\x9e\xba\xb3\x53\x7d\xa5\x32\xba\xe0\x33\xa9\x3a\x3c\x23\x29\xe6\x15\x03\xb4\x56\x6a\x09\xd6\x2c\x18\x17\x33\x61\x00\xd3\xef\xe4\x98\xa0\xf3\x5d\x1f\xb1\xb8\xd9\x6b\x28\x6e\xf6\xd2\x16\x31\x94\xde\xde\xd3\x7b\xd3\xaa\xfc\x70\xf9\x5a\x1d\xdd\xb9\x45\xfd\xbf\x72\x8c\xfb\x72\xcc\xe4\x31\x79\x2b\x59\x21\x27\xdf\x18\x9e\x5a\x05\xb8\x11\x86\xa7\x5f\x9f\x9f\x30\x0c\xd0\x5d\x7e\x4a\x8d\xc0\xff\x14\x8f\x55\x99\xc9\x2b\x00\x58\xd9\x79\x69\x2e\x93\xdb\x52\x65\x92\xc4\x99\x40\xfe\xa0\x14\xca\x84\xdd\x13\x06\x5c\x85\xa8\x80\x8b\xff\x58\xe5\xad\x86\x23\x55\x39\x67\x98\x29\xe6\x44\xe3\x66\x8b\x51\xb3\xba\x9f\x3f\xbe\x7f\xaa\xe9\xb5\xfb\x9a\x4d\xd3\x9e\x3e\x42\x53\xa6\x95\xf6\x2a\xed\xf4\x51\x1e\xe5\x51\x34\xfa\x1e\x12\xa2\xb0\xf3\x53\x93\x07\x1f\xb3\x6d\x5b\x95\x95\xfe\x0d\x00\x00\xff\xff\xe9\x8f\x90\xdc\xba\x02\x00\x00")
|
||||
|
||||
func route_twirp_eclier_tokens_get_allLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_tokens_get_allLua,
|
||||
"route_twirp_eclier_tokens_get_all.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_tokens_get_allLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_tokens_get_allLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_tokens_get_all.lua", size: 698, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
var _route_twirp_eclier_tokens_putLua = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x7c\x92\x41\x6b\xdc\x30\x10\x85\xef\xfa\x15\x0f\x9d\x6c\x88\x4d\x7a\xe8\xc5\xe0\x53\x93\x43\xa1\x34\x50\xd2\x53\x13\x8a\x56\x1e\x7b\x45\xbc\x92\xab\x91\x9c\xe4\xdf\x17\x49\xee\xae\x5b\xd8\x1e\x16\xd6\x7a\xdf\x1b\x3d\xcd\x4c\xd3\xe0\x93\x1b\x08\x13\x59\xf2\x2a\xd0\x80\xc3\x3b\x16\xef\x82\xd3\xcd\x44\xb6\x09\xaf\xc6\x2f\x3f\x49\xcf\x86\x3c\xd6\x8f\xed\x6d\x7b\x7b\xf7\x80\xaf\x0f\x8f\xb8\xbf\xfb\xfc\x28\x9a\x06\xec\xa2\xd7\xd4\xc1\xbb\x18\xa8\xcd\x56\x21\x58\x7b\xb3\x84\x76\x25\x7f\x40\x0f\x19\xdc\x0b\x59\xee\x96\x18\xe4\x1f\xe9\x48\xf3\x92\xa4\xfb\x37\xd2\x31\x10\xe3\x44\xe1\xe8\x06\x2c\x31\xc0\x59\x30\xf9\xd5\x68\x42\x71\x62\x74\x1e\x39\x0a\x16\xa5\x5f\xd4\x44\x78\xa3\x84\xb4\x91\xdb\x72\x71\x01\xcf\xe5\x55\x0c\x47\xe7\xd3\x05\x27\xa5\x8f\xc6\x52\x73\x7e\xa1\xdc\xa5\x63\xe3\x6c\x82\xca\xcb\xce\x4a\xe4\x74\x45\x0f\x29\x85\x98\x9d\x56\x33\xc6\x59\x4d\xe8\xe1\xe9\x57\x34\x9e\x20\xd3\xb7\xdc\x34\x5e\xf5\x5e\xe2\x55\x5f\x6c\x8c\x3e\x7b\x5b\x4b\xaf\x55\x2d\x52\xc3\xd2\x67\x79\xd1\x63\xca\x2c\x46\xee\x38\x78\x63\xa7\x4a\x9a\x41\xde\x40\xa6\xdf\xaa\xe6\x48\x19\x3a\x11\xe7\x34\xca\x4f\x30\x83\xac\xf7\xfc\xc1\x0d\xef\xff\x77\x64\x62\xe7\xe1\x4a\xb2\x76\x0b\xf1\x75\xcb\xa6\x67\xd3\xc1\xb9\xb9\x92\x4a\x07\xb3\x92\xbc\xc1\xa8\x66\xa6\xab\xc6\x0d\xab\xc5\xbf\x6d\x1c\xb9\xcb\x7f\x53\x03\xc6\x68\x75\x48\x5d\xf7\xd1\x56\xca\x4f\xb5\x00\xcc\x98\xfc\x3f\x3e\x3c\xa3\xef\x21\x9b\xb4\x1a\x12\xce\xff\x75\xb8\x9d\x86\x23\x59\x01\x00\x8b\x37\x36\x54\x97\xca\x75\x3e\xf5\x14\xa2\x4f\x00\xd9\x41\x08\xe4\x0a\xb7\xcf\xe8\xb1\x5b\x48\x01\x5c\x66\xca\x25\xde\xa2\x3c\x53\x89\x73\x96\x3d\x71\xda\x50\x5e\x75\x1e\x9e\x5a\xcc\xf7\x6f\x5f\x6e\xca\x46\xd6\x5d\xd9\xb7\xaa\x4e\x4b\x5d\xe5\x4a\xd9\x5a\x62\x49\x33\x74\x4f\xe1\x29\x48\xb4\x2d\x82\xdb\xc6\x95\x0a\xb6\x66\xc8\x51\x37\x2e\x8d\xe7\x1a\x99\xb4\x3d\x5b\xe6\x72\x8d\x2e\xea\x9e\x2f\xe3\xb8\xc6\x17\xb5\xae\x45\xea\xd4\xef\x00\x00\x00\xff\xff\x38\x3f\xda\x56\x06\x04\x00\x00")
|
||||
|
||||
func route_twirp_eclier_tokens_putLuaBytes() ([]byte, error) {
|
||||
return bindataRead(
|
||||
_route_twirp_eclier_tokens_putLua,
|
||||
"route_twirp_eclier_tokens_put.lua",
|
||||
)
|
||||
}
|
||||
|
||||
func route_twirp_eclier_tokens_putLua() (*asset, error) {
|
||||
bytes, err := route_twirp_eclier_tokens_putLuaBytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info := bindataFileInfo{name: "route_twirp_eclier_tokens_put.lua", size: 1030, mode: os.FileMode(420), modTime: time.Unix(1516605524, 0)}
|
||||
a := &asset{bytes: bytes, info: info}
|
||||
return a, nil
|
||||
}
|
||||
|
||||
// Asset loads and returns the asset for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func Asset(name string) ([]byte, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Asset %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.bytes, nil
|
||||
}
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
|
||||
// MustAsset is like Asset but panics when Asset would return an error.
|
||||
// It simplifies safe initialization of global variables.
|
||||
func MustAsset(name string) []byte {
|
||||
a, err := Asset(name)
|
||||
if err != nil {
|
||||
panic("asset: Asset(" + name + "): " + err.Error())
|
||||
}
|
||||
|
||||
return a
|
||||
}
|
||||
|
||||
// AssetInfo loads and returns the asset info for the given name.
|
||||
// It returns an error if the asset could not be found or
|
||||
// could not be loaded.
|
||||
func AssetInfo(name string) (os.FileInfo, error) {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
if f, ok := _bindata[cannonicalName]; ok {
|
||||
a, err := f()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("AssetInfo %s can't read by error: %v", name, err)
|
||||
}
|
||||
return a.info, nil
|
||||
}
|
||||
return nil, fmt.Errorf("AssetInfo %s not found", name)
|
||||
}
|
||||
|
||||
// AssetNames returns the names of the assets.
|
||||
func AssetNames() []string {
|
||||
names := make([]string, 0, len(_bindata))
|
||||
for name := range _bindata {
|
||||
names = append(names, name)
|
||||
}
|
||||
return names
|
||||
}
|
||||
|
||||
// _bindata is a table, holding each asset generator, mapped to its name.
|
||||
var _bindata = map[string]func() (*asset, error){
|
||||
"route_twirp_eclier_backends_kill.lua": route_twirp_eclier_backends_killLua,
|
||||
"route_twirp_eclier_backends_list.lua": route_twirp_eclier_backends_listLua,
|
||||
"route_twirp_eclier_routes_delete.lua": route_twirp_eclier_routes_deleteLua,
|
||||
"route_twirp_eclier_routes_get.lua": route_twirp_eclier_routes_getLua,
|
||||
"route_twirp_eclier_routes_get_all.lua": route_twirp_eclier_routes_get_allLua,
|
||||
"route_twirp_eclier_routes_put.lua": route_twirp_eclier_routes_putLua,
|
||||
"route_twirp_eclier_tokens_deactivate.lua": route_twirp_eclier_tokens_deactivateLua,
|
||||
"route_twirp_eclier_tokens_delete.lua": route_twirp_eclier_tokens_deleteLua,
|
||||
"route_twirp_eclier_tokens_get.lua": route_twirp_eclier_tokens_getLua,
|
||||
"route_twirp_eclier_tokens_get_all.lua": route_twirp_eclier_tokens_get_allLua,
|
||||
"route_twirp_eclier_tokens_put.lua": route_twirp_eclier_tokens_putLua,
|
||||
}
|
||||
|
||||
// AssetDir returns the file names below a certain
|
||||
// directory embedded in the file by go-bindata.
|
||||
// For example if you run go-bindata on data/... and data contains the
|
||||
// following hierarchy:
|
||||
// data/
|
||||
// foo.txt
|
||||
// img/
|
||||
// a.png
|
||||
// b.png
|
||||
// then AssetDir("data") would return []string{"foo.txt", "img"}
|
||||
// AssetDir("data/img") would return []string{"a.png", "b.png"}
|
||||
// AssetDir("foo.txt") and AssetDir("notexist") would return an error
|
||||
// AssetDir("") will return []string{"data"}.
|
||||
func AssetDir(name string) ([]string, error) {
|
||||
node := _bintree
|
||||
if len(name) != 0 {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
pathList := strings.Split(cannonicalName, "/")
|
||||
for _, p := range pathList {
|
||||
node = node.Children[p]
|
||||
if node == nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
}
|
||||
}
|
||||
if node.Func != nil {
|
||||
return nil, fmt.Errorf("Asset %s not found", name)
|
||||
}
|
||||
rv := make([]string, 0, len(node.Children))
|
||||
for childName := range node.Children {
|
||||
rv = append(rv, childName)
|
||||
}
|
||||
return rv, nil
|
||||
}
|
||||
|
||||
type bintree struct {
|
||||
Func func() (*asset, error)
|
||||
Children map[string]*bintree
|
||||
}
|
||||
var _bintree = &bintree{nil, map[string]*bintree{
|
||||
"route_twirp_eclier_backends_kill.lua": &bintree{route_twirp_eclier_backends_killLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_backends_list.lua": &bintree{route_twirp_eclier_backends_listLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_routes_delete.lua": &bintree{route_twirp_eclier_routes_deleteLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_routes_get.lua": &bintree{route_twirp_eclier_routes_getLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_routes_get_all.lua": &bintree{route_twirp_eclier_routes_get_allLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_routes_put.lua": &bintree{route_twirp_eclier_routes_putLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_tokens_deactivate.lua": &bintree{route_twirp_eclier_tokens_deactivateLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_tokens_delete.lua": &bintree{route_twirp_eclier_tokens_deleteLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_tokens_get.lua": &bintree{route_twirp_eclier_tokens_getLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_tokens_get_all.lua": &bintree{route_twirp_eclier_tokens_get_allLua, map[string]*bintree{}},
|
||||
"route_twirp_eclier_tokens_put.lua": &bintree{route_twirp_eclier_tokens_putLua, map[string]*bintree{}},
|
||||
}}
|
||||
|
||||
// RestoreAsset restores an asset under the given directory
|
||||
func RestoreAsset(dir, name string) error {
|
||||
data, err := Asset(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
info, err := AssetInfo(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.MkdirAll(_filePath(dir, filepath.Dir(name)), os.FileMode(0755))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = ioutil.WriteFile(_filePath(dir, name), data, info.Mode())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = os.Chtimes(_filePath(dir, name), info.ModTime(), info.ModTime())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RestoreAssets restores an asset under the given directory recursively
|
||||
func RestoreAssets(dir, name string) error {
|
||||
children, err := AssetDir(name)
|
||||
// File
|
||||
if err != nil {
|
||||
return RestoreAsset(dir, name)
|
||||
}
|
||||
// Dir
|
||||
for _, child := range children {
|
||||
err = RestoreAssets(dir, filepath.Join(name, child))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func _filePath(dir, name string) string {
|
||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "backends:kill"
|
||||
script.help = "Executes method kill on service backends for twirp package xeserv.us.route.backends"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for BackendId
|
||||
fs:string("id", "", "value for message arg id")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):backends():kill(flags)
|
||||
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "backends:list"
|
||||
script.help = "Executes method list on service backends for twirp package xeserv.us.route.backends"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for BackendSelector
|
||||
fs:string("domain", "", "value for message arg domain")
|
||||
fs:string("user", "", "value for message arg user")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):backends():list(flags)
|
||||
|
||||
print("bs:\t\t" .. tostring(resp.bs))
|
||||
print("backends:\t\t" .. tostring(resp.backends))
|
||||
end
|
|
@ -1,33 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "routes:delete"
|
||||
script.help = "Executes method delete on service routes for twirp package xeserv.us.route.routes"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for Route
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("creator", "", "value for message arg creator")
|
||||
fs:string("host", "", "value for message arg host")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):routes():delete(flags)
|
||||
|
||||
end
|
|
@ -1,35 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "routes:get"
|
||||
script.help = "Executes method get on service routes for twirp package xeserv.us.route.routes"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for GetRouteRequest
|
||||
fs:string("unused", "", "value for message arg unused")
|
||||
fs:string("id", "", "value for message arg id")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):routes():get(flags)
|
||||
|
||||
print("id:\t\t" .. tostring(resp.id))
|
||||
print("creator:\t\t" .. tostring(resp.creator))
|
||||
print("host:\t\t" .. tostring(resp.host))
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "routes:get_all"
|
||||
script.help = "Executes method get_all on service routes for twirp package xeserv.us.route.routes"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for Nil
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):routes():get_all(flags)
|
||||
|
||||
print("routes:\t\t" .. tostring(resp.routes))
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "routes:put"
|
||||
script.help = "Executes method put on service routes for twirp package xeserv.us.route.routes"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for Route
|
||||
fs:string("host", "", "value for message arg host")
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("creator", "", "value for message arg creator")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):routes():put(flags)
|
||||
|
||||
print("id:\t\t" .. tostring(resp.id))
|
||||
print("creator:\t\t" .. tostring(resp.creator))
|
||||
print("host:\t\t" .. tostring(resp.host))
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "tokens:deactivate"
|
||||
script.help = "Executes method deactivate on service tokens for twirp package xeserv.us.route.tokens"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for Token
|
||||
fs:bool("active", false, "value for message arg active")
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("body", "", "value for message arg body")
|
||||
fs:strings("scopes", "value for message arg scopes")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):tokens():deactivate(flags)
|
||||
|
||||
end
|
|
@ -1,34 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "tokens:delete"
|
||||
script.help = "Executes method delete on service tokens for twirp package xeserv.us.route.tokens"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for Token
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("body", "", "value for message arg body")
|
||||
fs:strings("scopes", "value for message arg scopes")
|
||||
fs:bool("active", false, "value for message arg active")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):tokens():delete(flags)
|
||||
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "tokens:get"
|
||||
script.help = "Executes method get on service tokens for twirp package xeserv.us.route.tokens"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for GetTokenRequest
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("token", "", "value for message arg token")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):tokens():get(flags)
|
||||
|
||||
print("id:\t\t" .. tostring(resp.id))
|
||||
print("body:\t\t" .. tostring(resp.body))
|
||||
print("scopes:\t\t" .. tostring(resp.scopes))
|
||||
print("active:\t\t" .. tostring(resp.active))
|
||||
end
|
|
@ -1,31 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "tokens:get_all"
|
||||
script.help = "Executes method get_all on service tokens for twirp package xeserv.us.route.tokens"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for Nil
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):tokens():get_all(flags)
|
||||
|
||||
print("tokens:\t\t" .. tostring(resp.tokens))
|
||||
end
|
|
@ -1,38 +0,0 @@
|
|||
-- Code generated by protoc-gen-twirp_eclier v5.0.0DO NOT EDIT
|
||||
-- source: route.proto
|
||||
|
||||
script.verb = "tokens:put"
|
||||
script.help = "Executes method put on service tokens for twirp package xeserv.us.route.tokens"
|
||||
script.author = "machine-generated"
|
||||
script.version = "v5.0.0"
|
||||
script.usage = ""
|
||||
|
||||
local flag = require "flag"
|
||||
local svc = require "svc"
|
||||
|
||||
local fs = flag.new()
|
||||
|
||||
-- flags for Token
|
||||
fs:string("id", "", "value for message arg id")
|
||||
fs:string("body", "", "value for message arg body")
|
||||
fs:strings("scopes", "value for message arg scopes")
|
||||
fs:bool("active", false, "value for message arg active")
|
||||
|
||||
script.usage = fs:usage()
|
||||
|
||||
function run(arg)
|
||||
if arg[1] == "-help" or arg[1] == "--help" then
|
||||
print(fs:usage())
|
||||
return
|
||||
end
|
||||
|
||||
arg[0] = script.verb
|
||||
local flags = fs:parse(arg)
|
||||
|
||||
local resp = svc.new(apiURL, token):tokens():put(flags)
|
||||
|
||||
print("id:\t\t" .. tostring(resp.id))
|
||||
print("body:\t\t" .. tostring(resp.body))
|
||||
print("scopes:\t\t" .. tostring(resp.scopes))
|
||||
print("active:\t\t" .. tostring(resp.active))
|
||||
end
|
|
@ -3,5 +3,4 @@
|
|||
protoc -I. \
|
||||
--go_out=:. \
|
||||
--twirp_out=. \
|
||||
--twirp_eclier_out=./eclier \
|
||||
route.proto
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
FROM xena/route-core
|
||||
FROM xena/alpine
|
||||
|
||||
COPY --from=0 /root/go/src/git.xeserv.us/xena/route/bin/linux/amd64/route-httpagent /usr/local/bin/route-httpagent
|
||||
|
||||
CMD /usr/local/bin/route-httpagent
|
|
@ -1,10 +0,0 @@
|
|||
FROM xena/route-core
|
||||
FROM xena/alpine
|
||||
|
||||
COPY --from=0 /root/go/src/git.xeserv.us/xena/route/bin/linux/amd64/routed /usr/local/bin/routed
|
||||
|
||||
VOLUME /routed
|
||||
|
||||
ENV BOLTDB_PATH /routed/route.db
|
||||
|
||||
CMD /usr/local/bin/routed
|
|
@ -1,7 +0,0 @@
|
|||
Copyright (C) 2014 Thomas Rooney
|
||||
|
||||
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.
|
|
@ -1,64 +0,0 @@
|
|||
# Gexpect
|
||||
|
||||
Gexpect is a pure golang expect-like module.
|
||||
|
||||
It makes it simpler to create and control other terminal applications.
|
||||
|
||||
child, err := gexpect.Spawn("python")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
child.Expect(">>>")
|
||||
child.SendLine("print 'Hello World'")
|
||||
child.Interact()
|
||||
child.Close()
|
||||
|
||||
## Examples
|
||||
|
||||
`Spawn` handles the argument parsing from a string
|
||||
|
||||
child.Spawn("/bin/sh -c 'echo \"my complicated command\" | tee log | cat > log2'")
|
||||
child.ReadLine() // ReadLine() (string, error)
|
||||
child.ReadUntil(' ') // ReadUntil(delim byte) ([]byte, error)
|
||||
|
||||
`ReadLine`, `ReadUntil` and `SendLine` send strings from/to `stdout/stdin` respectively
|
||||
|
||||
child, _ := gexpect.Spawn("cat")
|
||||
child.SendLine("echoing process_stdin") // SendLine(command string) (error)
|
||||
msg, _ := child.ReadLine() // msg = echoing process_stdin
|
||||
|
||||
`Wait` and `Close` allow for graceful and ungraceful termination.
|
||||
|
||||
child.Wait() // Waits until the child terminates naturally.
|
||||
child.Close() // Sends a kill command
|
||||
|
||||
`AsyncInteractChannels` spawns two go routines to pipe into and from `stdout`/`stdin`, allowing for some usecases to be a little simpler.
|
||||
|
||||
child, _ := gexpect.Spawn("sh")
|
||||
sender, receiver := child.AsyncInteractChannels()
|
||||
sender <- "echo Hello World\n" // Send to stdin
|
||||
line, open := <- receiver // Recieve a line from stdout/stderr
|
||||
// When the subprocess stops (e.g. with child.Close()) , receiver is closed
|
||||
if open {
|
||||
fmt.Printf("Received %s", line)
|
||||
}
|
||||
|
||||
`ExpectRegex` uses golang's internal regex engine to wait until a match from the process with the given regular expression (or an error on process termination with no match).
|
||||
|
||||
child, _ := gexpect.Spawn("echo accb")
|
||||
match, _ := child.ExpectRegex("a..b")
|
||||
// (match=true)
|
||||
|
||||
`ExpectRegexFind` allows for groups to be extracted from process stdout. The first element is an array of containing the total matched text, followed by each subexpression group match.
|
||||
|
||||
child, _ := gexpect.Spawn("echo 123 456 789")
|
||||
result, _ := child.ExpectRegexFind("\d+ (\d+) (\d+)")
|
||||
// result = []string{"123 456 789", "456", "789"}
|
||||
|
||||
See `gexpect_test.go` and the `examples` folder for full syntax
|
||||
|
||||
## Credits
|
||||
|
||||
github.com/kballard/go-shellquote
|
||||
github.com/kr/pty
|
||||
KMP Algorithm: "http://blog.databigbang.com/searching-for-substrings-in-streams-a-slight-modification-of-the-knuth-morris-pratt-algorithm-in-haxe/"
|
|
@ -1,449 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
package gexpect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"regexp"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
shell "github.com/kballard/go-shellquote"
|
||||
"github.com/kr/pty"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrEmptySearch = errors.New("empty search string")
|
||||
)
|
||||
|
||||
type ExpectSubprocess struct {
|
||||
Cmd *exec.Cmd
|
||||
buf *buffer
|
||||
outputBuffer []byte
|
||||
}
|
||||
|
||||
type buffer struct {
|
||||
f *os.File
|
||||
b bytes.Buffer
|
||||
collect bool
|
||||
|
||||
collection bytes.Buffer
|
||||
}
|
||||
|
||||
func (buf *buffer) StartCollecting() {
|
||||
buf.collect = true
|
||||
}
|
||||
|
||||
func (buf *buffer) StopCollecting() (result string) {
|
||||
result = string(buf.collection.Bytes())
|
||||
buf.collect = false
|
||||
buf.collection.Reset()
|
||||
return result
|
||||
}
|
||||
|
||||
func (buf *buffer) Read(chunk []byte) (int, error) {
|
||||
nread := 0
|
||||
if buf.b.Len() > 0 {
|
||||
n, err := buf.b.Read(chunk)
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
if n == len(chunk) {
|
||||
return n, nil
|
||||
}
|
||||
nread = n
|
||||
}
|
||||
fn, err := buf.f.Read(chunk[nread:])
|
||||
return fn + nread, err
|
||||
}
|
||||
|
||||
func (buf *buffer) ReadRune() (r rune, size int, err error) {
|
||||
l := buf.b.Len()
|
||||
|
||||
chunk := make([]byte, utf8.UTFMax)
|
||||
if l > 0 {
|
||||
n, err := buf.b.Read(chunk)
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
if utf8.FullRune(chunk[:n]) {
|
||||
r, rL := utf8.DecodeRune(chunk)
|
||||
if n > rL {
|
||||
buf.PutBack(chunk[rL:n])
|
||||
}
|
||||
if buf.collect {
|
||||
buf.collection.WriteRune(r)
|
||||
}
|
||||
return r, rL, nil
|
||||
}
|
||||
}
|
||||
// else add bytes from the file, then try that
|
||||
for l < utf8.UTFMax {
|
||||
fn, err := buf.f.Read(chunk[l : l+1])
|
||||
if err != nil {
|
||||
return 0, 0, err
|
||||
}
|
||||
l = l + fn
|
||||
|
||||
if utf8.FullRune(chunk[:l]) {
|
||||
r, rL := utf8.DecodeRune(chunk)
|
||||
if buf.collect {
|
||||
buf.collection.WriteRune(r)
|
||||
}
|
||||
return r, rL, nil
|
||||
}
|
||||
}
|
||||
return 0, 0, errors.New("File is not a valid UTF=8 encoding")
|
||||
}
|
||||
|
||||
func (buf *buffer) PutBack(chunk []byte) {
|
||||
if len(chunk) == 0 {
|
||||
return
|
||||
}
|
||||
if buf.b.Len() == 0 {
|
||||
buf.b.Write(chunk)
|
||||
return
|
||||
}
|
||||
d := make([]byte, 0, len(chunk)+buf.b.Len())
|
||||
d = append(d, chunk...)
|
||||
d = append(d, buf.b.Bytes()...)
|
||||
buf.b.Reset()
|
||||
buf.b.Write(d)
|
||||
}
|
||||
|
||||
func SpawnAtDirectory(command string, directory string) (*ExpectSubprocess, error) {
|
||||
expect, err := _spawn(command)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expect.Cmd.Dir = directory
|
||||
return _start(expect)
|
||||
}
|
||||
|
||||
func Command(command string) (*ExpectSubprocess, error) {
|
||||
expect, err := _spawn(command)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return expect, nil
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) Start() error {
|
||||
_, err := _start(expect)
|
||||
return err
|
||||
}
|
||||
|
||||
func Spawn(command string) (*ExpectSubprocess, error) {
|
||||
expect, err := _spawn(command)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return _start(expect)
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) Close() error {
|
||||
if err := expect.Cmd.Process.Kill(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := expect.buf.f.Close(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) AsyncInteractChannels() (send chan string, receive chan string) {
|
||||
receive = make(chan string)
|
||||
send = make(chan string)
|
||||
|
||||
go func() {
|
||||
for {
|
||||
str, err := expect.ReadLine()
|
||||
if err != nil {
|
||||
close(receive)
|
||||
return
|
||||
}
|
||||
receive <- str
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case sendCommand, exists := <-send:
|
||||
{
|
||||
if !exists {
|
||||
return
|
||||
}
|
||||
err := expect.Send(sendCommand)
|
||||
if err != nil {
|
||||
receive <- "gexpect Error: " + err.Error()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) ExpectRegex(regex string) (bool, error) {
|
||||
return regexp.MatchReader(regex, expect.buf)
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) expectRegexFind(regex string, output bool) ([]string, string, error) {
|
||||
re, err := regexp.Compile(regex)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
expect.buf.StartCollecting()
|
||||
pairs := re.FindReaderSubmatchIndex(expect.buf)
|
||||
stringIndexedInto := expect.buf.StopCollecting()
|
||||
l := len(pairs)
|
||||
numPairs := l / 2
|
||||
result := make([]string, numPairs)
|
||||
for i := 0; i < numPairs; i += 1 {
|
||||
result[i] = stringIndexedInto[pairs[i*2]:pairs[i*2+1]]
|
||||
}
|
||||
// convert indexes to strings
|
||||
|
||||
if len(result) == 0 {
|
||||
err = fmt.Errorf("ExpectRegex didn't find regex '%v'.", regex)
|
||||
} else {
|
||||
// The number in pairs[1] is an index of a first
|
||||
// character outside the whole match
|
||||
putBackIdx := pairs[1]
|
||||
if len(stringIndexedInto) > putBackIdx {
|
||||
stringToPutBack := stringIndexedInto[putBackIdx:]
|
||||
stringIndexedInto = stringIndexedInto[:putBackIdx]
|
||||
expect.buf.PutBack([]byte(stringToPutBack))
|
||||
}
|
||||
}
|
||||
return result, stringIndexedInto, err
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) expectTimeoutRegexFind(regex string, timeout time.Duration) (result []string, out string, err error) {
|
||||
t := make(chan bool)
|
||||
go func() {
|
||||
result, out, err = expect.ExpectRegexFindWithOutput(regex)
|
||||
t <- false
|
||||
}()
|
||||
go func() {
|
||||
time.Sleep(timeout)
|
||||
err = fmt.Errorf("ExpectRegex timed out after %v finding '%v'.\nOutput:\n%s", timeout, regex, expect.Collect())
|
||||
t <- true
|
||||
}()
|
||||
<-t
|
||||
return result, out, err
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) ExpectRegexFind(regex string) ([]string, error) {
|
||||
result, _, err := expect.expectRegexFind(regex, false)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) ExpectTimeoutRegexFind(regex string, timeout time.Duration) ([]string, error) {
|
||||
result, _, err := expect.expectTimeoutRegexFind(regex, timeout)
|
||||
return result, err
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) ExpectRegexFindWithOutput(regex string) ([]string, string, error) {
|
||||
return expect.expectRegexFind(regex, true)
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) ExpectTimeoutRegexFindWithOutput(regex string, timeout time.Duration) ([]string, string, error) {
|
||||
return expect.expectTimeoutRegexFind(regex, timeout)
|
||||
}
|
||||
|
||||
func buildKMPTable(searchString string) []int {
|
||||
pos := 2
|
||||
cnd := 0
|
||||
length := len(searchString)
|
||||
|
||||
var table []int
|
||||
if length < 2 {
|
||||
length = 2
|
||||
}
|
||||
|
||||
table = make([]int, length)
|
||||
table[0] = -1
|
||||
table[1] = 0
|
||||
|
||||
for pos < len(searchString) {
|
||||
if searchString[pos-1] == searchString[cnd] {
|
||||
cnd += 1
|
||||
table[pos] = cnd
|
||||
pos += 1
|
||||
} else if cnd > 0 {
|
||||
cnd = table[cnd]
|
||||
} else {
|
||||
table[pos] = 0
|
||||
pos += 1
|
||||
}
|
||||
}
|
||||
return table
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) ExpectTimeout(searchString string, timeout time.Duration) (e error) {
|
||||
result := make(chan error)
|
||||
go func() {
|
||||
result <- expect.Expect(searchString)
|
||||
}()
|
||||
select {
|
||||
case e = <-result:
|
||||
case <-time.After(timeout):
|
||||
e = fmt.Errorf("Expect timed out after %v waiting for '%v'.\nOutput:\n%s", timeout, searchString, expect.Collect())
|
||||
}
|
||||
return e
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) Expect(searchString string) (e error) {
|
||||
target := len(searchString)
|
||||
if target < 1 {
|
||||
return ErrEmptySearch
|
||||
}
|
||||
chunk := make([]byte, target*2)
|
||||
if expect.outputBuffer != nil {
|
||||
expect.outputBuffer = expect.outputBuffer[0:]
|
||||
}
|
||||
m := 0
|
||||
i := 0
|
||||
// Build KMP Table
|
||||
table := buildKMPTable(searchString)
|
||||
|
||||
for {
|
||||
n, err := expect.buf.Read(chunk)
|
||||
if n == 0 && err != nil {
|
||||
return err
|
||||
}
|
||||
if expect.outputBuffer != nil {
|
||||
expect.outputBuffer = append(expect.outputBuffer, chunk[:n]...)
|
||||
}
|
||||
offset := m + i
|
||||
for m+i-offset < n {
|
||||
if searchString[i] == chunk[m+i-offset] {
|
||||
i += 1
|
||||
if i == target {
|
||||
unreadIndex := m + i - offset
|
||||
if len(chunk) > unreadIndex {
|
||||
expect.buf.PutBack(chunk[unreadIndex:n])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
m += i - table[i]
|
||||
if table[i] > -1 {
|
||||
i = table[i]
|
||||
} else {
|
||||
i = 0
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) Send(command string) error {
|
||||
_, err := io.WriteString(expect.buf.f, command)
|
||||
return err
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) Capture() {
|
||||
if expect.outputBuffer == nil {
|
||||
expect.outputBuffer = make([]byte, 0)
|
||||
}
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) Collect() []byte {
|
||||
collectOutput := make([]byte, len(expect.outputBuffer))
|
||||
copy(collectOutput, expect.outputBuffer)
|
||||
expect.outputBuffer = nil
|
||||
return collectOutput
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) SendLine(command string) error {
|
||||
_, err := io.WriteString(expect.buf.f, command+"\r\n")
|
||||
return err
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) Interact() {
|
||||
defer expect.Cmd.Wait()
|
||||
io.Copy(os.Stdout, &expect.buf.b)
|
||||
go io.Copy(os.Stdout, expect.buf.f)
|
||||
go io.Copy(expect.buf.f, os.Stdin)
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) ReadUntil(delim byte) ([]byte, error) {
|
||||
join := make([]byte, 0, 512)
|
||||
chunk := make([]byte, 255)
|
||||
|
||||
for {
|
||||
n, err := expect.buf.Read(chunk)
|
||||
|
||||
for i := 0; i < n; i++ {
|
||||
if chunk[i] == delim {
|
||||
if len(chunk) > i+1 {
|
||||
expect.buf.PutBack(chunk[i+1:n])
|
||||
}
|
||||
return join, nil
|
||||
} else {
|
||||
join = append(join, chunk[i])
|
||||
}
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return join, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) Wait() error {
|
||||
return expect.Cmd.Wait()
|
||||
}
|
||||
|
||||
func (expect *ExpectSubprocess) ReadLine() (string, error) {
|
||||
str, err := expect.ReadUntil('\n')
|
||||
return string(str), err
|
||||
}
|
||||
|
||||
func _start(expect *ExpectSubprocess) (*ExpectSubprocess, error) {
|
||||
f, err := pty.Start(expect.Cmd)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
expect.buf.f = f
|
||||
|
||||
return expect, nil
|
||||
}
|
||||
|
||||
func _spawn(command string) (*ExpectSubprocess, error) {
|
||||
wrapper := new(ExpectSubprocess)
|
||||
|
||||
wrapper.outputBuffer = nil
|
||||
|
||||
splitArgs, err := shell.Split(command)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
numArguments := len(splitArgs) - 1
|
||||
if numArguments < 0 {
|
||||
return nil, errors.New("gexpect: No command given to spawn")
|
||||
}
|
||||
path, err := exec.LookPath(splitArgs[0])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if numArguments >= 1 {
|
||||
wrapper.Cmd = exec.Command(path, splitArgs[1:]...)
|
||||
} else {
|
||||
wrapper.Cmd = exec.Command(path)
|
||||
}
|
||||
wrapper.buf = new(buffer)
|
||||
|
||||
return wrapper, nil
|
||||
}
|
|
@ -1,419 +0,0 @@
|
|||
// +build !windows
|
||||
|
||||
package gexpect
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestEmptySearchString(t *testing.T) {
|
||||
t.Logf("Testing empty search string...")
|
||||
child, err := Spawn("echo Hello World")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = child.Expect("")
|
||||
if err != ErrEmptySearch {
|
||||
t.Fatalf("Expected empty search error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHelloWorld(t *testing.T) {
|
||||
t.Logf("Testing Hello World... ")
|
||||
child, err := Spawn("echo \"Hello World\"")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = child.Expect("Hello World")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDoubleHelloWorld(t *testing.T) {
|
||||
t.Logf("Testing Double Hello World... ")
|
||||
child, err := Spawn(`sh -c "echo Hello World ; echo Hello ; echo Hi"`)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = child.Expect("Hello World")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = child.Expect("Hello")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = child.Expect("Hi")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHelloWorldFailureCase(t *testing.T) {
|
||||
t.Logf("Testing Hello World Failure case... ")
|
||||
child, err := Spawn("echo \"Hello World\"")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = child.Expect("YOU WILL NEVER FIND ME")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
t.Fatal("Expected an error for TestHelloWorldFailureCase")
|
||||
}
|
||||
|
||||
func TestBiChannel(t *testing.T) {
|
||||
|
||||
t.Logf("Testing BiChannel screen... ")
|
||||
child, err := Spawn("cat")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sender, receiver := child.AsyncInteractChannels()
|
||||
wait := func(str string) {
|
||||
for {
|
||||
msg, open := <-receiver
|
||||
if !open {
|
||||
return
|
||||
}
|
||||
if strings.Contains(msg, str) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
endlChar := fmt.Sprintln("")
|
||||
sender <- fmt.Sprintf("echo%v", endlChar)
|
||||
wait("echo")
|
||||
sender <- fmt.Sprintf("echo2%v", endlChar)
|
||||
wait("echo2")
|
||||
child.Close()
|
||||
child.Wait()
|
||||
}
|
||||
|
||||
func TestCommandStart(t *testing.T) {
|
||||
t.Logf("Testing Command... ")
|
||||
|
||||
// Doing this allows you to modify the cmd struct prior to execution, for example to add environment variables
|
||||
child, err := Command("echo 'Hello World'")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
child.Start()
|
||||
child.Expect("Hello World")
|
||||
}
|
||||
|
||||
var regexMatchTests = []struct {
|
||||
re string
|
||||
good string
|
||||
bad string
|
||||
}{
|
||||
{`a`, `a`, `b`},
|
||||
{`.b`, `ab`, `ac`},
|
||||
{`a+hello`, `aaaahello`, `bhello`},
|
||||
{`(hello|world)`, `hello`, `unknown`},
|
||||
{`(hello|world)`, `world`, `unknown`},
|
||||
{"\u00a9", "\u00a9", `unknown`}, // 2 bytes long unicode character "copyright sign"
|
||||
}
|
||||
|
||||
func TestRegexMatch(t *testing.T) {
|
||||
t.Logf("Testing Regular Expression Matching... ")
|
||||
for _, tt := range regexMatchTests {
|
||||
runTest := func(input string) bool {
|
||||
var match bool
|
||||
child, err := Spawn("echo \"" + input + "\"")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
match, err = child.ExpectRegex(tt.re)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return match
|
||||
}
|
||||
if !runTest(tt.good) {
|
||||
t.Errorf("Regex Not matching [%#q] with pattern [%#q]", tt.good, tt.re)
|
||||
}
|
||||
if runTest(tt.bad) {
|
||||
t.Errorf("Regex Matching [%#q] with pattern [%#q]", tt.bad, tt.re)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var regexFindTests = []struct {
|
||||
re string
|
||||
input string
|
||||
matches []string
|
||||
}{
|
||||
{`he(l)lo wo(r)ld`, `hello world`, []string{"hello world", "l", "r"}},
|
||||
{`(a)`, `a`, []string{"a", "a"}},
|
||||
{`so.. (hello|world)`, `so.. hello`, []string{"so.. hello", "hello"}},
|
||||
{`(a+)hello`, `aaaahello`, []string{"aaaahello", "aaaa"}},
|
||||
{`\d+ (\d+) (\d+)`, `123 456 789`, []string{"123 456 789", "456", "789"}},
|
||||
{`\d+ (\d+) (\d+)`, "\u00a9 123 456 789 \u00a9", []string{"123 456 789", "456", "789"}}, // check unicode characters
|
||||
}
|
||||
|
||||
func TestRegexFind(t *testing.T) {
|
||||
t.Logf("Testing Regular Expression Search... ")
|
||||
for _, tt := range regexFindTests {
|
||||
runTest := func(input string) []string {
|
||||
child, err := Spawn("echo \"" + input + "\"")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
matches, err := child.ExpectRegexFind(tt.re)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return matches
|
||||
}
|
||||
matches := runTest(tt.input)
|
||||
if len(matches) != len(tt.matches) {
|
||||
t.Fatalf("Regex not producing the expected number of patterns.. got[%d] ([%s]) expected[%d] ([%s])",
|
||||
len(matches), strings.Join(matches, ","),
|
||||
len(tt.matches), strings.Join(tt.matches, ","))
|
||||
}
|
||||
for i, _ := range matches {
|
||||
if matches[i] != tt.matches[i] {
|
||||
t.Errorf("Regex Expected group [%s] and got group [%s] with pattern [%#q] and input [%s]",
|
||||
tt.matches[i], matches[i], tt.re, tt.input)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadLine(t *testing.T) {
|
||||
t.Logf("Testing ReadLine...")
|
||||
|
||||
child, err := Spawn("echo \"foo\nbar\"")
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s, err := child.ReadLine()
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s != "foo\r" {
|
||||
t.Fatalf("expected 'foo\\r', got '%s'", s)
|
||||
}
|
||||
s, err = child.ReadLine()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if s != "bar\r" {
|
||||
t.Fatalf("expected 'bar\\r', got '%s'", s)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegexWithOutput(t *testing.T) {
|
||||
t.Logf("Testing Regular Expression search with output...")
|
||||
|
||||
s := "You will not find me"
|
||||
p, err := Spawn("echo -n " + s)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot exec rkt: %v", err)
|
||||
}
|
||||
searchPattern := `I should not find you`
|
||||
result, out, err := p.ExpectRegexFindWithOutput(searchPattern)
|
||||
if err == nil {
|
||||
t.Fatalf("Shouldn't have found `%v` in `%v`", searchPattern, out)
|
||||
}
|
||||
if s != out {
|
||||
t.Fatalf("Child output didn't match: %s", out)
|
||||
}
|
||||
|
||||
err = p.Wait()
|
||||
if err != nil {
|
||||
t.Fatalf("Child didn't terminate correctly: %v", err)
|
||||
}
|
||||
|
||||
p, err = Spawn("echo You will find me")
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot exec rkt: %v", err)
|
||||
}
|
||||
searchPattern = `.*(You will).*`
|
||||
result, out, err = p.ExpectRegexFindWithOutput(searchPattern)
|
||||
if err != nil || result[1] != "You will" {
|
||||
t.Fatalf("Did not find pattern `%v` in `%v'\n", searchPattern, out)
|
||||
}
|
||||
err = p.Wait()
|
||||
if err != nil {
|
||||
t.Fatalf("Child didn't terminate correctly: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegexTimeoutWithOutput(t *testing.T) {
|
||||
t.Logf("Testing Regular Expression search with timeout and output...")
|
||||
|
||||
seconds := 2
|
||||
timeout := time.Duration(seconds-1) * time.Second
|
||||
|
||||
p, err := Spawn(fmt.Sprintf("sh -c 'sleep %d && echo You find me'", seconds))
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot exec rkt: %v", err)
|
||||
}
|
||||
searchPattern := `find me`
|
||||
result, out, err := p.ExpectTimeoutRegexFindWithOutput(searchPattern, timeout)
|
||||
if err == nil {
|
||||
t.Fatalf("Shouldn't have finished call with result: %v", result)
|
||||
}
|
||||
|
||||
seconds = 2
|
||||
timeout = time.Duration(seconds+1) * time.Second
|
||||
|
||||
p, err = Spawn(fmt.Sprintf("sh -c 'sleep %d && echo You find me'", seconds))
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot exec rkt: %v", err)
|
||||
}
|
||||
searchPattern = `find me`
|
||||
result, out, err = p.ExpectTimeoutRegexFindWithOutput(searchPattern, timeout)
|
||||
if err != nil {
|
||||
t.Fatalf("Didn't find %v in output: %v", searchPattern, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegexFindNoExcessBytes(t *testing.T) {
|
||||
t.Logf("Testing Regular Expressions returning output with no excess strings")
|
||||
repeats := 50
|
||||
tests := []struct {
|
||||
desc string
|
||||
loopBody string
|
||||
searchPattern string
|
||||
expectFullTmpl string
|
||||
unmatchedData string
|
||||
}{
|
||||
{
|
||||
desc: `matching lines line by line with $ at the end of the regexp`,
|
||||
loopBody: `echo "prefix: ${i} line"`,
|
||||
searchPattern: `(?m)^prefix:\s+(\d+) line\s??$`,
|
||||
expectFullTmpl: `prefix: %d line`,
|
||||
unmatchedData: "\n",
|
||||
// the "$" char at the end of regexp does not
|
||||
// match the \n, so it is left as an unmatched
|
||||
// data
|
||||
},
|
||||
{
|
||||
desc: `matching lines line by line with \n at the end of the regexp`,
|
||||
loopBody: `echo "prefix: ${i} line"`,
|
||||
searchPattern: `(?m)^prefix:\s+(\d+) line\s??\n`,
|
||||
expectFullTmpl: `prefix: %d line`,
|
||||
unmatchedData: "",
|
||||
},
|
||||
{
|
||||
desc: `matching chunks in single line chunk by chunk`,
|
||||
loopBody: `printf "a ${i} b"`,
|
||||
searchPattern: `a\s+(\d+)\s+b`,
|
||||
expectFullTmpl: `a %d b`,
|
||||
unmatchedData: "",
|
||||
},
|
||||
}
|
||||
seqCmd := fmt.Sprintf("`seq 1 %d`", repeats)
|
||||
shCmdTmpl := fmt.Sprintf(`sh -c 'for i in %s; do %%s; done'`, seqCmd)
|
||||
for _, tt := range tests {
|
||||
t.Logf("Test: %s", tt.desc)
|
||||
shCmd := fmt.Sprintf(shCmdTmpl, tt.loopBody)
|
||||
t.Logf("Running command: %s", shCmd)
|
||||
p, err := Spawn(shCmd)
|
||||
if err != nil {
|
||||
t.Fatalf("Cannot exec shell script: %v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := p.Wait(); err != nil {
|
||||
t.Fatalf("shell script didn't terminate correctly: %v", err)
|
||||
}
|
||||
}()
|
||||
for i := 1; i <= repeats; i++ {
|
||||
matches, output, err := p.ExpectRegexFindWithOutput(tt.searchPattern)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to get the match number %d: %v", i, err)
|
||||
}
|
||||
if len(matches) != 2 {
|
||||
t.Fatalf("Expected only 2 matches, got %d", len(matches))
|
||||
}
|
||||
full := strings.TrimSpace(matches[0])
|
||||
expFull := fmt.Sprintf(tt.expectFullTmpl, i)
|
||||
partial := matches[1]
|
||||
expPartial := fmt.Sprintf("%d", i)
|
||||
if full != expFull {
|
||||
t.Fatalf("Did not the expected full match %q, got %q", expFull, full)
|
||||
}
|
||||
if partial != expPartial {
|
||||
t.Fatalf("Did not the expected partial match %q, got %q", expPartial, partial)
|
||||
}
|
||||
// The output variable usually contains the
|
||||
// unmatched data followed by the whole match.
|
||||
// The first line is special as it has no data
|
||||
// preceding it.
|
||||
var expectedOutput string
|
||||
if i == 1 || tt.unmatchedData == "" {
|
||||
expectedOutput = matches[0]
|
||||
} else {
|
||||
expectedOutput = fmt.Sprintf("%s%s", tt.unmatchedData, matches[0])
|
||||
}
|
||||
if output != expectedOutput {
|
||||
t.Fatalf("The collected output %q should be the same as the whole match %q", output, expectedOutput)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBufferReadRune(t *testing.T) {
|
||||
tests := []struct {
|
||||
bufferContent []byte
|
||||
fileContent []byte
|
||||
expectedRune rune
|
||||
}{
|
||||
// unicode "copyright char" is \u00a9 is encoded as two bytes in utf8 0xc2 0xa9
|
||||
{[]byte{0xc2, 0xa9}, []byte{}, '\u00a9'}, // whole rune is already in buffer.b
|
||||
{[]byte{0xc2}, []byte{0xa9}, '\u00a9'}, // half of is in the buffer.b and another half still in buffer.f (file)
|
||||
{[]byte{}, []byte{0xc2, 0xa9}, '\u00a9'}, // whole rune is the file
|
||||
// some random noise in the end of file
|
||||
{[]byte{0xc2, 0xa9}, []byte{0x20, 0x20, 0x20, 0x20}, '\u00a9'},
|
||||
{[]byte{0xc2}, []byte{0xa9, 0x20, 0x20, 0x20, 0x20}, '\u00a9'},
|
||||
{[]byte{}, []byte{0xc2, 0xa9, 0x20, 0x20, 0x20, 0x20}, '\u00a9'},
|
||||
}
|
||||
|
||||
for i, tt := range tests {
|
||||
|
||||
// prepare tmp file with fileContent
|
||||
f, err := ioutil.TempFile("", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
n, err := f.Write(tt.fileContent)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if n != len(tt.fileContent) {
|
||||
t.Fatal("expected fileContent written to temp file")
|
||||
}
|
||||
_, err = f.Seek(0, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// new buffer
|
||||
buf := buffer{f: f, b: *bytes.NewBuffer(tt.bufferContent)}
|
||||
|
||||
// call ReadRune
|
||||
r, size, err := buf.ReadRune()
|
||||
|
||||
if r != tt.expectedRune {
|
||||
t.Fatalf("#%d: expected rune %+q but go is %+q", i, tt.expectedRune, r)
|
||||
}
|
||||
|
||||
if size != len(string(tt.expectedRune)) {
|
||||
t.Fatalf("#%d: expected rune %d bytes long but got just %d bytes long", i, len(string(tt.expectedRune)), size)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
.DS_Store
|
||||
doc
|
|
@ -1,223 +0,0 @@
|
|||
memo = "b40e77e679fec09015bfda27b7d1fc37f4ba6240cbe95cf9fb88b5c56e40ebdf"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ThomasRooney/gexpect"
|
||||
packages = ["."]
|
||||
revision = "5482f03509440585d13d8f648989e05903001842"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/x"
|
||||
packages = ["tools/glue/libs/gluaexpect","tools/glue/libs/gluasimplebox"]
|
||||
revision = "d0ebe3970f361daa31a135f1e0c7304eb1442f61"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ailncode/gluaxmlpath"
|
||||
packages = ["."]
|
||||
revision = "6ce478ecb4a60c4fc8929838e0b21b7fb7ca7440"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/brandur/simplebox"
|
||||
packages = ["."]
|
||||
revision = "84e9865bb03ad38c464043bf5382ce8c68ca5f0c"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluahttp"
|
||||
packages = ["."]
|
||||
revision = "b4bfe0c50fea948dcbf3966e120996d6607bbd89"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluaurl"
|
||||
packages = ["."]
|
||||
revision = "31cbb9bef199454415879f2e6d609d1136d60cad"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/cyberdelia/heroku-go"
|
||||
packages = ["v3"]
|
||||
revision = "bb8b6b1e9656ec0728638961f8e8b4211fee735d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/dickeyxxx/netrc"
|
||||
packages = ["."]
|
||||
revision = "3acf1b3de25d89c7688c63bb45f6b07f566555ec"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/google/go-querystring"
|
||||
packages = ["query"]
|
||||
revision = "53e6ce116135b80d037921a7fdd5138cf32d7a8a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/howeyc/gopass"
|
||||
packages = ["."]
|
||||
revision = "bf9dde6d0d2c004a008c27aaee91170c786f6db8"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kballard/go-shellquote"
|
||||
packages = ["."]
|
||||
revision = "d8ec1a69a250a17bb0e419c386eac1f3711dc142"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaenv"
|
||||
packages = ["."]
|
||||
revision = "2888db6bbe38923d59c42e443895875cc8ce0820"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluafs"
|
||||
packages = ["."]
|
||||
revision = "01391ed2d7ab89dc80157605b073403f960aa223"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaquestion"
|
||||
packages = ["."]
|
||||
revision = "311437c29ba54d027ad2af383661725ae2bfdcdc"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluassh"
|
||||
packages = ["."]
|
||||
revision = "2a7bd48d7568de8230c87ac1ef4a4c481e45814d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluatemplate"
|
||||
packages = ["."]
|
||||
revision = "d9e2c9d6b00f069a9da377a9ac529c827c1c7d71"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluayaml"
|
||||
packages = ["."]
|
||||
revision = "6fe413d49d73d785510ecf1529991ab0573e96c7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kr/fs"
|
||||
packages = ["."]
|
||||
revision = "2788f0dbd16903de03cb8186e5c7d97b69ad387b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kr/pty"
|
||||
packages = ["."]
|
||||
revision = "ce7fa45920dc37a92de8377972e52bc55ffa8d57"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mattn/go-runewidth"
|
||||
packages = ["."]
|
||||
revision = "737072b4e32b7a5018b4a7125da8d12de90e8045"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mitchellh/mapstructure"
|
||||
packages = ["."]
|
||||
revision = "cc8532a8e9a55ea36402aa21efdf403a60d34096"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/olekukonko/tablewriter"
|
||||
packages = ["."]
|
||||
revision = "44e365d423f4f06769182abfeeae2b91be9d529b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluaflag"
|
||||
packages = ["."]
|
||||
revision = "078088de689148194436293886e8e39809167332"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluash"
|
||||
packages = ["."]
|
||||
revision = "e145c563986f0b91f740a758a84bca46c163aec7"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pborman/uuid"
|
||||
packages = ["."]
|
||||
revision = "e790cca94e6cc75c7064b1332e63811d4aae1a53"
|
||||
version = "v1.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/pkg/sftp"
|
||||
packages = ["."]
|
||||
revision = "e84cc8c755ca39b7b64f510fe1fffc1b51f210a5"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yookoala/realpath"
|
||||
packages = ["."]
|
||||
revision = "c416d99ab5ed256fa30c1f3bab73152deb59bb69"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gluamapper"
|
||||
packages = ["."]
|
||||
revision = "d836955830e75240d46ce9f0e6d148d94f2e1d3a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gluare"
|
||||
packages = ["."]
|
||||
revision = "8e2742cd1bf2b904720ac66eca3c2091b2ea0720"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gopher-lua"
|
||||
packages = [".","ast","parse","pm"]
|
||||
revision = "33ebc07735566cd0c3c4b69e2839d522cc389852"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
packages = ["curve25519","ed25519","ed25519/internal/edwards25519","nacl/secretbox","poly1305","salsa20/salsa","ssh","ssh/agent","ssh/terminal"]
|
||||
revision = "dd85ac7e6a88fc6ca420478e934de5f1a42dd3c6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/net"
|
||||
packages = ["html","html/atom"]
|
||||
revision = "66aacef3dd8a676686c7ae3716979581e8b03c47"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
packages = ["unix"]
|
||||
revision = "9ccfe848b9db8435a24c424abbc07a921adf1df5"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/xmlpath.v2"
|
||||
packages = ["."]
|
||||
revision = "860cbeca3ebcc600db0b213c0e83ad6ce91f5739"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "gopkg.in/yaml.v2"
|
||||
packages = ["."]
|
||||
revision = "cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-json"
|
||||
packages = ["."]
|
||||
revision = "c128cc74278be889c4381681712931976fe0d88b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-luar"
|
||||
packages = ["."]
|
||||
revision = "80196fe2abc5682963fc7a5261f5a5d77509938b"
|
|
@ -1,72 +0,0 @@
|
|||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/Xe/x"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/ailncode/gluaxmlpath"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluahttp"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluaurl"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/dickeyxxx/netrc"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaenv"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluafs"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaquestion"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluassh"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluatemplate"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluayaml"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/olekukonko/tablewriter"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluaflag"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluash"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gluare"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gopher-lua"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-json"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-luar"
|
|
@ -1,121 +0,0 @@
|
|||
Creative Commons Legal Code
|
||||
|
||||
CC0 1.0 Universal
|
||||
|
||||
CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
|
||||
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
|
||||
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
|
||||
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
|
||||
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
|
||||
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
|
||||
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
|
||||
HEREUNDER.
|
||||
|
||||
Statement of Purpose
|
||||
|
||||
The laws of most jurisdictions throughout the world automatically confer
|
||||
exclusive Copyright and Related Rights (defined below) upon the creator
|
||||
and subsequent owner(s) (each and all, an "owner") of an original work of
|
||||
authorship and/or a database (each, a "Work").
|
||||
|
||||
Certain owners wish to permanently relinquish those rights to a Work for
|
||||
the purpose of contributing to a commons of creative, cultural and
|
||||
scientific works ("Commons") that the public can reliably and without fear
|
||||
of later claims of infringement build upon, modify, incorporate in other
|
||||
works, reuse and redistribute as freely as possible in any form whatsoever
|
||||
and for any purposes, including without limitation commercial purposes.
|
||||
These owners may contribute to the Commons to promote the ideal of a free
|
||||
culture and the further production of creative, cultural and scientific
|
||||
works, or to gain reputation or greater distribution for their Work in
|
||||
part through the use and efforts of others.
|
||||
|
||||
For these and/or other purposes and motivations, and without any
|
||||
expectation of additional consideration or compensation, the person
|
||||
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
|
||||
is an owner of Copyright and Related Rights in the Work, voluntarily
|
||||
elects to apply CC0 to the Work and publicly distribute the Work under its
|
||||
terms, with knowledge of his or her Copyright and Related Rights in the
|
||||
Work and the meaning and intended legal effect of CC0 on those rights.
|
||||
|
||||
1. Copyright and Related Rights. A Work made available under CC0 may be
|
||||
protected by copyright and related or neighboring rights ("Copyright and
|
||||
Related Rights"). Copyright and Related Rights include, but are not
|
||||
limited to, the following:
|
||||
|
||||
i. the right to reproduce, adapt, distribute, perform, display,
|
||||
communicate, and translate a Work;
|
||||
ii. moral rights retained by the original author(s) and/or performer(s);
|
||||
iii. publicity and privacy rights pertaining to a person's image or
|
||||
likeness depicted in a Work;
|
||||
iv. rights protecting against unfair competition in regards to a Work,
|
||||
subject to the limitations in paragraph 4(a), below;
|
||||
v. rights protecting the extraction, dissemination, use and reuse of data
|
||||
in a Work;
|
||||
vi. database rights (such as those arising under Directive 96/9/EC of the
|
||||
European Parliament and of the Council of 11 March 1996 on the legal
|
||||
protection of databases, and under any national implementation
|
||||
thereof, including any amended or successor version of such
|
||||
directive); and
|
||||
vii. other similar, equivalent or corresponding rights throughout the
|
||||
world based on applicable law or treaty, and any national
|
||||
implementations thereof.
|
||||
|
||||
2. Waiver. To the greatest extent permitted by, but not in contravention
|
||||
of, applicable law, Affirmer hereby overtly, fully, permanently,
|
||||
irrevocably and unconditionally waives, abandons, and surrenders all of
|
||||
Affirmer's Copyright and Related Rights and associated claims and causes
|
||||
of action, whether now known or unknown (including existing as well as
|
||||
future claims and causes of action), in the Work (i) in all territories
|
||||
worldwide, (ii) for the maximum duration provided by applicable law or
|
||||
treaty (including future time extensions), (iii) in any current or future
|
||||
medium and for any number of copies, and (iv) for any purpose whatsoever,
|
||||
including without limitation commercial, advertising or promotional
|
||||
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
|
||||
member of the public at large and to the detriment of Affirmer's heirs and
|
||||
successors, fully intending that such Waiver shall not be subject to
|
||||
revocation, rescission, cancellation, termination, or any other legal or
|
||||
equitable action to disrupt the quiet enjoyment of the Work by the public
|
||||
as contemplated by Affirmer's express Statement of Purpose.
|
||||
|
||||
3. Public License Fallback. Should any part of the Waiver for any reason
|
||||
be judged legally invalid or ineffective under applicable law, then the
|
||||
Waiver shall be preserved to the maximum extent permitted taking into
|
||||
account Affirmer's express Statement of Purpose. In addition, to the
|
||||
extent the Waiver is so judged Affirmer hereby grants to each affected
|
||||
person a royalty-free, non transferable, non sublicensable, non exclusive,
|
||||
irrevocable and unconditional license to exercise Affirmer's Copyright and
|
||||
Related Rights in the Work (i) in all territories worldwide, (ii) for the
|
||||
maximum duration provided by applicable law or treaty (including future
|
||||
time extensions), (iii) in any current or future medium and for any number
|
||||
of copies, and (iv) for any purpose whatsoever, including without
|
||||
limitation commercial, advertising or promotional purposes (the
|
||||
"License"). The License shall be deemed effective as of the date CC0 was
|
||||
applied by Affirmer to the Work. Should any part of the License for any
|
||||
reason be judged legally invalid or ineffective under applicable law, such
|
||||
partial invalidity or ineffectiveness shall not invalidate the remainder
|
||||
of the License, and in such case Affirmer hereby affirms that he or she
|
||||
will not (i) exercise any of his or her remaining Copyright and Related
|
||||
Rights in the Work or (ii) assert any associated claims and causes of
|
||||
action with respect to the Work, in either case contrary to Affirmer's
|
||||
express Statement of Purpose.
|
||||
|
||||
4. Limitations and Disclaimers.
|
||||
|
||||
a. No trademark or patent rights held by Affirmer are waived, abandoned,
|
||||
surrendered, licensed or otherwise affected by this document.
|
||||
b. Affirmer offers the Work as-is and makes no representations or
|
||||
warranties of any kind concerning the Work, express, implied,
|
||||
statutory or otherwise, including without limitation warranties of
|
||||
title, merchantability, fitness for a particular purpose, non
|
||||
infringement, or the absence of latent or other defects, accuracy, or
|
||||
the present or absence of errors, whether or not discoverable, all to
|
||||
the greatest extent permissible under applicable law.
|
||||
c. Affirmer disclaims responsibility for clearing rights of other persons
|
||||
that may apply to the Work or any use thereof, including without
|
||||
limitation any person's Copyright and Related Rights in the Work.
|
||||
Further, Affirmer disclaims responsibility for obtaining any necessary
|
||||
consents, permissions or other rights required for any use of the
|
||||
Work.
|
||||
d. Affirmer understands and acknowledges that Creative Commons is not a
|
||||
party to this document and has no duty or obligation with respect to
|
||||
this CC0 or use of the Work.
|
|
@ -1,38 +0,0 @@
|
|||
# eclier
|
||||
|
||||
Pronounced like eclair
|
||||
|
||||
The core of a command line application allowing for trivial user extension.
|
||||
|
||||
Every command and subcommand is its own `.lua` file that is either shipped as
|
||||
part of the built-in cartridge of commands or a plugin that the user installs.
|
||||
|
||||
The core contains the following:
|
||||
|
||||
- A module loading system for preparing different commands for use
|
||||
- The core subcommand router
|
||||
|
||||
## How to write plugins
|
||||
|
||||
Create a new file in the script home named after the plugin subcommand, for
|
||||
example: `scripts/hello.lua`:
|
||||
|
||||
```lua
|
||||
script.verb = "hello"
|
||||
script.help = "prints everyone's favorite hello world message"
|
||||
script.author = "Xe" -- put your github username here
|
||||
script.version = "1.0"
|
||||
script.usage = ""
|
||||
|
||||
function(run)
|
||||
print "Hello, world!"
|
||||
end
|
||||
```
|
||||
|
||||
And then run it using the example shell cli:
|
||||
|
||||
```console
|
||||
~/go/src/github.com/Xe/eclier:master λ go run ./example/main.go hello
|
||||
Hello, world!
|
||||
```
|
||||
|
|
@ -1,119 +0,0 @@
|
|||
package eclier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"os"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
// Constants for built-in commands.
|
||||
const (
|
||||
BuiltinScriptPath = "<built-in>"
|
||||
BuiltinAuthor = "<built-in>"
|
||||
BuiltinVersion = "<built-in>"
|
||||
)
|
||||
|
||||
type pluginCommand struct {
|
||||
r *Router
|
||||
fs *flag.FlagSet
|
||||
|
||||
dontShowBuiltin *bool
|
||||
}
|
||||
|
||||
// Close is a no-op.
|
||||
func (p *pluginCommand) Close() error { return nil }
|
||||
|
||||
// Init sets up the flags for this command.
|
||||
func (p *pluginCommand) Init() {
|
||||
p.fs = flag.NewFlagSet(p.Verb(), flag.ExitOnError)
|
||||
|
||||
p.dontShowBuiltin = p.fs.Bool("no-builtin", false, "if set, don't show built-in commands")
|
||||
}
|
||||
|
||||
// ScriptPath returns the built-in script path.
|
||||
func (p *pluginCommand) ScriptPath() string { return BuiltinScriptPath }
|
||||
|
||||
// Verb returns the command verb.
|
||||
func (p *pluginCommand) Verb() string { return "plugins" }
|
||||
|
||||
// Help returns the command help
|
||||
func (p *pluginCommand) Help() string {
|
||||
return `plugin lists all of the loaded commands and their script paths.`
|
||||
}
|
||||
|
||||
func (p *pluginCommand) Usage() string {
|
||||
return ` -no-builtin
|
||||
if set, don't show built-in commands`
|
||||
}
|
||||
|
||||
func (p *pluginCommand) Author() string { return BuiltinAuthor }
|
||||
|
||||
func (p *pluginCommand) Version() string { return BuiltinVersion }
|
||||
|
||||
// Run executes the command.
|
||||
func (p *pluginCommand) Run(ctx context.Context, arg []string) error {
|
||||
p.fs.Parse(arg)
|
||||
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetHeader([]string{"Verb", "Path"})
|
||||
|
||||
for _, c := range p.r.cmds {
|
||||
if c.ScriptPath() == BuiltinScriptPath && *p.dontShowBuiltin {
|
||||
continue
|
||||
}
|
||||
|
||||
table.Append([]string{c.Verb(), c.ScriptPath()})
|
||||
}
|
||||
|
||||
table.Render()
|
||||
return nil
|
||||
}
|
||||
|
||||
// NewBuiltinCommand makes it easier to write core commands for eclier.
|
||||
func NewBuiltinCommand(verb, help, usage string, doer func(context.Context, []string) error) Command {
|
||||
return &commandFunc{
|
||||
verb: verb,
|
||||
help: help,
|
||||
usage: usage,
|
||||
doer: doer,
|
||||
}
|
||||
}
|
||||
|
||||
// commandFunc is a simple alias for creating builtin commands.
|
||||
type commandFunc struct {
|
||||
verb string
|
||||
help string
|
||||
usage string
|
||||
doer func(context.Context, []string) error
|
||||
}
|
||||
|
||||
// Close deallocates resources set up by the initialization of the command.
|
||||
func (c *commandFunc) Close() error { return nil }
|
||||
|
||||
// Init is a no-op.
|
||||
func (c *commandFunc) Init() {}
|
||||
|
||||
// ScriptPath returns the built-in script path.
|
||||
func (c *commandFunc) ScriptPath() string { return BuiltinScriptPath }
|
||||
|
||||
// Verb returns the command verb.
|
||||
func (c *commandFunc) Verb() string { return c.verb }
|
||||
|
||||
// Help returns the command help.
|
||||
func (c *commandFunc) Help() string { return c.help }
|
||||
|
||||
// Usage returns the command usage.
|
||||
func (c *commandFunc) Usage() string { return c.usage }
|
||||
|
||||
// Author returns the built-in author.
|
||||
func (c *commandFunc) Author() string { return BuiltinAuthor }
|
||||
|
||||
// Version returns the built-in version.
|
||||
func (c *commandFunc) Version() string { return BuiltinVersion }
|
||||
|
||||
// Run runs the command handler.
|
||||
func (c *commandFunc) Run(ctx context.Context, arg []string) error {
|
||||
return c.doer(ctx, arg)
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package eclier
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
// Command is an individual subcommand.
|
||||
type Command interface {
|
||||
Close() error
|
||||
Init()
|
||||
ScriptPath() string
|
||||
Verb() string
|
||||
Help() string
|
||||
Usage() string
|
||||
Author() string
|
||||
Version() string
|
||||
Run(ctx context.Context, arg []string) error
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
file = {
|
||||
"./internal/gluanetrc/netrc.lua",
|
||||
"./internal/gluaheroku/heroku.lua",
|
||||
}
|
||||
|
||||
title = "eclier lua libraries"
|
||||
project = "eclier"
|
||||
description = "The lua libraries created for eclier demos and common utility."
|
|
@ -1,214 +0,0 @@
|
|||
package eclier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
"layeh.com/asar"
|
||||
)
|
||||
|
||||
// Router is the main subcommand router for eclier. At a high level what this is
|
||||
// doing is similar to http.ServeMux, but for CLI commands instead of HTTP handlers.
|
||||
type Router struct {
|
||||
lock sync.Mutex
|
||||
cmds map[string]Command
|
||||
|
||||
// configured data
|
||||
gluaCreationHook func(*lua.LState)
|
||||
scriptHomes []string
|
||||
cartridge map[string]string
|
||||
}
|
||||
|
||||
// NewRouter creates a new instance of Router and sets it up for use.
|
||||
func NewRouter(opts ...RouterOption) (*Router, error) {
|
||||
r := &Router{
|
||||
cmds: map[string]Command{},
|
||||
cartridge: map[string]string{},
|
||||
}
|
||||
|
||||
for _, opt := range opts {
|
||||
opt(r)
|
||||
}
|
||||
|
||||
// scan r.scriptHome for lua scripts, load them into their own lua states and
|
||||
// make a wrapper around them for the Command type.
|
||||
|
||||
for _, home := range r.scriptHomes {
|
||||
err := filepath.Walk(home, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
log.Printf("error in arg: %v", err)
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.HasSuffix(info.Name(), ".lua") {
|
||||
fname := filepath.Join(home, info.Name())
|
||||
fin, err := os.Open(fname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer fin.Close()
|
||||
|
||||
c := newGluaCommand(r.gluaCreationHook, fname, fin)
|
||||
r.cmds[c.Verb()] = c
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var helpCommand Command = NewBuiltinCommand("help", "shows help for subcommands", "help [subcommand]", func(ctx context.Context, arg []string) error {
|
||||
if len(arg) == 0 {
|
||||
table := tablewriter.NewWriter(os.Stdout)
|
||||
table.SetHeader([]string{"Verb", "Author", "Version", "Help"})
|
||||
|
||||
for _, cmd := range r.cmds {
|
||||
table.Append([]string{cmd.Verb(), cmd.Author(), cmd.Version(), cmd.Help()})
|
||||
}
|
||||
|
||||
table.Render()
|
||||
return nil
|
||||
}
|
||||
|
||||
cmd, ok := r.cmds[arg[0]]
|
||||
if !ok {
|
||||
fmt.Printf("can't find help for %s", arg[0])
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
fmt.Printf("Verb: %s\nAuthor: %s\nVersion: %s\nHelp: %s\nUsage: %s %s\n", cmd.Verb(), cmd.Author(), cmd.Version(), cmd.Help(), cmd.Verb(), cmd.Usage())
|
||||
return nil
|
||||
})
|
||||
|
||||
r.cmds["plugins"] = &pluginCommand{r: r}
|
||||
r.cmds["help"] = helpCommand
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
// AddCommand adds a given command instance to the eclier router.
|
||||
func (r *Router) AddCommand(cmd Command) {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
r.cmds[cmd.Verb()] = cmd
|
||||
}
|
||||
|
||||
// Run executes a single command given in slot 0 of the argument array.
|
||||
func (r *Router) Run(ctx context.Context, arg []string) error {
|
||||
r.lock.Lock()
|
||||
defer r.lock.Unlock()
|
||||
|
||||
if len(arg) == 0 {
|
||||
fmt.Printf("please specify a subcommand, such as `%s help`\n", filepath.Base(os.Args[0]))
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
cmd := arg[0]
|
||||
arg = arg[1:]
|
||||
|
||||
ci, ok := r.cmds[cmd]
|
||||
if !ok {
|
||||
fmt.Printf("No such command %s could be run.\n", cmd)
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
ci.Init()
|
||||
return ci.Run(ctx, arg)
|
||||
}
|
||||
|
||||
// RouterOption is a functional option for Router.
|
||||
type RouterOption func(*Router)
|
||||
|
||||
// WithScriptHome sets the router's script home to the given directory. This is
|
||||
// where lua files will be walked and parsed.
|
||||
func WithScriptHome(dir string) RouterOption {
|
||||
return func(r *Router) {
|
||||
r.scriptHomes = append(r.scriptHomes, dir)
|
||||
}
|
||||
}
|
||||
|
||||
// WithGluaCreationHook adds a custom bit of code that runs every time a new
|
||||
// gopher-lua LState is created. This allows users of this library to register
|
||||
// custom libraries to the pile of states.
|
||||
func WithGluaCreationHook(hook func(*lua.LState)) RouterOption {
|
||||
return func(r *Router) {
|
||||
r.gluaCreationHook = hook
|
||||
}
|
||||
}
|
||||
|
||||
// WithFilesystem loads a http.FileSystem full of lua scripts into this eclier
|
||||
// router.
|
||||
func WithFilesystem(shortName string, fs http.FileSystem) RouterOption {
|
||||
return func(r *Router) {
|
||||
fin, err := fs.Open("/")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer fin.Close()
|
||||
|
||||
childs, err := fin.Readdir(-1)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
for _, chl := range childs {
|
||||
if strings.HasSuffix(chl.Name(), ".lua") {
|
||||
fname := filepath.Join(shortName, chl.Name())
|
||||
sFin, err := fs.Open(chl.Name())
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer sFin.Close()
|
||||
|
||||
c := newGluaCommand(r.gluaCreationHook, fname, sFin)
|
||||
r.cmds[c.Verb()] = c
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WithAsarFile loads an asar file full of lua scripts into this eclier router.
|
||||
func WithAsarFile(shortName, fname string) RouterOption {
|
||||
return func(r *Router) {
|
||||
fin, err := os.Open(fname)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer fin.Close()
|
||||
|
||||
e, err := asar.Decode(fin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
err = e.Walk(func(path string, info os.FileInfo, err error) error {
|
||||
if strings.HasSuffix(info.Name(), ".lua") {
|
||||
fname := filepath.Join(shortName, "::", path)
|
||||
fin := e.Find(path)
|
||||
if fin == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
c := newGluaCommand(r.gluaCreationHook, fname, fin.Open())
|
||||
r.cmds[c.Verb()] = c
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,92 +0,0 @@
|
|||
package eclier
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"sync"
|
||||
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
type Script struct {
|
||||
Verb string
|
||||
Help string
|
||||
Usage string
|
||||
Author string
|
||||
Version string
|
||||
}
|
||||
|
||||
type gluaCommand struct {
|
||||
sync.Mutex
|
||||
script *Script
|
||||
L *lua.LState
|
||||
|
||||
filename string
|
||||
}
|
||||
|
||||
func newGluaCommand(preload func(*lua.LState), filename string, r io.Reader) Command {
|
||||
L := lua.NewState()
|
||||
preload(L)
|
||||
|
||||
script := &Script{}
|
||||
L.SetGlobal("script", luar.New(L, script))
|
||||
|
||||
data, err := ioutil.ReadAll(r)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = L.DoString(string(data))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return &gluaCommand{script: script, L: L, filename: filename}
|
||||
}
|
||||
|
||||
func (g *gluaCommand) Close() error {
|
||||
g.L.Close()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gluaCommand) Init() {}
|
||||
|
||||
func (g *gluaCommand) ScriptPath() string { return g.filename }
|
||||
|
||||
func (g *gluaCommand) Verb() string { return g.script.Verb }
|
||||
|
||||
func (g *gluaCommand) Help() string { return g.script.Help }
|
||||
|
||||
func (g *gluaCommand) Usage() string { return g.script.Usage }
|
||||
|
||||
func (g *gluaCommand) Author() string { return g.script.Author }
|
||||
|
||||
func (g *gluaCommand) Version() string { return g.script.Version }
|
||||
|
||||
func (g *gluaCommand) Run(ctx context.Context, arg []string) error {
|
||||
runf := g.L.GetGlobal("run")
|
||||
|
||||
if runf.Type() == lua.LTNil {
|
||||
return errors.New("no global function run in this script")
|
||||
}
|
||||
|
||||
tab := g.L.NewTable()
|
||||
|
||||
for _, a := range arg {
|
||||
tab.Append(lua.LString(a))
|
||||
}
|
||||
|
||||
err := g.L.CallByParam(lua.P{
|
||||
Fn: runf,
|
||||
NRet: 0,
|
||||
Protect: false,
|
||||
}, tab)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
Copyright (c) 2017 Christine Dodrill <me@christine.website>
|
||||
|
||||
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.
|
|
@ -1,7 +0,0 @@
|
|||
file = {
|
||||
"./netrc.lua",
|
||||
}
|
||||
|
||||
title = "gluanetrc"
|
||||
project = "Xe/gluanetrc"
|
||||
description = "netrc offers a simple interface to a user's netrc file in their home directory"
|
|
@ -1,81 +0,0 @@
|
|||
package gluanetrc
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/dickeyxxx/netrc"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
var n *netrc.Netrc
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
|
||||
fname := filepath.Join(os.Getenv("HOME"), ".netrc")
|
||||
|
||||
fout, err := os.Create(fname)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
fout.Close()
|
||||
|
||||
n, err = netrc.Parse(filepath.Join(fname))
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
var exports = map[string]lua.LGFunction{
|
||||
"machine": machine,
|
||||
"save": save,
|
||||
"remove_machine": removeMachine,
|
||||
"add_machine": addMachine,
|
||||
}
|
||||
|
||||
func addMachine(L *lua.LState) int {
|
||||
name := L.ToString(1)
|
||||
login := L.ToString(2)
|
||||
password := L.ToString(3)
|
||||
|
||||
n.AddMachine(name, login, password)
|
||||
|
||||
L.Push(luar.New(L, n.Machine(name)))
|
||||
return 1
|
||||
}
|
||||
|
||||
func removeMachine(L *lua.LState) int {
|
||||
name := L.ToString(1)
|
||||
|
||||
n.RemoveMachine(name)
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func machine(L *lua.LState) int {
|
||||
name := L.ToString(1)
|
||||
|
||||
m := n.Machine(string(name))
|
||||
|
||||
L.Push(luar.New(L, m))
|
||||
return 1
|
||||
}
|
||||
|
||||
func save(L *lua.LState) int {
|
||||
n.Save()
|
||||
return 0
|
||||
}
|
||||
|
||||
// Preload loads netrc into a gopher-lua's LState module registry.
|
||||
func Preload(L *lua.LState) {
|
||||
L.PreloadModule("netrc", Loader)
|
||||
}
|
||||
|
||||
// Loader loads the netrc modules.
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), exports)
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
--- Module netrc offers a simple interface to a user's netrc file in their home directory.
|
||||
-- @module netrc
|
||||
|
||||
local netrc = {}
|
||||
|
||||
--- add_machine adds a machine to the netrc manifest with a username and password.
|
||||
-- @param name string the domain name of the machine
|
||||
-- @param login string the user name to log in as
|
||||
-- @param password string the password or similar secret for the machine
|
||||
-- @return Machine
|
||||
function netrc.add_machine(name, login, password)
|
||||
end
|
||||
|
||||
--- machine loads netrc data for a given machine by domain name.
|
||||
-- Any changes made with the `set` method of a machine will be saved to the disk
|
||||
-- when the module's `save` function is called. If the given machine does not
|
||||
-- exist in the netrc file, this function will return nil.
|
||||
-- @param name string
|
||||
-- @return Machine
|
||||
-- @usage local creds = netrc.machine("api.foobar.com")
|
||||
-- @usage print(creds:get("username"), creds:get("password"))
|
||||
function netrc.machine(name)
|
||||
return nil
|
||||
end
|
||||
|
||||
--- remove_machine removes a single machine from the netrc manifest by name.
|
||||
-- @param name string the name of the machine to remove from the netrc manifest
|
||||
-- @usage netrc.remove_machine("api.digg.com")
|
||||
function netrc.remove_machine(name)
|
||||
end
|
||||
|
||||
--- save writes all changes made in machine `set` methods to the disk at $HOME/.netrc.
|
||||
-- This function will raise a lua error if the save fails. This function should
|
||||
-- not fail in the course of normal operation.
|
||||
-- @usage netrc.save()
|
||||
function netrc.save()
|
||||
end
|
||||
|
||||
--- Machine is a userdata wrapper around the go netrc.Machine type.
|
||||
-- https://godoc.org/github.com/dickeyxxx/netrc#Machine
|
||||
-- @type Machine
|
||||
|
||||
local Machine = {}
|
||||
|
||||
--- get gets a Machine value by key.
|
||||
-- @param key the netrc key to get
|
||||
-- @return string the value from the netrc
|
||||
-- @usage local cli = api.new(m:get("login"), m:get("password"))
|
||||
function Machine:get(key)
|
||||
end
|
||||
|
||||
--- set updates information in this Machine by a key, value pair.
|
||||
-- @param key the netrc key to set
|
||||
-- @param value the value to set the above key to
|
||||
-- @usage m:set("password", "hunter2")
|
||||
function Machine:set(key, value)
|
||||
end
|
||||
|
||||
return netrc
|
|
@ -1,661 +0,0 @@
|
|||
## `json`
|
||||
|
||||
```lua
|
||||
local json = require "json"
|
||||
```
|
||||
|
||||
Json encoder/decoder
|
||||
|
||||
The following functions are exposed by the library:
|
||||
|
||||
decode(string): Decodes a JSON string. Returns nil and an error string if
|
||||
the string could not be decoded.
|
||||
encode(value): Encodes a value into a JSON string. Returns nil and an error
|
||||
string if the value could not be encoded.
|
||||
|
||||
## `xmlpath`
|
||||
|
||||
```lua
|
||||
local xmlpath = require "xmlpath"
|
||||
```
|
||||
|
||||
XMLPath style iteration
|
||||
|
||||
xml ="<bookist><book>x1</book><book>x2</book><book>x3</book></booklist>"
|
||||
local xmlpath = require("xmlpath")
|
||||
node,err = xmlpath.loadxml(xml)
|
||||
path,err = xmlpath.compile("//book")
|
||||
|
||||
it = path:iter(node)
|
||||
for k,v in pairs(it) do
|
||||
print(k,v:string())
|
||||
end
|
||||
|
||||
## `http`
|
||||
|
||||
```lua
|
||||
local http = require("http")
|
||||
```
|
||||
|
||||
HTTP client library
|
||||
|
||||
### API
|
||||
|
||||
- [`http.delete(url [, options])`](#httpdeleteurl--options)
|
||||
- [`http.get(url [, options])`](#httpgeturl--options)
|
||||
- [`http.head(url [, options])`](#httpheadurl--options)
|
||||
- [`http.patch(url [, options])`](#httppatchurl--options)
|
||||
- [`http.post(url [, options])`](#httpposturl--options)
|
||||
- [`http.put(url [, options])`](#httpputurl--options)
|
||||
- [`http.request(method, url [, options])`](#httprequestmethod-url--options)
|
||||
- [`http.request_batch(requests)`](#httprequest_batchrequests)
|
||||
- [`http.response`](#httpresponse)
|
||||
|
||||
#### http.delete(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
#### http.get(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
#### http.head(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
#### http.patch(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| body | String | Request body. |
|
||||
| form | String | Deprecated. URL encoded request body. This will also set the `Content-Type` header to `application/x-www-form-urlencoded` |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
#### http.post(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| body | String | Request body. |
|
||||
| form | String | Deprecated. URL encoded request body. This will also set the `Content-Type` header to `application/x-www-form-urlencoded` |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
#### http.put(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| body | String | Request body. |
|
||||
| form | String | Deprecated. URL encoded request body. This will also set the `Content-Type` header to `application/x-www-form-urlencoded` |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
#### http.request(method, url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| method | String | The HTTP request method |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| body | String | Request body. |
|
||||
| form | String | Deprecated. URL encoded request body. This will also set the `Content-Type` header to `application/x-www-form-urlencoded` |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
#### http.request_batch(requests)
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| -------- | ----- | ----------- |
|
||||
| requests | Table | A table of requests to send. Each request item is by itself a table containing [http.request](#httprequestmethod-url--options) parameters for the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[[http.response](#httpresponse)] or ([[http.response](#httpresponse)], [error message])
|
||||
|
||||
#### http.response
|
||||
|
||||
The `http.response` table contains information about a completed HTTP request.
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ----------- | ------ | ----------- |
|
||||
| body | String | The HTTP response body |
|
||||
| body_size | Number | The size of the HTTP reponse body in bytes |
|
||||
| headers | Table | The HTTP response headers |
|
||||
| cookies | Table | The cookies sent by the server in the HTTP response |
|
||||
| status_code | Number | The HTTP response status code |
|
||||
| url | String | The final URL the request ended pointing to after redirects |
|
||||
|
||||
## `url`
|
||||
|
||||
```lua
|
||||
local url = require "url"
|
||||
```
|
||||
|
||||
URL parsing library
|
||||
|
||||
### API
|
||||
|
||||
- [`url.parse(url)`](#urlparseurl)
|
||||
- [`url.build(options)`](#urlbuildoptions)
|
||||
- [`url.build_query_string(query_params)`](#urlbuild_query_stringquery_params)
|
||||
- [`url.resolve(from, to)`](#urlresolvefrom-to)
|
||||
|
||||
#### url.parse(url)
|
||||
|
||||
Parse URL into a table of key/value components.
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL to parsed |
|
||||
|
||||
**Returns**
|
||||
|
||||
Table with parsed URL or (nil, error message)
|
||||
|
||||
| Name | Type | Description |
|
||||
| -------- | ------ | ----------- |
|
||||
| scheme | String | Scheme of the URL |
|
||||
| username | String | Username |
|
||||
| password | String | Password |
|
||||
| host | String | Host and port of the URL |
|
||||
| path | String | Path |
|
||||
| query | String | Query string |
|
||||
| fragment | String | Fragment |
|
||||
|
||||
#### url.build(options)
|
||||
|
||||
Assemble a URL string from a table of URL components.
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ----- | ----------- |
|
||||
| options | Table | Table with URL components, see [`url.parse`](#urlparseurl) for list of valid components |
|
||||
|
||||
**Returns**
|
||||
|
||||
String
|
||||
|
||||
#### url.build_query_string(query_params)
|
||||
|
||||
Assemble table of query string parameters into a string.
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------ | ----- | ----------- |
|
||||
| query_params | Table | Table with query parameters |
|
||||
|
||||
**Returns**
|
||||
|
||||
String
|
||||
|
||||
#### url.resolve(from, to)
|
||||
|
||||
Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.
|
||||
|
||||
| Name | Type | Description |
|
||||
| ---- | ------ | ----------- |
|
||||
| from | String | base URL |
|
||||
| to | String | href URL |
|
||||
|
||||
**Returns**
|
||||
|
||||
String or (nil, error message)
|
||||
|
||||
## `env`
|
||||
|
||||
```lua
|
||||
local env = require "env"
|
||||
```
|
||||
|
||||
Environment manipulation
|
||||
|
||||
### API
|
||||
|
||||
#### `env.set(key, value)`
|
||||
|
||||
Same `os.setenv`
|
||||
|
||||
#### `env.get(key)`
|
||||
|
||||
Same `os.getenv`
|
||||
|
||||
#### `env.loadfile(file)`
|
||||
|
||||
Loads environment variables from a file. The file is as the following:
|
||||
|
||||
```
|
||||
AAA=BBB
|
||||
CCC=DDD
|
||||
```
|
||||
|
||||
If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
## `fs`
|
||||
|
||||
```lua
|
||||
local fs = require "fs"
|
||||
```
|
||||
|
||||
Filesystem manipulation
|
||||
|
||||
### API
|
||||
|
||||
#### `fs.exists(file)`
|
||||
|
||||
Returns true if the file exists.
|
||||
|
||||
#### `fs.read(file)`
|
||||
|
||||
Reads file content and return it. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.write(file, content, [mode])`
|
||||
|
||||
Writes content to the file. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.mkdir(path, [mode, recursive])`
|
||||
|
||||
Create directory. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.remove(path, [recursive])`
|
||||
|
||||
Remove path. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.symlink(target, link)`
|
||||
|
||||
Create symbolic link. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.dirname(path)`
|
||||
|
||||
Returns all but the last element of path.
|
||||
|
||||
#### `fs.basename(path)`
|
||||
|
||||
Returns the last element of path.
|
||||
|
||||
#### `fs.realpath(path)`
|
||||
|
||||
Returns the real path of a given path in the os. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.getcwd()`
|
||||
|
||||
Returns the current working directory. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.chdir(path)`
|
||||
|
||||
Changes the current working directory. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.file()`
|
||||
|
||||
Returns the script file path. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.dir()`
|
||||
|
||||
Returns the directory path that is parent of the script file. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `fs.glob(pattern, function)`
|
||||
|
||||
Run the callback function with the files matching pattern. See below example:
|
||||
|
||||
```lua
|
||||
local fs = require("fs")
|
||||
local ret, err = fs.glob("/tmp/*", function(file)
|
||||
print(file.path)
|
||||
print(file.realpath)
|
||||
end)
|
||||
```
|
||||
|
||||
## `markdown`
|
||||
|
||||
```lua
|
||||
local markdown = require "markdown"
|
||||
```
|
||||
|
||||
Markdown -> HTML for string and file
|
||||
|
||||
### API
|
||||
|
||||
#### `markdown.dostring(text)`
|
||||
|
||||
Returns HTML string generated from the markdown text.
|
||||
|
||||
#### `markdown.dofile(file)`
|
||||
|
||||
Returns HTML string generated from the markdown text file. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
## `question`
|
||||
|
||||
```lua
|
||||
local question = require "question"
|
||||
```
|
||||
|
||||
Prompt library
|
||||
|
||||
### API
|
||||
|
||||
* `question.ask(text)`
|
||||
* `question.secret(text)`
|
||||
|
||||
## `ssh`
|
||||
|
||||
```lua
|
||||
local ssh = require "ssh"
|
||||
```
|
||||
|
||||
SSH client library
|
||||
|
||||
https://github.com/kohkimakimoto/gluassh/blob/master/gluassh_test.go
|
||||
|
||||
## `template`
|
||||
|
||||
```lua
|
||||
local template = require "template"
|
||||
```
|
||||
|
||||
Go text templates
|
||||
|
||||
### API
|
||||
|
||||
#### `template.dostring(text, table)`
|
||||
|
||||
Returns string generated by text template with the table values. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
#### `template.dofile(file, table)`
|
||||
|
||||
Returns string generated by file template with the table values. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
## `yaml`
|
||||
|
||||
```lua
|
||||
local yaml = require "yaml"
|
||||
```
|
||||
|
||||
Yaml -> table parser
|
||||
|
||||
### API
|
||||
|
||||
#### `yaml.parse(string)`
|
||||
|
||||
Parses yaml formatted string and returns a table. If this function fails, it returns `nil`, plus a string describing the error.
|
||||
|
||||
## `flag`
|
||||
|
||||
```lua
|
||||
local flag = require "flag"
|
||||
```
|
||||
|
||||
Command line flag parsing.
|
||||
|
||||
See the tests here: https://github.com/otm/gluaflag
|
||||
|
||||
```lua
|
||||
local flag = require "flag"
|
||||
|
||||
fs = flag.new()
|
||||
|
||||
fs:string("name", "foo", "String help string")
|
||||
fs:intArg("title", 1, "Title")
|
||||
fs:numberArg("title", 1, "Title")
|
||||
|
||||
flags = fs:parse(arg) -- arg is the remaining command line arguments
|
||||
assert(flags.title == 2, "expected title to be 2")
|
||||
assert(flags.title == 2.32, "expected title to be 2.32")
|
||||
```
|
||||
|
||||
## `sh`
|
||||
|
||||
```lua
|
||||
local sh = require "sh"
|
||||
```
|
||||
|
||||
gluash is a interface to call any program as it were a function. Programs are executed asynchronously to enable streaming of data in pipes.
|
||||
|
||||
In all discussions bellow the imported module will be referred to as `sh`.
|
||||
|
||||
Commands are called just like functions, executed on the sh module.
|
||||
|
||||
```lua
|
||||
sh.ls("/")
|
||||
```
|
||||
|
||||
For commands that have exotic names, names that are reserved words, or to execute absolute or relative paths call the sh module directly.
|
||||
|
||||
```lua
|
||||
sh("/bin/ls", "/")
|
||||
```
|
||||
|
||||
#### Multiple Arguments
|
||||
Commands with multiple arguments have to be invoked with a separate string for each argument.
|
||||
|
||||
```lua
|
||||
-- this works
|
||||
sh.ls("-la", "/")
|
||||
|
||||
-- this does not work
|
||||
sh.ls("-la /")
|
||||
```
|
||||
|
||||
#### Piping
|
||||
Piping in sh is done almost like piping in the shell. Just call next command as a method on the previous command.
|
||||
|
||||
```lua
|
||||
sh.du("-sb"):sort("-rn"):print()
|
||||
```
|
||||
|
||||
If the command has a exotic name, or a reserved word, call the command through `cmd(path, ...args)`. The first argument in `cmd` is the path.
|
||||
|
||||
```lua
|
||||
sh.du("-sb"):cmd("sort", "-rn"):print()
|
||||
```
|
||||
|
||||
### Waiting for Processes
|
||||
All commands are executed by default in the background, so one have to explicitly wait for a process to finish. There are several ways to wait for the command to finish.
|
||||
|
||||
* `print()` - write stdout and stderr to stdout.
|
||||
* `ok()` - aborts execution if the command's exit code is not zero
|
||||
* `success()` - returns true of the commands exit code is zero
|
||||
* `exitcode()` - returns the exit code of the command
|
||||
|
||||
### Abort by Default
|
||||
It is possible to set the module to abort on errors without checking. It can be practical in some occasions, however performance will be degraded. When global exit code checks are done the commands are run in series, even in pipes, and output is saved in memory buffers.
|
||||
|
||||
To enable global exit code settings call the sh module with an table with the key `abort` set to true.
|
||||
|
||||
```lua
|
||||
sh{abort=true}
|
||||
```
|
||||
|
||||
To read current settings in the module call the module with an empty table.
|
||||
```lua
|
||||
configuration = sh{}
|
||||
print("abort:", configuration.abort)
|
||||
```
|
||||
|
||||
### Analyzing Output
|
||||
There are several options to analyze the output of a command.
|
||||
|
||||
#### lines()
|
||||
An iterator is accessible by calling the method `lines()` on the command.
|
||||
|
||||
```lua
|
||||
for line in sh.cat("/etc/hosts"):lines() do
|
||||
print(line)
|
||||
end
|
||||
```
|
||||
|
||||
#### stdout([filename]), stderr([filename]), combinedOutput([filename])
|
||||
`stdout()`, `stderr()`, and `combinedOutput()` all returns the output of the command as a string. An optional `filename` can be given to the method, in that case the output is also written to the file. The file will be truncated.
|
||||
|
||||
```lua
|
||||
-- print output of command
|
||||
output = sh.echo("hello world"):combinedOutput("/tmp/output")
|
||||
print(output)
|
||||
```
|
||||
|
||||
In the example above will print `hello world` and it will write it to `/tmp/output`
|
||||
|
||||
### Glob Expansion
|
||||
There is no glob expansion done on arguments, however there is a glob functionality in sh.
|
||||
|
||||
```lua
|
||||
sh.ls(sh.glob("*.go"))
|
||||
```
|
||||
|
||||
## `re`
|
||||
|
||||
```lua
|
||||
local re = require "re"
|
||||
```
|
||||
|
||||
Regular Expressions
|
||||
|
||||
### API
|
||||
|
||||
re.find , re.gsub, re.match, re.gmatch are available. These functions have the same API as Lua pattern match.
|
||||
gluare uses the Go regexp package, so you can use regular expressions that are supported in the Go regexp package.
|
||||
|
||||
In addition, the following functions are defined:
|
||||
```
|
||||
gluare.quote(s string) -> string
|
||||
Arguments:
|
||||
|
||||
s string: a string value to escape meta characters
|
||||
|
||||
Returns:
|
||||
|
||||
string: escaped string
|
||||
gluare.quote returns a string that quotes all regular expression metacharacters inside the given text.
|
||||
```
|
||||
|
||||
## `simplebox`
|
||||
|
||||
```lua
|
||||
local simplebox = require "simplebox"
|
||||
```
|
||||
|
||||
Simple encryption
|
||||
|
||||
### API
|
||||
|
||||
#### Create a new instance of simplebox with a newly generated key
|
||||
|
||||
```lua
|
||||
local simplebox = require "simplebox"
|
||||
local key = simplebox.genkey()
|
||||
print("key is: " .. key)
|
||||
local sb = simplebox.new()
|
||||
|
||||
|
||||
```
|
|
@ -1,4 +0,0 @@
|
|||
FROM busybox
|
||||
|
||||
ADD glue /glue
|
||||
CMD /glue
|
|
@ -1,181 +0,0 @@
|
|||
memo = ""
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ThomasRooney/gexpect"
|
||||
packages = ["."]
|
||||
revision = "5482f03509440585d13d8f648989e05903001842"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ailncode/gluaxmlpath"
|
||||
packages = ["."]
|
||||
revision = "6ce478ecb4a60c4fc8929838e0b21b7fb7ca7440"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/brandur/simplebox"
|
||||
packages = ["."]
|
||||
revision = "84e9865bb03ad38c464043bf5382ce8c68ca5f0c"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluahttp"
|
||||
packages = ["."]
|
||||
revision = "b4bfe0c50fea948dcbf3966e120996d6607bbd89"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluaurl"
|
||||
packages = ["."]
|
||||
revision = "31cbb9bef199454415879f2e6d609d1136d60cad"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/howeyc/gopass"
|
||||
packages = ["."]
|
||||
revision = "bf9dde6d0d2c004a008c27aaee91170c786f6db8"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kballard/go-shellquote"
|
||||
packages = ["."]
|
||||
revision = "d8ec1a69a250a17bb0e419c386eac1f3711dc142"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaenv"
|
||||
packages = ["."]
|
||||
revision = "2888db6bbe38923d59c42e443895875cc8ce0820"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluafs"
|
||||
packages = ["."]
|
||||
revision = "01391ed2d7ab89dc80157605b073403f960aa223"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaquestion"
|
||||
packages = ["."]
|
||||
revision = "311437c29ba54d027ad2af383661725ae2bfdcdc"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluassh"
|
||||
packages = ["."]
|
||||
revision = "2a7bd48d7568de8230c87ac1ef4a4c481e45814d"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluatemplate"
|
||||
packages = ["."]
|
||||
revision = "d9e2c9d6b00f069a9da377a9ac529c827c1c7d71"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluayaml"
|
||||
packages = ["."]
|
||||
revision = "6fe413d49d73d785510ecf1529991ab0573e96c7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kr/fs"
|
||||
packages = ["."]
|
||||
revision = "2788f0dbd16903de03cb8186e5c7d97b69ad387b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kr/pty"
|
||||
packages = ["."]
|
||||
revision = "ce7fa45920dc37a92de8377972e52bc55ffa8d57"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/mitchellh/mapstructure"
|
||||
packages = ["."]
|
||||
revision = "cc8532a8e9a55ea36402aa21efdf403a60d34096"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluaflag"
|
||||
packages = ["."]
|
||||
revision = "078088de689148194436293886e8e39809167332"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluash"
|
||||
packages = ["."]
|
||||
revision = "e145c563986f0b91f740a758a84bca46c163aec7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/pkg/sftp"
|
||||
packages = ["."]
|
||||
revision = "e84cc8c755ca39b7b64f510fe1fffc1b51f210a5"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yookoala/realpath"
|
||||
packages = ["."]
|
||||
revision = "c416d99ab5ed256fa30c1f3bab73152deb59bb69"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gluamapper"
|
||||
packages = ["."]
|
||||
revision = "d836955830e75240d46ce9f0e6d148d94f2e1d3a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gluare"
|
||||
packages = ["."]
|
||||
revision = "8e2742cd1bf2b904720ac66eca3c2091b2ea0720"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gopher-lua"
|
||||
packages = [".","parse"]
|
||||
revision = "33ebc07735566cd0c3c4b69e2839d522cc389852"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
packages = ["nacl/secretbox","ssh/terminal","ssh","ssh/agent"]
|
||||
revision = "dd85ac7e6a88fc6ca420478e934de5f1a42dd3c6"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/net"
|
||||
packages = ["html"]
|
||||
revision = "66aacef3dd8a676686c7ae3716979581e8b03c47"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
packages = ["unix"]
|
||||
revision = "9ccfe848b9db8435a24c424abbc07a921adf1df5"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
name = "gopkg.in/xmlpath.v2"
|
||||
packages = ["."]
|
||||
revision = "860cbeca3ebcc600db0b213c0e83ad6ce91f5739"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "gopkg.in/yaml.v2"
|
||||
packages = ["."]
|
||||
revision = "cd8b52f8269e0feb286dfeef29f8fe4d5b397e0b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-json"
|
||||
packages = ["."]
|
||||
revision = "c128cc74278be889c4381681712931976fe0d88b"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-luar"
|
||||
packages = ["."]
|
||||
revision = "80196fe2abc5682963fc7a5261f5a5d77509938b"
|
|
@ -1,68 +0,0 @@
|
|||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/ThomasRooney/gexpect"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/ailncode/gluaxmlpath"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/brandur/simplebox"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluahttp"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/cjoudrey/gluaurl"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaenv"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluafs"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluaquestion"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluassh"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluatemplate"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/kohkimakimoto/gluayaml"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluaflag"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/otm/gluash"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gluare"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "github.com/yuin/gopher-lua"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-json"
|
||||
|
||||
[[dependencies]]
|
||||
branch = "master"
|
||||
name = "layeh.com/gopher-luar"
|
|
@ -1,18 +0,0 @@
|
|||
glue
|
||||
====
|
||||
|
||||
Basically gopher-lua's cmd/glua with the following modules imported:
|
||||
- https://godoc.org/layeh.com/gopher-json
|
||||
- https://github.com/ailncode/gluaxmlpath
|
||||
- https://github.com/cjoudrey/gluahttp
|
||||
- https://github.com/cjoudrey/gluaurl
|
||||
- https://github.com/kohkimakimoto/gluaenv
|
||||
- https://github.com/kohkimakimoto/gluafs
|
||||
- https://github.com/kohkimakimoto/gluamarkdown
|
||||
- https://github.com/kohkimakimoto/gluaquestion
|
||||
- https://github.com/kohkimakimoto/gluassh
|
||||
- https://github.com/kohkimakimoto/gluatemplate
|
||||
- https://github.com/kohkimakimoto/gluayaml
|
||||
- https://github.com/otm/gluaflag
|
||||
- https://github.com/otm/gluash
|
||||
- https://github.com/yuin/gluare
|
|
@ -1,6 +0,0 @@
|
|||
from "alpine:edge"
|
||||
|
||||
copy "glue", "/glue"
|
||||
cmd "/glue"
|
||||
flatten
|
||||
tag "xena/glue"
|
|
@ -1,20 +0,0 @@
|
|||
-- expects glue, $ go get -u github.com/Xe/tools/glue
|
||||
local sh = require "sh"
|
||||
sh { abort = true }
|
||||
|
||||
if os.getenv("CGO_ENABLED") ~= "0" then
|
||||
error("CGO_ENABLED must be set to 1")
|
||||
end
|
||||
|
||||
print "building glue..."
|
||||
sh.go("build"):print()
|
||||
sh.upx("--ultra-brute", "glue"):print()
|
||||
sh.box("box.rb"):print()
|
||||
|
||||
print "releasing to docker hub"
|
||||
sh.docker("push", "xena/glue"):print()
|
||||
|
||||
print "moving glue binary to $GOPATH/bin"
|
||||
sh.mv("glue", (os.getenv("GOPATH") .. "/bin/glue"))
|
||||
|
||||
print "build/release complete"
|
Binary file not shown.
|
@ -1,213 +0,0 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"flag"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime/pprof"
|
||||
|
||||
"github.com/Xe/x/tools/glue/libs/gluaexpect"
|
||||
"github.com/Xe/x/tools/glue/libs/gluasimplebox"
|
||||
"github.com/ailncode/gluaxmlpath"
|
||||
"github.com/cjoudrey/gluahttp"
|
||||
"github.com/cjoudrey/gluaurl"
|
||||
"github.com/kohkimakimoto/gluaenv"
|
||||
"github.com/kohkimakimoto/gluafs"
|
||||
"github.com/kohkimakimoto/gluaquestion"
|
||||
"github.com/kohkimakimoto/gluassh"
|
||||
"github.com/kohkimakimoto/gluatemplate"
|
||||
"github.com/kohkimakimoto/gluayaml"
|
||||
"github.com/otm/gluaflag"
|
||||
"github.com/otm/gluash"
|
||||
"github.com/yuin/gluare"
|
||||
"github.com/yuin/gopher-lua"
|
||||
"github.com/yuin/gopher-lua/parse"
|
||||
json "layeh.com/gopher-json"
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Exit(mainAux())
|
||||
}
|
||||
|
||||
func mainAux() int {
|
||||
var opt_e, opt_l, opt_p string
|
||||
var opt_i, opt_v, opt_dt, opt_dc bool
|
||||
var opt_m int
|
||||
flag.StringVar(&opt_e, "e", "", "")
|
||||
flag.StringVar(&opt_l, "l", "", "")
|
||||
flag.StringVar(&opt_p, "p", "", "")
|
||||
flag.IntVar(&opt_m, "mx", 0, "")
|
||||
flag.BoolVar(&opt_i, "i", false, "")
|
||||
flag.BoolVar(&opt_v, "v", false, "")
|
||||
flag.BoolVar(&opt_dt, "dt", false, "")
|
||||
flag.BoolVar(&opt_dc, "dc", false, "")
|
||||
flag.Usage = func() {
|
||||
fmt.Println(`Usage: glue [options] [script [args]].
|
||||
Available options are:
|
||||
-e stat execute string 'stat'
|
||||
-l name require library 'name'
|
||||
-mx MB memory limit(default: unlimited)
|
||||
-dt dump AST trees
|
||||
-dc dump VM codes
|
||||
-i enter interactive mode after executing 'script'
|
||||
-p file write cpu profiles to the file
|
||||
-v show version information
|
||||
`)
|
||||
}
|
||||
flag.Parse()
|
||||
if len(opt_p) != 0 {
|
||||
f, err := os.Create(opt_p)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
pprof.StartCPUProfile(f)
|
||||
defer pprof.StopCPUProfile()
|
||||
}
|
||||
if len(opt_e) == 0 && !opt_i && !opt_v && flag.NArg() == 0 {
|
||||
opt_i = true
|
||||
}
|
||||
|
||||
status := 0
|
||||
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
if opt_m > 0 {
|
||||
L.SetMx(opt_m)
|
||||
}
|
||||
|
||||
preload(L)
|
||||
|
||||
if opt_v || opt_i {
|
||||
fmt.Println(lua.PackageCopyRight)
|
||||
}
|
||||
|
||||
if len(opt_l) > 0 {
|
||||
if err := L.DoFile(opt_l); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
if nargs := flag.NArg(); nargs > 0 {
|
||||
script := flag.Arg(0)
|
||||
argtb := L.NewTable()
|
||||
for i := 1; i < nargs; i++ {
|
||||
L.RawSet(argtb, lua.LNumber(i), lua.LString(flag.Arg(i)))
|
||||
}
|
||||
L.SetGlobal("arg", argtb)
|
||||
if opt_dt || opt_dc {
|
||||
file, err := os.Open(script)
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
return 1
|
||||
}
|
||||
chunk, err2 := parse.Parse(file, script)
|
||||
if err2 != nil {
|
||||
fmt.Println(err2.Error())
|
||||
return 1
|
||||
}
|
||||
if opt_dt {
|
||||
fmt.Println(parse.Dump(chunk))
|
||||
}
|
||||
if opt_dc {
|
||||
proto, err3 := lua.Compile(chunk, script)
|
||||
if err3 != nil {
|
||||
fmt.Println(err3.Error())
|
||||
return 1
|
||||
}
|
||||
fmt.Println(proto.String())
|
||||
}
|
||||
}
|
||||
|
||||
if err := L.DoFile(script); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
status = 1
|
||||
}
|
||||
}
|
||||
|
||||
if len(opt_e) > 0 {
|
||||
if err := L.DoString(opt_e); err != nil {
|
||||
fmt.Println(err.Error())
|
||||
status = 1
|
||||
}
|
||||
}
|
||||
|
||||
if opt_i {
|
||||
doREPL(L)
|
||||
}
|
||||
return status
|
||||
}
|
||||
|
||||
func preload(L *lua.LState) {
|
||||
L.PreloadModule("re", gluare.Loader)
|
||||
L.PreloadModule("sh", gluash.Loader)
|
||||
L.PreloadModule("fs", gluafs.Loader)
|
||||
L.PreloadModule("env", gluaenv.Loader)
|
||||
L.PreloadModule("yaml", gluayaml.Loader)
|
||||
L.PreloadModule("question", gluaquestion.Loader)
|
||||
L.PreloadModule("ssh", gluassh.Loader)
|
||||
L.PreloadModule("http", gluahttp.NewHttpModule(&http.Client{}).Loader)
|
||||
L.PreloadModule("flag", gluaflag.Loader)
|
||||
L.PreloadModule("template", gluatemplate.Loader)
|
||||
L.PreloadModule("url", gluaurl.Loader)
|
||||
gluaexpect.Preload(L)
|
||||
gluasimplebox.Preload(L)
|
||||
gluaxmlpath.Preload(L)
|
||||
json.Preload(L)
|
||||
}
|
||||
|
||||
// do read/eval/print/loop
|
||||
func doREPL(L *lua.LState) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
if str, err := loadline(reader, L); err == nil {
|
||||
if err := L.DoString(str); err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
} else { // error on loadline
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func incomplete(err error) bool {
|
||||
if lerr, ok := err.(*lua.ApiError); ok {
|
||||
if perr, ok := lerr.Cause.(*parse.Error); ok {
|
||||
return perr.Pos.Line == parse.EOF
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func loadline(reader *bufio.Reader, L *lua.LState) (string, error) {
|
||||
fmt.Print("> ")
|
||||
if line, err := reader.ReadString('\n'); err == nil {
|
||||
if _, err := L.LoadString("return " + line); err == nil { // try add return <...> then compile
|
||||
return line, nil
|
||||
} else {
|
||||
return multiline(line, reader, L)
|
||||
}
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
func multiline(ml string, reader *bufio.Reader, L *lua.LState) (string, error) {
|
||||
for {
|
||||
if _, err := L.LoadString(ml); err == nil { // try compile
|
||||
return ml, nil
|
||||
} else if !incomplete(err) { // syntax error , but not EOF
|
||||
return ml, nil
|
||||
} else {
|
||||
fmt.Print(">> ")
|
||||
if line, err := reader.ReadString('\n'); err == nil {
|
||||
ml = ml + "\n" + line
|
||||
} else {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package gluaexpect
|
||||
|
||||
import (
|
||||
"github.com/ThomasRooney/gexpect"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
func Preload(L *lua.LState) {
|
||||
L.PreloadModule("expect", Loader)
|
||||
}
|
||||
|
||||
// Loader is the module loader function.
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), api)
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
||||
|
||||
var api = map[string]lua.LGFunction{
|
||||
"spawn": spawn,
|
||||
}
|
||||
|
||||
func spawn(L *lua.LState) int {
|
||||
cmd := L.CheckString(1)
|
||||
child, err := gexpect.Spawn(cmd)
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(luar.New(L, child))
|
||||
return 1
|
||||
}
|
|
@ -1,100 +0,0 @@
|
|||
package gluasimplebox
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
|
||||
"github.com/brandur/simplebox"
|
||||
lua "github.com/yuin/gopher-lua"
|
||||
luar "layeh.com/gopher-luar"
|
||||
)
|
||||
|
||||
func Preload(L *lua.LState) {
|
||||
L.PreloadModule("simplebox", Loader)
|
||||
}
|
||||
|
||||
// Loader is the module loader function.
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), api)
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
||||
|
||||
var api = map[string]lua.LGFunction{
|
||||
"new": newSecretBox,
|
||||
"genkey": genKey,
|
||||
}
|
||||
|
||||
func newSecretBox(L *lua.LState) int {
|
||||
key := L.CheckString(1)
|
||||
|
||||
k, err := parseKey(key)
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
sb := simplebox.NewFromSecretKey(k)
|
||||
|
||||
L.Push(luar.New(L, &box{sb: sb}))
|
||||
return 1
|
||||
}
|
||||
|
||||
func genKey(L *lua.LState) int {
|
||||
key, err := generateKey()
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(lua.LString(base64.URLEncoding.EncodeToString(key[:])))
|
||||
return 1
|
||||
}
|
||||
|
||||
func generateKey() (*[32]byte, error) {
|
||||
var k [32]byte
|
||||
_, err := rand.Read(k[:])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &k, nil
|
||||
}
|
||||
|
||||
func parseKey(s string) (*[32]byte, error) {
|
||||
k := &[32]byte{}
|
||||
raw, err := base64.URLEncoding.DecodeString(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if n := copy(k[:], raw); n < len(k) {
|
||||
return nil, errors.New("not valid")
|
||||
}
|
||||
return k, nil
|
||||
}
|
||||
|
||||
type box struct {
|
||||
sb *simplebox.SimpleBox
|
||||
}
|
||||
|
||||
func (b *box) Encrypt(data string) string {
|
||||
result := b.sb.Encrypt([]byte(data))
|
||||
return hex.EncodeToString(result)
|
||||
}
|
||||
|
||||
func (b *box) Decrypt(data string) (string, error) {
|
||||
d, err := hex.DecodeString(data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
plain, err := b.sb.Decrypt([]byte(d))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return string(plain), nil
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
# svc
|
||||
## Goals
|
||||
|
||||
- Standardize service deployments to have _one_ syntax and _one_ function for the following:
|
||||
1. Deployment
|
||||
2. Checking the status of a deployed service
|
||||
3. Killing off an old instance of the service
|
||||
|
||||
- Create a command line tool that deploys a service to a given provider
|
||||
given configuration in a simple yaml manifest (see example [here](https://github.com/Xe/tools/tree/master/svc/sample))
|
||||
|
||||
- Persist a mapping of service names -> identifier for keeping track of past deployments
|
||||
|
||||
## Subcommands
|
||||
|
||||
| cmd | what it does |
|
||||
|:--- |:------------ |
|
||||
| `spawn` | Launches a new instance of the given service name on the given backend |
|
||||
| `ps` | Inquires the status of all known deployed services and displays them in a clever little grid |
|
||||
| `create` | Creates a directory hierarchy at $SVCROOT for a new service by name |
|
||||
| `remove` | Stops a service and undeploys it from a given backend |
|
||||
| `cycle` | Pulls the latest image and restarts the service with the new image |
|
||||
| `inspect` | Inspects a single service, outputting its state in json |
|
||||
|
||||
### `spawn`
|
||||
|
||||
Launches a new instance of the given service name on the given backend
|
||||
|
||||
Usage: `svc spawn [options] <servicename> <backend>`
|
||||
|
||||
Options:
|
||||
|
||||
| option | type | effect |
|
||||
|:------ |:---- |:------ |
|
||||
| `-kahled` | bool | Creates another instance of this service if one exists on any backend, fails if service is exclusive and already spawned |
|
||||
|
||||
### `ps`
|
||||
|
||||
Inquires the status of all known deployed services and displays them in a clever little grid
|
||||
|
||||
Usage `svc ps [options] [servicename]`
|
||||
|
||||
Options:
|
||||
|
||||
| option | type | effect |
|
||||
|:------ |:---- |:------ |
|
||||
| `-backend` | string | If set, only show results for services running on the given backend |
|
||||
| `-match` | string | If set, regex-match on service details |
|
||||
| `-format` | string | Pretty-print container status using a Go template |
|
||||
|
||||
### `create`
|
||||
|
||||
Creates a directory hierarchy at $SVCROOT for a new service by name
|
||||
|
||||
Usage: `svc create <servicename>`
|
||||
|
||||
### `remove`
|
||||
|
||||
Stops a service and removes it from a given backend
|
||||
|
||||
Usage: `svc remove <servicename>`
|
||||
|
||||
### `cycle`
|
||||
|
||||
Pulls the latest image and restarts the service with the new image
|
||||
|
||||
This command ***NEVER*** stops the old container until the new container is running and passes
|
||||
healthchecks.
|
||||
|
||||
Usage: `svc cycle <servicename>`
|
||||
|
||||
### `inspect`
|
||||
|
||||
Inspects a single service from a single backend, outputting its state in json
|
||||
|
||||
By default this will output a list of the inspect state of all matching instances of a service
|
||||
running on a particular backend.
|
||||
|
||||
Usage: `svc inspect <servicename> <backend>`
|
|
@ -0,0 +1,24 @@
|
|||
package jwt
|
||||
|
||||
import (
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
type jwt struct {
|
||||
token string
|
||||
}
|
||||
|
||||
func NewFromToken(token string) credentials.PerRPCCredentials {
|
||||
return jwt{token: token}
|
||||
}
|
||||
|
||||
func (j jwt) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
|
||||
return map[string]string{
|
||||
"authorization": j.token,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (j jwt) RequireTransportSecurity() bool {
|
||||
return false
|
||||
}
|
|
@ -1,40 +0,0 @@
|
|||
# gluaxmlpath
|
||||
|
||||
gluaxmlpath provides an easy way to use [xmlpath](https://github.com/go-xmlpath/xmlpath) from within [GopherLua](https://github.com/yuin/gopher-lua).
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
go get github.com/ailncode/gluaxmlpath
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/ailncode/gluaxmlpath"
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
func main() {
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
|
||||
gluaxmlpath.Preload(L)
|
||||
|
||||
if err := L.DoString(`
|
||||
xml ="<bookist><book>x1</book><book>x2</book><book>x3</book></booklist>"
|
||||
local xmlpath = require("xmlpath")
|
||||
node,err = xmlpath.loadxml(xml)
|
||||
path,err = xmlpath.compile("//book")
|
||||
it = path:iter(node)
|
||||
for k,v in pairs(it) do
|
||||
print(k,v:string())
|
||||
end
|
||||
`); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
|
@ -1,37 +0,0 @@
|
|||
package gluaxmlpath
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/yuin/gopher-lua"
|
||||
xmlpath "gopkg.in/xmlpath.v2"
|
||||
)
|
||||
|
||||
var api = map[string]lua.LGFunction{
|
||||
"loadxml": loadXml,
|
||||
"compile": compile,
|
||||
}
|
||||
|
||||
func loadXml(L *lua.LState) int {
|
||||
xmlStr := L.CheckString(1)
|
||||
r := bytes.NewReader([]byte(xmlStr))
|
||||
node, err := xmlpath.ParseHTML(r)
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
L.Push(newNode(L, node))
|
||||
return 1
|
||||
}
|
||||
|
||||
func compile(L *lua.LState) int {
|
||||
xpathStr := L.CheckString(1)
|
||||
path, err := xmlpath.Compile(xpathStr)
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(err.Error()))
|
||||
return 2
|
||||
}
|
||||
L.Push(newPath(L, path))
|
||||
return 1
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package gluaxmlpath
|
||||
|
||||
import (
|
||||
"github.com/yuin/gopher-lua"
|
||||
)
|
||||
|
||||
// Preload adds xmlpath to the given Lua state's package.preload table. After it
|
||||
// has been preloaded, it can be loaded using require:
|
||||
//
|
||||
// local xmlpath = require("xmlpath")
|
||||
func Preload(L *lua.LState) {
|
||||
L.PreloadModule("xmlpath", Loader)
|
||||
}
|
||||
|
||||
// Loader is the module loader function.
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), api)
|
||||
registerType(L, mod)
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package gluaxmlpath
|
||||
|
||||
import (
|
||||
"github.com/yuin/gopher-lua"
|
||||
xmlpath "gopkg.in/xmlpath.v2"
|
||||
)
|
||||
|
||||
type Node struct {
|
||||
base *xmlpath.Node
|
||||
}
|
||||
type Path struct {
|
||||
base *xmlpath.Path
|
||||
}
|
||||
|
||||
type Iter struct {
|
||||
base *xmlpath.Iter
|
||||
}
|
||||
|
||||
const luaNodeTypeName = "xmlpath.node"
|
||||
const luaPathTypeName = "xmlpath.path"
|
||||
const luaIterTypeName = "xmlpath.iter"
|
||||
|
||||
func registerType(L *lua.LState, module *lua.LTable) {
|
||||
//reg node
|
||||
nodemt := L.NewTypeMetatable(luaNodeTypeName)
|
||||
L.SetField(module, "node", nodemt)
|
||||
L.SetField(nodemt, "__index", L.SetFuncs(L.NewTable(), map[string]lua.LGFunction{
|
||||
"string": nodeString,
|
||||
}))
|
||||
//reg path
|
||||
pathmt := L.NewTypeMetatable(luaPathTypeName)
|
||||
L.SetField(module, "path", pathmt)
|
||||
L.SetField(pathmt, "__index", L.SetFuncs(L.NewTable(), map[string]lua.LGFunction{
|
||||
"iter": iter,
|
||||
}))
|
||||
//reg iter
|
||||
itermt := L.NewTypeMetatable(luaIterTypeName)
|
||||
L.SetField(module, "iter", itermt)
|
||||
L.SetField(itermt, "__index", L.SetFuncs(L.NewTable(), map[string]lua.LGFunction{
|
||||
//"next": next,
|
||||
"node": node,
|
||||
}))
|
||||
}
|
||||
func newNode(L *lua.LState, n *xmlpath.Node) *lua.LUserData {
|
||||
ud := L.NewUserData()
|
||||
ud.Value = &Node{
|
||||
n,
|
||||
}
|
||||
L.SetMetatable(ud, L.GetTypeMetatable(luaNodeTypeName))
|
||||
return ud
|
||||
}
|
||||
func checkNode(L *lua.LState) *Node {
|
||||
ud := L.CheckUserData(1)
|
||||
if v, ok := ud.Value.(*Node); ok {
|
||||
return v
|
||||
}
|
||||
L.ArgError(1, "node expected")
|
||||
return nil
|
||||
}
|
||||
func newPath(L *lua.LState, p *xmlpath.Path) *lua.LUserData {
|
||||
ud := L.NewUserData()
|
||||
ud.Value = &Path{
|
||||
p,
|
||||
}
|
||||
L.SetMetatable(ud, L.GetTypeMetatable(luaPathTypeName))
|
||||
return ud
|
||||
}
|
||||
func checkPath(L *lua.LState) *Path {
|
||||
ud := L.CheckUserData(1)
|
||||
if v, ok := ud.Value.(*Path); ok {
|
||||
return v
|
||||
}
|
||||
L.ArgError(1, "path expected")
|
||||
return nil
|
||||
}
|
||||
func newIter(L *lua.LState, i *xmlpath.Iter) *lua.LUserData {
|
||||
ud := L.NewUserData()
|
||||
ud.Value = &Iter{
|
||||
i,
|
||||
}
|
||||
L.SetMetatable(ud, L.GetTypeMetatable(luaIterTypeName))
|
||||
return ud
|
||||
}
|
||||
func checkIter(L *lua.LState) *Iter {
|
||||
ud := L.CheckUserData(1)
|
||||
if v, ok := ud.Value.(*Iter); ok {
|
||||
return v
|
||||
}
|
||||
L.ArgError(1, "iter expected")
|
||||
return nil
|
||||
}
|
||||
|
||||
//iter := path.iter(node)
|
||||
func iter(L *lua.LState) int {
|
||||
path := checkPath(L)
|
||||
if L.GetTop() == 2 {
|
||||
ut := L.CheckUserData(2)
|
||||
if node, ok := ut.Value.(*Node); ok {
|
||||
it := path.base.Iter(node.base)
|
||||
ltab := L.NewTable()
|
||||
i := 1
|
||||
for it.Next() {
|
||||
L.RawSetInt(ltab, i, newNode(L, it.Node()))
|
||||
i++
|
||||
}
|
||||
L.Push(ltab)
|
||||
//L.Push(newIter(L, it))
|
||||
return 1
|
||||
}
|
||||
}
|
||||
L.ArgError(1, "node expected")
|
||||
return 0
|
||||
}
|
||||
|
||||
//support lua standard iterator
|
||||
//hasNext := iter.next()
|
||||
// func next(L *lua.LState) int {
|
||||
// iter := checkIter(L)
|
||||
// L.Push(lua.LBool(iter.base.Next()))
|
||||
// return 1
|
||||
// }
|
||||
|
||||
//node := iter.node()
|
||||
func node(L *lua.LState) int {
|
||||
iter := checkIter(L)
|
||||
L.Push(newNode(L, iter.base.Node()))
|
||||
return 1
|
||||
}
|
||||
|
||||
//string := node.string()
|
||||
func nodeString(L *lua.LState) int {
|
||||
node := checkNode(L)
|
||||
L.Push(lua.LString(node.base.String()))
|
||||
return 1
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
|
@ -1,15 +0,0 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.4
|
||||
- 1.5
|
||||
- 1.6
|
||||
|
||||
install:
|
||||
- go get github.com/yuin/gopher-lua
|
||||
|
||||
script:
|
||||
- go test -v
|
||||
|
||||
notifications:
|
||||
email: false
|
|
@ -1,22 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Christian Joudrey
|
||||
|
||||
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.
|
||||
|
|
@ -1,235 +0,0 @@
|
|||
# gluahttp
|
||||
|
||||
[![](https://travis-ci.org/cjoudrey/gluahttp.svg)](https://travis-ci.org/cjoudrey/gluahttp)
|
||||
|
||||
gluahttp provides an easy way to make HTTP requests from within [GopherLua](https://github.com/yuin/gopher-lua).
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
go get github.com/cjoudrey/gluahttp
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
import "github.com/yuin/gopher-lua"
|
||||
import "github.com/cjoudrey/gluahttp"
|
||||
|
||||
func main() {
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
|
||||
L.PreloadModule("http", NewHttpModule(&http.Client{}).Loader)
|
||||
|
||||
if err := L.DoString(`
|
||||
|
||||
local http = require("http")
|
||||
|
||||
response, error_message = http.request("GET", "http://example.com", {
|
||||
query="page=1"
|
||||
headers={
|
||||
Accept="*/*"
|
||||
}
|
||||
})
|
||||
|
||||
`); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
- [`http.delete(url [, options])`](#httpdeleteurl--options)
|
||||
- [`http.get(url [, options])`](#httpgeturl--options)
|
||||
- [`http.head(url [, options])`](#httpheadurl--options)
|
||||
- [`http.patch(url [, options])`](#httppatchurl--options)
|
||||
- [`http.post(url [, options])`](#httpposturl--options)
|
||||
- [`http.put(url [, options])`](#httpputurl--options)
|
||||
- [`http.request(method, url [, options])`](#httprequestmethod-url--options)
|
||||
- [`http.request_batch(requests)`](#httprequest_batchrequests)
|
||||
- [`http.response`](#httpresponse)
|
||||
|
||||
### http.delete(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
### http.get(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
### http.head(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
### http.patch(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| body | String | Request body. |
|
||||
| form | String | Deprecated. URL encoded request body. This will also set the `Content-Type` header to `application/x-www-form-urlencoded` |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
### http.post(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| body | String | Request body. |
|
||||
| form | String | Deprecated. URL encoded request body. This will also set the `Content-Type` header to `application/x-www-form-urlencoded` |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
### http.put(url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| body | String | Request body. |
|
||||
| form | String | Deprecated. URL encoded request body. This will also set the `Content-Type` header to `application/x-www-form-urlencoded` |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
### http.request(method, url [, options])
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| method | String | The HTTP request method |
|
||||
| url | String | URL of the resource to load |
|
||||
| options | Table | Additional options |
|
||||
|
||||
**Options**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| query | String | URL encoded query params |
|
||||
| cookies | Table | Additional cookies to send with the request |
|
||||
| body | String | Request body. |
|
||||
| form | String | Deprecated. URL encoded request body. This will also set the `Content-Type` header to `application/x-www-form-urlencoded` |
|
||||
| headers | Table | Additional headers to send with the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[http.response](#httpresponse) or (nil, error message)
|
||||
|
||||
### http.request_batch(requests)
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| -------- | ----- | ----------- |
|
||||
| requests | Table | A table of requests to send. Each request item is by itself a table containing [http.request](#httprequestmethod-url--options) parameters for the request |
|
||||
|
||||
**Returns**
|
||||
|
||||
[[http.response](#httpresponse)] or ([[http.response](#httpresponse)], [error message])
|
||||
|
||||
### http.response
|
||||
|
||||
The `http.response` table contains information about a completed HTTP request.
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ----------- | ------ | ----------- |
|
||||
| body | String | The HTTP response body |
|
||||
| body_size | Number | The size of the HTTP reponse body in bytes |
|
||||
| headers | Table | The HTTP response headers |
|
||||
| cookies | Table | The cookies sent by the server in the HTTP response |
|
||||
| status_code | Number | The HTTP response status code |
|
||||
| url | String | The final URL the request ended pointing to after redirects |
|
|
@ -1,212 +0,0 @@
|
|||
package gluahttp
|
||||
|
||||
import "github.com/yuin/gopher-lua"
|
||||
import "net/http"
|
||||
import "fmt"
|
||||
import "errors"
|
||||
import "io/ioutil"
|
||||
import "strings"
|
||||
|
||||
type httpModule struct {
|
||||
client *http.Client
|
||||
}
|
||||
|
||||
type empty struct{}
|
||||
|
||||
func NewHttpModule(client *http.Client) *httpModule {
|
||||
return &httpModule{
|
||||
client: client,
|
||||
}
|
||||
}
|
||||
|
||||
func (h *httpModule) Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), map[string]lua.LGFunction{
|
||||
"get": h.get,
|
||||
"delete": h.delete,
|
||||
"head": h.head,
|
||||
"patch": h.patch,
|
||||
"post": h.post,
|
||||
"put": h.put,
|
||||
"request": h.request,
|
||||
"request_batch": h.requestBatch,
|
||||
})
|
||||
registerHttpResponseType(mod, L)
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
||||
|
||||
func (h *httpModule) get(L *lua.LState) int {
|
||||
return h.doRequestAndPush(L, "get", L.ToString(1), L.ToTable(2))
|
||||
}
|
||||
|
||||
func (h *httpModule) delete(L *lua.LState) int {
|
||||
return h.doRequestAndPush(L, "delete", L.ToString(1), L.ToTable(2))
|
||||
}
|
||||
|
||||
func (h *httpModule) head(L *lua.LState) int {
|
||||
return h.doRequestAndPush(L, "head", L.ToString(1), L.ToTable(2))
|
||||
}
|
||||
|
||||
func (h *httpModule) patch(L *lua.LState) int {
|
||||
return h.doRequestAndPush(L, "patch", L.ToString(1), L.ToTable(2))
|
||||
}
|
||||
|
||||
func (h *httpModule) post(L *lua.LState) int {
|
||||
return h.doRequestAndPush(L, "post", L.ToString(1), L.ToTable(2))
|
||||
}
|
||||
|
||||
func (h *httpModule) put(L *lua.LState) int {
|
||||
return h.doRequestAndPush(L, "put", L.ToString(1), L.ToTable(2))
|
||||
}
|
||||
|
||||
func (h *httpModule) request(L *lua.LState) int {
|
||||
return h.doRequestAndPush(L, L.ToString(1), L.ToString(2), L.ToTable(3))
|
||||
}
|
||||
|
||||
func (h *httpModule) requestBatch(L *lua.LState) int {
|
||||
requests := L.ToTable(1)
|
||||
amountRequests := requests.Len()
|
||||
|
||||
errs := make([]error, amountRequests)
|
||||
responses := make([]*lua.LUserData, amountRequests)
|
||||
sem := make(chan empty, amountRequests)
|
||||
|
||||
i := 0
|
||||
|
||||
requests.ForEach(func(_ lua.LValue, value lua.LValue) {
|
||||
requestTable := toTable(value)
|
||||
|
||||
if requestTable != nil {
|
||||
method := requestTable.RawGet(lua.LNumber(1)).String()
|
||||
url := requestTable.RawGet(lua.LNumber(2)).String()
|
||||
options := toTable(requestTable.RawGet(lua.LNumber(3)))
|
||||
|
||||
go func(i int, L *lua.LState, method string, url string, options *lua.LTable) {
|
||||
response, err := h.doRequest(L, method, url, options)
|
||||
|
||||
if err == nil {
|
||||
errs[i] = nil
|
||||
responses[i] = response
|
||||
} else {
|
||||
errs[i] = err
|
||||
responses[i] = nil
|
||||
}
|
||||
|
||||
sem <- empty{}
|
||||
}(i, L, method, url, options)
|
||||
} else {
|
||||
errs[i] = errors.New("Request must be a table")
|
||||
responses[i] = nil
|
||||
sem <- empty{}
|
||||
}
|
||||
|
||||
i = i + 1
|
||||
})
|
||||
|
||||
for i = 0; i < amountRequests; i++ {
|
||||
<-sem
|
||||
}
|
||||
|
||||
hasErrors := false
|
||||
errorsTable := L.NewTable()
|
||||
responsesTable := L.NewTable()
|
||||
for i = 0; i < amountRequests; i++ {
|
||||
if errs[i] == nil {
|
||||
responsesTable.Append(responses[i])
|
||||
errorsTable.Append(lua.LNil)
|
||||
} else {
|
||||
responsesTable.Append(lua.LNil)
|
||||
errorsTable.Append(lua.LString(fmt.Sprintf("%s", errs[i])))
|
||||
hasErrors = true
|
||||
}
|
||||
}
|
||||
|
||||
if hasErrors {
|
||||
L.Push(responsesTable)
|
||||
L.Push(errorsTable)
|
||||
return 2
|
||||
} else {
|
||||
L.Push(responsesTable)
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
func (h *httpModule) doRequest(L *lua.LState, method string, url string, options *lua.LTable) (*lua.LUserData, error) {
|
||||
req, err := http.NewRequest(strings.ToUpper(method), url, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if options != nil {
|
||||
if reqCookies, ok := options.RawGet(lua.LString("cookies")).(*lua.LTable); ok {
|
||||
reqCookies.ForEach(func(key lua.LValue, value lua.LValue) {
|
||||
req.AddCookie(&http.Cookie{Name: key.String(), Value: value.String()})
|
||||
})
|
||||
}
|
||||
|
||||
switch reqQuery := options.RawGet(lua.LString("query")).(type) {
|
||||
case lua.LString:
|
||||
req.URL.RawQuery = reqQuery.String()
|
||||
}
|
||||
|
||||
body := options.RawGet(lua.LString("body"))
|
||||
if _, ok := body.(lua.LString); !ok {
|
||||
// "form" is deprecated.
|
||||
body = options.RawGet(lua.LString("form"))
|
||||
// Only set the Content-Type to application/x-www-form-urlencoded
|
||||
// when someone uses "form", not for "body".
|
||||
if _, ok := body.(lua.LString); ok {
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
}
|
||||
|
||||
switch reqBody := body.(type) {
|
||||
case lua.LString:
|
||||
body := reqBody.String()
|
||||
req.ContentLength = int64(len(body))
|
||||
req.Body = ioutil.NopCloser(strings.NewReader(body))
|
||||
}
|
||||
|
||||
// Set these last. That way the code above doesn't overwrite them.
|
||||
if reqHeaders, ok := options.RawGet(lua.LString("headers")).(*lua.LTable); ok {
|
||||
reqHeaders.ForEach(func(key lua.LValue, value lua.LValue) {
|
||||
req.Header.Set(key.String(), value.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
res, err := h.client.Do(req)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return newHttpResponse(res, &body, len(body), L), nil
|
||||
}
|
||||
|
||||
func (h *httpModule) doRequestAndPush(L *lua.LState, method string, url string, options *lua.LTable) int {
|
||||
response, err := h.doRequest(L, method, url, options)
|
||||
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(fmt.Sprintf("%s", err)))
|
||||
return 2
|
||||
}
|
||||
|
||||
L.Push(response)
|
||||
return 1
|
||||
}
|
||||
|
||||
func toTable(v lua.LValue) *lua.LTable {
|
||||
if lv, ok := v.(*lua.LTable); ok {
|
||||
return lv
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -1,433 +0,0 @@
|
|||
package gluahttp
|
||||
|
||||
import "github.com/yuin/gopher-lua"
|
||||
import "testing"
|
||||
import "io/ioutil"
|
||||
import "net/http"
|
||||
import "net"
|
||||
import "fmt"
|
||||
import "net/http/cookiejar"
|
||||
import "strings"
|
||||
|
||||
func TestRequestNoMethod(t *testing.T) {
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.request()
|
||||
|
||||
assert_equal(nil, response)
|
||||
assert_contains('unsupported protocol scheme ""', error)
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestNoUrl(t *testing.T) {
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.request("get")
|
||||
|
||||
assert_equal(nil, response)
|
||||
assert_contains('unsupported protocol scheme ""', error)
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestBatch(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
responses, errors = http.request_batch({
|
||||
{"get", "http://`+listener.Addr().String()+`", {query="page=1"}},
|
||||
{"post", "http://`+listener.Addr().String()+`/set_cookie"},
|
||||
{"post", ""},
|
||||
1
|
||||
})
|
||||
|
||||
assert_equal(nil, errors[1])
|
||||
assert_equal(nil, errors[2])
|
||||
assert_contains('unsupported protocol scheme ""', errors[3])
|
||||
assert_equal('Request must be a table', errors[4])
|
||||
|
||||
assert_equal('Requested GET / with query "page=1"', responses[1]["body"])
|
||||
assert_equal('Cookie set!', responses[2]["body"])
|
||||
assert_equal('12345', responses[2]["cookies"]["session_id"])
|
||||
assert_equal(nil, responses[3])
|
||||
assert_equal(nil, responses[4])
|
||||
|
||||
responses, errors = http.request_batch({
|
||||
{"get", "http://`+listener.Addr().String()+`/get_cookie"}
|
||||
})
|
||||
|
||||
assert_equal(nil, errors)
|
||||
assert_equal("session_id=12345", responses[1]["body"])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestGet(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.request("get", "http://`+listener.Addr().String()+`")
|
||||
|
||||
assert_equal('Requested GET / with query ""', response['body'])
|
||||
assert_equal(200, response['status_code'])
|
||||
assert_equal('29', response['headers']['Content-Length'])
|
||||
assert_equal('text/plain; charset=utf-8', response['headers']['Content-Type'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestGetWithRedirect(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.request("get", "http://`+listener.Addr().String()+`/redirect")
|
||||
|
||||
assert_equal('Requested GET / with query ""', response['body'])
|
||||
assert_equal(200, response['status_code'])
|
||||
assert_equal('http://`+listener.Addr().String()+`/', response['url'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestPostForm(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.request("post", "http://`+listener.Addr().String()+`", {
|
||||
form="username=bob&password=secret"
|
||||
})
|
||||
|
||||
assert_equal(
|
||||
'Requested POST / with query ""' ..
|
||||
'Content-Type: application/x-www-form-urlencoded' ..
|
||||
'Content-Length: 28' ..
|
||||
'Body: username=bob&password=secret', response['body'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestHeaders(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.request("post", "http://`+listener.Addr().String()+`", {
|
||||
headers={
|
||||
["Content-Type"]="application/json"
|
||||
}
|
||||
})
|
||||
|
||||
assert_equal(
|
||||
'Requested POST / with query ""' ..
|
||||
'Content-Type: application/json' ..
|
||||
'Content-Length: 0' ..
|
||||
'Body: ', response['body'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestQuery(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.request("get", "http://`+listener.Addr().String()+`", {
|
||||
query="page=2"
|
||||
})
|
||||
|
||||
assert_equal('Requested GET / with query "page=2"', response['body'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGet(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.get("http://`+listener.Addr().String()+`", {
|
||||
query="page=1"
|
||||
})
|
||||
|
||||
assert_equal('Requested GET / with query "page=1"', response['body'])
|
||||
assert_equal(200, response['status_code'])
|
||||
assert_equal('35', response['headers']['Content-Length'])
|
||||
assert_equal('text/plain; charset=utf-8', response['headers']['Content-Type'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDelete(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.delete("http://`+listener.Addr().String()+`", {
|
||||
query="page=1"
|
||||
})
|
||||
|
||||
assert_equal('Requested DELETE / with query "page=1"', response['body'])
|
||||
assert_equal(200, response['status_code'])
|
||||
assert_equal('38', response['headers']['Content-Length'])
|
||||
assert_equal('text/plain; charset=utf-8', response['headers']['Content-Type'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHead(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.head("http://`+listener.Addr().String()+`/head", {
|
||||
query="page=1"
|
||||
})
|
||||
|
||||
assert_equal(200, response['status_code'])
|
||||
assert_equal("/head?page=1", response['headers']['X-Request-Uri'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPost(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.post("http://`+listener.Addr().String()+`", {
|
||||
body="username=bob&password=secret"
|
||||
})
|
||||
|
||||
assert_equal(
|
||||
'Requested POST / with query ""' ..
|
||||
'Content-Type: ' ..
|
||||
'Content-Length: 28' ..
|
||||
'Body: username=bob&password=secret', response['body'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPatch(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.patch("http://`+listener.Addr().String()+`", {
|
||||
body='{"username":"bob"}',
|
||||
headers={
|
||||
["Content-Type"]="application/json"
|
||||
}
|
||||
})
|
||||
|
||||
assert_equal(
|
||||
'Requested PATCH / with query ""' ..
|
||||
'Content-Type: application/json' ..
|
||||
'Content-Length: 18' ..
|
||||
'Body: {"username":"bob"}', response['body'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPut(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.put("http://`+listener.Addr().String()+`", {
|
||||
body="username=bob&password=secret",
|
||||
headers={
|
||||
["Content-Type"]="application/x-www-form-urlencoded"
|
||||
}
|
||||
})
|
||||
|
||||
assert_equal(
|
||||
'Requested PUT / with query ""' ..
|
||||
'Content-Type: application/x-www-form-urlencoded' ..
|
||||
'Content-Length: 28' ..
|
||||
'Body: username=bob&password=secret', response['body'])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseCookies(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.get("http://`+listener.Addr().String()+`/set_cookie")
|
||||
|
||||
assert_equal('Cookie set!', response["body"])
|
||||
assert_equal('12345', response["cookies"]["session_id"])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRequestCookies(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.get("http://`+listener.Addr().String()+`/get_cookie", {
|
||||
cookies={
|
||||
["session_id"]="test"
|
||||
}
|
||||
})
|
||||
|
||||
assert_equal('session_id=test', response["body"])
|
||||
assert_equal(15, response["body_size"])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseBodySize(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.get("http://`+listener.Addr().String()+`/")
|
||||
|
||||
assert_equal(29, response["body_size"])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseBody(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
response, error = http.get("http://`+listener.Addr().String()+`/")
|
||||
|
||||
assert_equal("Requested XXX / with query \"\"", string.gsub(response.body, "GET", "XXX"))
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResponseUrl(t *testing.T) {
|
||||
listener, _ := net.Listen("tcp", "127.0.0.1:0")
|
||||
setupServer(listener)
|
||||
|
||||
if err := evalLua(t, `
|
||||
local http = require("http")
|
||||
|
||||
response, error = http.get("http://`+listener.Addr().String()+`/redirect")
|
||||
assert_equal("http://`+listener.Addr().String()+`/", response["url"])
|
||||
|
||||
response, error = http.get("http://`+listener.Addr().String()+`/get_cookie")
|
||||
assert_equal("http://`+listener.Addr().String()+`/get_cookie", response["url"])
|
||||
`); err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func evalLua(t *testing.T, script string) error {
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
|
||||
cookieJar, _ := cookiejar.New(nil)
|
||||
|
||||
L.PreloadModule("http", NewHttpModule(&http.Client{
|
||||
Jar: cookieJar,
|
||||
},
|
||||
).Loader)
|
||||
|
||||
L.SetGlobal("assert_equal", L.NewFunction(func(L *lua.LState) int {
|
||||
expected := L.Get(1)
|
||||
actual := L.Get(2)
|
||||
|
||||
if expected.Type() != actual.Type() || expected.String() != actual.String() {
|
||||
t.Errorf("Expected %s %q, got %s %q", expected.Type(), expected, actual.Type(), actual)
|
||||
}
|
||||
|
||||
return 0
|
||||
}))
|
||||
|
||||
L.SetGlobal("assert_contains", L.NewFunction(func(L *lua.LState) int {
|
||||
contains := L.Get(1)
|
||||
actual := L.Get(2)
|
||||
|
||||
if !strings.Contains(actual.String(), contains.String()) {
|
||||
t.Errorf("Expected %s %q contains %s %q", actual.Type(), actual, contains.Type(), contains)
|
||||
}
|
||||
|
||||
return 0
|
||||
}))
|
||||
|
||||
return L.DoString(script)
|
||||
}
|
||||
|
||||
func setupServer(listener net.Listener) {
|
||||
mux := http.NewServeMux()
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
|
||||
fmt.Fprintf(w, "Requested %s / with query %q", req.Method, req.URL.RawQuery)
|
||||
|
||||
if req.Method == "POST" || req.Method == "PATCH" || req.Method == "PUT" {
|
||||
body, _ := ioutil.ReadAll(req.Body)
|
||||
fmt.Fprintf(w, "Content-Type: %s", req.Header.Get("Content-Type"))
|
||||
fmt.Fprintf(w, "Content-Length: %s", req.Header.Get("Content-Length"))
|
||||
fmt.Fprintf(w, "Body: %s", body)
|
||||
}
|
||||
})
|
||||
mux.HandleFunc("/head", func(w http.ResponseWriter, req *http.Request) {
|
||||
if req.Method == "HEAD" {
|
||||
w.Header().Set("X-Request-Uri", req.URL.String())
|
||||
w.WriteHeader(http.StatusOK)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
}
|
||||
})
|
||||
mux.HandleFunc("/set_cookie", func(w http.ResponseWriter, req *http.Request) {
|
||||
http.SetCookie(w, &http.Cookie{Name: "session_id", Value: "12345"})
|
||||
fmt.Fprint(w, "Cookie set!")
|
||||
})
|
||||
mux.HandleFunc("/get_cookie", func(w http.ResponseWriter, req *http.Request) {
|
||||
session_id, _ := req.Cookie("session_id")
|
||||
fmt.Fprint(w, session_id)
|
||||
})
|
||||
mux.HandleFunc("/redirect", func(w http.ResponseWriter, req *http.Request) {
|
||||
http.Redirect(w, req, "/", http.StatusFound)
|
||||
})
|
||||
s := &http.Server{
|
||||
Handler: mux,
|
||||
}
|
||||
go s.Serve(listener)
|
||||
}
|
|
@ -1,98 +0,0 @@
|
|||
package gluahttp
|
||||
|
||||
import "github.com/yuin/gopher-lua"
|
||||
import "net/http"
|
||||
|
||||
const luaHttpResponseTypeName = "http.response"
|
||||
|
||||
type luaHttpResponse struct {
|
||||
res *http.Response
|
||||
body lua.LString
|
||||
bodySize int
|
||||
}
|
||||
|
||||
func registerHttpResponseType(module *lua.LTable, L *lua.LState) {
|
||||
mt := L.NewTypeMetatable(luaHttpResponseTypeName)
|
||||
L.SetField(mt, "__index", L.NewFunction(httpResponseIndex))
|
||||
|
||||
L.SetField(module, "response", mt)
|
||||
}
|
||||
|
||||
func newHttpResponse(res *http.Response, body *[]byte, bodySize int, L *lua.LState) *lua.LUserData {
|
||||
ud := L.NewUserData()
|
||||
ud.Value = &luaHttpResponse{
|
||||
res: res,
|
||||
body: lua.LString(*body),
|
||||
bodySize: bodySize,
|
||||
}
|
||||
L.SetMetatable(ud, L.GetTypeMetatable(luaHttpResponseTypeName))
|
||||
return ud
|
||||
}
|
||||
|
||||
func checkHttpResponse(L *lua.LState) *luaHttpResponse {
|
||||
ud := L.CheckUserData(1)
|
||||
if v, ok := ud.Value.(*luaHttpResponse); ok {
|
||||
return v
|
||||
}
|
||||
L.ArgError(1, "http.response expected")
|
||||
return nil
|
||||
}
|
||||
|
||||
func httpResponseIndex(L *lua.LState) int {
|
||||
res := checkHttpResponse(L)
|
||||
|
||||
switch L.CheckString(2) {
|
||||
case "headers":
|
||||
return httpResponseHeaders(res, L)
|
||||
case "cookies":
|
||||
return httpResponseCookies(res, L)
|
||||
case "status_code":
|
||||
return httpResponseStatusCode(res, L)
|
||||
case "url":
|
||||
return httpResponseUrl(res, L)
|
||||
case "body":
|
||||
return httpResponseBody(res, L)
|
||||
case "body_size":
|
||||
return httpResponseBodySize(res, L)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func httpResponseHeaders(res *luaHttpResponse, L *lua.LState) int {
|
||||
headers := L.NewTable()
|
||||
for key, _ := range res.res.Header {
|
||||
headers.RawSetString(key, lua.LString(res.res.Header.Get(key)))
|
||||
}
|
||||
L.Push(headers)
|
||||
return 1
|
||||
}
|
||||
|
||||
func httpResponseCookies(res *luaHttpResponse, L *lua.LState) int {
|
||||
cookies := L.NewTable()
|
||||
for _, cookie := range res.res.Cookies() {
|
||||
cookies.RawSetString(cookie.Name, lua.LString(cookie.Value))
|
||||
}
|
||||
L.Push(cookies)
|
||||
return 1
|
||||
}
|
||||
|
||||
func httpResponseStatusCode(res *luaHttpResponse, L *lua.LState) int {
|
||||
L.Push(lua.LNumber(res.res.StatusCode))
|
||||
return 1
|
||||
}
|
||||
|
||||
func httpResponseUrl(res *luaHttpResponse, L *lua.LState) int {
|
||||
L.Push(lua.LString(res.res.Request.URL.String()))
|
||||
return 1
|
||||
}
|
||||
|
||||
func httpResponseBody(res *luaHttpResponse, L *lua.LState) int {
|
||||
L.Push(res.body)
|
||||
return 1
|
||||
}
|
||||
|
||||
func httpResponseBodySize(res *luaHttpResponse, L *lua.LState) int {
|
||||
L.Push(lua.LNumber(res.bodySize))
|
||||
return 1
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
|
@ -1,14 +0,0 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- 1.3
|
||||
- 1.4
|
||||
|
||||
install:
|
||||
- go get github.com/yuin/gopher-lua
|
||||
|
||||
script:
|
||||
- go test -v
|
||||
|
||||
notifications:
|
||||
email: false
|
|
@ -1,22 +0,0 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Christian Joudrey
|
||||
|
||||
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.
|
||||
|
|
@ -1,109 +0,0 @@
|
|||
# gluaurl
|
||||
|
||||
[![](https://travis-ci.org/cjoudrey/gluaurl.svg)](https://travis-ci.org/cjoudrey/gluaurl)
|
||||
|
||||
gluahttp provides an easy way to parse and build URLs from within [GopherLua](https://github.com/yuin/gopher-lua).
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
go get github.com/cjoudrey/gluaurl
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
import "github.com/yuin/gopher-lua"
|
||||
import "github.com/cjoudrey/gluaurl"
|
||||
|
||||
func main() {
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
|
||||
L.PreloadModule("url", gluaurl.Loader)
|
||||
|
||||
if err := L.DoString(`
|
||||
|
||||
local url = require("url")
|
||||
|
||||
parsed_url = url.parse("http://example.com/")
|
||||
|
||||
print(parsed_url.host)
|
||||
|
||||
`); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
- [`url.parse(url)`](#urlparseurl)
|
||||
- [`url.build(options)`](#urlbuildoptions)
|
||||
- [`url.build_query_string(query_params)`](#urlbuild_query_stringquery_params)
|
||||
- [`url.resolve(from, to)`](#urlresolvefrom-to)
|
||||
|
||||
### url.parse(url)
|
||||
|
||||
Parse URL into a table of key/value components.
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ------ | ----------- |
|
||||
| url | String | URL to parsed |
|
||||
|
||||
**Returns**
|
||||
|
||||
Table with parsed URL or (nil, error message)
|
||||
|
||||
| Name | Type | Description |
|
||||
| -------- | ------ | ----------- |
|
||||
| scheme | String | Scheme of the URL |
|
||||
| username | String | Username |
|
||||
| password | String | Password |
|
||||
| host | String | Host and port of the URL |
|
||||
| path | String | Path |
|
||||
| query | String | Query string |
|
||||
| fragment | String | Fragment |
|
||||
|
||||
### url.build(options)
|
||||
|
||||
Assemble a URL string from a table of URL components.
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------- | ----- | ----------- |
|
||||
| options | Table | Table with URL components, see [`url.parse`](#urlparseurl) for list of valid components |
|
||||
|
||||
**Returns**
|
||||
|
||||
String
|
||||
|
||||
### url.build_query_string(query_params)
|
||||
|
||||
Assemble table of query string parameters into a string.
|
||||
|
||||
**Attributes**
|
||||
|
||||
| Name | Type | Description |
|
||||
| ------------ | ----- | ----------- |
|
||||
| query_params | Table | Table with query parameters |
|
||||
|
||||
**Returns**
|
||||
|
||||
String
|
||||
|
||||
### url.resolve(from, to)
|
||||
|
||||
Take a base URL, and a href URL, and resolve them as a browser would for an anchor tag.
|
||||
|
||||
| Name | Type | Description |
|
||||
| ---- | ------ | ----------- |
|
||||
| from | String | base URL |
|
||||
| to | String | href URL |
|
||||
|
||||
**Returns**
|
||||
|
||||
String or (nil, error message)
|
|
@ -1,178 +0,0 @@
|
|||
package gluaurl
|
||||
|
||||
import "github.com/yuin/gopher-lua"
|
||||
import "net/url"
|
||||
import "strings"
|
||||
import "fmt"
|
||||
import "sort"
|
||||
import "regexp"
|
||||
|
||||
var rBracket = regexp.MustCompile("\\[\\]$")
|
||||
|
||||
func Loader(L *lua.LState) int {
|
||||
mod := L.SetFuncs(L.NewTable(), map[string]lua.LGFunction{
|
||||
"parse": parse,
|
||||
"build": build,
|
||||
"build_query_string": buildQueryString,
|
||||
"resolve": resolve,
|
||||
})
|
||||
L.Push(mod)
|
||||
return 1
|
||||
}
|
||||
|
||||
func parse(L *lua.LState) int {
|
||||
parsed := L.NewTable()
|
||||
|
||||
url, err := url.Parse(L.CheckString(1))
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(fmt.Sprintf("%s", err)))
|
||||
return 2
|
||||
}
|
||||
|
||||
parsed.RawSetString("scheme", lua.LString(url.Scheme))
|
||||
|
||||
if url.User != nil {
|
||||
parsed.RawSetString("username", lua.LString(url.User.Username()))
|
||||
|
||||
if password, hasPassword := url.User.Password(); hasPassword {
|
||||
parsed.RawSetString("password", lua.LString(password))
|
||||
} else {
|
||||
parsed.RawSetString("password", lua.LNil)
|
||||
}
|
||||
|
||||
} else {
|
||||
parsed.RawSetString("username", lua.LNil)
|
||||
parsed.RawSetString("password", lua.LNil)
|
||||
}
|
||||
|
||||
parsed.RawSetString("host", lua.LString(url.Host))
|
||||
parsed.RawSetString("path", lua.LString(url.Path))
|
||||
parsed.RawSetString("query", lua.LString(url.RawQuery))
|
||||
parsed.RawSetString("fragment", lua.LString(url.Fragment))
|
||||
|
||||
L.Push(parsed)
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
func build(L *lua.LState) int {
|
||||
options := L.CheckTable(1)
|
||||
|
||||
buildUrl := url.URL{}
|
||||
|
||||
if scheme := options.RawGetString("scheme"); scheme != lua.LNil {
|
||||
buildUrl.Scheme = scheme.String()
|
||||
}
|
||||
|
||||
if username := options.RawGetString("username"); username != lua.LNil {
|
||||
if password := options.RawGetString("password"); password != lua.LNil {
|
||||
buildUrl.User = url.UserPassword(username.String(), password.String())
|
||||
} else {
|
||||
buildUrl.User = url.User(username.String())
|
||||
}
|
||||
}
|
||||
|
||||
if host := options.RawGetString("host"); host != lua.LNil {
|
||||
buildUrl.Host = host.String()
|
||||
}
|
||||
|
||||
if path := options.RawGetString("path"); path != lua.LNil {
|
||||
buildUrl.Path = path.String()
|
||||
}
|
||||
|
||||
if query := options.RawGetString("query"); query != lua.LNil {
|
||||
buildUrl.RawQuery = query.String()
|
||||
}
|
||||
|
||||
if fragment := options.RawGetString("fragment"); fragment != lua.LNil {
|
||||
buildUrl.Fragment = fragment.String()
|
||||
}
|
||||
|
||||
L.Push(lua.LString(buildUrl.String()))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
func buildQueryString(L *lua.LState) int {
|
||||
options := L.CheckTable(1)
|
||||
|
||||
ret := make([]string, 0)
|
||||
|
||||
options.ForEach(func(key, value lua.LValue) {
|
||||
toQueryString(key.String(), value, &ret)
|
||||
})
|
||||
|
||||
sort.Strings(ret)
|
||||
|
||||
L.Push(lua.LString(strings.Join(ret, "&")))
|
||||
|
||||
return 1
|
||||
}
|
||||
|
||||
func toQueryString(prefix string, lv lua.LValue, ret *[]string) {
|
||||
switch v := lv.(type) {
|
||||
case lua.LBool:
|
||||
*ret = append(*ret, url.QueryEscape(prefix)+"="+v.String())
|
||||
break
|
||||
|
||||
case lua.LNumber:
|
||||
*ret = append(*ret, url.QueryEscape(prefix)+"="+v.String())
|
||||
break
|
||||
|
||||
case lua.LString:
|
||||
*ret = append(*ret, url.QueryEscape(prefix)+"="+url.QueryEscape(v.String()))
|
||||
break
|
||||
|
||||
case *lua.LTable:
|
||||
maxn := v.MaxN()
|
||||
if maxn == 0 {
|
||||
ret2 := make([]string, 0)
|
||||
v.ForEach(func(key lua.LValue, value lua.LValue) {
|
||||
toQueryString(prefix+"["+key.String()+"]", value, &ret2)
|
||||
})
|
||||
sort.Strings(ret2)
|
||||
*ret = append(*ret, strings.Join(ret2, "&"))
|
||||
} else {
|
||||
ret2 := make([]string, 0)
|
||||
for i := 1; i <= maxn; i++ {
|
||||
vi := v.RawGetInt(i)
|
||||
|
||||
if rBracket.MatchString(prefix) {
|
||||
ret2 = append(ret2, url.QueryEscape(prefix)+"="+vi.String())
|
||||
} else {
|
||||
if vi.Type() == lua.LTTable {
|
||||
toQueryString(fmt.Sprintf("%s[%d]", prefix, i-1), vi, &ret2)
|
||||
} else {
|
||||
toQueryString(prefix+"[]", vi, &ret2)
|
||||
}
|
||||
}
|
||||
}
|
||||
*ret = append(*ret, strings.Join(ret2, "&"))
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func resolve(L *lua.LState) int {
|
||||
from := L.CheckString(1)
|
||||
to := L.CheckString(2)
|
||||
|
||||
fromUrl, err := url.Parse(from)
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(fmt.Sprintf("%s", err)))
|
||||
return 2
|
||||
}
|
||||
|
||||
toUrl, err := url.Parse(to)
|
||||
if err != nil {
|
||||
L.Push(lua.LNil)
|
||||
L.Push(lua.LString(fmt.Sprintf("%s", err)))
|
||||
return 2
|
||||
}
|
||||
|
||||
resolvedUrl := fromUrl.ResolveReference(toUrl).String()
|
||||
L.Push(lua.LString(resolvedUrl))
|
||||
return 1
|
||||
}
|
|
@ -1,250 +0,0 @@
|
|||
package gluaurl
|
||||
|
||||
import "github.com/yuin/gopher-lua"
|
||||
import "testing"
|
||||
import "os"
|
||||
import "bytes"
|
||||
import "io"
|
||||
import "strings"
|
||||
|
||||
func TestParse(t *testing.T) {
|
||||
output, err := evalScript(`
|
||||
local url = require("url")
|
||||
|
||||
parsed = url.parse("http://bob:secret@example.com:8080/products?page=2#something")
|
||||
|
||||
print(parsed.scheme)
|
||||
print(parsed.username)
|
||||
print(parsed.password)
|
||||
print(parsed.host)
|
||||
print(parsed.path)
|
||||
print(parsed.query)
|
||||
print(parsed.fragment)
|
||||
`)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
} else {
|
||||
if expected := `http
|
||||
bob
|
||||
secret
|
||||
example.com:8080
|
||||
/products
|
||||
page=2
|
||||
something
|
||||
`; expected != output {
|
||||
t.Errorf("Expected output does not match actual output\nExpected: %s\nActual: %s", expected, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseOnlyHost(t *testing.T) {
|
||||
output, err := evalScript(`
|
||||
local url = require("url")
|
||||
|
||||
parsed = url.parse("https://example.com")
|
||||
|
||||
print(parsed.scheme)
|
||||
print(parsed.username)
|
||||
print(parsed.password)
|
||||
print(parsed.host)
|
||||
print(parsed.path)
|
||||
print(parsed.query)
|
||||
print(parsed.fragment)
|
||||
`)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
} else {
|
||||
if expected := `https
|
||||
nil
|
||||
nil
|
||||
example.com
|
||||
|
||||
|
||||
|
||||
`; expected != output {
|
||||
t.Errorf("Expected output does not match actual output\nExpected: %s\nActual: %s", expected, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuild(t *testing.T) {
|
||||
output, err := evalScript(`
|
||||
local url = require("url")
|
||||
|
||||
built = url.build({
|
||||
scheme="https",
|
||||
username="bob",
|
||||
password="secret",
|
||||
host="example.com:8080",
|
||||
path="/products",
|
||||
query="page=2",
|
||||
fragment="something"
|
||||
})
|
||||
|
||||
print(built)
|
||||
`)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
} else {
|
||||
if expected := `https://bob:secret@example.com:8080/products?page=2#something
|
||||
`; expected != output {
|
||||
t.Errorf("Expected output does not match actual output\nExpected: %s\nActual: %s", expected, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildEmpty(t *testing.T) {
|
||||
output, err := evalScript(`
|
||||
local url = require("url")
|
||||
|
||||
built = url.build({})
|
||||
|
||||
print(built)
|
||||
`)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
} else {
|
||||
if expected := `
|
||||
`; expected != output {
|
||||
t.Errorf("Expected output does not match actual output\nExpected: %s\nActual: %s", expected, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuildQueryString(t *testing.T) {
|
||||
output, err := evalScript(`
|
||||
local url = require("url")
|
||||
|
||||
function assert_query_string(options, expected, message)
|
||||
actual = url.build_query_string(options)
|
||||
|
||||
if expected ~= actual then
|
||||
print("Failed to build '" .. message .. "'")
|
||||
print("Expected:")
|
||||
print(expected)
|
||||
print("Actual:")
|
||||
print(actual)
|
||||
end
|
||||
end
|
||||
|
||||
assert_query_string(
|
||||
{foo="bar", baz=42, quux="All your base are belong to us"},
|
||||
"baz=42&foo=bar&quux=All+your+base+are+belong+to+us",
|
||||
"simple"
|
||||
)
|
||||
|
||||
assert_query_string(
|
||||
{someName={1, 2, 3}, regularThing="blah"},
|
||||
"regularThing=blah&someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3",
|
||||
"with array"
|
||||
)
|
||||
|
||||
assert_query_string(
|
||||
{foo={"a", "b", "c"}},
|
||||
"foo%5B%5D=a&foo%5B%5D=b&foo%5B%5D=c",
|
||||
"with array of strings"
|
||||
)
|
||||
|
||||
assert_query_string(
|
||||
{foo={"baz", 42, "All your base are belong to us"}},
|
||||
"foo%5B%5D=baz&foo%5B%5D=42&foo%5B%5D=All+your+base+are+belong+to+us",
|
||||
"more array"
|
||||
)
|
||||
|
||||
assert_query_string(
|
||||
{foo={bar="baz", beep=42, quux="All your base are belong to us"}},
|
||||
"foo%5Bbar%5D=baz&foo%5Bbeep%5D=42&foo%5Bquux%5D=All+your+base+are+belong+to+us",
|
||||
"even more arrays"
|
||||
)
|
||||
|
||||
assert_query_string(
|
||||
{a={1,2}, b={c=3, d={4,5}, e={ x={6}, y=7, z={8,9} }, f=true, g=false, h=""}, i={10,11}, j=true, k=false, l={"",0}, m="cowboy hat?" },
|
||||
"a%5B%5D=1&a%5B%5D=2&b%5Bc%5D=3&b%5Bd%5D%5B%5D=4&b%5Bd%5D%5B%5D=5&b%5Be%5D%5Bx%5D%5B%5D=6&b%5Be%5D%5By%5D=7&b%5Be%5D%5Bz%5D%5B%5D=8&b%5Be%5D%5Bz%5D%5B%5D=9&b%5Bf%5D=true&b%5Bg%5D=false&b%5Bh%5D=&i%5B%5D=10&i%5B%5D=11&j=true&k=false&l%5B%5D=&l%5B%5D=0&m=cowboy+hat%3F",
|
||||
"huge structure"
|
||||
)
|
||||
|
||||
assert_query_string(
|
||||
{ a={0, { 1, 2 }, { 3, { 4, 5 }, { 6 } }, { b= { 7, { 8, 9 }, { { c=10, d=11 } }, { { 12 } }, { { { 13 } } }, { e= { f= { g={ 14, { 15 } } } } }, 16 } }, 17 } },
|
||||
"a%5B%5D=0&a%5B1%5D%5B%5D=1&a%5B1%5D%5B%5D=2&a%5B2%5D%5B%5D=3&a%5B2%5D%5B1%5D%5B%5D=4&a%5B2%5D%5B1%5D%5B%5D=5&a%5B2%5D%5B2%5D%5B%5D=6&a%5B3%5D%5Bb%5D%5B%5D=7&a%5B3%5D%5Bb%5D%5B1%5D%5B%5D=8&a%5B3%5D%5Bb%5D%5B1%5D%5B%5D=9&a%5B3%5D%5Bb%5D%5B2%5D%5B0%5D%5Bc%5D=10&a%5B3%5D%5Bb%5D%5B2%5D%5B0%5D%5Bd%5D=11&a%5B3%5D%5Bb%5D%5B3%5D%5B0%5D%5B%5D=12&a%5B3%5D%5Bb%5D%5B4%5D%5B0%5D%5B0%5D%5B%5D=13&a%5B3%5D%5Bb%5D%5B5%5D%5Be%5D%5Bf%5D%5Bg%5D%5B%5D=14&a%5B3%5D%5Bb%5D%5B5%5D%5Be%5D%5Bf%5D%5Bg%5D%5B1%5D%5B%5D=15&a%5B3%5D%5Bb%5D%5B%5D=16&a%5B%5D=17",
|
||||
"nested arrays"
|
||||
)
|
||||
|
||||
assert_query_string(
|
||||
{ a= {1,2,3}, ["b[]"]= {4,5,6}, ["c[d]"]= {7,8,9}, e= { f= {10}, g= {11,12}, h= 13 } },
|
||||
"a%5B%5D=1&a%5B%5D=2&a%5B%5D=3&b%5B%5D=4&b%5B%5D=5&b%5B%5D=6&c%5Bd%5D%5B%5D=7&c%5Bd%5D%5B%5D=8&c%5Bd%5D%5B%5D=9&e%5Bf%5D%5B%5D=10&e%5Bg%5D%5B%5D=11&e%5Bg%5D%5B%5D=12&e%5Bh%5D=13",
|
||||
"make sure params are not double-encoded"
|
||||
)
|
||||
|
||||
`)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
} else {
|
||||
if expected := ``; expected != output {
|
||||
t.Error(output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestResolve(t *testing.T) {
|
||||
output, err := evalScript(`
|
||||
local url = require("url")
|
||||
|
||||
print(url.resolve('/one/two/three', 'four'))
|
||||
print(url.resolve('http://example.com/', '/one'))
|
||||
print(url.resolve('http://example.com/one', '/two'))
|
||||
print(url.resolve('https://example.com/one', '//example2.com'))
|
||||
`)
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Failed to evaluate script: %s", err)
|
||||
} else {
|
||||
if expected := `/one/two/four
|
||||
http://example.com/one
|
||||
http://example.com/two
|
||||
https://example2.com
|
||||
`; expected != output {
|
||||
t.Errorf("Expected output does not match actual output\nExpected: %s\nActual: %s", expected, output)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func evalScript(script string) (string, error) {
|
||||
L := lua.NewState()
|
||||
defer L.Close()
|
||||
|
||||
L.PreloadModule("url", Loader)
|
||||
|
||||
var err error
|
||||
|
||||
out := captureStdout(func() {
|
||||
err = L.DoString(script)
|
||||
})
|
||||
|
||||
return out, err
|
||||
}
|
||||
|
||||
func captureStdout(inner func()) string {
|
||||
oldStdout := os.Stdout
|
||||
r, w, _ := os.Pipe()
|
||||
os.Stdout = w
|
||||
|
||||
outC := make(chan string)
|
||||
go func() {
|
||||
var buf bytes.Buffer
|
||||
io.Copy(&buf, r)
|
||||
outC <- buf.String()
|
||||
}()
|
||||
|
||||
inner()
|
||||
|
||||
w.Close()
|
||||
os.Stdout = oldStdout
|
||||
out := strings.Replace(<-outC, "\r", "", -1)
|
||||
|
||||
return out
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
# Compiled Object files, Static and Dynamic libs (Shared Objects)
|
||||
*.o
|
||||
*.a
|
||||
*.so
|
||||
|
||||
# Folders
|
||||
_obj
|
||||
_test
|
||||
|
||||
# Architecture specific extensions/prefixes
|
||||
*.[568vq]
|
||||
[568vq].out
|
||||
|
||||
*.cgo1.go
|
||||
*.cgo2.c
|
||||
_cgo_defun.c
|
||||
_cgo_gotypes.go
|
||||
_cgo_export.*
|
||||
|
||||
_testmain.go
|
||||
|
||||
*.exe
|
||||
*.test
|
||||
*.prof
|
|
@ -1,10 +0,0 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.2
|
||||
- 1.3
|
||||
- 1.3.3
|
||||
- 1.4
|
||||
- tip
|
||||
|
||||
install: go get -t -tags integration ./...
|
||||
script: go test -tags integration
|
|
@ -1,340 +0,0 @@
|
|||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc., <http://fsf.org/>
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
{description}
|
||||
Copyright (C) {year} {fullname}
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
{signature of Ty Coon}, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
dotsql [![Build Status](https://travis-ci.org/gchaincl/dotsql.svg)](https://travis-ci.org/gchaincl/dotsql)
|
||||
======
|
||||
|
||||
A Golang library for using SQL.
|
||||
|
||||
It is not an ORM, it is not a query builder. Dotsql is a library that helps you
|
||||
keep sql files in one place and use it with ease.
|
||||
|
||||
_Dotsql is heavily inspired by_ [yesql](https://github.com/krisajenkins/yesql).
|
||||
|
||||
Installation
|
||||
--
|
||||
Simple install the package to your `$GOPATH` with the `go` tool from shell:
|
||||
```bash
|
||||
$ go get github.com/gchaincl/dotsql
|
||||
```
|
||||
Make sure Git is installed on your machine and in your system's `$PATH`
|
||||
|
||||
Usage [![GoDoc](https://godoc.org/github.com/gchaincl/dotsql?status.svg)](https://godoc.org/github.com/gchaincl/dotsql)
|
||||
--
|
||||
|
||||
First of all, you need to define queries into a file:
|
||||
|
||||
```sql
|
||||
-- name: create-users-table
|
||||
CREATE TABLE users (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
name VARCHAR(255),
|
||||
email VARCHAR(255)
|
||||
);
|
||||
-- name: create-user
|
||||
INSERT INTO users (name, email) VALUES(?, ?)
|
||||
-- name: find-one-user-by-email
|
||||
SELECT id,name,email FROM users WHERE email = ? LIMIT 1
|
||||
--name: drop-users-table
|
||||
DROP TABLE users
|
||||
```
|
||||
|
||||
Notice that every query has a name tag (`--name:<some name>`),
|
||||
this will be helpful for referring to a specific query
|
||||
|
||||
Then you should be able to run something like:
|
||||
|
||||
```go
|
||||
// Get a database handle
|
||||
db, err := sql.Open("sqlite3", ":memory:")
|
||||
|
||||
// Loads queries from file
|
||||
dot, err := dotsql.LoadFromFile("queries.sql")
|
||||
|
||||
// Run queries
|
||||
res, err := dot.Exec(db, "create-users-table")
|
||||
res, err := dot.Exec(db, "create-user", "User Name", "main@example.com")
|
||||
rows, err := dot.Query(db, "find-one-user-by-email", "main@example.com")
|
||||
|
||||
stmt, err := dot.Prepare(db, "drop-users-table")
|
||||
result, err := stmt.Exec()
|
||||
```
|
||||
|
||||
For a complete example please refer to [integration_test.go](https://github.com/gchaincl/dotsql/blob/master/integration_test.go) and [test_schema.sql](https://github.com/gchaincl/dotsql/blob/master/test_schema.sql)
|
||||
|
||||
Development
|
||||
--
|
||||
|
||||
Dotsql is in a very early stage so api may change. Contributions are welcome!
|
||||
Integration tests are tagged with `+integration`, so if you want to run them you should:
|
||||
```bash
|
||||
go test -tags=integration
|
||||
```
|
||||
_If integration tests takes too long remember to_ `go install code.google.com/p/go-sqlite/go1/sqlite3`
|
||||
|
||||
Otherwise just run:
|
||||
```bash
|
||||
go test
|
||||
```
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue