Compare commits

..

68 Commits

Author SHA1 Message Date
d2f75c693a Merge pull request 'alias-fqdn' (#9) from alias-fqdn into master
Reviewed-on: #9
2025-01-25 13:46:29 +01:00
363c35efed
update test data file 2025-01-25 09:55:39 +03:00
0f361a065b Merge branch 'master' into alias-fqdn 2025-01-24 13:08:29 +01:00
lash
4d1045a9f9
Adapt override to non-pointer values 2025-01-24 15:03:47 +03:00
lash
f3a6485bb3
Avoid overwrite of env configs 2025-01-24 15:02:31 +03:00
cd37adc288
update test 2025-01-24 15:02:30 +03:00
6f0994d692
feat: show alias as part of the profile information 2025-01-24 15:02:30 +03:00
lash
fbaba15776
Adapt override to non-pointer values 2025-01-24 10:15:37 +00:00
lash
9a094f440f
Avoid overwrite of env configs 2025-01-24 08:47:23 +00:00
6c77ff58ab Merge branch 'master' into alias-fqdn 2025-01-24 09:44:50 +01:00
c8ddafcf66
run go mod tidy 2025-01-24 11:41:25 +03:00
5f1a659789
request alias on initial profile setup 2025-01-24 11:41:00 +03:00
0d4be0f7fc
return nil when error is key not found 2025-01-24 10:12:28 +03:00
b6161da749
fix failing test 2025-01-24 09:32:21 +03:00
f1c4d5f1f9
docker: change bin name -> sarafu-at 2025-01-24 09:26:00 +03:00
73b876dbdd
ci/cd: add Dockerfile and GH builds 2025-01-24 09:25:09 +03:00
18e865ba26
set UseApi and storageservice to HttpAccountService 2025-01-24 07:59:33 +03:00
d7c909f028
update sarafu-api dep 2025-01-24 07:58:03 +03:00
908a52cda6
Merge branch 'master' into alias-fqdn 2025-01-24 07:41:33 +03:00
526dc822fb Merge pull request 'remove unused New conn argument' (#14) from fix-remote-new-args into master
Reviewed-on: #14
2025-01-23 09:29:25 +01:00
1249e45d54
remove unused New conn argument 2025-01-23 11:22:34 +03:00
lash
99d03e3bc9
Fix signal handling for termination, proper engine cleanup 2025-01-22 19:08:57 +00:00
lash
1e495763f5
Fmt 2025-01-22 18:37:27 +00:00
lash
5e83c89e03
Correct override handling for mode 2025-01-22 16:40:32 +00:00
lash
1909b60bf4
Reinstate resource-dir switch 2025-01-22 09:42:39 +00:00
lash
49335a290f
Gofmt, remove commented code 2025-01-21 15:43:26 +00:00
lash
2c8e60e1bb
Add gdbmdb testutil 2025-01-21 15:02:32 +00:00
lash
4baacb325d Merge branch 'master' into lash/dbtx 2025-01-21 14:26:48 +00:00
lash
c243edd4c4
Make override constructor for args population 2025-01-21 14:25:55 +00:00
44846c5950 Merge pull request 'Add transactional vise db ability' (#11) from lash/dbtx into master
Reviewed-on: #11
2025-01-21 15:15:15 +01:00
lash
592c57b72d
Update deps, unique fsdbs in testfsdb 2025-01-21 14:14:52 +00:00
lash
341f0b9cc8 Merge branch 'master' into lash/dbtx 2025-01-21 13:45:33 +00:00
lash
1c911ee73f Merge branch 'master' into lash/dbtx 2025-01-21 13:44:56 +00:00
lash
00b9079a55
Clean up spaces 2025-01-21 13:44:32 +00:00
ec6b078de3
fix: import config and model packages 2025-01-21 15:23:21 +03:00
0b4fde9d1e
Merge branch 'master' into alias-fqdn 2025-01-21 12:53:50 +03:00
66be350ad1
remove accountservice implementation check 2025-01-21 12:48:17 +03:00
lash
156511e499
Build vise-asm binary in makefile 2025-01-21 08:17:23 +00:00
lash
8b68130ed4
Remove bin files 2025-01-21 08:11:26 +00:00
lash
7ab8eef623 Merge branch 'reset-account-blocked-flag' into lash/dbtx 2025-01-21 08:02:56 +00:00
7d513ac2a7 Merge pull request 'reset account blocked flag' (#13) from reset-account-blocked-flag into master
Reviewed-on: #13
2025-01-21 07:47:33 +01:00
fbee26da08
added CheckBlockedStatus to reset the flag_account_blocked if the incorrect PIN attempt has been reset 2025-01-21 02:29:59 +03:00
4fb3474b51
reset the incorrect PIN attempts to 0 when the PIN is reset 2025-01-21 02:28:19 +03:00
lash
b31011b390
Update deps 2025-01-20 12:37:02 +00:00
lash
358567e52e Merge remote-tracking branch 'origin/master' into lash/dbtx 2025-01-20 12:01:35 +00:00
9c05e0b4a2 Merge pull request 'Encrypt PIN in temporary value' (#12) from encrypt-pin into master
Reviewed-on: #12
2025-01-20 13:00:37 +01:00
57fb1d0ef3 Merge branch 'master' into encrypt-pin 2025-01-20 12:59:57 +01:00
2dcec2e9fb
update tests to match changes in menuhandler 2025-01-20 14:46:12 +03:00
286a72f12e
hash the PIN in temporary value and arrange functions 2025-01-20 14:44:53 +03:00
lash
933943636e
Implement conns in testutil 2025-01-20 10:28:42 +00:00
1e69f2167a
Merge branch 'master' into alias-fqdn 2025-01-20 12:32:29 +03:00
4e584cea92
increase size limit to allow fqdn for the alias 2025-01-20 12:16:05 +03:00
lash
20feef4103
WIP integrate multiple conns, menutraversal now panics 2025-01-19 18:27:47 +00:00
lash
8d5d3f1dc8
WIP implement multi connstr config 2025-01-19 16:32:55 +00:00
lash
0f54ab4b4a
Update deps, fix connbusy error in postgres get 2025-01-19 11:11:34 +00:00
lash
be47c999ca
Integrate tx enabled vise db 2025-01-19 09:46:37 +00:00
lash
c719db8b92
Update dep 2025-01-18 19:35:48 +00:00
lash
16cb2846b7
Update govise dep; removes hardcoded datatype 2025-01-18 09:00:44 +00:00
lash
bc2abc2464
Update govise dep, dump keys fix 2025-01-18 08:23:40 +00:00
f435046385
Merge branch 'master' into alias-fqdn 2025-01-18 08:01:58 +03:00
efaf0ab22e
feat: construct an account alias 2025-01-18 07:53:42 +03:00
e29bcb5b27
define and parse alias search domains 2025-01-18 07:52:08 +03:00
cdb22f8cbb
add key for the account alias 2025-01-18 07:50:55 +03:00
lash
9cb9e02442 Merge branch 'master' into lash/update-dump 2025-01-17 18:56:43 +00:00
6aa4bd8906
add alias search domains 2025-01-17 15:02:58 +03:00
lash
ab03e6d529
Rehabilitate debug db tets, improve dump format 2025-01-17 11:09:30 +00:00
lash
9b66146ef1
Remove generate tool (use devapi main instead) 2025-01-17 10:36:29 +00:00
lash
825c06c3bb
Rehabilitate dump tool 2025-01-17 10:36:02 +00:00
133 changed files with 1298 additions and 1060 deletions

16
.dockerignore Normal file
View File

@ -0,0 +1,16 @@
/**
!/args
!/cmd/africastalking
!/cmd/ssh
!/config
!/debug
!/handlers
!/internal
!/profile
!/services
!/ssh
!/store
!/LICENSE
!/README.md
!/go.*
!/.env.example

View File

@ -18,3 +18,6 @@ DATA_URL_BASE=http://localhost:5006
#Language
DEFAULT_LANGUAGE=eng
LANGUAGES=eng, swa
#Alias search domains
ALIAS_SEARCH_DOMAINS=sarafu.local, sarafu.eth

56
.github/workflows/docker.yaml vendored Normal file
View File

@ -0,0 +1,56 @@
name: release
on:
push:
tags:
- "v*"
jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Check out repo
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Login to GHCR Docker registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set outputs
run: |
echo "RELEASE_TAG=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV \
&& echo "RELEASE_SHORT_COMMIT=$(git rev-parse --short HEAD)" >> $GITHUB_ENV
- name: Build and push image
uses: docker/build-push-action@v2
with:
context: ./
file: ./Dockerfile
platforms: linux/amd64
push: true
build-args: |
BUILD=${{ env.RELEASE_SHORT_COMMIT }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
tags: |
ghcr.io/grassrootseconomics/sarafu-vise:latest
ghcr.io/grassrootseconomics/sarafu-vise:${{ env.RELEASE_TAG }}

50
Dockerfile Normal file
View File

@ -0,0 +1,50 @@
FROM golang:1.23.4-bookworm AS build
ENV CGO_ENABLED=1
ARG BUILDPLATFORM
ARG TARGETPLATFORM
ARG BUILD=dev
WORKDIR /build
RUN apt-get update && apt-get install -y --no-install-recommends \
libgdbm-dev \
git \
&& rm -rf /var/lib/apt/lists/*
RUN git clone https://git.defalsify.org/vise.git go-vise
COPY . ./sarafu-vise
WORKDIR /build/sarafu-vise/services/registration
RUN echo "Compiling go-vise files"
RUN make VISE_PATH=/build/go-vise -B
WORKDIR /build/sarafu-vise
RUN echo "Building on $BUILDPLATFORM, building for $TARGETPLATFORM"
RUN go mod download
RUN go build -tags logtrace,online -o sarafu-at -ldflags="-X main.build=${BUILD} -s -w" cmd/africastalking/main.go
RUN go build -tags logtrace,online -o sarafu-ssh -ldflags="-X main.build=${BUILD} -s -w" cmd/ssh/main.go
FROM debian:bookworm-slim
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y --no-install-recommends \
libgdbm-dev \
ca-certificates \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /service
COPY --from=build /build/sarafu-vise/sarafu-at .
COPY --from=build /build/sarafu-vise/sarafu-ssh .
COPY --from=build /build/sarafu-vise/LICENSE .
COPY --from=build /build/sarafu-vise/README.md .
COPY --from=build /build/sarafu-vise/services ./services
COPY --from=build /build/sarafu-vise/.env.example .
RUN mv .env.example .env
EXPOSE 7123
EXPOSE 7122
CMD ["./sarafu-at"]

View File

@ -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,5 +30,3 @@ func(lv *LangVar) String() string {
func (lv *LangVar) Langs() []lang.Language {
return lv.v
}

View File

@ -12,18 +12,18 @@ import (
"syscall"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/lang"
"git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/resource"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/visedriver/request"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking"
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
at "git.grassecon.net/grassrootseconomics/visedriver-africastalking/africastalking"
)
var (
@ -36,8 +36,7 @@ var (
func main() {
config.LoadConfig()
var connStr string
var resourceDir string
override := config.NewOverride()
var size uint
var engineDebug bool
var host string
@ -46,10 +45,11 @@ func main() {
var gettextDir string
var langs args.LangVar
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
flag.StringVar(&connStr, "c", "", "connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&host, "h", config.Host(), "http host")
flag.UintVar(&port, "p", config.Port(), "http port")
@ -57,16 +57,14 @@ func main() {
flag.Var(&langs, "language", "add symbol resolution for language")
flag.Parse()
if connStr == "" {
connStr = config.DbConn()
}
connData, err := storage.ToConnData(connStr)
config.Apply(override)
conns, err := config.GetConns()
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
os.Exit(1)
}
logg.Infof("start command", "build", build, "conn", connData, "resourcedir", resourceDir, "outputsize", size)
logg.Infof("start command", "build", build, "conn", conns, "outputsize", size)
ctx := context.Background()
ln, err := lang.LanguageFromCode(config.Language())
@ -89,7 +87,7 @@ func main() {
cfg.EngineDebug = true
}
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
menuStorageService := storage.NewMenuStorageService(conns)
rs, err := menuStorageService.GetResource(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "menustorageservice: %v\n", err)
@ -101,7 +99,6 @@ func main() {
fmt.Fprintf(os.Stderr, "userdatadb: %v\n", err)
os.Exit(1)
}
defer userdataStore.Close()
dbResource, ok := rs.(*resource.DbResource)
if !ok {
@ -120,7 +117,7 @@ func main() {
os.Exit(1)
}
accountService := services.New(ctx, menuStorageService, connData)
accountService := services.New(ctx, menuStorageService)
hl, err := lhs.GetHandler(accountService)
if err != nil {
@ -133,7 +130,6 @@ func main() {
fmt.Fprintf(os.Stderr, "getstatestore: %v\n", err)
os.Exit(1)
}
defer stateStore.Close()
rp := &at.ATRequestParser{}
bsh := request.NewBaseRequestHandler(cfg, rs, stateStore, userdataStore, rp, hl)
@ -146,7 +142,10 @@ func main() {
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
Handler: mux,
}
s.RegisterOnShutdown(sh.Shutdown)
shutdownFunc := func() {
sh.Shutdown(ctx)
}
s.RegisterOnShutdown(shutdownFunc)
cint := make(chan os.Signal)
cterm := make(chan os.Signal)

View File

@ -14,12 +14,12 @@ import (
"git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/resource"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/visedriver/request"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
"git.grassecon.net/grassrootseconomics/sarafu-vise/args"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
"git.grassecon.net/grassrootseconomics/visedriver/request"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
)
var (
@ -44,9 +44,8 @@ func (p *asyncRequestParser) GetInput(r any) ([]byte, error) {
func main() {
config.LoadConfig()
var connStr string
override := config.NewOverride()
var sessionId string
var resourceDir string
var size uint
var engineDebug bool
var host string
@ -56,8 +55,11 @@ func main() {
var langs args.LangVar
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
flag.StringVar(&connStr, "c", "", "connection string")
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&host, "h", config.Host(), "http host")
@ -66,16 +68,14 @@ func main() {
flag.Var(&langs, "language", "add symbol resolution for language")
flag.Parse()
if connStr == "" {
connStr = config.DbConn()
}
connData, err := storage.ToConnData(connStr)
config.Apply(override)
conns, err := config.GetConns()
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
os.Exit(1)
}
logg.Infof("start command", "conn", connData, "resourcedir", resourceDir, "outputsize", size, "sessionId", sessionId)
logg.Infof("start command", "conn", conns, "outputsize", size, "sessionId", sessionId)
ctx := context.Background()
@ -99,7 +99,7 @@ func main() {
cfg.EngineDebug = true
}
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
menuStorageService := storage.NewMenuStorageService(conns)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
@ -116,7 +116,7 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
defer userdataStore.Close()
//defer userdataStore.Close(ctx)
dbResource, ok := rs.(*resource.DbResource)
if !ok {
@ -126,7 +126,7 @@ func main() {
lhs, err := handlers.NewLocalHandlerService(ctx, pfp, true, dbResource, cfg, rs)
lhs.SetDataStore(&userdataStore)
accountService := services.New(ctx, menuStorageService, connData)
accountService := services.New(ctx, menuStorageService)
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()
//defer stateStore.Close(ctx)
rp := &asyncRequestParser{
sessionId: sessionId,
@ -161,7 +161,7 @@ func main() {
case _ = <-cint:
case _ = <-cterm:
}
sh.Shutdown()
sh.Shutdown(ctx)
}()
for true {
@ -177,7 +177,7 @@ func main() {
fmt.Errorf("error in output: %v", err)
os.Exit(1)
}
rqs, err = sh.Reset(rqs)
rqs, err = sh.Reset(ctx, rqs)
if err != nil {
logg.ErrorCtxf(ctx, "error in reset: %v", "err", err)
fmt.Errorf("error in reset: %v", err)

View File

@ -17,13 +17,13 @@ import (
"git.defalsify.org/vise.git/resource"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
httprequest "git.grassecon.net/grassrootseconomics/visedriver/request/http"
"git.grassecon.net/grassrootseconomics/visedriver/request"
httprequest "git.grassecon.net/grassrootseconomics/visedriver/request/http"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"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,8 +35,7 @@ var (
func main() {
config.LoadConfig()
var connStr string
var resourceDir string
override := config.NewOverride()
var size uint
var engineDebug bool
var host string
@ -45,8 +44,11 @@ func main() {
var gettextDir string
var langs args.LangVar
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
flag.StringVar(&connStr, "c", "", "connection string")
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&host, "h", config.Host(), "http host")
@ -55,16 +57,14 @@ func main() {
flag.Var(&langs, "language", "add symbol resolution for language")
flag.Parse()
if connStr == "" {
connStr = config.DbConn()
}
connData, err := storage.ToConnData(connStr)
config.Apply(override)
conns, err := config.GetConns()
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
os.Exit(1)
}
logg.Infof("start command", "conn", connData, "resourcedir", resourceDir, "outputsize", size)
logg.Infof("start command", "conn", conns, "outputsize", size)
ctx := context.Background()
@ -88,7 +88,7 @@ func main() {
cfg.EngineDebug = true
}
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
menuStorageService := storage.NewMenuStorageService(conns)
rs, err := menuStorageService.GetResource(ctx)
if err != nil {
@ -101,7 +101,6 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
defer userdataStore.Close()
dbResource, ok := rs.(*resource.DbResource)
if !ok {
@ -116,7 +115,7 @@ func main() {
os.Exit(1)
}
accountService := services.New(ctx, menuStorageService, connData)
accountService := services.New(ctx, menuStorageService)
hl, err := lhs.GetHandler(accountService)
if err != nil {
@ -129,7 +128,6 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
defer stateStore.Close()
//accountService := services.New(ctx, menuStorageService, connData)
@ -140,7 +138,10 @@ func main() {
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
Handler: sh,
}
s.RegisterOnShutdown(sh.Shutdown)
shutdownFunc := func() {
sh.Shutdown(ctx)
}
s.RegisterOnShutdown(shutdownFunc)
cint := make(chan os.Signal)
cterm := make(chan os.Signal)

View File

@ -5,17 +5,19 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"path"
"syscall"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/lang"
"git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/resource"
"git.defalsify.org/vise.git/lang"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/sarafu-vise/services"
"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/storage"
)
var (
@ -27,34 +29,33 @@ var (
func main() {
config.LoadConfig()
var connStr string
override := config.NewOverride()
var size uint
var sessionId string
var engineDebug bool
var resourceDir string
var err error
var gettextDir string
var langs args.LangVar
flag.StringVar(&resourceDir, "resourcedir", scriptDir, "resource dir")
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&connStr, "c", "", "connection string")
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&gettextDir, "gettext", "", "use gettext translations from given directory")
flag.Var(&langs, "language", "add symbol resolution for language")
flag.Parse()
if connStr == "" {
connStr = config.DbConn()
}
connData, err := storage.ToConnData(connStr)
config.Apply(override)
conns, err := config.GetConns()
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v\n", err)
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
os.Exit(1)
}
logg.Infof("start command", "conn", connData, "outputsize", size)
logg.Infof("start command", "conn", conns, "outputsize", size)
if len(langs.Langs()) == 0 {
langs.Set(config.Language())
@ -80,7 +81,7 @@ func main() {
MenuSeparator: menuSeparator,
}
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
menuStorageService := storage.NewMenuStorageService(conns)
if err != nil {
fmt.Fprintf(os.Stderr, "menu storage service error: %v\n", err)
os.Exit(1)
@ -122,7 +123,7 @@ func main() {
os.Exit(1)
}
accountService := services.New(ctx, menuStorageService, connData)
accountService := services.New(ctx, menuStorageService)
hl, err := lhs.GetHandler(accountService)
if err != nil {
fmt.Fprintf(os.Stderr, "get accounts service handler: %v\n", err)
@ -135,6 +136,21 @@ func main() {
en = en.WithDebug(nil)
}
cint := make(chan os.Signal)
cterm := make(chan os.Signal)
signal.Notify(cint, os.Interrupt, syscall.SIGINT)
signal.Notify(cterm, os.Interrupt, syscall.SIGTERM)
go func() {
var s os.Signal
select {
case s = <-cterm:
case s = <-cint:
}
logg.InfoCtxf(ctx, "stopping on signal", "sig", s)
en.Finish(ctx)
os.Exit(0)
}()
err = engine.Loop(ctx, en, os.Stdin, os.Stdout, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)

View File

@ -31,34 +31,31 @@ var (
func main() {
config.LoadConfig()
var connStr string
override := config.NewOverride()
var authConnStr string
var resourceDir string
var size uint
var engineDebug bool
var stateDebug bool
var host string
var port uint
flag.StringVar(&connStr, "c", "", "connection string")
flag.StringVar(&authConnStr, "authdb", "", "auth connection string")
flag.StringVar(&resourceDir, "resourcedir", path.Join("services", "registration"), "resource dir")
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
flag.StringVar(&override.ResourceConn, "resource", "?", "resource connection string")
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.UintVar(&size, "s", 160, "max size of output")
flag.StringVar(&host, "h", config.HostSSH(), "socket host")
flag.UintVar(&port, "p", config.PortSSH(), "socket port")
flag.Parse()
if connStr == "" {
connStr = config.DbConn()
}
if authConnStr == "" {
authConnStr = connStr
}
connData, err := storage.ToConnData(connStr)
config.Apply(override)
conns, err := config.GetConns()
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
os.Exit(1)
}
authConnData, err := storage.ToConnData(authConnStr)
if err != nil {
fmt.Fprintf(os.Stderr, "auth connstr err: %v", err)
@ -79,7 +76,7 @@ func main() {
logg.WarnCtxf(ctx, "!!!!! Do not expose to internet and only use with tunnel!")
logg.WarnCtxf(ctx, "!!!!! (See ssh -L <...>)")
logg.Infof("start command", "conn", connData, "authconn", authConnData, "resourcedir", resourceDir, "outputsize", size, "keyfile", sshKeyFile, "host", host, "port", port)
logg.Infof("start command", "conn", conns, "authconn", authConnData, "outputsize", size, "keyfile", sshKeyFile, "host", host, "port", port)
pfp := path.Join(scriptDir, "pp.csv")
@ -102,7 +99,7 @@ func main() {
}
defer func() {
logg.TraceCtxf(ctx, "shutdown auth key store reached")
err = authKeyStore.Close()
err = authKeyStore.Close(ctx)
if err != nil {
logg.ErrorCtxf(ctx, "keystore close error", "err", err)
}
@ -117,8 +114,7 @@ func main() {
Cfg: cfg,
Debug: engineDebug,
FlagFile: pfp,
Conn: connData,
ResourceDir: resourceDir,
Conn: conns,
SrvKeyFile: sshKeyFile,
Host: host,
Port: port,

View File

@ -34,7 +34,7 @@ func main() {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
defer store.Close()
defer store.Close(ctx)
err = store.AddFromFile(ctx, sshKeyFile, sessionId)
if err != nil {

20
config/args.go Normal file
View File

@ -0,0 +1,20 @@
package config
import (
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
)
func NewOverride() *viseconfig.Override {
o := &viseconfig.Override{
StateConnMode: storage.DBMODE_TEXT,
ResourceConnMode: storage.DBMODE_TEXT,
UserConnMode: storage.DBMODE_BINARY,
}
return o
}
func Apply(o *viseconfig.Override) error {
viseconfig.ApplyConn(o)
return nil
}

View File

@ -1,13 +1,24 @@
package config
import (
"git.grassecon.net/grassrootseconomics/visedriver/env"
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
"strings"
apiconfig "git.grassecon.net/grassrootseconomics/sarafu-api/config"
viseconfig "git.grassecon.net/grassrootseconomics/visedriver/config"
"git.grassecon.net/grassrootseconomics/visedriver/env"
)
func init() {
var (
GetConns = viseconfig.GetConns
EnvPath string
)
func loadEnv() {
if EnvPath == "" {
env.LoadEnvVariables()
} else {
env.LoadEnvVariablesPath(EnvPath)
}
}
const (
@ -15,10 +26,11 @@ 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
@ -30,9 +42,16 @@ func LoadConfig() error {
return nil
}
func DbConn() string {
return viseconfig.DbConn
func SearchDomains() []string {
var ParsedDomains []string
SearchDomains := env.GetEnv("ALIAS_SEARCH_DOMAINS", defaultDomain)
SearchDomainList := strings.Split(env.GetEnv("ALIAS_SEARCH_DOMAINS", SearchDomains), ",")
for _, domain := range SearchDomainList {
ParsedDomains = append(ParsedDomains, strings.ReplaceAll(domain, " ", ""))
}
return ParsedDomains
}
func Language() string {
return viseconfig.DefaultLanguage

View File

@ -1,11 +1,11 @@
package debug
import (
"fmt"
"encoding/binary"
"fmt"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
visedb "git.defalsify.org/vise.git/db"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
)
var (
@ -32,18 +32,10 @@ func (k KeyInfo) String() string {
func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
o := KeyInfo{}
b := []byte(sessionId)
if len(k) <= len(b) {
return o, fmt.Errorf("storage key missing")
}
o.SessionId = sessionId
o.Typ = uint8(k[0])
k = k[1:]
o.SessionId = string(k[:len(b)])
k = k[len(b):]
if o.Typ == visedb.DATATYPE_USERDATA {
if len(k) == 0 {
@ -53,28 +45,17 @@ func ToKeyInfo(k []byte, sessionId string) (KeyInfo, error) {
o.SubTyp = storedb.DataTyp(v)
o.Label = subTypToString(o.SubTyp)
k = k[2:]
if len(k) != 0 {
return o, fmt.Errorf("excess key information: %x", k)
}
} else {
o.Label = typToString(o.Typ)
}
if len(k) != 0 {
return o, fmt.Errorf("excess key information")
k = k[2:]
}
return o, nil
}
func FromKey(k []byte) (KeyInfo, error) {
o := KeyInfo{}
if len(k) < 4 {
return o, fmt.Errorf("insufficient key length")
}
sessionIdBytes := k[1:len(k)-2]
return ToKeyInfo(k, string(sessionIdBytes))
}
func subTypToString(v storedb.DataTyp) string {
return dbTypStr[v+visedb.DATATYPE_USERDATA+1]
}

View File

@ -1,3 +1,4 @@
//go:build debugdb
// +build debugdb
package debug
@ -29,6 +30,9 @@ 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"

View File

@ -3,14 +3,13 @@ package debug
import (
"testing"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
visedb "git.defalsify.org/vise.git/db"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
)
func TestDebugDbSubKeyInfo(t *testing.T) {
s := "foo"
b := []byte{0x20}
b = append(b, []byte(s)...)
b = append(b, []byte{0x00, 0x02}...)
r, err := ToKeyInfo(b, s)
if err != nil {
@ -56,7 +55,6 @@ func TestDebugDbKeyInfo(t *testing.T) {
func TestDebugDbKeyInfoRestore(t *testing.T) {
s := "bar"
b := []byte{visedb.DATATYPE_USERDATA}
b = append(b, []byte(s)...)
k := storedb.ToBytes(storedb.DATA_ACTIVE_SYM)
b = append(b, k...)

View File

@ -10,9 +10,9 @@ import (
"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/internal/cmd"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
"git.grassecon.net/grassrootseconomics/sarafu-vise/internal/cmd"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
)
var (
@ -23,22 +23,24 @@ var (
func main() {
config.LoadConfig()
override := config.NewOverride()
var sessionId string
var connStr string
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&connStr, "c", "", "connection string")
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
flag.Parse()
if connStr == "" {
connStr = config.DbConn()
}
connData, err := storage.ToConnData(connStr)
config.Apply(override)
conns, err := config.GetConns()
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v\n", err)
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
os.Exit(1)
}
ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId)
@ -49,16 +51,16 @@ func main() {
os.Exit(1)
}
x := cmd.NewCmd(connData, sessionId, flagParser)
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", connData, "subcmd", x)
logg.Infof("start command", "conn", conns, "subcmd", x)
menuStorageService := storage.NewMenuStorageService(connData, "")
menuStorageService := storage.NewMenuStorageService(conns)
if err != nil {
fmt.Fprintf(os.Stderr, "menu storage service error: %v\n", err)
os.Exit(1)

View File

@ -8,13 +8,12 @@ import (
"path"
"strings"
"git.defalsify.org/vise.git/logging"
"git.defalsify.org/vise.git/lang"
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/visedriver/config"
)
const (
changeHeadSrc = `LOAD reset_account_authorized 0
LOAD reset_incorrect 0
CATCH incorrect_pin flag_incorrect_pin 1
@ -63,7 +62,7 @@ func main() {
}
logg.Tracef("using languages", "lang", config.Languages)
for i, v := range(config.Languages) {
for i, v := range config.Languages {
ln, err := lang.LanguageFromCode(v)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing language: %s\n", v)

View File

@ -7,11 +7,11 @@ import (
"os"
"path"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/sarafu-vise/debug"
"git.defalsify.org/vise.git/db"
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/sarafu-vise/debug"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
)
var (
@ -19,55 +19,58 @@ var (
scriptDir = path.Join("services", "registration")
)
func formatItem(k []byte, v []byte) (string, error) {
o, err := debug.FromKey(k)
func formatItem(k []byte, v []byte, sessionId string) (string, error) {
o, err := debug.ToKeyInfo(k, sessionId)
if err != nil {
return "", err
}
s := fmt.Sprintf("%vValue: %v\n\n", o, string(v))
s := fmt.Sprintf("%v\t%v\n", o.Label, string(v))
return s, nil
}
func main() {
config.LoadConfig()
var connStr string
override := config.NewOverride()
var sessionId string
var database string
var engineDebug bool
var err error
var first bool
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&connStr, "c", ".state", "connection string")
flag.StringVar(&override.DbConn, "c", "?", "default connection string (replaces all unspecified strings)")
flag.StringVar(&override.ResourceConn, "resource", "?", "resource data directory")
flag.StringVar(&override.UserConn, "userdata", "?", "userdata store connection string")
flag.StringVar(&override.StateConn, "state", "?", "state store connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.Parse()
if connStr != "" {
connStr = config.DbConn()
}
connData, err := storage.ToConnData(connStr)
config.Apply(override)
conns, err := config.GetConns()
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
fmt.Fprintf(os.Stderr, "conn specification error: %v\n", err)
os.Exit(1)
}
logg.Infof("start command", "conn", connData)
logg.Infof("start command", "conn", conns)
ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId)
ctx = context.WithValue(ctx, "Database", database)
resourceDir := scriptDir
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
menuStorageService := storage.NewMenuStorageService(conns)
store, err := menuStorageService.GetUserdataDb(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "get userdata db: %v\n", err.Error())
os.Exit(1)
}
store.SetSession(sessionId)
store.SetPrefix(db.DATATYPE_USERDATA)
d, err := store.Dump(ctx, []byte(sessionId))
d, err := store.Dump(ctx, []byte(""))
if err != nil {
fmt.Fprintf(os.Stderr, "store dump fail: %v\n", err.Error())
os.Exit(1)
@ -78,15 +81,19 @@ func main() {
if k == nil {
break
}
r, err := formatItem(k, v)
if !first {
fmt.Printf("Session ID: %s\n---\n", sessionId)
first = true
}
r, err := formatItem(append([]byte{db.DATATYPE_USERDATA}, k...), v, sessionId)
if err != nil {
fmt.Fprintf(os.Stderr, "format db item error: %v", err)
fmt.Fprintf(os.Stderr, "format db item error: %v\n", err)
os.Exit(1)
}
fmt.Printf(r)
}
err = store.Close()
err = store.Close(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)

View File

@ -1,86 +0,0 @@
package main
import (
"context"
"crypto/sha1"
"flag"
"fmt"
"os"
"path"
testdataloader "github.com/peteole/testdata-loader"
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/sarafu-vise/config"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
)
var (
logg = logging.NewVanilla()
baseDir = testdataloader.GetBasePath()
scriptDir = path.Join("services", "registration")
)
func main() {
config.LoadConfig()
var connStr string
var sessionId string
var database string
var engineDebug bool
var err error
flag.StringVar(&sessionId, "session-id", "075xx2123", "session id")
flag.StringVar(&connStr, "c", "", "connection string")
flag.BoolVar(&engineDebug, "d", false, "use engine debug output")
flag.Parse()
if connStr != "" {
connStr = config.DbConn()
}
connData, err := storage.ToConnData(connStr)
if err != nil {
fmt.Fprintf(os.Stderr, "connstr err: %v", err)
os.Exit(1)
}
logg.Infof("start command", "conn", connData)
ctx := context.Background()
ctx = context.WithValue(ctx, "SessionId", sessionId)
ctx = context.WithValue(ctx, "Database", database)
resourceDir := scriptDir
menuStorageService := storage.NewMenuStorageService(connData, resourceDir)
userDb, err := menuStorageService.GetUserdataDb(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
userStore := store.UserDataStore{userDb}
h := sha1.New()
h.Write([]byte(sessionId))
address := h.Sum(nil)
addressString := fmt.Sprintf("%x", address)
err = userStore.WriteEntry(ctx, sessionId, storedb.DATA_PUBLIC_KEY, []byte(addressString))
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
err = userStore.WriteEntry(ctx, addressString, storedb.DATA_PUBLIC_KEY_REVERSE, []byte(sessionId))
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
err = userDb.Close()
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
}

10
go.mod
View File

@ -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.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
git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84
github.com/alecthomas/assert/v2 v2.2.2
github.com/gofrs/uuid v4.4.0+incompatible
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta

20
go.sum
View File

@ -1,13 +1,13 @@
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=
git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9 h1:sPcqXQcywxA8W3W+9qQncLPmsrgqTIlec7vmD4/7vyA=
git.defalsify.org/vise.git v0.2.3-0.20250120121301-10739fb4a8c9/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d h1:5mzLas+jxTUtusOKx4XvU+n2QvrV/mH17MnJRy46siQ=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250121134736-ba8cbbccea7d/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1 h1:BJHfokTHzrw9QjQ+4s2HmSER0iBPuE7byW5oQC2zLIQ=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250123142805-2181388f5bf1/go.mod h1:gOn89ipaDcDvmQXRMQYKUqcw/sJcwVOPVt2eC6Geip8=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa h1:yQLKwby3eD/zNjNw/INU5lGiLuWPEHdsgASwMA4UptE=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250124100946-03d19283f6fa/go.mod h1:pjKp9L/ZsWW3kMB0UoIl1yv9TBIuU33mn9Aghxp7vGk=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84 h1:VoBmqsjlRdz+IPbtKsAkc1IrMepjR+QlesZT31Jokrk=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250121135340-ca97e23e8c84/go.mod h1:DpibtYpnT3nG4Kn556hRAkdu4+CtiI/6MbnQHal51mQ=
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=

File diff suppressed because it is too large Load Diff

View File

@ -54,7 +54,7 @@ func InitializeTestStore(t *testing.T) (context.Context, *store.UserDataStore) {
store := &store.UserDataStore{Db: db}
t.Cleanup(func() {
db.Close() // Ensure the DB is closed after each test
db.Close(ctx) // Ensure the DB is closed after each test
})
return ctx, store
@ -265,6 +265,7 @@ func TestWithPersister(t *testing.T) {
h.SetPersister(p)
assert.Equal(t, p, h.pe, "The persister should be set correctly.")
//assert.Equal(t, h, result, "The returned handler should be the same instance.")
}
func TestWithPersister_PanicWhenAlreadySet(t *testing.T) {
@ -1222,13 +1223,20 @@ func TestVerifyCreatePin(t *testing.T) {
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte("1234"))
// 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) {
// Call the method under test
res, err := h.VerifyCreatePin(ctx, "verify_create_pin", []byte(tt.input))
@ -1671,7 +1679,7 @@ func TestValidateRecipient(t *testing.T) {
},
{
name: "Test with alias recepient",
input: []byte("alias123"),
input: []byte("alias123.sarafu.local"),
expectedResult: resource.Result{},
},
}
@ -1789,37 +1797,37 @@ func TestGetProfile(t *testing.T) {
}{
{
name: "Test with full profile information in eng",
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB},
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB, storedb.DATA_ACCOUNT_ALIAS},
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
languageCode: "eng",
result: resource.Result{
Content: fmt.Sprintf(
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
"John Doee", "Male", "49", "Kilifi", "Bananas",
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\nYour alias: %s\n",
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
),
},
},
{
name: "Test with with profile information in swa",
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB},
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB, storedb.DATA_ACCOUNT_ALIAS},
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
languageCode: "swa",
result: resource.Result{
Content: fmt.Sprintf(
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\n",
"John Doee", "Male", "49", "Kilifi", "Bananas",
"Jina: %s\nJinsia: %s\nUmri: %s\nEneo: %s\nUnauza: %s\nLakabu yako: %s\n",
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
),
},
},
{
name: "Test with with profile information with language that is not yet supported",
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB},
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976"},
keys: []storedb.DataTyp{storedb.DATA_FAMILY_NAME, storedb.DATA_FIRST_NAME, storedb.DATA_GENDER, storedb.DATA_OFFERINGS, storedb.DATA_LOCATION, storedb.DATA_YOB, storedb.DATA_ACCOUNT_ALIAS},
profileInfo: []string{"Doee", "John", "Male", "Bananas", "Kilifi", "1976", "DoeJohn"},
languageCode: "nor",
result: resource.Result{
Content: fmt.Sprintf(
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\n",
"John Doee", "Male", "49", "Kilifi", "Bananas",
"Name: %s\nGender: %s\nAge: %s\nLocation: %s\nYou provide: %s\nYour alias: %s\n",
"John Doee", "Male", "49", "Kilifi", "Bananas", "DoeJohn",
),
},
},
@ -1907,13 +1915,13 @@ func TestConfirmPin(t *testing.T) {
tests := []struct {
name string
input []byte
temporarypin []byte
temporarypin string
expectedResult resource.Result
}{
{
name: "Test with correct pin confirmation",
input: []byte("1234"),
temporarypin: []byte("1234"),
temporarypin: "1234",
expectedResult: resource.Result{
FlagReset: []uint32{flag_pin_mismatch},
},
@ -1921,14 +1929,21 @@ func TestConfirmPin(t *testing.T) {
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// Hash the PIN
hashedPIN, err := pin.HashPIN(tt.temporarypin)
if err != nil {
logg.ErrorCtxf(ctx, "failed to hash temporaryPin", "error", err)
t.Fatal(err)
}
// Set up the expected behavior of the mock
err := store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(tt.temporarypin))
err = store.WriteEntry(ctx, sessionId, storedb.DATA_TEMPORARY_VALUE, []byte(hashedPIN))
if err != nil {
t.Fatal(err)
}
//Call the function under test
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.temporarypin)
res, _ := h.ConfirmPinChange(ctx, "confirm_pin_change", tt.input)
//Assert that the result set to content is what was expected
assert.Equal(t, res, tt.expectedResult, "Result should contain flags set according to user input")

View File

@ -35,13 +35,6 @@ func (eu *EventsUpdater) HandleCustodialRegistration(ctx context.Context, ev *ap
if err != nil {
return err
}
// err = pe.Load(identity.SessionId)
// if err != nil {
// return err
// }
// st := pe.GetState()
// st.SetFlag(accountCreatedFlag)
// return pe.Save(identity.SessionId)
logg.DebugCtxf(ctx, "received custodial registration event", "identity", identity)
return nil
}

View File

@ -4,12 +4,12 @@ import (
"context"
"fmt"
"git.defalsify.org/vise.git/persist"
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
"git.defalsify.org/vise.git/persist"
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
"git.grassecon.net/grassrootseconomics/sarafu-api/remote"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
)
var (

View File

@ -6,10 +6,10 @@ import (
"strings"
"git.defalsify.org/vise.git/db"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
"git.grassecon.net/grassrootseconomics/common/identity"
apievent "git.grassecon.net/grassrootseconomics/sarafu-api/event"
"git.grassecon.net/grassrootseconomics/sarafu-vise/store"
storedb "git.grassecon.net/grassrootseconomics/sarafu-vise/store/db"
)
// execute all
@ -47,7 +47,6 @@ func (eu *EventsUpdater) updateToken(ctx context.Context, identity identity.Iden
return nil
}
// set default token to given symbol.
func (eu *EventsUpdater) updateDefaultToken(ctx context.Context, identity identity.Identity, userStore *store.UserDataStore, activeSym string) error {
pfxDb := toPrefixDb(userStore, identity.SessionId)
@ -59,7 +58,6 @@ func (eu *EventsUpdater) updateDefaultToken(ctx context.Context, identity identi
return store.UpdateVoucherData(ctx, userStore, identity.SessionId, tokenData)
}
// handle token transfer.
//
// if from and to are NOT the same, handle code will be executed once for each side of the transfer.
@ -189,7 +187,7 @@ func (eu *EventsUpdater) updateTokenTransferList(ctx context.Context, identity i
return err
}
for i, tx := range(txs) {
for i, tx := range txs {
r = append(r, eu.formatFunc(apievent.EventTokenTransferTag, i, tx))
}

View File

@ -60,7 +60,9 @@ func (ls *LocalHandlerService) GetHandler(accountService remote.AccountService)
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)

View File

@ -5,8 +5,8 @@ import (
"fmt"
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/application"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
)
var (
@ -22,9 +22,8 @@ type Cmd struct {
exec func(ctx context.Context, ss storage.StorageService) error
}
func NewCmd(conn storage.ConnData, sessionId string, flagParser *application.FlagManager) *Cmd {
func NewCmd(sessionId string, flagParser *application.FlagManager) *Cmd {
return &Cmd{
conn: conn,
sessionId: sessionId,
flagParser: flagParser,
}
@ -95,5 +94,3 @@ func (c *Cmd) Parse(args []string) error {
return fmt.Errorf("unknown subcommand: %s", cmd)
}

View File

@ -427,7 +427,7 @@
},
{
"input": "1234",
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\n\n0:Back\n9:Quit"
"expectedContent": "My profile:\nName: foo bar\nGender: male\nAge: 80\nLocation: Kilifi\nYou provide: Bananas\nYour alias: \n\n0:Back\n9:Quit"
},
{
"input": "0",

View File

@ -9,12 +9,14 @@ import (
"regexp"
"testing"
"github.com/gofrs/uuid"
"git.grassecon.net/grassrootseconomics/visedriver/testutil/driver"
"git.defalsify.org/vise.git/logging"
"git.grassecon.net/grassrootseconomics/sarafu-vise/testutil"
"git.grassecon.net/grassrootseconomics/visedriver/testutil/driver"
"github.com/gofrs/uuid"
)
var (
logg = logging.NewVanilla().WithDomain("menutraversaltest")
testData = driver.ReadData()
sessionID string
src = rand.NewSource(42)
@ -22,9 +24,6 @@ var (
)
var groupTestFile = flag.String("test-file", "group_test.json", "The test file to use for running the group tests")
var database = flag.String("db", "gdbm", "Specify the database (gdbm or postgres)")
var connStr = flag.String("conn", ".test_state", "connection string")
var dbSchema = flag.String("schema", "test", "Specify the database schema (default test)")
func GenerateSessionId() string {
uu := uuid.NewGenWithOptions(uuid.WithRandomReader(g))
@ -80,12 +79,7 @@ func extractSendAmount(response []byte) string {
}
func TestMain(m *testing.M) {
// Parse the flags
flag.Parse()
sessionID = GenerateSessionId()
// set the db
testutil.SetDatabase(*database, *connStr, *dbSchema)
// Cleanup the db after tests
defer testutil.CleanDatabase()
@ -100,7 +94,8 @@ func TestAccountCreationSuccessful(t *testing.T) {
for _, session := range sessions {
groups := driver.FilterGroupsByName(session.Groups, "account_creation_successful")
for _, group := range groups {
for _, step := range group.Steps {
for i, step := range group.Steps {
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
cont, err := en.Exec(ctx, []byte(step.Input))
if err != nil {
t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
@ -142,7 +137,8 @@ func TestAccountRegistrationRejectTerms(t *testing.T) {
for _, session := range sessions {
groups := driver.FilterGroupsByName(session.Groups, "account_creation_reject_terms")
for _, group := range groups {
for _, step := range group.Steps {
for i, step := range group.Steps {
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
cont, err := en.Exec(ctx, []byte(step.Input))
if err != nil {
t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)
@ -177,7 +173,8 @@ func TestMainMenuHelp(t *testing.T) {
for _, session := range sessions {
groups := driver.FilterGroupsByName(session.Groups, "main_menu_help")
for _, group := range groups {
for _, step := range group.Steps {
for i, step := range group.Steps {
logg.TraceCtxf(ctx, "executing step", "i", i, "step", step)
cont, err := en.Exec(ctx, []byte(step.Input))
if err != nil {
t.Fatalf("Test case '%s' failed at input '%s': %v", group.Name, step.Input, err)

View File

@ -1,16 +1,17 @@
//go:build !online
// +build !online
package services
import (
"fmt"
"context"
"fmt"
"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-api/remote"
"git.grassecon.net/grassrootseconomics/sarafu-vise/handlers/event"
"git.grassecon.net/grassrootseconomics/visedriver/storage"
)
type localEmitter struct {
@ -37,7 +38,7 @@ func (d *localEmitter) emit(ctx context.Context, msg apievent.Msg) error {
return err
}
func New(ctx context.Context, storageService storage.StorageService, conn storage.ConnData) remote.AccountService {
func New(ctx context.Context, storageService storage.StorageService) remote.AccountService {
svc := devremote.NewDevAccountService(ctx, storageService)
svc = svc.WithAutoVoucher(ctx, "FOO", 42)
eu := event.NewEventsUpdater(svc, storageService)

View File

@ -4,8 +4,8 @@ TXTS = $(wildcard ./*.txt.orig)
VISE_PATH := ../../go-vise
# Rule to build .bin files from .vis files
%.vis:
go run $(VISE_PATH)/dev/asm/main.go -f pp.csv $(basename $@).vis > $(basename $@).bin
%.vis: buildasm
./vise-asm -f pp.csv $(basename $@).vis > $(basename $@).bin
@echo "Built $(basename $@).bin from $(basename $@).vis"
# Rule to copy .orig files to .txt
@ -19,5 +19,10 @@ all: $(INPUTS) $(TXTS)
clean:
rm -vf *.bin
rm -vf ./vise-asm
buildasm:
go build -v -o ./vise-asm $(VISE_PATH)/dev/asm/main.go
.PHONY: clean

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,3 +1,5 @@
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

Binary file not shown.

View File

@ -3,7 +3,7 @@ RELOAD transaction_reset
CATCH no_voucher flag_no_active_voucher 1
MOUT back 0
HALT
LOAD validate_recipient 20
LOAD validate_recipient 50
RELOAD validate_recipient
CATCH invalid_recipient flag_invalid_recipient 1
CATCH invite_recipient flag_invalid_recipient_with_invite 1

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More