Skip to content

Commit

Permalink
Replace Cayley with SQLite3
Browse files Browse the repository at this point in the history
  • Loading branch information
dstotijn committed Oct 4, 2020
1 parent d48f1f0 commit ba7d88d
Show file tree
Hide file tree
Showing 22 changed files with 649 additions and 861 deletions.
43 changes: 35 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
env:
- GO111MODULE=on
- CGO_ENABLED=1
before:
hooks:
- make clean
- go mod download
- go generate ./...
- make embed
builds:
- main: ./cmd/hetty
- id: hetty-darwin-amd64
main: ./cmd/hetty
goarch:
- amd64
goos:
- darwin
env:
- CGO_ENABLED=0
- CC=o64-clang
- CXX=o64-clang++
flags:
- -mod=readonly
ldflags:
- id: hetty-linux-amd64
main: ./cmd/hetty
goarch:
- amd64
goos:
- linux
flags:
- -mod=readonly
ldflags:
- id: hetty-windows-amd64
main: ./cmd/hetty
goarch:
- amd64
goos:
- windows
- darwin
hooks:
pre: make embed
env:
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
flags:
- -mod=readonly
ldflags:
- -buildmode=exe
archives:
- replacements:
darwin: Darwin
darwin: macOS
linux: Linux
windows: Windows
386: i386
Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
ARG GO_VERSION=1.15
ARG CGO_ENABLED=0
ARG CGO_ENABLED=1
ARG NODE_VERSION=14.11

FROM golang:${GO_VERSION}-alpine AS go-builder
WORKDIR /app
RUN apk add --no-cache build-base
COPY go.mod go.sum ./
RUN go mod download
COPY cmd ./cmd
Expand Down
29 changes: 27 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
PACKAGE_NAME := github.com/dstotijn/hetty
GOLANG_CROSS_VERSION ?= v1.15.2

setup:
go mod download
go generate ./...
Expand All @@ -9,12 +12,34 @@ embed:
.PHONY: embed

build: embed
go build ./cmd/hetty
env CGO_ENABLED=1 go build ./cmd/hetty
.PHONY: build

clean:
rm -rf cmd/hetty/rice-box.go
.PHONY: clean

release-dry-run:
@docker run \
--rm \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/admin/dist:/go/src/$(PACKAGE_NAME)/admin/dist \
-w /go/src/$(PACKAGE_NAME) \
troian/golang-cross:${GOLANG_CROSS_VERSION} \
--rm-dist --skip-validate --skip-publish
.PHONY: release-dry-run

release:
goreleaser -p 1
@if [ ! -f ".release-env" ]; then \
echo "\033[91mFile \`.release-env\` is missing.\033[0m";\
exit 1;\
fi
@docker run \
--rm \
-v `pwd`:/go/src/$(PACKAGE_NAME) \
-v `pwd`/admin/dist:/go/src/$(PACKAGE_NAME)/admin/dist \
-w /go/src/$(PACKAGE_NAME) \
--env-file .release-env \
troian/golang-cross:${GOLANG_CROSS_VERSION} \
release --rm-dist
.PHONY: release
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ on Docker Hub.
$ docker run \
-v $HOME/.hetty/hetty_key.pem:/root/.hetty/hetty_key.pem \
-v $HOME/.hetty/hetty_cert.pem:/root/.hetty/hetty_cert.pem \
-v $HOME/.hetty/hetty.bolt:/root/.hetty/hetty.bolt \
-v $HOME/.hetty/hetty.db:/root/.hetty/hetty.db \
-p 127.0.0.1:8080:8080 \
dstotijn/hetty
```
Expand All @@ -81,7 +81,7 @@ Usage of ./hetty:
-cert string
CA certificate filepath. Creates a new CA certificate is file doesn't exist (default "~/.hetty/hetty_cert.pem")
-db string
Database file path (default "~/.hetty/hetty.bolt")
Database file path (default "~/.hetty/hetty.db")
-key string
CA private key filepath. Creates a new CA private key if file doesn't exist (default "~/.hetty/hetty_key.pem")
```
Expand All @@ -103,11 +103,6 @@ write-up on its mission and roadmap. A short summary/braindump:
it as a CLI tool.
- Pluggable architecture for the MITM proxy and future modules, making it
possible for hook into the core engine.
- I’ve chosen [Cayley](https://cayley.io/) as the graph database (backed by
BoltDB storage on disk) for now (not sure if it will work in the long run).
The benefit is that Cayley (also written in Go)
is embedded as a library. Because of this, the complete application is self contained
in a single running binary.
- Talk to the community, and focus on the features that the majority.
Less features means less code to maintain.

