Skip to content

Commit

Permalink
Merge pull request #10 from bitmaelum/softdelete
Browse files Browse the repository at this point in the history
initial commit on softdelete
  • Loading branch information
jaytaph authored Mar 9, 2021
2 parents 4a44a64 + 846b13b commit a4d1901
Show file tree
Hide file tree
Showing 34 changed files with 1,657 additions and 205 deletions.
12 changes: 5 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ jobs:
test:
strategy:
matrix:
go-version: [ 1.13.x, 1.14.x, 1.15.x ]
os: [ ubuntu-latest ]
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x ]
os: [ ubuntu-20.04 ]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
Expand Down Expand Up @@ -38,9 +38,7 @@ jobs:
- name: Go test
run: |
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
- name: Upload coverage report
uses: codecov/codecov-action@v1
- name: Upload coverage report to coverall
uses: shogo82148/actions-goveralls@v1
with:
file: ./coverage.txt
flags: unittests
name: codecov-umbrella
path-to-profile: coverage.txt
3 changes: 2 additions & 1 deletion .github/workflows/deploy_staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
apt-get install -y zip awscli
- name: Build and zip
run: |
CGO_ENABLED=0 GOOS=linux go build -o main cmd/lambda/main.go
COMMIT=$(shell git rev-parse HEAD)
CGO_ENABLED=0 GOOS=linux go build -o main -X 'github.com/bitmaelum/key-resolver-go/internal.GitCommit=${COMMIT}' cmd/lambda/main.go
zip -r ./function.zip main
- name: deploy zip to lambda
run: |
Expand Down
19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
<img alt="logo" align=right height=70 src="https://bitmaelum.com/logo_and_name.svg">

