Compare commits
91 Commits
lash/event
...
master
Author | SHA1 | Date | |
---|---|---|---|
d2f75c693a | |||
363c35efed | |||
0f361a065b | |||
|
4d1045a9f9 | ||
|
f3a6485bb3 | ||
cd37adc288 | |||
6f0994d692 | |||
|
fbaba15776 | ||
|
9a094f440f | ||
6c77ff58ab | |||
c8ddafcf66 | |||
5f1a659789 | |||
0d4be0f7fc | |||
b6161da749 | |||
f1c4d5f1f9 | |||
73b876dbdd | |||
18e865ba26 | |||
d7c909f028 | |||
908a52cda6 | |||
526dc822fb | |||
1249e45d54 | |||
|
99d03e3bc9 | ||
|
1e495763f5 | ||
|
5e83c89e03 | ||
|
1909b60bf4 | ||
|
49335a290f | ||
|
2c8e60e1bb | ||
|
4baacb325d | ||
|
c243edd4c4 | ||
44846c5950 | |||
|
592c57b72d | ||
|
341f0b9cc8 | ||
|
1c911ee73f | ||
|
00b9079a55 | ||
ec6b078de3 | |||
0b4fde9d1e | |||
66be350ad1 | |||
|
156511e499 | ||
|
8b68130ed4 | ||
|
7ab8eef623 | ||
7d513ac2a7 | |||
fbee26da08 | |||
4fb3474b51 | |||
|
b31011b390 | ||
|
358567e52e | ||
9c05e0b4a2 | |||
57fb1d0ef3 | |||
2dcec2e9fb | |||
286a72f12e | |||
|
933943636e | ||
1e69f2167a | |||
4e584cea92 | |||
|
20feef4103 | ||
|
8d5d3f1dc8 | ||
|
0f54ab4b4a | ||
|
be47c999ca | ||
|
c719db8b92 | ||
|
16cb2846b7 | ||
|
bc2abc2464 | ||
f435046385 | |||
efaf0ab22e | |||
e29bcb5b27 | |||
cdb22f8cbb | |||
|
9cb9e02442 | ||
6aa4bd8906 | |||
|
ab03e6d529 | ||
|
9b66146ef1 | ||
|
825c06c3bb | ||
71ff251d51 | |||
4cc0de59a7 | |||
4b8505680b | |||
104db94826 | |||
ecee5b4dee | |||
|
879baa03fc | ||
|
ecac4ae009 | ||
|
6b404f56c9 | ||
ca7dc6779a | |||
471bbea5ca | |||
|
78fae3526b | ||
|
e410158432 | ||
|
ff06b92ffd | ||
0a7152d6b8 | |||
|
47da078244 | ||
acfb6c1d76 | |||
|
f8b38dd210 | ||
|
ac492e8403 | ||
|
ac00e4619e | ||
|
604f3103c7 | ||
|
26b32a8b93 | ||
|
960a3d9075 | ||
|
55356a0c64 |
16
.dockerignore
Normal file
16
.dockerignore
Normal file
@ -0,0 +1,16 @@
|
||||
/**
|
||||
!/args
|
||||
!/cmd/africastalking
|
||||
!/cmd/ssh
|
||||
!/config
|
||||
!/debug
|
||||
!/handlers
|
||||
!/internal
|
||||
!/profile
|
||||
!/services
|
||||
!/ssh
|
||||
!/store
|
||||
!/LICENSE
|
||||
!/README.md
|
||||
!/go.*
|
||||
!/.env.example
|
@ -18,3 +18,6 @@ DATA_URL_BASE=http://localhost:5006
|
||||
#Language
|
||||
DEFAULT_LANGUAGE=eng
|
||||
LANGUAGES=eng, swa
|
||||
|
||||
#Alias search domains
|
||||
ALIAS_SEARCH_DOMAINS=sarafu.local, sarafu.eth
|
||||
|
56
.github/workflows/docker.yaml
vendored
Normal file
56
.github/workflows/docker.yaml
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
name: release
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
jobs:
|
||||
docker:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v2
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v2
|
||||
|
||||
- name: Check out repo
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Cache Docker layers
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: /tmp/.buildx-cache
|
||||
key: ${{ runner.os }}-buildx-${{ github.sha }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-buildx-
|
||||
|
||||
- name: Login to GHCR Docker registry
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Set outputs
|
||||
run: |
|
||||
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV \
|
||||
&& echo "RELEASE_SHORT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
|
||||
|
||||
- name: Build and push image
|
||||
uses: docker/build-push-action@v2
|
||||
with:
|
||||
context: ./
|
||||
file: ./Dockerfile
|
||||
platforms: linux/amd64
|
||||
push: true
|
||||
build-args: |
|
||||
BUILD=${{ env.RELEASE_SHORT_COMMIT }}
|
||||
cache-from: type=local,src=/tmp/.buildx-cache
|
||||
cache-to: type=local,dest=/tmp/.buildx-cache
|
||||
tags: |
|
||||
ghcr.io/grassrootseconomics/sarafu-vise:latest
|
||||
ghcr.io/grassrootseconomics/sarafu-vise:${{ env.RELEASE_TAG }}
|
50
Dockerfile
Normal file
50
Dockerfile
Normal file
@ -0,0 +1,50 @@
|
||||
FROM golang:1.23.4-bookworm AS build
|
||||
|
||||
ENV CGO_ENABLED=1
|
||||
|
||||
ARG BUILDPLATFORM
|
||||
ARG TARGETPLATFORM
|
||||
ARG BUILD=dev
|
||||
|
||||
WORKDIR /build
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libgdbm-dev \
|
||||
git \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
RUN git clone https://git.defalsify.org/vise.git go-vise
|
||||
COPY . ./sarafu-vise
|
||||
|
||||
WORKDIR /build/sarafu-vise/services/registration
|
||||
RUN echo "Compiling go-vise files"
|
||||
RUN make VISE_PATH=/build/go-vise -B
|
||||
|
||||
WORKDIR /build/sarafu-vise
|
||||
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
|
||||
RUN go mod download
|
||||
RUN go build -tags logtrace,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
|
||||
RUN go build -tags logtrace,online -o sarafu-ssh -ldflags="-X main.build=${BUILD} -s -w" cmd/ssh/main.go
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
libgdbm-dev \
|
||||
ca-certificates \
|
||||
&& apt-get clean \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
WORKDIR /service
|
||||
|
||||
COPY --from=build /build/sarafu-vise/sarafu-at .
|
||||
COPY --from=build /build/sarafu-vise/sarafu-ssh .
|
||||
COPY --from=build /build/sarafu-vise/LICENSE .
|
||||
COPY --from=build /build/sarafu-vise/README.md .
|
||||
COPY --from=build /build/sarafu-vise/services ./services
|
||||
COPY --from=build /build/sarafu-vise/.env.example .
|
||||
RUN mv .env.example .env
|
||||
|
||||
EXPOSE 7123
|
||||
EXPOSE 7122
|
||||
|
||||
CMD ["./sarafu-at"]
|
10
args/lang.go
10
args/lang.go
@ -10,7 +10,7 @@ type LangVar struct {
|
||||
v []lang.Language
|
||||
}
|
||||
|
||||
func(lv *LangVar) Set(s string) error {
|
||||
func (lv *LangVar) Set(s string) error {
|
||||
v, err := lang.LanguageFromCode(s)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -19,16 +19,14 @@ func(lv *LangVar) Set(s string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func(lv *LangVar) String() string {
|
||||
func (lv *LangVar) String() string {
|
||||
var s []string
|
||||
for _, v := range(lv.v) {
|
||||
for _, v := range lv.v {
|
||||
s = append(s, v.Code)
|
||||
}
|
||||
return strings.Join(s, ",")
|
||||
}
|
||||
|
||||
func(lv *LangVar) Langs() []lang.Language {
|
||||
func (lv *LangVar) Langs() []lang.Language {
|
||||
return lv.v
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,19 +12,18 @@ import (
|
||||
"syscall"
|
||||
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
|
||||
at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
|
||||
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -37,8 +36,7 @@ var (
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
var connStr string
|
||||
var resourceDir string
|
||||
override := config.NewOverride()
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
var host string
|
||||
@ -47,10 +45,11 @@ func main() {
|
||||
var gettextDir string
|
||||
var langs args.LangVar
|
||||
|
||||
|
||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||
flag.StringVar(&connStr, "c", "", "connection string")
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
|
||||
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
|
||||
flag.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.StringVar(&host, "h", config.Host(), "http host")
|
||||
flag.UintVar(&port, "p", config.Port(), "http port")
|
||||
@ -58,16 +57,14 @@ func main() {
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.Parse()
|
||||
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "build", build, "conn", connData, "resourcedir", resourceDir, "outputsize", size)
|
||||
logg.Infof("start command", "build", build, "conn", conns, "outputsize", size)
|
||||
|
||||
ctx := context.Background()
|
||||
ln, err := lang.LanguageFromCode(config.Language())
|
||||
@ -90,7 +87,7 @@ func main() {
|
||||
cfg.EngineDebug = true
|
||||
}
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
rs, err := menuStorageService.GetResource(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "menustorageservice: %v\n", err)
|
||||
@ -102,7 +99,6 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "userdatadb: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer userdataStore.Close()
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
@ -121,7 +117,8 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
accountService := &httpremote.HTTPAccountService{}
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "httpaccountservice: %v\n", err)
|
||||
@ -133,7 +130,6 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "getstatestore: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer stateStore.Close()
|
||||
|
||||
rp := &at.ATRequestParser{}
|
||||
bsh := request.NewBaseRequestHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
||||
@ -146,7 +142,10 @@ func main() {
|
||||
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
||||
Handler: mux,
|
||||
}
|
||||
s.RegisterOnShutdown(sh.Shutdown)
|
||||
shutdownFunc := func() {
|
||||
sh.Shutdown(ctx)
|
||||
}
|
||||
s.RegisterOnShutdown(shutdownFunc)
|
||||
|
||||
cint := make(chan os.Signal)
|
||||
cterm := make(chan os.Signal)
|
||||
|
@ -14,12 +14,12 @@ import (
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -44,9 +44,8 @@ func (p *asyncRequestParser) GetInput(r any) ([]byte, error) {
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
var connStr string
|
||||
override := config.NewOverride()
|
||||
var sessionId string
|
||||
var resourceDir string
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
var host string
|
||||
@ -56,8 +55,11 @@ func main() {
|
||||
var langs args.LangVar
|
||||
|
||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||
flag.StringVar(&connStr, "c", "", "connection string")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
|
||||
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.StringVar(&host, "h", config.Host(), "http host")
|
||||
@ -66,16 +68,14 @@ func main() {
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.Parse()
|
||||
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", connData, "resourcedir", resourceDir, "outputsize", size, "sessionId", sessionId)
|
||||
logg.Infof("start command", "conn", conns, "outputsize", size, "sessionId", sessionId)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@ -99,7 +99,7 @@ func main() {
|
||||
cfg.EngineDebug = true
|
||||
}
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
@ -116,7 +116,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer userdataStore.Close()
|
||||
//defer userdataStore.Close(ctx)
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
@ -125,7 +125,8 @@ func main() {
|
||||
|
||||
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
||||
lhs.SetDataStore(&userdataStore)
|
||||
accountService := &httpremote.HTTPAccountService{}
|
||||
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
if err != nil {
|
||||
@ -138,7 +139,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer stateStore.Close()
|
||||
//defer stateStore.Close(ctx)
|
||||
|
||||
rp := &asyncRequestParser{
|
||||
sessionId: sessionId,
|
||||
@ -160,7 +161,7 @@ func main() {
|
||||
case _ = <-cint:
|
||||
case _ = <-cterm:
|
||||
}
|
||||
sh.Shutdown()
|
||||
sh.Shutdown(ctx)
|
||||
}()
|
||||
|
||||
for true {
|
||||
@ -176,7 +177,7 @@ func main() {
|
||||
fmt.Errorf("error in output: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
rqs, err = sh.Reset(rqs)
|
||||
rqs, err = sh.Reset(ctx, rqs)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "error in reset: %v", "err", err)
|
||||
fmt.Errorf("error in reset: %v", err)
|
||||
|
@ -17,13 +17,13 @@ import (
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
httprequest "git.grassecon.net/grassrootseconomics/visedriver/request/http"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
httprequest "git.grassecon.net/grassrootseconomics/visedriver/request/http"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
|
||||
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -35,8 +35,7 @@ var (
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
var connStr string
|
||||
var resourceDir string
|
||||
override := config.NewOverride()
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
var host string
|
||||
@ -45,8 +44,11 @@ func main() {
|
||||
var gettextDir string
|
||||
var langs args.LangVar
|
||||
|
||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||
flag.StringVar(&connStr, "c", "", "connection string")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
|
||||
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
|
||||
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.StringVar(&host, "h", config.Host(), "http host")
|
||||
@ -55,16 +57,14 @@ func main() {
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.Parse()
|
||||
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", connData, "resourcedir", resourceDir, "outputsize", size)
|
||||
logg.Infof("start command", "conn", conns, "outputsize", size)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@ -88,7 +88,7 @@ func main() {
|
||||
cfg.EngineDebug = true
|
||||
}
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
|
||||
rs, err := menuStorageService.GetResource(ctx)
|
||||
if err != nil {
|
||||
@ -101,7 +101,6 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer userdataStore.Close()
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
@ -116,7 +115,8 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
accountService := &httpremote.HTTPAccountService{}
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
@ -128,7 +128,8 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer stateStore.Close()
|
||||
|
||||
//accountService := services.New(ctx, menuStorageService, connData)
|
||||
|
||||
rp := &httprequest.DefaultRequestParser{}
|
||||
bsh := request.NewBaseRequestHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
||||
@ -137,7 +138,10 @@ func main() {
|
||||
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
||||
Handler: sh,
|
||||
}
|
||||
s.RegisterOnShutdown(sh.Shutdown)
|
||||
shutdownFunc := func() {
|
||||
sh.Shutdown(ctx)
|
||||
}
|
||||
s.RegisterOnShutdown(shutdownFunc)
|
||||
|
||||
cint := make(chan os.Signal)
|
||||
cterm := make(chan os.Signal)
|
||||
|
92
cmd/main.go
92
cmd/main.go
@ -5,21 +5,19 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"path"
|
||||
"syscall"
|
||||
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
httpremote "git.grassecon.net/grassrootseconomics/sarafu-api/remote/http"
|
||||
devremote "git.grassecon.net/grassrootseconomics/sarafu-api/dev"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -28,66 +26,36 @@ var (
|
||||
menuSeparator = ": "
|
||||
)
|
||||
|
||||
type devEmitter struct {
|
||||
h *apievent.EventsHandler
|
||||
}
|
||||
|
||||
func (d *devEmitter) emit(ctx context.Context, msg apievent.Msg) error {
|
||||
var err error
|
||||
if msg.Typ == apievent.EventTokenTransferTag {
|
||||
tx, ok := msg.Item.(devremote.Tx)
|
||||
if !ok {
|
||||
return fmt.Errorf("not a valid tx")
|
||||
}
|
||||
logg.InfoCtxf(ctx, "tx emit", "tx", tx)
|
||||
ev := tx.ToTransferEvent()
|
||||
err = d.h.Handle(ctx, apievent.EventTokenTransferTag, &ev)
|
||||
} else if msg.Typ == apievent.EventRegistrationTag {
|
||||
acc, ok := msg.Item.(devremote.Account)
|
||||
if !ok {
|
||||
return fmt.Errorf("not a valid tx")
|
||||
}
|
||||
logg.InfoCtxf(ctx, "account emit", "account", acc)
|
||||
ev := acc.ToRegistrationEvent()
|
||||
err = d.h.Handle(ctx, apievent.EventRegistrationTag, &ev)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
var accountService remote.AccountService
|
||||
var fakeDir string
|
||||
var connStr string
|
||||
override := config.NewOverride()
|
||||
var size uint
|
||||
var sessionId string
|
||||
var engineDebug bool
|
||||
var resourceDir string
|
||||
var err error
|
||||
var gettextDir string
|
||||
var langs args.LangVar
|
||||
|
||||
flag.StringVar(&resourceDir, "resourcedir", scriptDir, "resource dir")
|
||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||
flag.StringVar(&connStr, "c", "", "connection string")
|
||||
flag.StringVar(&fakeDir, "fakedir", "", "if valid path, enables fake api with fsdb backend")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory")
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.Parse()
|
||||
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", connData, "outputsize", size)
|
||||
logg.Infof("start command", "conn", conns, "outputsize", size)
|
||||
|
||||
if len(langs.Langs()) == 0 {
|
||||
langs.Set(config.Language())
|
||||
@ -113,7 +81,7 @@ func main() {
|
||||
MenuSeparator: menuSeparator,
|
||||
}
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "menu storage service error: %v\n", err)
|
||||
os.Exit(1)
|
||||
@ -155,18 +123,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if fakeDir != "" {
|
||||
svc := devremote.NewDevAccountService(ctx, fakeDir).WithAutoVoucher(ctx, "FOO", 42)
|
||||
eu := event.NewEventsUpdater(svc, menuStorageService)
|
||||
emitter := &devEmitter{
|
||||
h: eu.ToEventsHandler(),
|
||||
}
|
||||
svc = svc.WithEmitter(emitter.emit)
|
||||
svc.AddVoucher(ctx, "BAR")
|
||||
accountService = svc
|
||||
} else {
|
||||
accountService = &httpremote.HTTPAccountService{}
|
||||
}
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "get accounts service handler: %v\n", err)
|
||||
@ -179,6 +136,21 @@ func main() {
|
||||
en = en.WithDebug(nil)
|
||||
}
|
||||
|
||||
cint := make(chan os.Signal)
|
||||
cterm := make(chan os.Signal)
|
||||
signal.Notify(cint, os.Interrupt, syscall.SIGINT)
|
||||
signal.Notify(cterm, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
var s os.Signal
|
||||
select {
|
||||
case s = <-cterm:
|
||||
case s = <-cint:
|
||||
}
|
||||
logg.InfoCtxf(ctx, "stopping on signal", "sig", s)
|
||||
en.Finish(ctx)
|
||||
os.Exit(0)
|
||||
}()
|
||||
|
||||
err = engine.Loop(ctx, en, os.Stdin, os.Stdout, nil)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)
|
||||
|
@ -31,34 +31,31 @@ var (
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
var connStr string
|
||||
override := config.NewOverride()
|
||||
var authConnStr string
|
||||
var resourceDir string
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
var stateDebug bool
|
||||
var host string
|
||||
var port uint
|
||||
flag.StringVar(&connStr, "c", "", "connection string")
|
||||
flag.StringVar(&authConnStr, "authdb", "", "auth connection string")
|
||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
flag.StringVar(&override.ResourceConn, "resource", "?", "resource connection string")
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.StringVar(&host, "h", config.HostSSH(), "socket host")
|
||||
flag.UintVar(&port, "p", config.PortSSH(), "socket port")
|
||||
flag.Parse()
|
||||
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
if authConnStr == "" {
|
||||
authConnStr = connStr
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
authConnData, err := storage.ToConnData(authConnStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "auth connstr err: %v", err)
|
||||
@ -79,14 +76,14 @@ func main() {
|
||||
logg.WarnCtxf(ctx, "!!!!! Do not expose to internet and only use with tunnel!")
|
||||
logg.WarnCtxf(ctx, "!!!!! (See ssh -L <...>)")
|
||||
|
||||
logg.Infof("start command", "conn", connData, "authconn", authConnData, "resourcedir", resourceDir, "outputsize", size, "keyfile", sshKeyFile, "host", host, "port", port)
|
||||
logg.Infof("start command", "conn", conns, "authconn", authConnData, "outputsize", size, "keyfile", sshKeyFile, "host", host, "port", port)
|
||||
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
OutputSize: uint32(size),
|
||||
FlagCount: uint32(16),
|
||||
FlagCount: uint32(128),
|
||||
}
|
||||
if stateDebug {
|
||||
cfg.StateDebug = true
|
||||
@ -102,7 +99,7 @@ func main() {
|
||||
}
|
||||
defer func() {
|
||||
logg.TraceCtxf(ctx, "shutdown auth key store reached")
|
||||
err = authKeyStore.Close()
|
||||
err = authKeyStore.Close(ctx)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "keystore close error", "err", err)
|
||||
}
|
||||
@ -114,14 +111,13 @@ func main() {
|
||||
signal.Notify(cterm, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
runner := &ssh.SshRunner{
|
||||
Cfg: cfg,
|
||||
Debug: engineDebug,
|
||||
FlagFile: pfp,
|
||||
Conn: connData,
|
||||
ResourceDir: resourceDir,
|
||||
SrvKeyFile: sshKeyFile,
|
||||
Host: host,
|
||||
Port: port,
|
||||
Cfg: cfg,
|
||||
Debug: engineDebug,
|
||||
FlagFile: pfp,
|
||||
Conn: conns,
|
||||
SrvKeyFile: sshKeyFile,
|
||||
Host: host,
|
||||
Port: port,
|
||||
}
|
||||
go func() {
|
||||
select {
|
||||
|
@ -34,7 +34,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer store.Close()
|
||||
defer store.Close(ctx)
|
||||
|
||||
err = store.AddFromFile(ctx, sshKeyFile, sessionId)
|
||||
if err != nil {
|
||||
|
20
config/args.go
Normal file
20
config/args.go
Normal file
@ -0,0 +1,20 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
func NewOverride() *viseconfig.Override {
|
||||
o := &viseconfig.Override{
|
||||
StateConnMode: storage.DBMODE_TEXT,
|
||||
ResourceConnMode: storage.DBMODE_TEXT,
|
||||
UserConnMode: storage.DBMODE_BINARY,
|
||||
}
|
||||
return o
|
||||
}
|
||||
|
||||
func Apply(o *viseconfig.Override) error {
|
||||
viseconfig.ApplyConn(o)
|
||||
return nil
|
||||
}
|
@ -1,24 +1,36 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/env"
|
||||
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||
"strings"
|
||||
|
||||
apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config"
|
||||
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/env"
|
||||
)
|
||||
|
||||
func init() {
|
||||
env.LoadEnvVariables()
|
||||
var (
|
||||
GetConns = viseconfig.GetConns
|
||||
EnvPath string
|
||||
)
|
||||
|
||||
func loadEnv() {
|
||||
if EnvPath == "" {
|
||||
env.LoadEnvVariables()
|
||||
} else {
|
||||
env.LoadEnvVariablesPath(EnvPath)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
defaultSSHHost string = "127.0.0.1"
|
||||
defaultSSHPort uint = 7122
|
||||
defaultSSHHost string = "127.0.0.1"
|
||||
defaultSSHPort uint = 7122
|
||||
defaultHTTPHost string = "127.0.0.1"
|
||||
defaultHTTPPort uint = 7123
|
||||
defaultHTTPPort uint = 7123
|
||||
defaultDomain = "sarafu.local"
|
||||
)
|
||||
|
||||
|
||||
func LoadConfig() error {
|
||||
loadEnv()
|
||||
err := viseconfig.LoadConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -30,10 +42,17 @@ func LoadConfig() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func DbConn() string {
|
||||
return viseconfig.DbConn
|
||||
func SearchDomains() []string {
|
||||
var ParsedDomains []string
|
||||
SearchDomains := env.GetEnv("ALIAS_SEARCH_DOMAINS", defaultDomain)
|
||||
SearchDomainList := strings.Split(env.GetEnv("ALIAS_SEARCH_DOMAINS", SearchDomains), ",")
|
||||
for _, domain := range SearchDomainList {
|
||||
ParsedDomains = append(ParsedDomains, strings.ReplaceAll(domain, " ", ""))
|
||||
}
|
||||
return ParsedDomains
|
||||
}
|
||||
|
||||
|
||||
func Language() string {
|
||||
return viseconfig.DefaultLanguage
|
||||
}
|
||||
|
41
debug/db.go
41
debug/db.go
@ -1,11 +1,11 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
visedb "git.defalsify.org/vise.git/db"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -13,10 +13,10 @@ var (
|
||||
)
|
||||
|
||||
type KeyInfo struct {
|
||||
SessionId string
|
||||
Typ uint8
|
||||
SubTyp storedb.DataTyp
|
||||
Label string
|
||||
SessionId string
|
||||
Typ uint8
|
||||
SubTyp storedb.DataTyp
|
||||
Label string
|
||||
Description string
|
||||
}
|
||||
|
||||
@ -32,18 +32,10 @@ func (k KeyInfo) String() string {
|
||||
|
||||
func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
|
||||
o := KeyInfo{}
|
||||
b := []byte(sessionId)
|
||||
|
||||
if len(k) <= len(b) {
|
||||
return o, fmt.Errorf("storage key missing")
|
||||
}
|
||||
|
||||
o.SessionId = sessionId
|
||||
|
||||
o.Typ = uint8(k[0])
|
||||
k = k[1:]
|
||||
o.SessionId = string(k[:len(b)])
|
||||
k = k[len(b):]
|
||||
|
||||
if o.Typ == visedb.DATATYPE_USERDATA {
|
||||
if len(k) == 0 {
|
||||
@ -53,30 +45,19 @@ func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
|
||||
o.SubTyp = storedb.DataTyp(v)
|
||||
o.Label = subTypToString(o.SubTyp)
|
||||
k = k[2:]
|
||||
if len(k) != 0 {
|
||||
return o, fmt.Errorf("excess key information: %x", k)
|
||||
}
|
||||
} else {
|
||||
o.Label = typToString(o.Typ)
|
||||
}
|
||||
|
||||
if len(k) != 0 {
|
||||
return o, fmt.Errorf("excess key information")
|
||||
k = k[2:]
|
||||
}
|
||||
|
||||
return o, nil
|
||||
}
|
||||
|
||||
func FromKey(k []byte) (KeyInfo, error) {
|
||||
o := KeyInfo{}
|
||||
|
||||
if len(k) < 4 {
|
||||
return o, fmt.Errorf("insufficient key length")
|
||||
}
|
||||
|
||||
sessionIdBytes := k[1:len(k)-2]
|
||||
return ToKeyInfo(k, string(sessionIdBytes))
|
||||
}
|
||||
|
||||
func subTypToString(v storedb.DataTyp) string {
|
||||
return dbTypStr[v + visedb.DATATYPE_USERDATA + 1]
|
||||
return dbTypStr[v+visedb.DATATYPE_USERDATA+1]
|
||||
}
|
||||
|
||||
func typToString(v uint8) string {
|
||||
|
@ -1,3 +1,4 @@
|
||||
//go:build debugdb
|
||||
// +build debugdb
|
||||
|
||||
package debug
|
||||
@ -11,34 +12,37 @@ import (
|
||||
func init() {
|
||||
DebugCap |= 1
|
||||
dbTypStr[db.DATATYPE_STATE] = "internal state"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TRACKING_ID] = "tracking id"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_PUBLIC_KEY] = "public key"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACCOUNT_PIN] = "account pin"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_FIRST_NAME] = "first name"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_FAMILY_NAME] = "family name"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_YOB] = "year of birth"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_LOCATION] = "location"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_GENDER] = "gender"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_OFFERINGS] = "offerings"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_RECIPIENT] = "recipient"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_AMOUNT] = "amount"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TEMPORARY_VALUE] = "temporary value"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACTIVE_SYM] = "active sym"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACTIVE_BAL] = "active bal"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_BLOCKED_NUMBER] = "blocked number"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_PUBLIC_KEY_REVERSE] = "public_key_reverse"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACTIVE_DECIMAL] = "active decimal"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_ACTIVE_ADDRESS] = "active address"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_VOUCHER_SYMBOLS] = "voucher symbols"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_VOUCHER_BALANCES] = "voucher balances"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_VOUCHER_DECIMALS] = "voucher decimals"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_VOUCHER_ADDRESSES] = "voucher addresses"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_SENDERS] = "tx senders"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_RECIPIENTS] = "tx recipients"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_VALUES] = "tx values"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_ADDRESSES] = "tx addresses"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_HASHES] = "tx hashes"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_DATES] = "tx dates"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_SYMBOLS] = "tx symbols"
|
||||
dbTypStr[db.DATATYPE_USERDATA + 1 + storedb.DATA_TX_DECIMALS] = "tx decimals"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TRACKING_ID] = "tracking id"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_PUBLIC_KEY] = "public key"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACCOUNT_PIN] = "account pin"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_FIRST_NAME] = "first name"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_FAMILY_NAME] = "family name"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_YOB] = "year of birth"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_LOCATION] = "location"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_GENDER] = "gender"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_OFFERINGS] = "offerings"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_RECIPIENT] = "recipient"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_AMOUNT] = "amount"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TEMPORARY_VALUE] = "temporary value"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACTIVE_SYM] = "active sym"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACTIVE_BAL] = "active bal"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_BLOCKED_NUMBER] = "blocked number"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_PUBLIC_KEY_REVERSE] = "public_key_reverse"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACTIVE_DECIMAL] = "active decimal"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_ACTIVE_ADDRESS] = "active address"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_INCORRECT_PIN_ATTEMPTS] = "incorrect pin attempts"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_SELECTED_LANGUAGE_CODE] = "selected language"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_INITIAL_LANGUAGE_CODE] = "initial language"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_VOUCHER_SYMBOLS] = "voucher symbols"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_VOUCHER_BALANCES] = "voucher balances"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_VOUCHER_DECIMALS] = "voucher decimals"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_VOUCHER_ADDRESSES] = "voucher addresses"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_SENDERS] = "tx senders"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_RECIPIENTS] = "tx recipients"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_VALUES] = "tx values"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_ADDRESSES] = "tx addresses"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_HASHES] = "tx hashes"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_DATES] = "tx dates"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_SYMBOLS] = "tx symbols"
|
||||
dbTypStr[db.DATATYPE_USERDATA+1+storedb.DATA_TX_DECIMALS] = "tx decimals"
|
||||
}
|
||||
|
@ -3,14 +3,13 @@ package debug
|
||||
import (
|
||||
"testing"
|
||||
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
visedb "git.defalsify.org/vise.git/db"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
)
|
||||
|
||||
func TestDebugDbSubKeyInfo(t *testing.T) {
|
||||
s := "foo"
|
||||
b := []byte{0x20}
|
||||
b = append(b, []byte(s)...)
|
||||
b = append(b, []byte{0x00, 0x02}...)
|
||||
r, err := ToKeyInfo(b, s)
|
||||
if err != nil {
|
||||
@ -25,7 +24,7 @@ func TestDebugDbSubKeyInfo(t *testing.T) {
|
||||
if r.SubTyp != 2 {
|
||||
t.Fatalf("expected 2, got %d", r.SubTyp)
|
||||
}
|
||||
if DebugCap & 1 > 0 {
|
||||
if DebugCap&1 > 0 {
|
||||
if r.Label != "tracking id" {
|
||||
t.Fatalf("expected 'tracking id', got '%s'", r.Label)
|
||||
}
|
||||
@ -46,7 +45,7 @@ func TestDebugDbKeyInfo(t *testing.T) {
|
||||
if r.Typ != 16 {
|
||||
t.Fatalf("expected 16, got %d", r.Typ)
|
||||
}
|
||||
if DebugCap & 1 > 0 {
|
||||
if DebugCap&1 > 0 {
|
||||
if r.Label != "internal state" {
|
||||
t.Fatalf("expected 'internal_state', got '%s'", r.Label)
|
||||
}
|
||||
@ -56,7 +55,6 @@ func TestDebugDbKeyInfo(t *testing.T) {
|
||||
func TestDebugDbKeyInfoRestore(t *testing.T) {
|
||||
s := "bar"
|
||||
b := []byte{visedb.DATATYPE_USERDATA}
|
||||
b = append(b, []byte(s)...)
|
||||
k := storedb.ToBytes(storedb.DATA_ACTIVE_SYM)
|
||||
b = append(b, k...)
|
||||
|
||||
@ -70,7 +68,7 @@ func TestDebugDbKeyInfoRestore(t *testing.T) {
|
||||
if r.Typ != 32 {
|
||||
t.Fatalf("expected 32, got %d", r.Typ)
|
||||
}
|
||||
if DebugCap & 1 > 0 {
|
||||
if DebugCap&1 > 0 {
|
||||
if r.Label != "active sym" {
|
||||
t.Fatalf("expected 'active sym', got '%s'", r.Label)
|
||||
}
|
||||
|
@ -1,7 +0,0 @@
|
||||
{
|
||||
"admins": [
|
||||
{
|
||||
"phonenumber" : "<replace with any admin number to test with >"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithDomain("adminstore")
|
||||
)
|
||||
|
||||
type Admin struct {
|
||||
PhoneNumber string `json:"phonenumber"`
|
||||
}
|
||||
|
||||
type Config struct {
|
||||
Admins []Admin `json:"admins"`
|
||||
}
|
||||
|
||||
func Seed(ctx context.Context) error {
|
||||
var config Config
|
||||
adminstore, err := store.NewAdminStore(ctx, "../admin_numbers")
|
||||
store := adminstore.FsStore
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer store.Close()
|
||||
data, err := os.ReadFile("admin_numbers.json")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := json.Unmarshal(data, &config); err != nil {
|
||||
return err
|
||||
}
|
||||
for _, admin := range config.Admins {
|
||||
err := store.Put(ctx, []byte(admin.PhoneNumber), []byte("1"))
|
||||
if err != nil {
|
||||
logg.Printf(logging.LVL_DEBUG, "Failed to insert admin number", admin.PhoneNumber)
|
||||
return err
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
@ -2,16 +2,74 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/devtools/admin/commands"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/internal/cmd"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithContextKey("SessionId")
|
||||
scriptDir = path.Join("services", "registration")
|
||||
)
|
||||
|
||||
func main() {
|
||||
ctx := context.Background()
|
||||
err := commands.Seed(ctx)
|
||||
config.LoadConfig()
|
||||
|
||||
override := config.NewOverride()
|
||||
var sessionId string
|
||||
|
||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
|
||||
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize a list of admins with error %s", err)
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
flagParser, err := application.NewFlagManager(pfp)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "flagparser fail: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
x := cmd.NewCmd(sessionId, flagParser)
|
||||
err = x.Parse(flag.Args())
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cmd parse fail: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", conns, "subcmd", x)
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "menu storage service error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = x.Exec(ctx, menuStorageService)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "cmd exec error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,13 +8,12 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
changeHeadSrc = `LOAD reset_account_authorized 0
|
||||
LOAD reset_incorrect 0
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
@ -29,8 +28,8 @@ MOVE language_changed
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla()
|
||||
mouts string
|
||||
logg = logging.NewVanilla()
|
||||
mouts string
|
||||
incmps string
|
||||
)
|
||||
|
||||
@ -63,7 +62,7 @@ func main() {
|
||||
}
|
||||
logg.Tracef("using languages", "lang", config.Languages)
|
||||
|
||||
for i, v := range(config.Languages) {
|
||||
for i, v := range config.Languages {
|
||||
ln, err := lang.LanguageFromCode(v)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "error parsing language: %s\n", v)
|
||||
@ -76,7 +75,7 @@ func main() {
|
||||
incmps += fmt.Sprintf("INCMP %s %v\n", v, n)
|
||||
|
||||
p := path.Join(srcDir, v)
|
||||
w, err := os.OpenFile(p, os.O_WRONLY | os.O_CREATE | os.O_EXCL, 0600)
|
||||
w, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed open language set template output: %v\n", err)
|
||||
os.Exit(1)
|
||||
@ -93,7 +92,7 @@ func main() {
|
||||
src += "INCMP . *\n"
|
||||
|
||||
p := path.Join(srcDir, "select_language.vis")
|
||||
w, err := os.OpenFile(p, os.O_WRONLY | os.O_CREATE | os.O_EXCL, 0600)
|
||||
w, err := os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed open select language vis output: %v\n", err)
|
||||
os.Exit(1)
|
||||
@ -107,7 +106,7 @@ func main() {
|
||||
|
||||
src = changeHeadSrc + src
|
||||
p = path.Join(srcDir, "change_language.vis")
|
||||
w, err = os.OpenFile(p, os.O_WRONLY | os.O_CREATE | os.O_EXCL, 0600)
|
||||
w, err = os.OpenFile(p, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "failed open select language vis output: %v\n", err)
|
||||
os.Exit(1)
|
||||
|
@ -7,11 +7,11 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/debug"
|
||||
"git.defalsify.org/vise.git/db"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/debug"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -19,55 +19,58 @@ var (
|
||||
scriptDir = path.Join("services", "registration")
|
||||
)
|
||||
|
||||
func formatItem(k []byte, v []byte) (string, error) {
|
||||
o, err := debug.FromKey(k)
|
||||
func formatItem(k []byte, v []byte, sessionId string) (string, error) {
|
||||
o, err := debug.ToKeyInfo(k, sessionId)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
s := fmt.Sprintf("%vValue: %v\n\n", o, string(v))
|
||||
s := fmt.Sprintf("%v\t%v\n", o.Label, string(v))
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
var connStr string
|
||||
override := config.NewOverride()
|
||||
var sessionId string
|
||||
var database string
|
||||
var engineDebug bool
|
||||
var err error
|
||||
var first bool
|
||||
|
||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||
flag.StringVar(&connStr, "c", ".state", "connection string")
|
||||
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
|
||||
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
|
||||
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
|
||||
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.Parse()
|
||||
|
||||
if connStr != "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", connData)
|
||||
logg.Infof("start command", "conn", conns)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
ctx = context.WithValue(ctx, "Database", database)
|
||||
|
||||
resourceDir := scriptDir
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
|
||||
store, err := menuStorageService.GetUserdataDb(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "get userdata db: %v\n", err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
store.SetSession(sessionId)
|
||||
store.SetPrefix(db.DATATYPE_USERDATA)
|
||||
|
||||
d, err := store.Dump(ctx, []byte(sessionId))
|
||||
d, err := store.Dump(ctx, []byte(""))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "store dump fail: %v\n", err.Error())
|
||||
os.Exit(1)
|
||||
@ -78,15 +81,19 @@ func main() {
|
||||
if k == nil {
|
||||
break
|
||||
}
|
||||
r, err := formatItem(k, v)
|
||||
if !first {
|
||||
fmt.Printf("Session ID: %s\n---\n", sessionId)
|
||||
first = true
|
||||
}
|
||||
r, err := formatItem(append([]byte{db.DATATYPE_USERDATA}, k...), v, sessionId)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "format db item error: %v", err)
|
||||
fmt.Fprintf(os.Stderr, "format db item error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf(r)
|
||||
}
|
||||
|
||||
err = store.Close()
|
||||
err = store.Close(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
|
@ -1,86 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha1"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
|
||||
testdataloader "github.com/peteole/testdata-loader"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla()
|
||||
baseDir = testdataloader.GetBasePath()
|
||||
scriptDir = path.Join("services", "registration")
|
||||
)
|
||||
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
var connStr string
|
||||
var sessionId string
|
||||
var database string
|
||||
var engineDebug bool
|
||||
var err error
|
||||
|
||||
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
|
||||
flag.StringVar(&connStr, "c", "", "connection string")
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.Parse()
|
||||
|
||||
if connStr != "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", connData)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
ctx = context.WithValue(ctx, "Database", database)
|
||||
|
||||
resourceDir := scriptDir
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
|
||||
userDb, err := menuStorageService.GetUserdataDb(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
userStore := store.UserDataStore{userDb}
|
||||
|
||||
h := sha1.New()
|
||||
h.Write([]byte(sessionId))
|
||||
address := h.Sum(nil)
|
||||
addressString := fmt.Sprintf("%x", address)
|
||||
|
||||
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(addressString))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = userStore.WriteEntry(ctx, addressString, storedb.DATA_PUBLIC_KEY_REVERSE, []byte(sessionId))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = userDb.Close()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
10
go.mod
10
go.mod
@ -3,11 +3,11 @@ module git.grassecon.net/grassrootseconomics/sarafu-vise
|
||||
go 1.23.4
|
||||
|
||||
require (
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84
|
||||
github.com/alecthomas/assert/v2 v2.2.2
|
||||
github.com/gofrs/uuid v4.4.0+incompatible
|
||||
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta
|
||||
|
20
go.sum
20
go.sum
@ -1,13 +1,13 @@
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d h1:bPAOVZOX4frSGhfOdcj7kc555f8dc9DmMd2YAyC2AMw=
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250103172917-3e190a44568d/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05 h1:BenzGx6aDHKDwE23/mWIFD2InYIXyzHroZWV3MF5WUk=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7 h1:P+Bi5jcQbnCrLnKNC5k8XDTBsocyZTVifqDyZY6d0w8=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250113213645-7c697394b5e7/go.mod h1:X9aQF93xw3vcW2QftJfzLewvbotRM0U00DRtdmFw294=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b h1:6SieNUSEKbkjzquuwazs/lVG56zdEWF10zQQEMRJfMs=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250113213325-5228aef0889b/go.mod h1:E6W7ZOa7ZvVr0Bc5ot0LNSwpSPYq4hXlAIvEPy3AJ7U=
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d h1:q/NO1rEgK3pia32D/tCq5hXfEuJp84COZRwceFvy/MM=
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d/go.mod h1:AH15xABcvaJr1TCGlih3oGSuwWC0E5IdbHQwuu+E1KI=
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9 h1:sPcqXQcywxA8W3W+9qQncLPmsrgqTIlec7vmD4/7vyA=
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ=
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1 h1:BJHfokTHzrw9QjQ+4s2HmSER0iBPuE7byW5oQC2zLIQ=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa h1:yQLKwby3eD/zNjNw/INU5lGiLuWPEHdsgASwMA4UptE=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa/go.mod h1:pjKp9L/ZsWW3kMB0UoIl1yv9TBIuU33mn9Aghxp7vGk=
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84 h1:VoBmqsjlRdz+IPbtKsAkc1IrMepjR+QlesZT31Jokrk=
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84/go.mod h1:DpibtYpnT3nG4Kn556hRAkdu4+CtiI/6MbnQHal51mQ=
|
||||
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
|
||||
github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
|
||||
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -14,11 +14,11 @@ import (
|
||||
"git.defalsify.org/vise.git/persist"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
"git.defalsify.org/vise.git/state"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
"git.grassecon.net/grassrootseconomics/common/pin"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/models"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/mocks"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/testutil/testservice"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
|
||||
"github.com/alecthomas/assert/v2"
|
||||
@ -54,7 +54,7 @@ func InitializeTestStore(t *testing.T) (context.Context, *store.UserDataStore) {
|
||||
store := &store.UserDataStore{Db: db}
|
||||
|
||||
t.Cleanup(func() {
|
||||
db.Close() // Ensure the DB is closed after each test
|
||||
db.Close(ctx) // Ensure the DB is closed after each test
|
||||
})
|
||||
|
||||
return ctx, store
|
||||
@ -84,7 +84,7 @@ func TestNewMenuHandlers(t *testing.T) {
|
||||
|
||||
// Test case for valid UserDataStore
|
||||
t.Run("Valid UserDataStore", func(t *testing.T) {
|
||||
handlers, err := NewMenuHandlers(fm.parser, store, nil, &accountService, mockReplaceSeparator)
|
||||
handlers, err := NewMenuHandlers(fm, store, &accountService, mockReplaceSeparator)
|
||||
if err != nil {
|
||||
t.Fatalf("expected no error, got %v", err)
|
||||
}
|
||||
@ -108,7 +108,7 @@ func TestNewMenuHandlers(t *testing.T) {
|
||||
|
||||
// Test case for nil UserDataStore
|
||||
t.Run("Nil UserDataStore", func(t *testing.T) {
|
||||
handlers, err := NewMenuHandlers(fm.parser, nil, nil, &accountService, mockReplaceSeparator)
|
||||
handlers, err := NewMenuHandlers(fm, nil, &accountService, mockReplaceSeparator)
|
||||
if err == nil {
|
||||
t.Fatal("expected an error, got none")
|
||||
}
|
||||
@ -132,16 +132,9 @@ func TestInit(t *testing.T) {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
adminstore, err := store.NewAdminStore(ctx, "admin_numbers")
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
st := state.NewState(128)
|
||||
ca := cache.NewCache()
|
||||
|
||||
flag_admin_privilege, _ := fm.GetFlag("flag_admin_privilege")
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
setup func() (*MenuHandlers, context.Context)
|
||||
@ -161,49 +154,40 @@ func TestInit(t *testing.T) {
|
||||
setup: func() (*MenuHandlers, context.Context) {
|
||||
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
adminstore: adminstore,
|
||||
flagManager: fm,
|
||||
pe: pe,
|
||||
}
|
||||
return h, context.WithValue(ctx, "SessionId", sessionId)
|
||||
},
|
||||
input: []byte("1"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_admin_privilege},
|
||||
},
|
||||
input: []byte("1"),
|
||||
expectedResult: resource.Result{},
|
||||
},
|
||||
{
|
||||
name: "Non-admin session initialization",
|
||||
setup: func() (*MenuHandlers, context.Context) {
|
||||
pe := persist.NewPersister(testStore).WithSession("0712345678").WithContent(st, ca)
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
adminstore: adminstore,
|
||||
flagManager: fm,
|
||||
pe: pe,
|
||||
}
|
||||
return h, context.WithValue(context.Background(), "SessionId", "0712345678")
|
||||
},
|
||||
input: []byte("1"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_admin_privilege},
|
||||
},
|
||||
input: []byte("1"),
|
||||
expectedResult: resource.Result{},
|
||||
},
|
||||
{
|
||||
name: "Move to top node on empty input",
|
||||
setup: func() (*MenuHandlers, context.Context) {
|
||||
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
adminstore: adminstore,
|
||||
flagManager: fm,
|
||||
pe: pe,
|
||||
}
|
||||
st.Code = []byte("some pending bytecode")
|
||||
return h, context.WithValue(ctx, "SessionId", sessionId)
|
||||
},
|
||||
input: []byte(""),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_admin_privilege},
|
||||
},
|
||||
input: []byte(""),
|
||||
expectedResult: resource.Result{},
|
||||
},
|
||||
}
|
||||
|
||||
@ -256,7 +240,7 @@ func TestCreateAccount(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
mockAccountService.On("CreateAccount").Return(tt.serverResponse, nil)
|
||||
@ -320,7 +304,7 @@ func TestSaveFirstname(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -365,7 +349,7 @@ func TestSaveFamilyname(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
st: mockState,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@ -408,7 +392,7 @@ func TestSaveYoB(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -452,7 +436,7 @@ func TestSaveLocation(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -496,7 +480,7 @@ func TestSaveOfferings(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -564,7 +548,7 @@ func TestSaveGender(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
st: mockState,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
expectedResult := resource.Result{}
|
||||
@ -595,11 +579,11 @@ func TestSaveTemporaryPin(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_incorrect_pin, _ := fm.parser.GetFlag("flag_incorrect_pin")
|
||||
flag_incorrect_pin, _ := fm.GetFlag("flag_incorrect_pin")
|
||||
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
userdataStore: store,
|
||||
}
|
||||
|
||||
@ -812,7 +796,7 @@ func TestSetLanguage(t *testing.T) {
|
||||
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
userdataStore: store,
|
||||
st: mockState,
|
||||
}
|
||||
@ -825,6 +809,17 @@ func TestSetLanguage(t *testing.T) {
|
||||
|
||||
// Assert that the Result FlagSet has the required flags after language switch
|
||||
assert.Equal(t, res, tt.expectedResult, "Result should match expected result")
|
||||
code, err := store.ReadEntry(ctx, sessionId, storedb.DATA_SELECTED_LANGUAGE_CODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
assert.Equal(t, string(code), tt.expectedResult.Content)
|
||||
code, err = store.ReadEntry(ctx, sessionId, storedb.DATA_INITIAL_LANGUAGE_CODE)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
assert.Equal(t, string(code), "eng")
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -835,7 +830,7 @@ func TestResetAllowUpdate(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update")
|
||||
flag_allow_update, _ := fm.GetFlag("flag_allow_update")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@ -856,7 +851,7 @@ func TestResetAllowUpdate(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@ -877,7 +872,7 @@ func TestResetAccountAuthorized(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_account_authorized, _ := fm.parser.GetFlag("flag_account_authorized")
|
||||
flag_account_authorized, _ := fm.GetFlag("flag_account_authorized")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@ -898,7 +893,7 @@ func TestResetAccountAuthorized(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@ -922,8 +917,8 @@ func TestIncorrectPinReset(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_incorrect_pin, _ := fm.parser.GetFlag("flag_incorrect_pin")
|
||||
flag_account_blocked, _ := fm.parser.GetFlag("flag_account_blocked")
|
||||
flag_incorrect_pin, _ := fm.GetFlag("flag_incorrect_pin")
|
||||
flag_account_blocked, _ := fm.GetFlag("flag_account_blocked")
|
||||
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
@ -981,7 +976,7 @@ func TestIncorrectPinReset(t *testing.T) {
|
||||
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
userdataStore: store,
|
||||
}
|
||||
|
||||
@ -1003,7 +998,7 @@ func TestResetIncorrectYob(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_incorrect_date_format, _ := fm.parser.GetFlag("flag_incorrect_date_format")
|
||||
flag_incorrect_date_format, _ := fm.GetFlag("flag_incorrect_date_format")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@ -1024,7 +1019,7 @@ func TestResetIncorrectYob(t *testing.T) {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@ -1062,7 +1057,7 @@ func TestAuthorize(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -1130,12 +1125,12 @@ func TestVerifyYob(t *testing.T) {
|
||||
// Create required mocks
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
mockState := state.NewState(16)
|
||||
flag_incorrect_date_format, _ := fm.parser.GetFlag("flag_incorrect_date_format")
|
||||
flag_incorrect_date_format, _ := fm.GetFlag("flag_incorrect_date_format")
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
|
||||
h := &MenuHandlers{
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -1195,14 +1190,14 @@ func TestVerifyCreatePin(t *testing.T) {
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
mockState := state.NewState(16)
|
||||
|
||||
flag_valid_pin, _ := fm.parser.GetFlag("flag_valid_pin")
|
||||
flag_pin_mismatch, _ := fm.parser.GetFlag("flag_pin_mismatch")
|
||||
flag_pin_set, _ := fm.parser.GetFlag("flag_pin_set")
|
||||
flag_valid_pin, _ := fm.GetFlag("flag_valid_pin")
|
||||
flag_pin_mismatch, _ := fm.GetFlag("flag_pin_mismatch")
|
||||
flag_pin_set, _ := fm.GetFlag("flag_pin_set")
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -1228,13 +1223,20 @@ func TestVerifyCreatePin(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
// Hash the correct PIN
|
||||
hashedPIN, err := pin.HashPIN("1234")
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to hash temporaryPin", "error", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(hashedPIN))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte("1234"))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Call the method under test
|
||||
res, err := h.VerifyCreatePin(ctx, "verify_create_pin", []byte(tt.input))
|
||||
|
||||
@ -1296,7 +1298,7 @@ func TestCheckAccountStatus(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(tt.publicKey))
|
||||
@ -1336,7 +1338,7 @@ func TestTransactionReset(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -1376,14 +1378,14 @@ func TestResetTransactionAmount(t *testing.T) {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
|
||||
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
|
||||
flag_invalid_amount, _ := fm.GetFlag("flag_invalid_amount")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@ -1420,14 +1422,14 @@ func TestInitiateTransaction(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
account_authorized_flag, _ := fm.parser.GetFlag("flag_account_authorized")
|
||||
account_authorized_flag, _ := fm.GetFlag("flag_account_authorized")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@ -1513,7 +1515,7 @@ func TestQuit(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
flag_account_authorized, _ := fm.parser.GetFlag("flag_account_authorized")
|
||||
flag_account_authorized, _ := fm.GetFlag("flag_account_authorized")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
@ -1523,7 +1525,7 @@ func TestQuit(t *testing.T) {
|
||||
|
||||
h := &MenuHandlers{
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -1566,14 +1568,14 @@ func TestValidateAmount(t *testing.T) {
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
|
||||
flag_invalid_amount, _ := fm.GetFlag("flag_invalid_amount")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -1640,8 +1642,8 @@ func TestValidateRecipient(t *testing.T) {
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
flag_invalid_recipient, _ := fm.parser.GetFlag("flag_invalid_recipient")
|
||||
flag_invalid_recipient_with_invite, _ := fm.parser.GetFlag("flag_invalid_recipient_with_invite")
|
||||
flag_invalid_recipient, _ := fm.GetFlag("flag_invalid_recipient")
|
||||
flag_invalid_recipient_with_invite, _ := fm.GetFlag("flag_invalid_recipient_with_invite")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@ -1677,7 +1679,7 @@ func TestValidateRecipient(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Test with alias recepient",
|
||||
input: []byte("alias123"),
|
||||
input: []byte("alias123.sarafu.local"),
|
||||
expectedResult: resource.Result{},
|
||||
},
|
||||
}
|
||||
@ -1693,12 +1695,12 @@ func TestValidateRecipient(t *testing.T) {
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
// Create the MenuHandlers instance
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
|
||||
aliasResponse := &dataserviceapi.AliasAddress{
|
||||
aliasResponse := &models.AliasAddress{
|
||||
Address: "0xd4c288865Ce0985a481Eef3be02443dF5E2e4Ea9",
|
||||
}
|
||||
|
||||
@ -1795,37 +1797,37 @@ func TestGetProfile(t *testing.T) {
|
||||
}{
|
||||
{
|
||||
name: "Test with full profile information in eng",
|
||||
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
||||
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB, storedb.DATA_ACCOUNT_ALIAS},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
|
||||
languageCode: "eng",
|
||||
result: resource.Result{
|
||||
Content: fmt.Sprintf(
|
||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas",
|
||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\nYour alias: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test with with profile information in swa",
|
||||
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
||||
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB, storedb.DATA_ACCOUNT_ALIAS},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
|
||||
languageCode: "swa",
|
||||
result: resource.Result{
|
||||
Content: fmt.Sprintf(
|
||||
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas",
|
||||
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\nLakabu yako: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test with with profile information with language that is not yet supported",
|
||||
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
|
||||
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB, storedb.DATA_ACCOUNT_ALIAS},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
|
||||
languageCode: "nor",
|
||||
result: resource.Result{
|
||||
Content: fmt.Sprintf(
|
||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas",
|
||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\nYour alias: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
|
||||
),
|
||||
},
|
||||
},
|
||||
@ -1856,10 +1858,10 @@ func TestVerifyNewPin(t *testing.T) {
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
flag_valid_pin, _ := fm.parser.GetFlag("flag_valid_pin")
|
||||
flag_valid_pin, _ := fm.GetFlag("flag_valid_pin")
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
@ -1902,24 +1904,24 @@ func TestConfirmPin(t *testing.T) {
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
flag_pin_mismatch, _ := fm.parser.GetFlag("flag_pin_mismatch")
|
||||
flag_pin_mismatch, _ := fm.GetFlag("flag_pin_mismatch")
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
temporarypin []byte
|
||||
temporarypin string
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "Test with correct pin confirmation",
|
||||
input: []byte("1234"),
|
||||
temporarypin: []byte("1234"),
|
||||
temporarypin: "1234",
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_pin_mismatch},
|
||||
},
|
||||
@ -1927,14 +1929,21 @@ func TestConfirmPin(t *testing.T) {
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
// Hash the PIN
|
||||
hashedPIN, err := pin.HashPIN(tt.temporarypin)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed to hash temporaryPin", "error", err)
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// Set up the expected behavior of the mock
|
||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.temporarypin))
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(hashedPIN))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
//Call the function under test
|
||||
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.temporarypin)
|
||||
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.input)
|
||||
|
||||
//Assert that the result set to content is what was expected
|
||||
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")
|
||||
@ -2036,7 +2045,7 @@ func TestSetDefaultVoucher(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
}
|
||||
|
||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
@ -2144,7 +2153,7 @@ func TestViewVoucher(t *testing.T) {
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
prefixDb: spdb,
|
||||
}
|
||||
|
||||
@ -2217,7 +2226,7 @@ func TestGetVoucherDetails(t *testing.T) {
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm.parser,
|
||||
flagManager: fm,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS, []byte(tokA_AAddress))
|
||||
|
@ -27,7 +27,7 @@ func (eh *EventsUpdater) handleCustodialRegistration(ctx context.Context, ev any
|
||||
}
|
||||
|
||||
func (eu *EventsUpdater) HandleCustodialRegistration(ctx context.Context, ev *apievent.EventCustodialRegistration) error {
|
||||
pe, userStore, err := eu.getStore(ctx)
|
||||
_, userStore, err := eu.getStore(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -35,11 +35,6 @@ func (eu *EventsUpdater) HandleCustodialRegistration(ctx context.Context, ev *ap
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = pe.Load(identity.SessionId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
st := pe.GetState()
|
||||
st.SetFlag(accountCreatedFlag)
|
||||
return pe.Save(identity.SessionId)
|
||||
logg.DebugCtxf(ctx, "received custodial registration event", "identity", identity)
|
||||
return nil
|
||||
}
|
||||
|
@ -4,12 +4,12 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.defalsify.org/vise.git/persist"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||
"git.defalsify.org/vise.git/persist"
|
||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -17,9 +17,9 @@ var (
|
||||
)
|
||||
|
||||
type EventsUpdater struct {
|
||||
api remote.AccountService
|
||||
api remote.AccountService
|
||||
formatFunc func(string, int, any) string
|
||||
store storage.StorageService
|
||||
store storage.StorageService
|
||||
}
|
||||
|
||||
func NewEventsUpdater(api remote.AccountService, store storage.StorageService) *EventsUpdater {
|
||||
|
@ -6,10 +6,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.defalsify.org/vise.git/db"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
"git.grassecon.net/grassrootseconomics/common/identity"
|
||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
)
|
||||
|
||||
// execute all
|
||||
@ -47,7 +47,6 @@ func (eu *EventsUpdater) updateToken(ctx context.Context, identity identity.Iden
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
// set default token to given symbol.
|
||||
func (eu *EventsUpdater) updateDefaultToken(ctx context.Context, identity identity.Identity, userStore *store.UserDataStore, activeSym string) error {
|
||||
pfxDb := toPrefixDb(userStore, identity.SessionId)
|
||||
@ -59,7 +58,6 @@ func (eu *EventsUpdater) updateDefaultToken(ctx context.Context, identity identi
|
||||
return store.UpdateVoucherData(ctx, userStore, identity.SessionId, tokenData)
|
||||
}
|
||||
|
||||
|
||||
// handle token transfer.
|
||||
//
|
||||
// if from and to are NOT the same, handle code will be executed once for each side of the transfer.
|
||||
@ -189,7 +187,7 @@ func (eu *EventsUpdater) updateTokenTransferList(ctx context.Context, identity i
|
||||
return err
|
||||
}
|
||||
|
||||
for i, tx := range(txs) {
|
||||
for i, tx := range txs {
|
||||
r = append(r, eu.formatFunc(apievent.EventTokenTransferTag, i, tx))
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"git.defalsify.org/vise.git/asm"
|
||||
"git.defalsify.org/vise.git/db"
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
"git.defalsify.org/vise.git/persist"
|
||||
@ -12,47 +11,35 @@ import (
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
)
|
||||
|
||||
type HandlerService interface {
|
||||
GetHandler() (*application.MenuHandlers, error)
|
||||
}
|
||||
|
||||
func getParser(fp string, debug bool) (*asm.FlagParser, error) {
|
||||
flagParser := asm.NewFlagParser().WithDebug()
|
||||
_, err := flagParser.Load(fp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return flagParser, nil
|
||||
}
|
||||
|
||||
type LocalHandlerService struct {
|
||||
Parser *asm.FlagParser
|
||||
Parser *application.FlagManager
|
||||
DbRs *resource.DbResource
|
||||
Pe *persist.Persister
|
||||
UserdataStore *db.Db
|
||||
AdminStore *store.AdminStore
|
||||
Cfg engine.Config
|
||||
Rs resource.Resource
|
||||
}
|
||||
|
||||
func NewLocalHandlerService(ctx context.Context, fp string, debug bool, dbResource *resource.DbResource, cfg engine.Config, rs resource.Resource) (*LocalHandlerService, error) {
|
||||
parser, err := getParser(fp, debug)
|
||||
parser, err := application.NewFlagManager(fp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
adminstore, err := store.NewAdminStore(ctx, "admin_numbers")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if debug {
|
||||
parser.SetDebug()
|
||||
}
|
||||
|
||||
return &LocalHandlerService{
|
||||
Parser: parser,
|
||||
DbRs: dbResource,
|
||||
AdminStore: adminstore,
|
||||
Cfg: cfg,
|
||||
Rs: rs,
|
||||
Parser: parser,
|
||||
DbRs: dbResource,
|
||||
Cfg: cfg,
|
||||
Rs: rs,
|
||||
}, nil
|
||||
}
|
||||
|
||||
@ -69,12 +56,13 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator)
|
||||
}
|
||||
|
||||
appHandlers, err := application.NewMenuHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, accountService, replaceSeparatorFunc)
|
||||
appHandlers, err := application.NewMenuHandlers(ls.Parser, *ls.UserdataStore, accountService, replaceSeparatorFunc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
//appHandlers = appHandlers.WithPersister(ls.Pe)
|
||||
appHandlers.SetPersister(ls.Pe)
|
||||
ls.DbRs.AddLocalFunc("check_blocked_status", appHandlers.CheckBlockedStatus)
|
||||
ls.DbRs.AddLocalFunc("set_language", appHandlers.SetLanguage)
|
||||
ls.DbRs.AddLocalFunc("create_account", appHandlers.CreateAccount)
|
||||
ls.DbRs.AddLocalFunc("save_temporary_pin", appHandlers.SaveTemporaryPin)
|
||||
|
96
internal/cmd/cmd.go
Normal file
96
internal/cmd/cmd.go
Normal file
@ -0,0 +1,96 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithDomain("cmd").WithContextKey("SessionId")
|
||||
)
|
||||
|
||||
type Cmd struct {
|
||||
sessionId string
|
||||
conn storage.ConnData
|
||||
flagParser *application.FlagManager
|
||||
cmd int
|
||||
enable bool
|
||||
exec func(ctx context.Context, ss storage.StorageService) error
|
||||
}
|
||||
|
||||
func NewCmd(sessionId string, flagParser *application.FlagManager) *Cmd {
|
||||
return &Cmd{
|
||||
sessionId: sessionId,
|
||||
flagParser: flagParser,
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cmd) Exec(ctx context.Context, ss storage.StorageService) error {
|
||||
return c.exec(ctx, ss)
|
||||
}
|
||||
|
||||
func (c *Cmd) execAdmin(ctx context.Context, ss storage.StorageService) error {
|
||||
pe, err := ss.GetPersister(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
err = pe.Load(c.sessionId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
err := pe.Save(c.sessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "failed persister save: %v", err)
|
||||
}
|
||||
}()
|
||||
|
||||
st := pe.GetState()
|
||||
flag, err := c.flagParser.GetFlag("flag_admin_privilege")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c.enable {
|
||||
logg.InfoCtxf(ctx, "setting admin flag", "flag", flag)
|
||||
st.SetFlag(flag)
|
||||
} else {
|
||||
st.ResetFlag(flag)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Cmd) parseCmdAdmin(cmd string, param string, more []string) (bool, error) {
|
||||
if cmd == "admin" {
|
||||
if param == "1" {
|
||||
c.enable = true
|
||||
} else if param != "0" {
|
||||
return false, fmt.Errorf("invalid parameter: %v", param)
|
||||
}
|
||||
c.exec = c.execAdmin
|
||||
return true, nil
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (c *Cmd) Parse(args []string) error {
|
||||
if len(args) < 2 {
|
||||
return fmt.Errorf("Wrong number of arguments: %v", args)
|
||||
}
|
||||
cmd := args[0]
|
||||
param := args[1]
|
||||
args = args[2:]
|
||||
|
||||
r, err := c.parseCmdAdmin(cmd, param, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r {
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("unknown subcommand: %s", cmd)
|
||||
}
|
@ -427,7 +427,7 @@
|
||||
},
|
||||
{
|
||||
"input": "1234",
|
||||
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back\n9:Quit"
|
||||
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: \n\n0:Back\n9:Quit"
|
||||
},
|
||||
{
|
||||
"input": "0",
|
||||
|
@ -9,12 +9,14 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/testutil/driver"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/testutil"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/testutil/driver"
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithDomain("menutraversaltest")
|
||||
testData = driver.ReadData()
|
||||
sessionID string
|
||||
src = rand.NewSource(42)
|
||||
@ -22,9 +24,6 @@ var (
|
||||
)
|
||||
|
||||
var groupTestFile = flag.String("test-file", "group_test.json", "The test file to use for running the group tests")
|
||||
var database = flag.String("db", "gdbm", "Specify the database (gdbm or postgres)")
|
||||
var connStr = flag.String("conn", ".test_state", "connection string")
|
||||
var dbSchema = flag.String("schema", "test", "Specify the database schema (default test)")
|
||||
|
||||
func GenerateSessionId() string {
|
||||
uu := uuid.NewGenWithOptions(uuid.WithRandomReader(g))
|
||||
@ -80,12 +79,7 @@ func extractSendAmount(response []byte) string {
|
||||
}
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
// Parse the flags
|
||||
flag.Parse()
|
||||
sessionID = GenerateSessionId()
|
||||
// set the db
|
||||
testutil.SetDatabase(*database, *connStr, *dbSchema)
|
||||
|
||||
// Cleanup the db after tests
|
||||
defer testutil.CleanDatabase()
|
||||
|
||||
@ -100,7 +94,8 @@ func TestAccountCreationSuccessful(t *testing.T) {
|
||||
for _, session := range sessions {
|
||||
groups := driver.FilterGroupsByName(session.Groups, "account_creation_successful")
|
||||
for _, group := range groups {
|
||||
for _, step := range group.Steps {
|
||||
for i, step := range group.Steps {
|
||||
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
|
||||
cont, err := en.Exec(ctx, []byte(step.Input))
|
||||
if err != nil {
|
||||
t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
|
||||
@ -142,7 +137,8 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
|
||||
for _, session := range sessions {
|
||||
groups := driver.FilterGroupsByName(session.Groups, "account_creation_reject_terms")
|
||||
for _, group := range groups {
|
||||
for _, step := range group.Steps {
|
||||
for i, step := range group.Steps {
|
||||
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
|
||||
cont, err := en.Exec(ctx, []byte(step.Input))
|
||||
if err != nil {
|
||||
t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
|
||||
@ -177,7 +173,8 @@ func TestMainMenuHelp(t *testing.T) {
|
||||
for _, session := range sessions {
|
||||
groups := driver.FilterGroupsByName(session.Groups, "main_menu_help")
|
||||
for _, group := range groups {
|
||||
for _, step := range group.Steps {
|
||||
for i, step := range group.Steps {
|
||||
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
|
||||
cont, err := en.Exec(ctx, []byte(step.Input))
|
||||
if err != nil {
|
||||
t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
|
||||
|
51
services/local.go
Normal file
51
services/local.go
Normal file
@ -0,0 +1,51 @@
|
||||
//go:build !online
|
||||
// +build !online
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
devremote "git.grassecon.net/grassrootseconomics/sarafu-api/dev"
|
||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
)
|
||||
|
||||
type localEmitter struct {
|
||||
h *apievent.EventsHandler
|
||||
}
|
||||
|
||||
func (d *localEmitter) emit(ctx context.Context, msg apievent.Msg) error {
|
||||
var err error
|
||||
if msg.Typ == apievent.EventTokenTransferTag {
|
||||
tx, ok := msg.Item.(devremote.Tx)
|
||||
if !ok {
|
||||
return fmt.Errorf("not a valid tx")
|
||||
}
|
||||
ev := tx.ToTransferEvent()
|
||||
err = d.h.Handle(ctx, apievent.EventTokenTransferTag, &ev)
|
||||
} else if msg.Typ == apievent.EventRegistrationTag {
|
||||
acc, ok := msg.Item.(devremote.Account)
|
||||
if !ok {
|
||||
return fmt.Errorf("not a valid tx")
|
||||
}
|
||||
ev := acc.ToRegistrationEvent()
|
||||
err = d.h.Handle(ctx, apievent.EventRegistrationTag, &ev)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func New(ctx context.Context, storageService storage.StorageService) remote.AccountService {
|
||||
svc := devremote.NewDevAccountService(ctx, storageService)
|
||||
svc = svc.WithAutoVoucher(ctx, "FOO", 42)
|
||||
eu := event.NewEventsUpdater(svc, storageService)
|
||||
emitter := &localEmitter{
|
||||
h: eu.ToEventsHandler(),
|
||||
}
|
||||
svc = svc.WithEmitter(emitter.emit)
|
||||
svc.AddVoucher(ctx, "BAR")
|
||||
return svc
|
||||
}
|
@ -4,8 +4,8 @@ TXTS = $(wildcard ./*.txt.orig)
|
||||
VISE_PATH := ../../go-vise
|
||||
|
||||
# Rule to build .bin files from .vis files
|
||||
%.vis:
|
||||
go run $(VISE_PATH)/dev/asm/main.go -f pp.csv $(basename $@).vis > $(basename $@).bin
|
||||
%.vis: buildasm
|
||||
./vise-asm -f pp.csv $(basename $@).vis > $(basename $@).bin
|
||||
@echo "Built $(basename $@).bin from $(basename $@).vis"
|
||||
|
||||
# Rule to copy .orig files to .txt
|
||||
@ -19,5 +19,10 @@ all: $(INPUTS) $(TXTS)
|
||||
|
||||
clean:
|
||||
rm -vf *.bin
|
||||
rm -vf ./vise-asm
|
||||
|
||||
buildasm:
|
||||
go build -v -o ./vise-asm $(VISE_PATH)/dev/asm/main.go
|
||||
|
||||
|
||||
.PHONY: clean
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1 +1 @@
|
||||
Your account is still being created.
|
||||
Your account is still being created. For more help, please call: 0757628885
|
Binary file not shown.
@ -1 +1 @@
|
||||
Akaunti yako bado inatengenezwa
|
||||
Akaunti yako bado inatengenezwa. Kwa usaidizi zaidi, piga: 0757628885
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,9 +1,11 @@
|
||||
LOAD check_blocked_status 1
|
||||
RELOAD check_blocked_status
|
||||
CATCH blocked_account flag_account_blocked 1
|
||||
CATCH select_language flag_language_set 0
|
||||
CATCH terms flag_account_created 0
|
||||
LOAD check_account_status 0
|
||||
RELOAD check_account_status
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH api_failure flag_api_call_error 1
|
||||
CATCH account_pending flag_account_pending 1
|
||||
CATCH create_pin flag_pin_set 0
|
||||
CATCH main flag_account_success 1
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,7 +3,7 @@ RELOAD transaction_reset
|
||||
CATCH no_voucher flag_no_active_voucher 1
|
||||
MOUT back 0
|
||||
HALT
|
||||
LOAD validate_recipient 20
|
||||
LOAD validate_recipient 50
|
||||
RELOAD validate_recipient
|
||||
CATCH invalid_recipient flag_invalid_recipient 1
|
||||
CATCH invite_recipient flag_invalid_recipient_with_invite 1
|
||||
|
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user