Expand Down
2 changes: 1 addition & 1 deletion admin/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function Layout({ title, page, children }: Props): JSX.Element {
<MenuIcon />
</IconButton>
<Typography variant="h5" noWrap>
<span className={title !== "" && classes.titleHighlight}>
<span className={title !== "" ? classes.titleHighlight : ""}>
Hetty://
</span>
{title}
Expand Down
2 changes: 1 addition & 1 deletion admin/src/components/reqlog/LogDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const HTTP_REQUEST_LOG = gql`
`;

interface Props {
requestId: string;
requestId: number;
}

function LogDetail({ requestId: id }: Props): JSX.Element {
Expand Down
6 changes: 3 additions & 3 deletions admin/src/components/reqlog/LogsOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ const HTTP_REQUEST_LOGS = gql`

function LogsOverview(): JSX.Element {
const router = useRouter();
const detailReqLogId = router.query.id as string;
console.log(detailReqLogId);
const detailReqLogId =
router.query.id && parseInt(router.query.id as string, 10);

const { loading, error, data } = useQuery(HTTP_REQUEST_LOGS, {
pollInterval: 1000,
});

const handleLogClick = (reqId: string) => {
const handleLogClick = (reqId: number) => {
router.push("/proxy/logs?id=" + reqId, undefined, {
shallow: false,
});
Expand Down
8 changes: 4 additions & 4 deletions admin/src/components/reqlog/RequestList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const useStyles = makeStyles((theme: Theme) =>

interface Props {
logs: Array<any>;
selectedReqLogId?: string;
onLogClick(requestId: string): void;
selectedReqLogId?: number;
onLogClick(requestId: number): void;
theme: Theme;
}

Expand Down Expand Up @@ -63,8 +63,8 @@ function RequestList({

interface RequestListTableProps {
logs?: any;
selectedReqLogId?: string;
onLogClick(requestId: string): void;
selectedReqLogId?: number;
onLogClick(requestId: number): void;
theme: Theme;
}

Expand Down
6 changes: 3 additions & 3 deletions cmd/hetty/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

rice "github.com/GeertJohan/go.rice"
"github.com/dstotijn/hetty/pkg/api"
"github.com/dstotijn/hetty/pkg/db/cayley"
"github.com/dstotijn/hetty/pkg/db/sqlite"
"github.com/dstotijn/hetty/pkg/proxy"
"github.com/dstotijn/hetty/pkg/reqlog"
"github.com/dstotijn/hetty/pkg/scope"
Expand All @@ -33,7 +33,7 @@ var (
func main() {
flag.StringVar(&caCertFile, "cert", "~/.hetty/hetty_cert.pem", "CA certificate filepath. Creates a new CA certificate is file doesn't exist")
flag.StringVar(&caKeyFile, "key", "~/.hetty/hetty_key.pem", "CA private key filepath. Creates a new CA private key if file doesn't exist")
flag.StringVar(&dbFile, "db", "~/.hetty/hetty.bolt", "Database file path")
flag.StringVar(&dbFile, "db", "~/.hetty/hetty.db", "Database file path")
flag.StringVar(&addr, "addr", ":8080", "TCP address to listen on, in the form \"host:port\"")
flag.StringVar(&adminPath, "adminPath", "", "File path to admin build")
flag.Parse()
Expand All @@ -59,7 +59,7 @@ func main() {
log.Fatalf("[FATAL] Could not create/load CA key pair: %v", err)
}

db, err := cayley.NewDatabase(dbFile)
db, err := sqlite.New(dbFile)
if err != nil {
log.Fatalf("[FATAL] Could not initialize database: %v", err)
}
Expand Down
9 changes: 4 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ go 1.15
require (
github.com/99designs/gqlgen v0.11.3
github.com/GeertJohan/go.rice v1.0.0
github.com/cayleygraph/cayley v0.7.7
github.com/cayleygraph/quad v1.1.0
github.com/google/uuid v1.1.2
github.com/gorilla/mux v1.7.4
github.com/hidal-go/hidalgo v0.0.0-20190814174001-42e03f3b5eaa
github.com/gorilla/websocket v1.4.0 // indirect
github.com/hashicorp/golang-lru v0.5.1 // indirect
github.com/mattn/go-sqlite3 v1.14.4
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.1.2 // indirect
github.com/vektah/gqlparser/v2 v2.0.1
golang.org/x/tools v0.0.0-20200925191224-5d1fdd8fa346 // indirect
)
Loading

0 comments on commit ba7d88d

Please sign in to comment.