Compare commits
No commits in common. "master" and "lash/api-select" have entirely different histories.
master
...
lash/api-s
@ -1,16 +0,0 @@
|
||||
/**
|
||||
!/args
|
||||
!/cmd/africastalking
|
||||
!/cmd/ssh
|
||||
!/config
|
||||
!/debug
|
||||
!/handlers
|
||||
!/internal
|
||||
!/profile
|
||||
!/services
|
||||
!/ssh
|
||||
!/store
|
||||
!/LICENSE
|
||||
!/README.md
|
||||
!/go.*
|
||||
!/.env.example
|
@ -18,6 +18,3 @@ 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
56
.github/workflows/docker.yaml
vendored
@ -1,56 +0,0 @@
|
||||
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
50
Dockerfile
@ -1,50 +0,0 @@
|
||||
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"]
|
@ -21,7 +21,7 @@ func (lv *LangVar) Set(s string) error {
|
||||
|
||||
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, ",")
|
||||
@ -30,3 +30,5 @@ func (lv *LangVar) String() string {
|
||||
func(lv *LangVar) Langs() []lang.Language {
|
||||
return lv.v
|
||||
}
|
||||
|
||||
|
||||
|
@ -12,18 +12,19 @@ import (
|
||||
"syscall"
|
||||
|
||||
"git.defalsify.org/vise.git/engine"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"git.defalsify.org/vise.git/resource"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
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"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -36,7 +37,8 @@ var (
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
override := config.NewOverride()
|
||||
var connStr string
|
||||
var resourceDir string
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
var host string
|
||||
@ -45,11 +47,10 @@ 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")
|
||||
@ -57,14 +58,16 @@ func main() {
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "build", build, "conn", conns, "outputsize", size)
|
||||
logg.Infof("start command", "build", build, "conn", connData, "resourcedir", resourceDir, "outputsize", size)
|
||||
|
||||
ctx := context.Background()
|
||||
ln, err := lang.LanguageFromCode(config.Language())
|
||||
@ -87,7 +90,7 @@ func main() {
|
||||
cfg.EngineDebug = true
|
||||
}
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
rs, err := menuStorageService.GetResource(ctx)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "menustorageservice: %v\n", err)
|
||||
@ -99,6 +102,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "userdatadb: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer userdataStore.Close()
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
@ -117,8 +121,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
|
||||
accountService := &httpremote.HTTPAccountService{}
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "httpaccountservice: %v\n", err)
|
||||
@ -130,6 +133,7 @@ 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)
|
||||
@ -142,10 +146,7 @@ func main() {
|
||||
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
||||
Handler: mux,
|
||||
}
|
||||
shutdownFunc := func() {
|
||||
sh.Shutdown(ctx)
|
||||
}
|
||||
s.RegisterOnShutdown(shutdownFunc)
|
||||
s.RegisterOnShutdown(sh.Shutdown)
|
||||
|
||||
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/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"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -44,8 +44,9 @@ func (p *asyncRequestParser) GetInput(r any) ([]byte, error) {
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
override := config.NewOverride()
|
||||
var connStr string
|
||||
var sessionId string
|
||||
var resourceDir string
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
var host string
|
||||
@ -55,11 +56,8 @@ func main() {
|
||||
var langs args.LangVar
|
||||
|
||||
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.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.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.StringVar(&host, "h", config.Host(), "http host")
|
||||
@ -68,14 +66,16 @@ func main() {
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", conns, "outputsize", size, "sessionId", sessionId)
|
||||
logg.Infof("start command", "conn", connData, "resourcedir", resourceDir, "outputsize", size, "sessionId", sessionId)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@ -99,7 +99,7 @@ func main() {
|
||||
cfg.EngineDebug = true
|
||||
}
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
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(ctx)
|
||||
defer userdataStore.Close()
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
@ -126,7 +126,7 @@ func main() {
|
||||
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
|
||||
lhs.SetDataStore(&userdataStore)
|
||||
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
accountService := services.New(ctx, menuStorageService, connData)
|
||||
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
if err != nil {
|
||||
@ -139,7 +139,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
//defer stateStore.Close(ctx)
|
||||
defer stateStore.Close()
|
||||
|
||||
rp := &asyncRequestParser{
|
||||
sessionId: sessionId,
|
||||
@ -161,7 +161,7 @@ func main() {
|
||||
case _ = <-cint:
|
||||
case _ = <-cterm:
|
||||
}
|
||||
sh.Shutdown(ctx)
|
||||
sh.Shutdown()
|
||||
}()
|
||||
|
||||
for true {
|
||||
@ -177,7 +177,7 @@ func main() {
|
||||
fmt.Errorf("error in output: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
rqs, err = sh.Reset(ctx, rqs)
|
||||
rqs, err = sh.Reset(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"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
httprequest "git.grassecon.net/grassrootseconomics/visedriver/request/http"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/request"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/storage"
|
||||
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -35,7 +35,8 @@ var (
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
override := config.NewOverride()
|
||||
var connStr string
|
||||
var resourceDir string
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
var host string
|
||||
@ -44,11 +45,8 @@ func main() {
|
||||
var gettextDir string
|
||||
var langs args.LangVar
|
||||
|
||||
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.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.UintVar(&size, "s", 160, "max size of output")
|
||||
flag.StringVar(&host, "h", config.Host(), "http host")
|
||||
@ -57,14 +55,16 @@ func main() {
|
||||
flag.Var(&langs, "language", "add symbol resolution for language")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", conns, "outputsize", size)
|
||||
logg.Infof("start command", "conn", connData, "resourcedir", resourceDir, "outputsize", size)
|
||||
|
||||
ctx := context.Background()
|
||||
|
||||
@ -88,7 +88,7 @@ func main() {
|
||||
cfg.EngineDebug = true
|
||||
}
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
|
||||
rs, err := menuStorageService.GetResource(ctx)
|
||||
if err != nil {
|
||||
@ -101,6 +101,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer userdataStore.Close()
|
||||
|
||||
dbResource, ok := rs.(*resource.DbResource)
|
||||
if !ok {
|
||||
@ -115,7 +116,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
accountService := services.New(ctx, menuStorageService, connData)
|
||||
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
if err != nil {
|
||||
@ -128,6 +129,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
defer stateStore.Close()
|
||||
|
||||
//accountService := services.New(ctx, menuStorageService, connData)
|
||||
|
||||
@ -138,10 +140,7 @@ func main() {
|
||||
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
||||
Handler: sh,
|
||||
}
|
||||
shutdownFunc := func() {
|
||||
sh.Shutdown(ctx)
|
||||
}
|
||||
s.RegisterOnShutdown(shutdownFunc)
|
||||
s.RegisterOnShutdown(sh.Shutdown)
|
||||
|
||||
cint := make(chan os.Signal)
|
||||
cterm := make(chan os.Signal)
|
||||
|
48
cmd/main.go
48
cmd/main.go
@ -5,19 +5,17 @@ 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.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"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/storage"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -29,33 +27,34 @@ var (
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
override := config.NewOverride()
|
||||
var connStr string
|
||||
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(&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.StringVar(&connStr, "c", "", "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()
|
||||
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", conns, "outputsize", size)
|
||||
logg.Infof("start command", "conn", connData, "outputsize", size)
|
||||
|
||||
if len(langs.Langs()) == 0 {
|
||||
langs.Set(config.Language())
|
||||
@ -81,7 +80,7 @@ func main() {
|
||||
MenuSeparator: menuSeparator,
|
||||
}
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "menu storage service error: %v\n", err)
|
||||
os.Exit(1)
|
||||
@ -123,7 +122,7 @@ func main() {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
accountService := services.New(ctx, menuStorageService)
|
||||
accountService := services.New(ctx, menuStorageService, connData)
|
||||
hl, err := lhs.GetHandler(accountService)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "get accounts service handler: %v\n", err)
|
||||
@ -136,21 +135,6 @@ 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,31 +31,34 @@ var (
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
override := config.NewOverride()
|
||||
var connStr string
|
||||
var authConnStr string
|
||||
var resourceDir string
|
||||
var size uint
|
||||
var engineDebug bool
|
||||
var stateDebug bool
|
||||
var host string
|
||||
var port uint
|
||||
|
||||
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.StringVar(&connStr, "c", "", "connection string")
|
||||
flag.StringVar(&authConnStr, "authdb", "", "auth connection string")
|
||||
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
|
||||
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()
|
||||
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if connStr == "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
if authConnStr == "" {
|
||||
authConnStr = connStr
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
authConnData, err := storage.ToConnData(authConnStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "auth connstr err: %v", err)
|
||||
@ -76,14 +79,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", conns, "authconn", authConnData, "outputsize", size, "keyfile", sshKeyFile, "host", host, "port", port)
|
||||
logg.Infof("start command", "conn", connData, "authconn", authConnData, "resourcedir", resourceDir, "outputsize", size, "keyfile", sshKeyFile, "host", host, "port", port)
|
||||
|
||||
pfp := path.Join(scriptDir, "pp.csv")
|
||||
|
||||
cfg := engine.Config{
|
||||
Root: "root",
|
||||
OutputSize: uint32(size),
|
||||
FlagCount: uint32(128),
|
||||
FlagCount: uint32(16),
|
||||
}
|
||||
if stateDebug {
|
||||
cfg.StateDebug = true
|
||||
@ -99,7 +102,7 @@ func main() {
|
||||
}
|
||||
defer func() {
|
||||
logg.TraceCtxf(ctx, "shutdown auth key store reached")
|
||||
err = authKeyStore.Close(ctx)
|
||||
err = authKeyStore.Close()
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(ctx, "keystore close error", "err", err)
|
||||
}
|
||||
@ -114,7 +117,8 @@ func main() {
|
||||
Cfg: cfg,
|
||||
Debug: engineDebug,
|
||||
FlagFile: pfp,
|
||||
Conn: conns,
|
||||
Conn: connData,
|
||||
ResourceDir: resourceDir,
|
||||
SrvKeyFile: sshKeyFile,
|
||||
Host: host,
|
||||
Port: port,
|
||||
|
@ -34,7 +34,7 @@ func main() {
|
||||
fmt.Fprintf(os.Stderr, "%v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer store.Close(ctx)
|
||||
defer store.Close()
|
||||
|
||||
err = store.AddFromFile(ctx, sshKeyFile, sessionId)
|
||||
if err != nil {
|
||||
|
@ -1,20 +0,0 @@
|
||||
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,13 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config"
|
||||
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/env"
|
||||
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||
apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config"
|
||||
)
|
||||
|
||||
var (
|
||||
GetConns = viseconfig.GetConns
|
||||
EnvPath string
|
||||
)
|
||||
|
||||
func loadEnv() {
|
||||
if EnvPath == "" {
|
||||
func init() {
|
||||
env.LoadEnvVariables()
|
||||
} else {
|
||||
env.LoadEnvVariablesPath(EnvPath)
|
||||
}
|
||||
}
|
||||
|
||||
const (
|
||||
@ -26,11 +15,10 @@ const (
|
||||
defaultSSHPort uint = 7122
|
||||
defaultHTTPHost string = "127.0.0.1"
|
||||
defaultHTTPPort uint = 7123
|
||||
defaultDomain = "sarafu.local"
|
||||
)
|
||||
|
||||
|
||||
func LoadConfig() error {
|
||||
loadEnv()
|
||||
err := viseconfig.LoadConfig()
|
||||
if err != nil {
|
||||
return err
|
||||
@ -42,16 +30,9 @@ func LoadConfig() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
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, " ", ""))
|
||||
func DbConn() string {
|
||||
return viseconfig.DbConn
|
||||
}
|
||||
return ParsedDomains
|
||||
}
|
||||
|
||||
|
||||
func Language() string {
|
||||
return viseconfig.DefaultLanguage
|
||||
|
31
debug/db.go
31
debug/db.go
@ -1,11 +1,11 @@
|
||||
package debug
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"encoding/binary"
|
||||
|
||||
visedb "git.defalsify.org/vise.git/db"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
visedb "git.defalsify.org/vise.git/db"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -32,10 +32,18 @@ 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 {
|
||||
@ -45,17 +53,28 @@ 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)
|
||||
k = k[2:]
|
||||
}
|
||||
|
||||
if len(k) != 0 {
|
||||
return o, fmt.Errorf("excess key information")
|
||||
}
|
||||
|
||||
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]
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
//go:build debugdb
|
||||
// +build debugdb
|
||||
|
||||
package debug
|
||||
@ -30,9 +29,6 @@ func init() {
|
||||
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"
|
||||
|
@ -3,13 +3,14 @@ package debug
|
||||
import (
|
||||
"testing"
|
||||
|
||||
visedb "git.defalsify.org/vise.git/db"
|
||||
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
|
||||
visedb "git.defalsify.org/vise.git/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 {
|
||||
@ -55,6 +56,7 @@ 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...)
|
||||
|
||||
|
7
devtools/admin/admin_numbers.json
Normal file
7
devtools/admin/admin_numbers.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"admins": [
|
||||
{
|
||||
"phonenumber" : "<replace with any admin number to test with >"
|
||||
}
|
||||
]
|
||||
}
|
47
devtools/admin/commands/seed.go
Normal file
47
devtools/admin/commands/seed.go
Normal file
@ -0,0 +1,47 @@
|
||||
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,74 +2,16 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"log"
|
||||
|
||||
"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")
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/devtools/admin/commands"
|
||||
)
|
||||
|
||||
func main() {
|
||||
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 {
|
||||
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)
|
||||
err := commands.Seed(ctx)
|
||||
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)
|
||||
log.Fatalf("Failed to initialize a list of admins with error %s", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,12 +8,13 @@ import (
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.defalsify.org/vise.git/lang"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/config"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
changeHeadSrc = `LOAD reset_account_authorized 0
|
||||
LOAD reset_incorrect 0
|
||||
CATCH incorrect_pin flag_incorrect_pin 1
|
||||
@ -62,7 +63,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)
|
||||
|
@ -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,58 +19,55 @@ var (
|
||||
scriptDir = path.Join("services", "registration")
|
||||
)
|
||||
|
||||
func formatItem(k []byte, v []byte, sessionId string) (string, error) {
|
||||
o, err := debug.ToKeyInfo(k, sessionId)
|
||||
func formatItem(k []byte, v []byte) (string, error) {
|
||||
o, err := debug.FromKey(k)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
s := fmt.Sprintf("%v\t%v\n", o.Label, string(v))
|
||||
|
||||
s := fmt.Sprintf("%vValue: %v\n\n", o, string(v))
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
config.LoadConfig()
|
||||
|
||||
override := config.NewOverride()
|
||||
var connStr string
|
||||
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(&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.StringVar(&connStr, "c", ".state", "connection string")
|
||||
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
|
||||
flag.Parse()
|
||||
|
||||
config.Apply(override)
|
||||
conns, err := config.GetConns()
|
||||
if connStr != "" {
|
||||
connStr = config.DbConn()
|
||||
}
|
||||
connData, err := storage.ToConnData(connStr)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
logg.Infof("start command", "conn", conns)
|
||||
logg.Infof("start command", "conn", connData)
|
||||
|
||||
ctx := context.Background()
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
ctx = context.WithValue(ctx, "Database", database)
|
||||
|
||||
menuStorageService := storage.NewMenuStorageService(conns)
|
||||
resourceDir := scriptDir
|
||||
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
|
||||
|
||||
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(""))
|
||||
d, err := store.Dump(ctx, []byte(sessionId))
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "store dump fail: %v\n", err.Error())
|
||||
os.Exit(1)
|
||||
@ -81,19 +78,15 @@ func main() {
|
||||
if k == nil {
|
||||
break
|
||||
}
|
||||
if !first {
|
||||
fmt.Printf("Session ID: %s\n---\n", sessionId)
|
||||
first = true
|
||||
}
|
||||
r, err := formatItem(append([]byte{db.DATATYPE_USERDATA}, k...), v, sessionId)
|
||||
r, err := formatItem(k, v)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "format db item error: %v\n", err)
|
||||
fmt.Fprintf(os.Stderr, "format db item error: %v", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Printf(r)
|
||||
}
|
||||
|
||||
err = store.Close(ctx)
|
||||
err = store.Close()
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, err.Error())
|
||||
os.Exit(1)
|
||||
|
86
devtools/store/generate/main.go
Normal file
86
devtools/store/generate/main.go
Normal file
@ -0,0 +1,86 @@
|
||||
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.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
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250115000535-e2d329b3f739
|
||||
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250115072214-bca7c5de969f
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63
|
||||
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d
|
||||
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.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=
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250115000535-e2d329b3f739 h1:w7pj1oh7jXrfajahVYU7m7AfHst4C6jNVzDVoaqJ7e8=
|
||||
git.defalsify.org/vise.git v0.2.3-0.20250115000535-e2d329b3f739/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-20250115072214-bca7c5de969f h1:FgccQi8vipX6dUt+GRiRDYHMR3UqC+plz73vw7y3fyU=
|
||||
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250115072214-bca7c5de969f/go.mod h1:tbA4whUGMUIDgQVdIW0sxWPuuXOvZRSny5zeku5hX4k=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63 h1:bX7klKZpX+ZZu1LKbtOXDAhV/KK0YwExehiIi0jusAM=
|
||||
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63/go.mod h1:Syw9TZyigPAM7t9FvicOm36iUnidt45f0SxzT2JniQ8=
|
||||
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=
|
||||
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/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-api/testutil/mocks"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
|
||||
"git.grassecon.net/grassrootseconomics/common/pin"
|
||||
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(ctx) // Ensure the DB is closed after each test
|
||||
db.Close() // 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, store, &accountService, mockReplaceSeparator)
|
||||
handlers, err := NewMenuHandlers(fm.parser, store, nil, &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, nil, &accountService, mockReplaceSeparator)
|
||||
handlers, err := NewMenuHandlers(fm.parser, nil, nil, &accountService, mockReplaceSeparator)
|
||||
if err == nil {
|
||||
t.Fatal("expected an error, got none")
|
||||
}
|
||||
@ -132,9 +132,16 @@ 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)
|
||||
@ -154,40 +161,49 @@ func TestInit(t *testing.T) {
|
||||
setup: func() (*MenuHandlers, context.Context) {
|
||||
pe := persist.NewPersister(testStore).WithSession(sessionId).WithContent(st, ca)
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
adminstore: adminstore,
|
||||
pe: pe,
|
||||
}
|
||||
return h, context.WithValue(ctx, "SessionId", sessionId)
|
||||
},
|
||||
input: []byte("1"),
|
||||
expectedResult: resource.Result{},
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_admin_privilege},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Non-admin session initialization",
|
||||
setup: func() (*MenuHandlers, context.Context) {
|
||||
pe := persist.NewPersister(testStore).WithSession("0712345678").WithContent(st, ca)
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
adminstore: adminstore,
|
||||
pe: pe,
|
||||
}
|
||||
return h, context.WithValue(context.Background(), "SessionId", "0712345678")
|
||||
},
|
||||
input: []byte("1"),
|
||||
expectedResult: resource.Result{},
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_admin_privilege},
|
||||
},
|
||||
},
|
||||
{
|
||||
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,
|
||||
flagManager: fm.parser,
|
||||
adminstore: adminstore,
|
||||
pe: pe,
|
||||
}
|
||||
st.Code = []byte("some pending bytecode")
|
||||
return h, context.WithValue(ctx, "SessionId", sessionId)
|
||||
},
|
||||
input: []byte(""),
|
||||
expectedResult: resource.Result{},
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_admin_privilege},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@ -240,7 +256,7 @@ func TestCreateAccount(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
mockAccountService.On("CreateAccount").Return(tt.serverResponse, nil)
|
||||
@ -304,7 +320,7 @@ func TestSaveFirstname(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -349,7 +365,7 @@ func TestSaveFamilyname(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
st: mockState,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@ -392,7 +408,7 @@ func TestSaveYoB(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -436,7 +452,7 @@ func TestSaveLocation(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -480,7 +496,7 @@ func TestSaveOfferings(t *testing.T) {
|
||||
// Create the MenuHandlers instance with the mock store
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -548,7 +564,7 @@ func TestSaveGender(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
st: mockState,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
expectedResult := resource.Result{}
|
||||
@ -579,11 +595,11 @@ func TestSaveTemporaryPin(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_incorrect_pin, _ := fm.GetFlag("flag_incorrect_pin")
|
||||
flag_incorrect_pin, _ := fm.parser.GetFlag("flag_incorrect_pin")
|
||||
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
userdataStore: store,
|
||||
}
|
||||
|
||||
@ -796,7 +812,7 @@ func TestSetLanguage(t *testing.T) {
|
||||
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
userdataStore: store,
|
||||
st: mockState,
|
||||
}
|
||||
@ -830,7 +846,7 @@ func TestResetAllowUpdate(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_allow_update, _ := fm.GetFlag("flag_allow_update")
|
||||
flag_allow_update, _ := fm.parser.GetFlag("flag_allow_update")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@ -851,7 +867,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,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@ -872,7 +888,7 @@ func TestResetAccountAuthorized(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_account_authorized, _ := fm.GetFlag("flag_account_authorized")
|
||||
flag_account_authorized, _ := fm.parser.GetFlag("flag_account_authorized")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@ -893,7 +909,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,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@ -917,8 +933,8 @@ func TestIncorrectPinReset(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_incorrect_pin, _ := fm.GetFlag("flag_incorrect_pin")
|
||||
flag_account_blocked, _ := fm.GetFlag("flag_account_blocked")
|
||||
flag_incorrect_pin, _ := fm.parser.GetFlag("flag_incorrect_pin")
|
||||
flag_account_blocked, _ := fm.parser.GetFlag("flag_account_blocked")
|
||||
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
@ -976,7 +992,7 @@ func TestIncorrectPinReset(t *testing.T) {
|
||||
|
||||
// Create the MenuHandlers instance with the mock flag manager
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
userdataStore: store,
|
||||
}
|
||||
|
||||
@ -998,7 +1014,7 @@ func TestResetIncorrectYob(t *testing.T) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
flag_incorrect_date_format, _ := fm.GetFlag("flag_incorrect_date_format")
|
||||
flag_incorrect_date_format, _ := fm.parser.GetFlag("flag_incorrect_date_format")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@ -1019,7 +1035,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,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
// Call the method
|
||||
@ -1057,7 +1073,7 @@ func TestAuthorize(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -1125,12 +1141,12 @@ func TestVerifyYob(t *testing.T) {
|
||||
// Create required mocks
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
mockState := state.NewState(16)
|
||||
flag_incorrect_date_format, _ := fm.GetFlag("flag_incorrect_date_format")
|
||||
flag_incorrect_date_format, _ := fm.parser.GetFlag("flag_incorrect_date_format")
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
|
||||
h := &MenuHandlers{
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -1190,14 +1206,14 @@ func TestVerifyCreatePin(t *testing.T) {
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
mockState := state.NewState(16)
|
||||
|
||||
flag_valid_pin, _ := fm.GetFlag("flag_valid_pin")
|
||||
flag_pin_mismatch, _ := fm.GetFlag("flag_pin_mismatch")
|
||||
flag_pin_set, _ := fm.GetFlag("flag_pin_set")
|
||||
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")
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
st: mockState,
|
||||
}
|
||||
|
||||
@ -1223,20 +1239,13 @@ 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))
|
||||
|
||||
@ -1298,7 +1307,7 @@ func TestCheckAccountStatus(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(tt.publicKey))
|
||||
@ -1338,7 +1347,7 @@ func TestTransactionReset(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -1378,14 +1387,14 @@ func TestResetTransactionAmount(t *testing.T) {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
|
||||
flag_invalid_amount, _ := fm.GetFlag("flag_invalid_amount")
|
||||
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@ -1422,14 +1431,14 @@ func TestInitiateTransaction(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
account_authorized_flag, _ := fm.GetFlag("flag_account_authorized")
|
||||
account_authorized_flag, _ := fm.parser.GetFlag("flag_account_authorized")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
@ -1515,7 +1524,7 @@ func TestQuit(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Logf(err.Error())
|
||||
}
|
||||
flag_account_authorized, _ := fm.GetFlag("flag_account_authorized")
|
||||
flag_account_authorized, _ := fm.parser.GetFlag("flag_account_authorized")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
@ -1525,7 +1534,7 @@ func TestQuit(t *testing.T) {
|
||||
|
||||
h := &MenuHandlers{
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -1568,14 +1577,14 @@ func TestValidateAmount(t *testing.T) {
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
flag_invalid_amount, _ := fm.GetFlag("flag_invalid_amount")
|
||||
flag_invalid_amount, _ := fm.parser.GetFlag("flag_invalid_amount")
|
||||
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
@ -1642,8 +1651,8 @@ func TestValidateRecipient(t *testing.T) {
|
||||
ctx, store := InitializeTestStore(t)
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
flag_invalid_recipient, _ := fm.GetFlag("flag_invalid_recipient")
|
||||
flag_invalid_recipient_with_invite, _ := fm.GetFlag("flag_invalid_recipient_with_invite")
|
||||
flag_invalid_recipient, _ := fm.parser.GetFlag("flag_invalid_recipient")
|
||||
flag_invalid_recipient_with_invite, _ := fm.parser.GetFlag("flag_invalid_recipient_with_invite")
|
||||
|
||||
// Define test cases
|
||||
tests := []struct {
|
||||
@ -1679,7 +1688,7 @@ func TestValidateRecipient(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "Test with alias recepient",
|
||||
input: []byte("alias123.sarafu.local"),
|
||||
input: []byte("alias123"),
|
||||
expectedResult: resource.Result{},
|
||||
},
|
||||
}
|
||||
@ -1695,7 +1704,7 @@ func TestValidateRecipient(t *testing.T) {
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
// Create the MenuHandlers instance
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
@ -1797,37 +1806,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, storedb.DATA_ACCOUNT_ALIAS},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
|
||||
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"},
|
||||
languageCode: "eng",
|
||||
result: resource.Result{
|
||||
Content: fmt.Sprintf(
|
||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\nYour alias: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
|
||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas",
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
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, storedb.DATA_ACCOUNT_ALIAS},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
|
||||
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"},
|
||||
languageCode: "swa",
|
||||
result: resource.Result{
|
||||
Content: fmt.Sprintf(
|
||||
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\nLakabu yako: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
|
||||
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas",
|
||||
),
|
||||
},
|
||||
},
|
||||
{
|
||||
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, storedb.DATA_ACCOUNT_ALIAS},
|
||||
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
|
||||
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"},
|
||||
languageCode: "nor",
|
||||
result: resource.Result{
|
||||
Content: fmt.Sprintf(
|
||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\nYour alias: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
|
||||
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
|
||||
"John Doee", "Male", "49", "Kilifi", "Bananas",
|
||||
),
|
||||
},
|
||||
},
|
||||
@ -1858,10 +1867,10 @@ func TestVerifyNewPin(t *testing.T) {
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
|
||||
flag_valid_pin, _ := fm.GetFlag("flag_valid_pin")
|
||||
flag_valid_pin, _ := fm.parser.GetFlag("flag_valid_pin")
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
h := &MenuHandlers{
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
ctx := context.WithValue(context.Background(), "SessionId", sessionId)
|
||||
@ -1904,24 +1913,24 @@ func TestConfirmPin(t *testing.T) {
|
||||
ctx = context.WithValue(ctx, "SessionId", sessionId)
|
||||
|
||||
fm, _ := NewFlagManager(flagsPath)
|
||||
flag_pin_mismatch, _ := fm.GetFlag("flag_pin_mismatch")
|
||||
flag_pin_mismatch, _ := fm.parser.GetFlag("flag_pin_mismatch")
|
||||
mockAccountService := new(mocks.MockAccountService)
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
input []byte
|
||||
temporarypin string
|
||||
temporarypin []byte
|
||||
expectedResult resource.Result
|
||||
}{
|
||||
{
|
||||
name: "Test with correct pin confirmation",
|
||||
input: []byte("1234"),
|
||||
temporarypin: "1234",
|
||||
temporarypin: []byte("1234"),
|
||||
expectedResult: resource.Result{
|
||||
FlagReset: []uint32{flag_pin_mismatch},
|
||||
},
|
||||
@ -1929,21 +1938,14 @@ 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(hashedPIN))
|
||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.temporarypin))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
//Call the function under test
|
||||
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.input)
|
||||
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.temporarypin)
|
||||
|
||||
//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")
|
||||
@ -2045,7 +2047,7 @@ func TestSetDefaultVoucher(t *testing.T) {
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
accountService: mockAccountService,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
}
|
||||
|
||||
err := store.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(publicKey))
|
||||
@ -2153,7 +2155,7 @@ func TestViewVoucher(t *testing.T) {
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
prefixDb: spdb,
|
||||
}
|
||||
|
||||
@ -2226,7 +2228,7 @@ func TestGetVoucherDetails(t *testing.T) {
|
||||
|
||||
h := &MenuHandlers{
|
||||
userdataStore: store,
|
||||
flagManager: fm,
|
||||
flagManager: fm.parser,
|
||||
accountService: mockAccountService,
|
||||
}
|
||||
err = store.WriteEntry(ctx, sessionId, storedb.DATA_ACTIVE_ADDRESS, []byte(tokA_AAddress))
|
||||
|
@ -35,6 +35,13 @@ 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/logging"
|
||||
"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.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"
|
||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -6,10 +6,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"git.defalsify.org/vise.git/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"
|
||||
"git.grassecon.net/grassrootseconomics/common/identity"
|
||||
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
|
||||
)
|
||||
|
||||
// execute all
|
||||
@ -47,6 +47,7 @@ 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)
|
||||
@ -58,6 +59,7 @@ 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.
|
||||
@ -187,7 +189,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,6 +4,7 @@ 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"
|
||||
@ -11,33 +12,45 @@ 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 *application.FlagManager
|
||||
Parser *asm.FlagParser
|
||||
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 := application.NewFlagManager(fp)
|
||||
parser, err := getParser(fp, debug)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if debug {
|
||||
parser.SetDebug()
|
||||
adminstore, err := store.NewAdminStore(ctx, "admin_numbers")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &LocalHandlerService{
|
||||
Parser: parser,
|
||||
DbRs: dbResource,
|
||||
AdminStore: adminstore,
|
||||
Cfg: cfg,
|
||||
Rs: rs,
|
||||
}, nil
|
||||
@ -56,13 +69,12 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
|
||||
return strings.ReplaceAll(input, ":", ls.Cfg.MenuSeparator)
|
||||
}
|
||||
|
||||
appHandlers, err := application.NewMenuHandlers(ls.Parser, *ls.UserdataStore, accountService, replaceSeparatorFunc)
|
||||
appHandlers, err := application.NewMenuHandlers(ls.Parser, *ls.UserdataStore, ls.AdminStore, 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)
|
||||
|
@ -1,96 +0,0 @@
|
||||
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\nYour alias: \n\n0:Back\n9:Quit"
|
||||
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back\n9:Quit"
|
||||
},
|
||||
{
|
||||
"input": "0",
|
||||
|
@ -9,14 +9,12 @@ import (
|
||||
"regexp"
|
||||
"testing"
|
||||
|
||||
"git.defalsify.org/vise.git/logging"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/testutil"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/testutil/driver"
|
||||
"github.com/gofrs/uuid"
|
||||
"git.grassecon.net/grassrootseconomics/visedriver/testutil/driver"
|
||||
"git.grassecon.net/grassrootseconomics/sarafu-vise/testutil"
|
||||
)
|
||||
|
||||
var (
|
||||
logg = logging.NewVanilla().WithDomain("menutraversaltest")
|
||||
testData = driver.ReadData()
|
||||
sessionID string
|
||||
src = rand.NewSource(42)
|
||||
@ -24,6 +22,9 @@ 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))
|
||||
@ -79,7 +80,12 @@ 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()
|
||||
|
||||
@ -94,8 +100,7 @@ func TestAccountCreationSuccessful(t *testing.T) {
|
||||
for _, session := range sessions {
|
||||
groups := driver.FilterGroupsByName(session.Groups, "account_creation_successful")
|
||||
for _, group := range groups {
|
||||
for i, step := range group.Steps {
|
||||
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
|
||||
for _, step := range group.Steps {
|
||||
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)
|
||||
@ -137,8 +142,7 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
|
||||
for _, session := range sessions {
|
||||
groups := driver.FilterGroupsByName(session.Groups, "account_creation_reject_terms")
|
||||
for _, group := range groups {
|
||||
for i, step := range group.Steps {
|
||||
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
|
||||
for _, step := range group.Steps {
|
||||
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)
|
||||
@ -173,8 +177,7 @@ func TestMainMenuHelp(t *testing.T) {
|
||||
for _, session := range sessions {
|
||||
groups := driver.FilterGroupsByName(session.Groups, "main_menu_help")
|
||||
for _, group := range groups {
|
||||
for i, step := range group.Steps {
|
||||
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
|
||||
for _, step := range group.Steps {
|
||||
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)
|
||||
|
@ -1,17 +1,16 @@
|
||||
//go:build !online
|
||||
// +build !online
|
||||
|
||||
package services
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"context"
|
||||
|
||||
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"
|
||||
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/handlers/event"
|
||||
)
|
||||
|
||||
type localEmitter struct {
|
||||
@ -38,7 +37,7 @@ func (d *localEmitter) emit(ctx context.Context, msg apievent.Msg) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func New(ctx context.Context, storageService storage.StorageService) remote.AccountService {
|
||||
func New(ctx context.Context, storageService storage.StorageService, conn storage.ConnData) remote.AccountService {
|
||||
svc := devremote.NewDevAccountService(ctx, storageService)
|
||||
svc = svc.WithAutoVoucher(ctx, "FOO", 42)
|
||||
eu := event.NewEventsUpdater(svc, storageService)
|
||||
|
@ -4,8 +4,8 @@ TXTS = $(wildcard ./*.txt.orig)
|
||||
VISE_PATH := ../../go-vise
|
||||
|
||||
# Rule to build .bin files from .vis files
|
||||
%.vis: buildasm
|
||||
./vise-asm -f pp.csv $(basename $@).vis > $(basename $@).bin
|
||||
%.vis:
|
||||
go run $(VISE_PATH)/dev/asm/main.go -f pp.csv $(basename $@).vis > $(basename $@).bin
|
||||
@echo "Built $(basename $@).bin from $(basename $@).vis"
|
||||
|
||||
# Rule to copy .orig files to .txt
|
||||
@ -19,10 +19,5 @@ 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
|
||||
|
BIN
services/registration/_catch.bin
Normal file
BIN
services/registration/_catch.bin
Normal file
Binary file not shown.
BIN
services/registration/account_creation.bin
Normal file
BIN
services/registration/account_creation.bin
Normal file
Binary file not shown.
BIN
services/registration/account_creation_failed.bin
Normal file
BIN
services/registration/account_creation_failed.bin
Normal file
Binary file not shown.
@ -1 +1 @@
|
||||
Your account is still being created. For more help, please call: 0757628885
|
||||
Your account is still being created.
|
BIN
services/registration/account_pending.bin
Normal file
BIN
services/registration/account_pending.bin
Normal file
Binary file not shown.
@ -1 +1 @@
|
||||
Akaunti yako bado inatengenezwa. Kwa usaidizi zaidi, piga: 0757628885
|
||||
Akaunti yako bado inatengenezwa
|
BIN
services/registration/address.bin
Normal file
BIN
services/registration/address.bin
Normal file
Binary file not shown.
BIN
services/registration/amount.bin
Normal file
BIN
services/registration/amount.bin
Normal file
Binary file not shown.
BIN
services/registration/api_failure.bin
Normal file
BIN
services/registration/api_failure.bin
Normal file
Binary file not shown.
BIN
services/registration/balances.bin
Normal file
BIN
services/registration/balances.bin
Normal file
Binary file not shown.
BIN
services/registration/blocked_account.bin
Normal file
BIN
services/registration/blocked_account.bin
Normal file
Binary file not shown.
BIN
services/registration/change_language.bin
Normal file
BIN
services/registration/change_language.bin
Normal file
Binary file not shown.
BIN
services/registration/check_statement.bin
Normal file
BIN
services/registration/check_statement.bin
Normal file
Binary file not shown.
BIN
services/registration/community_balance.bin
Normal file
BIN
services/registration/community_balance.bin
Normal file
Binary file not shown.
BIN
services/registration/confirm_create_pin.bin
Normal file
BIN
services/registration/confirm_create_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/confirm_others_new_pin.bin
Normal file
BIN
services/registration/confirm_others_new_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/confirm_pin_change.bin
Normal file
BIN
services/registration/confirm_pin_change.bin
Normal file
Binary file not shown.
BIN
services/registration/create_pin.bin
Normal file
BIN
services/registration/create_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/create_pin_mismatch.bin
Normal file
BIN
services/registration/create_pin_mismatch.bin
Normal file
Binary file not shown.
BIN
services/registration/display_profile_info.bin
Normal file
BIN
services/registration/display_profile_info.bin
Normal file
Binary file not shown.
BIN
services/registration/edit_family_name.bin
Normal file
BIN
services/registration/edit_family_name.bin
Normal file
Binary file not shown.
BIN
services/registration/edit_first_name.bin
Normal file
BIN
services/registration/edit_first_name.bin
Normal file
Binary file not shown.
BIN
services/registration/edit_location.bin
Normal file
BIN
services/registration/edit_location.bin
Normal file
Binary file not shown.
BIN
services/registration/edit_offerings.bin
Normal file
BIN
services/registration/edit_offerings.bin
Normal file
Binary file not shown.
BIN
services/registration/edit_profile.bin
Normal file
BIN
services/registration/edit_profile.bin
Normal file
Binary file not shown.
BIN
services/registration/edit_yob.bin
Normal file
BIN
services/registration/edit_yob.bin
Normal file
Binary file not shown.
BIN
services/registration/enter_other_number.bin
Normal file
BIN
services/registration/enter_other_number.bin
Normal file
Binary file not shown.
BIN
services/registration/enter_others_new_pin.bin
Normal file
BIN
services/registration/enter_others_new_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/enter_pin.bin
Normal file
BIN
services/registration/enter_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/help.bin
Normal file
BIN
services/registration/help.bin
Normal file
Binary file not shown.
BIN
services/registration/incorrect_date_format.bin
Normal file
BIN
services/registration/incorrect_date_format.bin
Normal file
Binary file not shown.
BIN
services/registration/incorrect_pin.bin
Normal file
BIN
services/registration/incorrect_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/invalid_amount.bin
Normal file
BIN
services/registration/invalid_amount.bin
Normal file
Binary file not shown.
BIN
services/registration/invalid_others_pin.bin
Normal file
BIN
services/registration/invalid_others_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/invalid_pin.bin
Normal file
BIN
services/registration/invalid_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/invalid_recipient.bin
Normal file
BIN
services/registration/invalid_recipient.bin
Normal file
Binary file not shown.
BIN
services/registration/invite_recipient.bin
Normal file
BIN
services/registration/invite_recipient.bin
Normal file
Binary file not shown.
BIN
services/registration/invite_result.bin
Normal file
BIN
services/registration/invite_result.bin
Normal file
Binary file not shown.
BIN
services/registration/language_changed.bin
Normal file
BIN
services/registration/language_changed.bin
Normal file
Binary file not shown.
0
services/registration/list_offering.bin
Normal file
0
services/registration/list_offering.bin
Normal file
BIN
services/registration/main.bin
Normal file
BIN
services/registration/main.bin
Normal file
Binary file not shown.
BIN
services/registration/my_account.bin
Normal file
BIN
services/registration/my_account.bin
Normal file
Binary file not shown.
BIN
services/registration/my_balance.bin
Normal file
BIN
services/registration/my_balance.bin
Normal file
Binary file not shown.
BIN
services/registration/my_vouchers.bin
Normal file
BIN
services/registration/my_vouchers.bin
Normal file
Binary file not shown.
BIN
services/registration/new_pin.bin
Normal file
BIN
services/registration/new_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/no_admin_privilege.bin
Normal file
BIN
services/registration/no_admin_privilege.bin
Normal file
Binary file not shown.
BIN
services/registration/no_transfers.bin
Normal file
BIN
services/registration/no_transfers.bin
Normal file
Binary file not shown.
BIN
services/registration/no_voucher.bin
Normal file
BIN
services/registration/no_voucher.bin
Normal file
Binary file not shown.
BIN
services/registration/old_pin.bin
Normal file
BIN
services/registration/old_pin.bin
Normal file
Binary file not shown.
BIN
services/registration/others_pin_mismatch.bin
Normal file
BIN
services/registration/others_pin_mismatch.bin
Normal file
Binary file not shown.
BIN
services/registration/pin_entry.bin
Normal file
BIN
services/registration/pin_entry.bin
Normal file
Binary file not shown.
BIN
services/registration/pin_management.bin
Normal file
BIN
services/registration/pin_management.bin
Normal file
Binary file not shown.
BIN
services/registration/pin_reset_mismatch.bin
Normal file
BIN
services/registration/pin_reset_mismatch.bin
Normal file
Binary file not shown.
BIN
services/registration/pin_reset_result.bin
Normal file
BIN
services/registration/pin_reset_result.bin
Normal file
Binary file not shown.
BIN
services/registration/pin_reset_success.bin
Normal file
BIN
services/registration/pin_reset_success.bin
Normal file
Binary file not shown.
BIN
services/registration/profile_update_success.bin
Normal file
BIN
services/registration/profile_update_success.bin
Normal file
Binary file not shown.
BIN
services/registration/quit.bin
Normal file
BIN
services/registration/quit.bin
Normal file
Binary file not shown.
BIN
services/registration/root.bin
Normal file
BIN
services/registration/root.bin
Normal file
Binary file not shown.
@ -1,5 +1,3 @@
|
||||
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
|
||||
|
BIN
services/registration/select_gender.bin
Normal file
BIN
services/registration/select_gender.bin
Normal file
Binary file not shown.
BIN
services/registration/select_language.bin
Normal file
BIN
services/registration/select_language.bin
Normal file
Binary file not shown.
BIN
services/registration/select_voucher.bin
Normal file
BIN
services/registration/select_voucher.bin
Normal file
Binary file not shown.
BIN
services/registration/send.bin
Normal file
BIN
services/registration/send.bin
Normal file
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 50
|
||||
LOAD validate_recipient 20
|
||||
RELOAD validate_recipient
|
||||
CATCH invalid_recipient flag_invalid_recipient 1
|
||||
CATCH invite_recipient flag_invalid_recipient_with_invite 1
|
||||
|
BIN
services/registration/set_default.bin
Normal file
BIN
services/registration/set_default.bin
Normal file
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