Skip to content

Commit a4d1901

Browse files
authored
Merge pull request #10 from bitmaelum/softdelete
initial commit on softdelete
2 parents 4a44a64 + 846b13b commit a4d1901

34 files changed

+1657
-205
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ jobs:
44
test:
55
strategy:
66
matrix:
7-
go-version: [ 1.13.x, 1.14.x, 1.15.x ]
8-
os: [ ubuntu-latest ]
7+
go-version: [ 1.13.x, 1.14.x, 1.15.x, 1.16.x ]
8+
os: [ ubuntu-20.04 ]
99
runs-on: ${{ matrix.os }}
1010
steps:
1111
- name: Install Go
@@ -38,9 +38,7 @@ jobs:
3838
- name: Go test
3939
run: |
4040
go test -race -coverprofile=coverage.txt -covermode=atomic ./...
41-
- name: Upload coverage report
42-
uses: codecov/codecov-action@v1
41+
- name: Upload coverage report to coverall
42+
uses: shogo82148/actions-goveralls@v1
4343
with:
44-
file: ./coverage.txt
45-
flags: unittests
46-
name: codecov-umbrella
44+
path-to-profile: coverage.txt

.github/workflows/deploy_staging.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
apt-get install -y zip awscli
1717
- name: Build and zip
1818
run: |
19-
CGO_ENABLED=0 GOOS=linux go build -o main cmd/lambda/main.go
19+
COMMIT=$(shell git rev-parse HEAD)
20+
CGO_ENABLED=0 GOOS=linux go build -o main -X 'github.com/bitmaelum/key-resolver-go/internal.GitCommit=${COMMIT}' cmd/lambda/main.go
2021
zip -r ./function.zip main
2122
- name: deploy zip to lambda
2223
run: |

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,16 @@
1+
<img alt="logo" align=right height=70 src="https://bitmaelum.com/logo_and_name.svg">
2+
13
[![Go Report Card](https://goreportcard.com/badge/github.com/bitmaelum/key-resolver-go)](https://goreportcard.com/report/github.com/bitmaelum/key-resolver-go)
2-
![BitMaelum CI](https://github.com/bitmaelum/key-resolver-go/workflows/BitMaelum%20CI/badge.svg?branch=develop)
3-
[![codecov](https://codecov.io/gh/bitmaelum/key-resolver-go/branch/develop/graph/badge.svg)](https://codecov.io/gh/bitmaelum/key-resolver-go)
4+
[![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)
5+
[![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)
46
![License](https://img.shields.io/github/license/bitmaelum/key-resolver-go)
57
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/bitmaelum/key-resolver-go)
6-
[![Gitter](https://badges.gitter.im/bitmaelum/community.svg)](https://gitter.im/bitmaelum/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
78
[![Maintainability Rating](https://sonarcloud.io/api/project_badges/measure?project=bitmaelum_bitmaelum-suite&metric=sqale_rating)](https://sonarcloud.io/dashboard?id=bitmaelum_bitmaelum-suite)
89

9-
10-
____ _ _ __ __ _
11-
| _ \(_) | | \/ | | |
12-
| |_) |_| |_| \ / | __ _ ___| |_ _ _ __ ___
13-
| _ <| | __| |\/| |/ _` |/ _ \ | | | | '_ ` _ \
14-
| |_) | | |_| | | | (_| | __/ | |_| | | | | | |
15-
|____/|_|\__|_| |_|\__,_|\___|_|\__,_|_| |_| |_|
16-
P r i v a c y i s y o u r s a g a i n
1710

18-
# Key resolver
11+
<hr>
1912

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

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

cmd/bm-keyresolver/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ func main() {
117117
router.HandleFunc("/address/{hash}", requestWrapper(handler.DeleteAddressHash)).Methods("DELETE")
118118
router.HandleFunc("/address/{hash}", requestWrapper(handler.PostAddressHash)).Methods("POST")
119119

120+
router.HandleFunc("/address/{hash}/status/{fingerprint}", requestWrapper(handler.GetKeyStatus)).Methods("GET")
121+
router.HandleFunc("/address/{hash}/status/{fingerprint}", requestWrapper(handler.SetKeyStatus)).Methods("POST")
122+
120123
router.HandleFunc("/routing/{hash}", requestWrapper(handler.GetRoutingHash)).Methods("GET")
121124
router.HandleFunc("/routing/{hash}", requestWrapper(handler.DeleteRoutingHash)).Methods("DELETE")
122125
router.HandleFunc("/routing/{hash}", requestWrapper(handler.PostRoutingHash)).Methods("POST")

cmd/lambda/main.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,26 @@ import (
3434
"github.com/bitmaelum/key-resolver-go/internal/http"
3535
)
3636

37+
type HandlerFunc func(hash.Hash, http.Request) *http.Response
38+
39+
var handlerMapping = map[string]HandlerFunc{
40+
"GET /address/{hash}": handler.GetAddressHash,
41+
"POST /address/{hash}/delete": handler.SoftDeleteAddressHash,
42+
"POST /address/{hash}/undelete": handler.SoftUndeleteAddressHash,
43+
"GET /address/{hash}/status/{fingerprint}": handler.GetKeyStatus,
44+
"POST /address/{hash}/status/{fingerprint}": handler.SetKeyStatus,
45+
"DELETE /address/{hash}": handler.DeleteAddressHash,
46+
"POST /address/{hash}": handler.PostAddressHash,
47+
"GET /routing/{hash}": handler.GetRoutingHash,
48+
"DELETE /routing/{hash}": handler.DeleteRoutingHash,
49+
"POST /routing/{hash}": handler.PostRoutingHash,
50+
"GET /organisation/{hash}": handler.GetOrganisationHash,
51+
"POST /organisation/{hash}/delete": handler.SoftDeleteOrganisationHash,
52+
"POST /organisation/{hash}/undelete": handler.SoftUndeleteOrganisationHash,
53+
"DELETE /organisation/{hash}": handler.DeleteOrganisationHash,
54+
"POST /organisation/{hash}": handler.PostOrganisationHash,
55+
}
56+
3757
// HandleRequest checks the incoming route and calls the correct handler for it
3858
func HandleRequest(req events.APIGatewayV2HTTPRequest) (*events.APIGatewayV2HTTPResponse, error) {
3959
if req.RouteKey == "GET /" {
@@ -53,30 +73,10 @@ func HandleRequest(req events.APIGatewayV2HTTPRequest) (*events.APIGatewayV2HTTP
5373
var httpResp *http.Response
5474
httpReq := apigateway.ReqToHTTP(&req)
5575

56-
switch req.RouteKey {
57-
// Address endpoints
58-
case "GET /address/{hash}":
59-
httpResp = handler.GetAddressHash(*h, *httpReq)
60-
case "DELETE /address/{hash}":
61-
httpResp = handler.DeleteAddressHash(*h, *httpReq)
62-
case "POST /address/{hash}":
63-
httpResp = handler.PostAddressHash(*h, *httpReq)
64-
65-
// Routing endpoints
66-
case "GET /routing/{hash}":
67-
httpResp = handler.GetRoutingHash(*h, *httpReq)
68-
case "DELETE /routing/{hash}":
69-
httpResp = handler.DeleteRoutingHash(*h, *httpReq)
70-
case "POST /routing/{hash}":
71-
httpResp = handler.PostRoutingHash(*h, *httpReq)
72-
73-
// Organisation endpoints
74-
case "GET /organisation/{hash}":
75-
httpResp = handler.GetOrganisationHash(*h, *httpReq)
76-
case "DELETE /organisation/{hash}":
77-
httpResp = handler.DeleteOrganisationHash(*h, *httpReq)
78-
case "POST /organisation/{hash}":
79-
httpResp = handler.PostOrganisationHash(*h, *httpReq)
76+
// Check mapping and call correct handler func
77+
f, ok := handlerMapping[req.RouteKey]
78+
if ok {
79+
httpResp = f(*h, *httpReq)
8080
}
8181

8282
if httpResp == nil {

cmd/lambda/main_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,16 @@ func TestHandleRequest404(t *testing.T) {
6969
assert.Equal(t, "application/json", res.Headers["Content-Type"])
7070
assert.Equal(t, "{\n \"error\": \"Forbidden\"\n}", res.Body)
7171
}
72+
73+
func TestHandleConfig(t *testing.T) {
74+
req := &events.APIGatewayV2HTTPRequest{
75+
RouteKey: "GET /config.json",
76+
}
77+
78+
res, err := HandleRequest(*req)
79+
assert.NoError(t, err)
80+
81+
assert.Equal(t, 200, res.StatusCode)
82+
assert.Equal(t, "application/json", res.Headers["Content-Type"])
83+
assert.JSONEq(t, res.Body, "{\"proof_of_work\":{\"address\": 27,\"organisation\":29}}")
84+
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ require (
66
github.com/aws/aws-lambda-go v1.19.1
77
github.com/aws/aws-sdk-go v1.34.14
88
github.com/bitmaelum/bitmaelum-suite v0.0.0-20201115094342-919e00359ffc
9-
github.com/boltdb/bolt v1.3.1
109
github.com/gorilla/mux v1.7.4
1110
github.com/gusaul/go-dynamock v0.0.0-20200325102056-aaeeb0c0e9c1
1211
github.com/mattn/go-sqlite3 v1.14.1
1312
github.com/stretchr/testify v1.6.1
13+
go.etcd.io/bbolt v1.3.5
1414
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
1515
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
1616
github.com/bitmaelum/bitmaelum-suite v0.0.0-20201115094342-919e00359ffc h1:12qg9x0s9a38ru7UvggYKxTFnVt3zlDc5xwr8sJY4OY=
1717
github.com/bitmaelum/bitmaelum-suite v0.0.0-20201115094342-919e00359ffc/go.mod h1:t5Rc5fsWnZsjIh3S2PW4xgl07+rPr/CA3QO1apvDHSc=
18-
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
19-
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
2018
github.com/c2h5oh/datasize v0.0.0-20200112174442-28bbd4740fee/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M=
2119
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
2220
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
@@ -183,6 +181,7 @@ github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q
183181
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
184182
github.com/zalando/go-keyring v0.1.0/go.mod h1:RaxNwUITJaHVdQ0VC7pELPZ3tOWn13nr0gZMZEhpVU0=
185183
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
184+
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
186185
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
187186
go.opentelemetry.io/otel v0.11.0/go.mod h1:G8UCk+KooF2HLkgo8RHX9epABH/aRGYET7gQOqBVdB0=
188187
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
@@ -259,6 +258,7 @@ golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3
259258
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
260259
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
261260
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
261+
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
262262
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
263263
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
264264
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=

0 commit comments

Comments
 (0)