commit 16454d75b6eccf44fd85ca2356de570e16a31964
parent ca0966b5857f2dd2c2ca8634a7a2c7ec7b815413
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Thu, 7 Aug 2025 17:23:03 +0200
add taler-directory-config tool
Diffstat:
2 files changed, 132 insertions(+), 8 deletions(-)
diff --git a/Makefile.in b/Makefile.in
@@ -1,4 +1,4 @@
-all: server cli
+all: server tools
SCRIPT_TARGET:=$(shell dirname $(shell go list -f '{{.Target}}' ./cmd/taldir-server))
TALER_DIRECTORY_HOME=${datadir}/taler-directory
@@ -7,14 +7,17 @@ GITVER=`git describe --tags | sed 's/v//'`
server:
${GO} build -o taler-directory -ldflags "-X main.version=${VERSION} -X main.taldirdatahome=${TALER_DIRECTORY_HOME}" ./cmd/taldir-server
-cli:
- ${GO} build -ldflags "-X main.version=${VERSION} -X main.taldirdatahome=${TALER_DIRECTORY_HOME}" ./cmd/taldir-cli
+tools:
+ ${GO} build -o taler-directory-cli -ldflags "-X main.version=${VERSION} -X main.taldirdatahome=${TALER_DIRECTORY_HOME}" ./cmd/taldir-cli
+ ${GO} build -o taler-directory-config -ldflags "-X main.version=${VERSION} -X main.taldirdatahome=${TALER_DIRECTORY_HOME}" ./cmd/taldir-config
-install: server cli
+
+install: server tools
-mkdir -p ${DESTDIR}${bindir}
-mkdir -p ${DESTDIR}${TALER_DIRECTORY_HOME}
install ./taler-directory ${DESTDIR}${bindir}
- install ./taldir-cli ${DESTDIR}${bindir}
+ install ./taler-directory-cli ${DESTDIR}${bindir}
+ install ./taler-directory-config ${DESTDIR}${bindir}
cp -r ./web ${DESTDIR}${TALER_DIRECTORY_HOME}/
cp -r ./static ${DESTDIR}${TALER_DIRECTORY_HOME}/
chmod +x scripts/validators/*
@@ -24,13 +27,13 @@ install: server cli
cp taldir.conf.example ${DESTDIR}${TALER_DIRECTORY_HOME}
uninstall:
- ${RM} ${DESTDIR}${bindir}/taler-directory
- ${RM} ${DESTDIR}${bindir}/taldir-*
+ ${RM} ${DESTDIR}${bindir}/taler-directory*
-${RM} -r ${DESTDIR}${TALER_DIRECTORY_HOME}
format:
${GO} fmt ./cmd/taldir-server/*.go
${GO} fmt ./cmd/taldir-cli/*.go
+ ${GO} fmt ./cmd/taldir-config/*.go
${GO} fmt ./pkg/rest/*.go
check:
@@ -45,4 +48,4 @@ gana:
dist:
git archive --format=tar.gz -o taldir-${GITVER}.tar.gz --prefix=taldir-${GITVER}/ HEAD
-.PHONY: all gana server cli check format uninstall install dist
+.PHONY: all gana server tools check format uninstall install dist
diff --git a/cmd/taldir-config/main.go b/cmd/taldir-config/main.go
@@ -0,0 +1,121 @@
+// This file is part of taldir, the Taler Directory implementation.
+// Copyright (C) 2025 Martin Schanzenbach
+//
+// Taldir is free software: you can redistribute it and/or modify it
+// under the terms of the GNU Affero General Public License as published
+// by the Free Software Foundation, either version 3 of the License,
+// or (at your option) any later version.
+//
+// Taldir is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+//
+// SPDX-License-Identifier: AGPL3.0-or-later
+
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os"
+
+ "rsc.io/getopt"
+
+ "gopkg.in/ini.v1"
+)
+
+var (
+ version string
+ taldirdatahome string
+ verbose bool // FIXME do something with this?
+)
+
+func printHelp() {
+ fmt.Print("taler-directory-config\n\n")
+ getopt.PrintDefaults()
+ fmt.Print("\nReport bugs to gnunet-developers@gnu.org.\n",
+ "Home page: https://taler.net\n",
+ "General help using GNU software: http://www.gnu.org/gethelp/\n")
+}
+
+func printKey(key *ini.Key, onlyValue bool) {
+ if onlyValue {
+ fmt.Printf("%s\n", key.String())
+ return
+ }
+ fmt.Printf("%s = %s\n", key.Name(), key.String())
+}
+
+func printCfgOptions(sec *ini.Section, option *string, onlyValue *bool) {
+ if len(*option) == 0 {
+ for _, key := range sec.Keys() {
+ printKey(key, *onlyValue)
+ }
+ return
+ }
+ if ! sec.HasKey(*option) {
+ fmt.Printf("Section `%s' does not have option `%s'!\n", sec.Name(), *option)
+ os.Exit(1)
+ }
+ key := sec.Key(*option)
+ printKey(key, *onlyValue)
+}
+
+func printCfgSections(f *ini.File) {
+ for _, sec := range f.Sections() {
+ fmt.Println(sec.Name())
+ }
+}
+
+
+func main() {
+ var cfg *ini.File
+ var err error
+ var sectionFlag = flag.String("s", "", "Section to use")
+ getopt.Alias("s", "section")
+ var listSectionFlag = flag.Bool("S", false, "List all sections")
+ getopt.Alias("S", "list-sections")
+ var optionFlag = flag.String("o", "", "Option to output")
+ getopt.Alias("o", "option")
+ var onlyValueFlag = flag.Bool("O", false, "Output only value")
+ getopt.Alias("O", "only-value")
+ var cfgFlag = flag.String("c", "", "Configuration file to use")
+ getopt.Alias("c", "config")
+ var helpFlag = flag.Bool("h", false, "Print help")
+ getopt.Alias("h", "help")
+
+ getopt.Parse()
+ if *helpFlag {
+ printHelp()
+ return
+ }
+ cfgfile := "taldir.conf"
+ if len(*cfgFlag) != 0 {
+ cfg, err = ini.LooseLoad(*cfgFlag)
+ if err != nil {
+ fmt.Printf("Failed to read config: %v\n", err)
+ os.Exit(1)
+ }
+ } else {
+ // FIXME also try in datahome
+ cfg, err = ini.LooseLoad(cfgfile)
+ if err != nil {
+ fmt.Printf("Failed to read config: %v\n", err)
+ os.Exit(1)
+ }
+ }
+ if *listSectionFlag {
+ printCfgSections(cfg)
+ return
+ }
+ if len(*sectionFlag) == 0 {
+ fmt.Println("No section given!")
+ os.Exit(1)
+ }
+ sec := cfg.Section(*sectionFlag)
+ printCfgOptions(sec, optionFlag, onlyValueFlag)
+}