[![Go Report Card](https://goreportcard.com/badge/github.com/bitmaelum/key-resolver-go)](https://goreportcard.com/report/github.com/bitmaelum/key-resolver-go)
![BitMaelum CI](https://github.com/bitmaelum/key-resolver-go/workflows/BitMaelum%20CI/badge.svg?branch=develop)
[![codecov](https://codecov.io/gh/bitmaelum/key-resolver-go/branch/develop/graph/badge.svg)](https://codecov.io/gh/bitmaelum/key-resolver-go)
[![BitMaelum Key Resolver](https://github.com/bitmaelum/key-resolver-go/actions/workflows/ci.yml/badge.svg)](https://github.com/bitmaelum/key-resolver-go/actions/workflows/ci.yml)
[![Coverage Status](https://coveralls.io/repos/github/bitmaelum/key-resolver-go/badge.svg?branch=master)](https://coveralls.io/github/bitmaelum/key-resolver-go?branch=master)
![License](https://img.shields.io/github/license/bitmaelum/key-resolver-go)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/bitmaelum/key-resolver-go)
[![Gitter](https://badges.gitter.im/bitmaelum/community.svg)](https://gitter.im/bitmaelum/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=bitmaelum_bitmaelum-suite&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=bitmaelum_bitmaelum-suite)


____ _ _ __ __ _
| _ \(_) | | \/ | | |
| |_) |_| |_| \ / | __ _ ___| |_ _ _ __ ___
| _ <| | __| |\/| |/ _` |/ _ \ | | | | '_ ` _ \
| |_) | | |_| | | | (_| | __/ | |_| | | | | | |
|____/|_|\__|_| |_|\__,_|\___|_|\__,_|_| |_| |_|
P r i v a c y i s y o u r s a g a i n

# Key resolver
<hr>

[![codecov](https://codecov.io/gh/bitmaelum/key-resolver-go/branch/develop/graph/badge.svg?token=IHXRZZO8KQ)](undefined)
# Key resolver

This repository holds the (centralized) account and routing resolver for BitMaelum.

Expand Down
3 changes: 3 additions & 0 deletions cmd/bm-keyresolver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ func main() {
router.HandleFunc("/address/{hash}", requestWrapper(handler.DeleteAddressHash)).Methods("DELETE")
router.HandleFunc("/address/{hash}", requestWrapper(handler.PostAddressHash)).Methods("POST")

router.HandleFunc("/address/{hash}/status/{fingerprint}", requestWrapper(handler.GetKeyStatus)).Methods("GET")
router.HandleFunc("/address/{hash}/status/{fingerprint}", requestWrapper(handler.SetKeyStatus)).Methods("POST")

router.HandleFunc("/routing/{hash}", requestWrapper(handler.GetRoutingHash)).Methods("GET")
router.HandleFunc("/routing/{hash}", requestWrapper(handler.DeleteRoutingHash)).Methods("DELETE")
router.HandleFunc("/routing/{hash}", requestWrapper(handler.PostRoutingHash)).Methods("POST")
Expand Down
48 changes: 24 additions & 24 deletions cmd/lambda/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,26 @@ import (
"github.com/bitmaelum/key-resolver-go/internal/http"
)

type HandlerFunc func(hash.Hash, http.Request) *http.Response

var handlerMapping = map[string]HandlerFunc{
"GET /address/{hash}": handler.GetAddressHash,
"POST /address/{hash}/delete": handler.SoftDeleteAddressHash,
"POST /address/{hash}/undelete": handler.SoftUndeleteAddressHash,
"GET /address/{hash}/status/{fingerprint}": handler.GetKeyStatus,
"POST /address/{hash}/status/{fingerprint}": handler.SetKeyStatus,
"DELETE /address/{hash}": handler.DeleteAddressHash,
"POST /address/{hash}": handler.PostAddressHash,
"GET /routing/{hash}": handler.GetRoutingHash,
"DELETE /routing/{hash}": handler.DeleteRoutingHash,
"POST /routing/{hash}": handler.PostRoutingHash,
"GET /organisation/{hash}": handler.GetOrganisationHash,
"POST /organisation/{hash}/delete": handler.SoftDeleteOrganisationHash,
"POST /organisation/{hash}/undelete": handler.SoftUndeleteOrganisationHash,
"DELETE /organisation/{hash}": handler.DeleteOrganisationHash,
"POST /organisation/{hash}": handler.PostOrganisationHash,
}

// HandleRequest checks the incoming route and calls the correct handler for it
func HandleRequest(req events.APIGatewayV2HTTPRequest) (*events.APIGatewayV2HTTPResponse, error) {
if req.RouteKey == "GET /" {
Expand All @@ -53,30 +73,10 @@ func HandleRequest(req events.APIGatewayV2HTTPRequest) (*events.APIGatewayV2HTTP
var httpResp *http.Response
httpReq := apigateway.ReqToHTTP(&req)

switch req.RouteKey {
// Address endpoints
case "GET /address/{hash}":
httpResp = handler.GetAddressHash(*h, *httpReq)
case "DELETE /address/{hash}":
httpResp = handler.DeleteAddressHash(*h, *httpReq)
case "POST /address/{hash}":
httpResp = handler.PostAddressHash(*h, *httpReq)

// Routing endpoints
case "GET /routing/{hash}":
httpResp = handler.GetRoutingHash(*h, *httpReq)
case "DELETE /routing/{hash}":
httpResp = handler.DeleteRoutingHash(*h, *httpReq)
case "POST /routing/{hash}":
httpResp = handler.PostRoutingHash(*h, *httpReq)

// Organisation endpoints
case "GET /organisation/{hash}":
httpResp = handler.GetOrganisationHash(*h, *httpReq)
case "DELETE /organisation/{hash}":
httpResp = handler.DeleteOrganisationHash(*h, *httpReq)
case "POST /organisation/{hash}":
httpResp = handler.PostOrganisationHash(*h, *httpReq)
// Check mapping and call correct handler func
f, ok := handlerMapping[req.RouteKey]
if ok {
httpResp = f(*h, *httpReq)
}

if httpResp == nil {
Expand Down
13 changes: 13 additions & 0 deletions cmd/lambda/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,16 @@ func TestHandleRequest404(t *testing.T) {
assert.Equal(t, "application/json", res.Headers["Content-Type"])
assert.Equal(t, "{\n \"error\": \"Forbidden\"\n}", res.Body)
}

func TestHandleConfig(t *testing.T) {
req := &events.APIGatewayV2HTTPRequest{
RouteKey: "GET /config.json",
}

res, err := HandleRequest(*req)
assert.NoError(t, err)

assert.Equal(t, 200, res.StatusCode)
assert.Equal(t, "application/json", res.Headers["Content-Type"])
assert.JSONEq(t, res.Body, "{\"proof_of_work\":{\"address\": 27,\"organisation\":29}}")
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ require (
github.com/aws/aws-lambda-go v1.19.1
github.com/aws/aws-sdk-go v1.34.14
github.com/bitmaelum/bitmaelum-suite v0.0.0-20201115094342-919e00359ffc
github.com/boltdb/bolt v1.3.1
github.com/gorilla/mux v1.7.4
github.com/gusaul/go-dynamock v0.0.0-20200325102056-aaeeb0c0e9c1
github.com/mattn/go-sqlite3 v1.14.1
github.com/stretchr/testify v1.6.1
go.etcd.io/bbolt v1.3.5
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/bitmaelum/bitmaelum-suite v0.0.0-20201115094342-919e00359ffc h1:12qg9x0s9a38ru7UvggYKxTFnVt3zlDc5xwr8sJY4OY=
github.com/bitmaelum/bitmaelum-suite v0.0.0-20201115094342-919e00359ffc/go.mod h1:t5Rc5fsWnZsjIh3S2PW4xgl07+rPr/CA3QO1apvDHSc=
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -183,6 +181,7 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
github.com/zalando/go-keyring v0.1.0/go.mod h1:RaxNwUITJaHVdQ0VC7pELPZ3tOWn13nr0gZMZEhpVU0=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
go.opentelemetry.io/otel v0.11.0/go.mod h1:G8UCk+KooF2HLkgo8RHX9epABH/aRGYET7gQOqBVdB0=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
Expand Down Expand Up @@ -259,6 +258,7 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
Expand Down
Loading

0 comments on commit a4d1901

Please sign in to comment.