Compare commits
3 Commits
5bd51b280e
...
ffa00ae15c
Author | SHA1 | Date | |
---|---|---|---|
ffa00ae15c | |||
13294b42d3 | |||
81159e77d1 |
@ -13,26 +13,23 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/asm"
|
"git.defalsify.org/vise.git/asm"
|
||||||
"git.defalsify.org/vise.git/db"
|
|
||||||
fsdb "git.defalsify.org/vise.git/db/fs"
|
|
||||||
gdbmdb "git.defalsify.org/vise.git/db/gdbm"
|
|
||||||
"git.defalsify.org/vise.git/engine"
|
"git.defalsify.org/vise.git/engine"
|
||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
"git.defalsify.org/vise.git/resource"
|
"git.defalsify.org/vise.git/resource"
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers"
|
"git.grassecon.net/urdt/ussd/internal/handlers"
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
|
|
||||||
httpserver "git.grassecon.net/urdt/ussd/internal/http"
|
httpserver "git.grassecon.net/urdt/ussd/internal/http"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
)
|
)
|
||||||
|
|
||||||
type atRequestParser struct {}
|
type atRequestParser struct{}
|
||||||
|
|
||||||
func(arp *atRequestParser) GetSessionId(rq any) (string, error) {
|
func (arp *atRequestParser) GetSessionId(rq any) (string, error) {
|
||||||
rqv, ok := rq.(*http.Request)
|
rqv, ok := rq.(*http.Request)
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", handlers.ErrInvalidRequest
|
return "", handlers.ErrInvalidRequest
|
||||||
@ -49,7 +46,7 @@ func(arp *atRequestParser) GetSessionId(rq any) (string, error) {
|
|||||||
return phoneNumber, nil
|
return phoneNumber, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(arp *atRequestParser) GetInput(rq any) ([]byte, error) {
|
func (arp *atRequestParser) GetInput(rq any) ([]byte, error) {
|
||||||
rqv, ok := rq.(*http.Request)
|
rqv, ok := rq.(*http.Request)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, handlers.ErrInvalidRequest
|
return nil, handlers.ErrInvalidRequest
|
||||||
@ -68,7 +65,6 @@ func(arp *atRequestParser) GetInput(rq any) ([]byte, error) {
|
|||||||
return []byte(parts[len(parts)-1]), nil
|
return []byte(parts[len(parts)-1]), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func getFlags(fp string, debug bool) (*asm.FlagParser, error) {
|
func getFlags(fp string, debug bool) (*asm.FlagParser, error) {
|
||||||
flagParser := asm.NewFlagParser().WithDebug()
|
flagParser := asm.NewFlagParser().WithDebug()
|
||||||
_, err := flagParser.Load(fp)
|
_, err := flagParser.Load(fp)
|
||||||
@ -78,86 +74,6 @@ func getFlags(fp string, debug bool) (*asm.FlagParser, error) {
|
|||||||
return flagParser, nil
|
return flagParser, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore db.Db) (*ussd.Handlers, error) {
|
|
||||||
|
|
||||||
ussdHandlers, err := ussd.NewHandlers(appFlags, userdataStore)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
|
||||||
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
|
||||||
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
|
|
||||||
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
|
|
||||||
rs.AddLocalFunc("check_identifier", ussdHandlers.CheckIdentifier)
|
|
||||||
rs.AddLocalFunc("check_account_status", ussdHandlers.CheckAccountStatus)
|
|
||||||
rs.AddLocalFunc("authorize_account", ussdHandlers.Authorize)
|
|
||||||
rs.AddLocalFunc("quit", ussdHandlers.Quit)
|
|
||||||
rs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
|
|
||||||
rs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
|
|
||||||
rs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset)
|
|
||||||
rs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount)
|
|
||||||
rs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount)
|
|
||||||
rs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
|
|
||||||
rs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient)
|
|
||||||
rs.AddLocalFunc("get_sender", ussdHandlers.GetSender)
|
|
||||||
rs.AddLocalFunc("get_amount", ussdHandlers.GetAmount)
|
|
||||||
rs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin)
|
|
||||||
rs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname)
|
|
||||||
rs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname)
|
|
||||||
rs.AddLocalFunc("save_gender", ussdHandlers.SaveGender)
|
|
||||||
rs.AddLocalFunc("save_location", ussdHandlers.SaveLocation)
|
|
||||||
rs.AddLocalFunc("save_yob", ussdHandlers.SaveYob)
|
|
||||||
rs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings)
|
|
||||||
rs.AddLocalFunc("quit_with_balance", ussdHandlers.QuitWithBalance)
|
|
||||||
rs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized)
|
|
||||||
rs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate)
|
|
||||||
rs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
|
||||||
rs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
|
|
||||||
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
|
||||||
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
|
||||||
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
|
||||||
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
|
||||||
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
|
||||||
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
|
||||||
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
|
|
||||||
|
|
||||||
return ussdHandlers, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureDbDir(dbDir string) error {
|
|
||||||
err := os.MkdirAll(dbDir, 0700)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("state dir create exited with error: %v\n", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getStateStore(dbDir string, ctx context.Context) (db.Db, error) {
|
|
||||||
store := gdbmdb.NewGdbmDb()
|
|
||||||
storeFile := path.Join(dbDir, "state.gdbm")
|
|
||||||
store.Connect(ctx, storeFile)
|
|
||||||
return store, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getUserdataDb(dbDir string, ctx context.Context) db.Db {
|
|
||||||
store := gdbmdb.NewGdbmDb()
|
|
||||||
storeFile := path.Join(dbDir, "userdata.gdbm")
|
|
||||||
store.Connect(ctx, storeFile)
|
|
||||||
|
|
||||||
return store
|
|
||||||
}
|
|
||||||
|
|
||||||
func getResource(resourceDir string, ctx context.Context) (resource.Resource, error) {
|
|
||||||
store := fsdb.NewFsDb()
|
|
||||||
err := store.Connect(ctx, resourceDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rfs := resource.NewDbResource(store)
|
|
||||||
return rfs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var dbDir string
|
var dbDir string
|
||||||
var resourceDir string
|
var resourceDir string
|
||||||
@ -175,7 +91,7 @@ func main() {
|
|||||||
flag.UintVar(&port, "p", 7123, "http port")
|
flag.UintVar(&port, "p", 7123, "http port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logg.Infof("start command", "dbdir", dbDir, "resourcedir", resourceDir, "outputsize", size)
|
logg.Infof("start command", "dbdir", dbDir, "resourcedir", resourceDir, "outputsize", size)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
pfp := path.Join(scriptDir, "pp.csv")
|
pfp := path.Join(scriptDir, "pp.csv")
|
||||||
@ -197,19 +113,21 @@ func main() {
|
|||||||
cfg.EngineDebug = true
|
cfg.EngineDebug = true
|
||||||
}
|
}
|
||||||
|
|
||||||
rs, err := getResource(resourceDir, ctx)
|
menuStorageService := storage.MenuStorageService{}
|
||||||
|
|
||||||
|
rs, err := menuStorageService.GetResource(scriptDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ensureDbDir(dbDir)
|
err = menuStorageService.EnsureDbDir(dbDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
userdataStore := getUserdataDb(dbDir, ctx)
|
userdataStore := menuStorageService.GetUserdataDb(dbDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -220,14 +138,26 @@ func main() {
|
|||||||
if !ok {
|
if !ok {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
lhs := handlers.LocalHandlerService{
|
||||||
|
Parser: flagParser,
|
||||||
|
DbRs: dbResource,
|
||||||
|
UserdataStore: userdataStore,
|
||||||
|
Cfg: cfg,
|
||||||
|
Rs: rs,
|
||||||
|
}
|
||||||
|
|
||||||
hl, err := getHandler(flagParser, dbResource, userdataStore)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
stateStore, err := getStateStore(dbDir, ctx)
|
hl, err := lhs.GetHandler()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
|
||||||
|
stateStore, err := menuStorageService.GetStateStore(dbDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -238,7 +168,7 @@ func main() {
|
|||||||
bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
||||||
sh := httpserver.NewATSessionHandler(bsh)
|
sh := httpserver.NewATSessionHandler(bsh)
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
||||||
Handler: sh,
|
Handler: sh,
|
||||||
}
|
}
|
||||||
s.RegisterOnShutdown(sh.Shutdown)
|
s.RegisterOnShutdown(sh.Shutdown)
|
||||||
|
@ -10,32 +10,29 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/asm"
|
"git.defalsify.org/vise.git/asm"
|
||||||
"git.defalsify.org/vise.git/db"
|
|
||||||
fsdb "git.defalsify.org/vise.git/db/fs"
|
|
||||||
gdbmdb "git.defalsify.org/vise.git/db/gdbm"
|
|
||||||
"git.defalsify.org/vise.git/engine"
|
"git.defalsify.org/vise.git/engine"
|
||||||
"git.defalsify.org/vise.git/resource"
|
|
||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
|
"git.defalsify.org/vise.git/resource"
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers"
|
"git.grassecon.net/urdt/ussd/internal/handlers"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
)
|
)
|
||||||
|
|
||||||
type asyncRequestParser struct {
|
type asyncRequestParser struct {
|
||||||
sessionId string
|
sessionId string
|
||||||
input []byte
|
input []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func(p *asyncRequestParser) GetSessionId(r any) (string, error) {
|
func (p *asyncRequestParser) GetSessionId(r any) (string, error) {
|
||||||
return p.sessionId, nil
|
return p.sessionId, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func(p *asyncRequestParser) GetInput(r any) ([]byte, error) {
|
func (p *asyncRequestParser) GetInput(r any) ([]byte, error) {
|
||||||
return p.input, nil
|
return p.input, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,86 +45,6 @@ func getFlags(fp string, debug bool) (*asm.FlagParser, error) {
|
|||||||
return flagParser, nil
|
return flagParser, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore db.Db) (*ussd.Handlers, error) {
|
|
||||||
|
|
||||||
ussdHandlers, err := ussd.NewHandlers(appFlags, userdataStore)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
|
||||||
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
|
||||||
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
|
|
||||||
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
|
|
||||||
rs.AddLocalFunc("check_identifier", ussdHandlers.CheckIdentifier)
|
|
||||||
rs.AddLocalFunc("check_account_status", ussdHandlers.CheckAccountStatus)
|
|
||||||
rs.AddLocalFunc("authorize_account", ussdHandlers.Authorize)
|
|
||||||
rs.AddLocalFunc("quit", ussdHandlers.Quit)
|
|
||||||
rs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
|
|
||||||
rs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
|
|
||||||
rs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset)
|
|
||||||
rs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount)
|
|
||||||
rs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount)
|
|
||||||
rs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
|
|
||||||
rs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient)
|
|
||||||
rs.AddLocalFunc("get_sender", ussdHandlers.GetSender)
|
|
||||||
rs.AddLocalFunc("get_amount", ussdHandlers.GetAmount)
|
|
||||||
rs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin)
|
|
||||||
rs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname)
|
|
||||||
rs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname)
|
|
||||||
rs.AddLocalFunc("save_gender", ussdHandlers.SaveGender)
|
|
||||||
rs.AddLocalFunc("save_location", ussdHandlers.SaveLocation)
|
|
||||||
rs.AddLocalFunc("save_yob", ussdHandlers.SaveYob)
|
|
||||||
rs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings)
|
|
||||||
rs.AddLocalFunc("quit_with_balance", ussdHandlers.QuitWithBalance)
|
|
||||||
rs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized)
|
|
||||||
rs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate)
|
|
||||||
rs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
|
||||||
rs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
|
|
||||||
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
|
||||||
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
|
||||||
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
|
||||||
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
|
||||||
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
|
||||||
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
|
||||||
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
|
|
||||||
|
|
||||||
return ussdHandlers, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureDbDir(dbDir string) error {
|
|
||||||
err := os.MkdirAll(dbDir, 0700)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("state dir create exited with error: %v\n", err)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getStateStore(dbDir string, ctx context.Context) (db.Db, error) {
|
|
||||||
store := gdbmdb.NewGdbmDb()
|
|
||||||
storeFile := path.Join(dbDir, "state.gdbm")
|
|
||||||
store.Connect(ctx, storeFile)
|
|
||||||
return store, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getUserdataDb(dbDir string, ctx context.Context) db.Db {
|
|
||||||
store := gdbmdb.NewGdbmDb()
|
|
||||||
storeFile := path.Join(dbDir, "userdata.gdbm")
|
|
||||||
store.Connect(ctx, storeFile)
|
|
||||||
|
|
||||||
return store
|
|
||||||
}
|
|
||||||
|
|
||||||
func getResource(resourceDir string, ctx context.Context) (resource.Resource, error) {
|
|
||||||
store := fsdb.NewFsDb()
|
|
||||||
err := store.Connect(ctx, resourceDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rfs := resource.NewDbResource(store)
|
|
||||||
return rfs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var sessionId string
|
var sessionId string
|
||||||
var dbDir string
|
var dbDir string
|
||||||
@ -147,7 +64,7 @@ func main() {
|
|||||||
flag.UintVar(&port, "p", 7123, "http port")
|
flag.UintVar(&port, "p", 7123, "http port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logg.Infof("start command", "dbdir", dbDir, "resourcedir", resourceDir, "outputsize", size, "sessionId", sessionId)
|
logg.Infof("start command", "dbdir", dbDir, "resourcedir", resourceDir, "outputsize", size, "sessionId", sessionId)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
pfp := path.Join(scriptDir, "pp.csv")
|
pfp := path.Join(scriptDir, "pp.csv")
|
||||||
@ -169,19 +86,20 @@ func main() {
|
|||||||
cfg.EngineDebug = true
|
cfg.EngineDebug = true
|
||||||
}
|
}
|
||||||
|
|
||||||
rs, err := getResource(resourceDir, ctx)
|
menuStorageService := storage.MenuStorageService{}
|
||||||
|
rs, err := menuStorageService.GetResource(scriptDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ensureDbDir(dbDir)
|
err = menuStorageService.EnsureDbDir(dbDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
userdataStore := getUserdataDb(dbDir, ctx)
|
userdataStore := menuStorageService.GetUserdataDb(dbDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -193,13 +111,21 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
hl, err := getHandler(flagParser, dbResource, userdataStore)
|
lhs := handlers.LocalHandlerService{
|
||||||
|
Parser: flagParser,
|
||||||
|
DbRs: dbResource,
|
||||||
|
UserdataStore: userdataStore,
|
||||||
|
Cfg: cfg,
|
||||||
|
Rs: rs,
|
||||||
|
}
|
||||||
|
|
||||||
|
hl, err := lhs.GetHandler()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
stateStore, err := getStateStore(dbDir, ctx)
|
stateStore, err := menuStorageService.GetStateStore(dbDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -212,7 +138,7 @@ func main() {
|
|||||||
sh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
sh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
||||||
cfg.SessionId = sessionId
|
cfg.SessionId = sessionId
|
||||||
rqs := handlers.RequestSession{
|
rqs := handlers.RequestSession{
|
||||||
Ctx: ctx,
|
Ctx: ctx,
|
||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
}
|
}
|
||||||
@ -248,7 +174,7 @@ func main() {
|
|||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
_, err = fmt.Scanln(&rqs.Input)
|
_, err = fmt.Scanln(&rqs.Input)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Errorf("error in input: %v", err)
|
fmt.Errorf("error in input: %v", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
104
cmd/http/main.go
104
cmd/http/main.go
@ -12,20 +12,17 @@ import (
|
|||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/asm"
|
"git.defalsify.org/vise.git/asm"
|
||||||
"git.defalsify.org/vise.git/db"
|
|
||||||
fsdb "git.defalsify.org/vise.git/db/fs"
|
|
||||||
gdbmdb "git.defalsify.org/vise.git/db/gdbm"
|
|
||||||
"git.defalsify.org/vise.git/engine"
|
"git.defalsify.org/vise.git/engine"
|
||||||
"git.defalsify.org/vise.git/resource"
|
|
||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
|
"git.defalsify.org/vise.git/resource"
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers"
|
"git.grassecon.net/urdt/ussd/internal/handlers"
|
||||||
httpserver "git.grassecon.net/urdt/ussd/internal/http"
|
httpserver "git.grassecon.net/urdt/ussd/internal/http"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logg = logging.NewVanilla()
|
logg = logging.NewVanilla()
|
||||||
scriptDir = path.Join("services", "registration")
|
scriptDir = path.Join("services", "registration")
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -38,52 +35,6 @@ func getFlags(fp string, debug bool) (*asm.FlagParser, error) {
|
|||||||
return flagParser, nil
|
return flagParser, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getHandler(appFlags *asm.FlagParser, rs *resource.DbResource, userdataStore db.Db) (*ussd.Handlers, error) {
|
|
||||||
|
|
||||||
ussdHandlers, err := ussd.NewHandlers(appFlags, userdataStore)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rs.AddLocalFunc("set_language", ussdHandlers.SetLanguage)
|
|
||||||
rs.AddLocalFunc("create_account", ussdHandlers.CreateAccount)
|
|
||||||
rs.AddLocalFunc("save_pin", ussdHandlers.SavePin)
|
|
||||||
rs.AddLocalFunc("verify_pin", ussdHandlers.VerifyPin)
|
|
||||||
rs.AddLocalFunc("check_identifier", ussdHandlers.CheckIdentifier)
|
|
||||||
rs.AddLocalFunc("check_account_status", ussdHandlers.CheckAccountStatus)
|
|
||||||
rs.AddLocalFunc("authorize_account", ussdHandlers.Authorize)
|
|
||||||
rs.AddLocalFunc("quit", ussdHandlers.Quit)
|
|
||||||
rs.AddLocalFunc("check_balance", ussdHandlers.CheckBalance)
|
|
||||||
rs.AddLocalFunc("validate_recipient", ussdHandlers.ValidateRecipient)
|
|
||||||
rs.AddLocalFunc("transaction_reset", ussdHandlers.TransactionReset)
|
|
||||||
rs.AddLocalFunc("max_amount", ussdHandlers.MaxAmount)
|
|
||||||
rs.AddLocalFunc("validate_amount", ussdHandlers.ValidateAmount)
|
|
||||||
rs.AddLocalFunc("reset_transaction_amount", ussdHandlers.ResetTransactionAmount)
|
|
||||||
rs.AddLocalFunc("get_recipient", ussdHandlers.GetRecipient)
|
|
||||||
rs.AddLocalFunc("get_sender", ussdHandlers.GetSender)
|
|
||||||
rs.AddLocalFunc("get_amount", ussdHandlers.GetAmount)
|
|
||||||
rs.AddLocalFunc("reset_incorrect", ussdHandlers.ResetIncorrectPin)
|
|
||||||
rs.AddLocalFunc("save_firstname", ussdHandlers.SaveFirstname)
|
|
||||||
rs.AddLocalFunc("save_familyname", ussdHandlers.SaveFamilyname)
|
|
||||||
rs.AddLocalFunc("save_gender", ussdHandlers.SaveGender)
|
|
||||||
rs.AddLocalFunc("save_location", ussdHandlers.SaveLocation)
|
|
||||||
rs.AddLocalFunc("save_yob", ussdHandlers.SaveYob)
|
|
||||||
rs.AddLocalFunc("save_offerings", ussdHandlers.SaveOfferings)
|
|
||||||
rs.AddLocalFunc("quit_with_balance", ussdHandlers.QuitWithBalance)
|
|
||||||
rs.AddLocalFunc("reset_account_authorized", ussdHandlers.ResetAccountAuthorized)
|
|
||||||
rs.AddLocalFunc("reset_allow_update", ussdHandlers.ResetAllowUpdate)
|
|
||||||
rs.AddLocalFunc("get_profile_info", ussdHandlers.GetProfileInfo)
|
|
||||||
rs.AddLocalFunc("verify_yob", ussdHandlers.VerifyYob)
|
|
||||||
rs.AddLocalFunc("reset_incorrect_date_format", ussdHandlers.ResetIncorrectYob)
|
|
||||||
rs.AddLocalFunc("set_reset_single_edit", ussdHandlers.SetResetSingleEdit)
|
|
||||||
rs.AddLocalFunc("initiate_transaction", ussdHandlers.InitiateTransaction)
|
|
||||||
rs.AddLocalFunc("save_temporary_pin", ussdHandlers.SaveTemporaryPin)
|
|
||||||
rs.AddLocalFunc("verify_new_pin", ussdHandlers.VerifyNewPin)
|
|
||||||
rs.AddLocalFunc("confirm_pin_change", ussdHandlers.ConfirmPinChange)
|
|
||||||
rs.AddLocalFunc("quit_with_help",ussdHandlers.QuitWithHelp)
|
|
||||||
|
|
||||||
return ussdHandlers, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func ensureDbDir(dbDir string) error {
|
func ensureDbDir(dbDir string) error {
|
||||||
err := os.MkdirAll(dbDir, 0700)
|
err := os.MkdirAll(dbDir, 0700)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -92,32 +43,6 @@ func ensureDbDir(dbDir string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getStateStore(dbDir string, ctx context.Context) (db.Db, error) {
|
|
||||||
store := gdbmdb.NewGdbmDb()
|
|
||||||
storeFile := path.Join(dbDir, "state.gdbm")
|
|
||||||
store.Connect(ctx, storeFile)
|
|
||||||
return store, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func getUserdataDb(dbDir string, ctx context.Context) db.Db {
|
|
||||||
store := gdbmdb.NewGdbmDb()
|
|
||||||
storeFile := path.Join(dbDir, "userdata.gdbm")
|
|
||||||
store.Connect(ctx, storeFile)
|
|
||||||
|
|
||||||
return store
|
|
||||||
}
|
|
||||||
|
|
||||||
func getResource(resourceDir string, ctx context.Context) (resource.Resource, error) {
|
|
||||||
store := fsdb.NewFsDb()
|
|
||||||
err := store.Connect(ctx, resourceDir)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
rfs := resource.NewDbResource(store)
|
|
||||||
return rfs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var dbDir string
|
var dbDir string
|
||||||
var resourceDir string
|
var resourceDir string
|
||||||
@ -135,7 +60,7 @@ func main() {
|
|||||||
flag.UintVar(&port, "p", 7123, "http port")
|
flag.UintVar(&port, "p", 7123, "http port")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
logg.Infof("start command", "dbdir", dbDir, "resourcedir", resourceDir, "outputsize", size)
|
logg.Infof("start command", "dbdir", dbDir, "resourcedir", resourceDir, "outputsize", size)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
pfp := path.Join(scriptDir, "pp.csv")
|
pfp := path.Join(scriptDir, "pp.csv")
|
||||||
@ -157,19 +82,20 @@ func main() {
|
|||||||
cfg.EngineDebug = true
|
cfg.EngineDebug = true
|
||||||
}
|
}
|
||||||
|
|
||||||
rs, err := getResource(resourceDir, ctx)
|
menuStorageService := storage.MenuStorageService{}
|
||||||
|
rs, err := menuStorageService.GetResource(scriptDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ensureDbDir(dbDir)
|
err = menuStorageService.EnsureDbDir(dbDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
userdataStore := getUserdataDb(dbDir, ctx)
|
userdataStore := menuStorageService.GetUserdataDb(dbDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -181,13 +107,21 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
hl, err := getHandler(flagParser, dbResource, userdataStore)
|
lhs := handlers.LocalHandlerService{
|
||||||
|
Parser: flagParser,
|
||||||
|
DbRs: dbResource,
|
||||||
|
UserdataStore: userdataStore,
|
||||||
|
Cfg: cfg,
|
||||||
|
Rs: rs,
|
||||||
|
}
|
||||||
|
|
||||||
|
hl, err := lhs.GetHandler()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
stateStore, err := getStateStore(dbDir, ctx)
|
stateStore, err := menuStorageService.GetStateStore(dbDir, ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -198,7 +132,7 @@ func main() {
|
|||||||
bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
||||||
sh := httpserver.ToSessionHandler(bsh)
|
sh := httpserver.ToSessionHandler(bsh)
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
||||||
Handler: sh,
|
Handler: sh,
|
||||||
}
|
}
|
||||||
s.RegisterOnShutdown(sh.Shutdown)
|
s.RegisterOnShutdown(sh.Shutdown)
|
||||||
|
Loading…
Reference in New Issue
Block a user