summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRose Hogenson <rosehogenson@posteo.net>2025-10-25 16:18:00 -0700
committerRose Hogenson <rosehogenson@posteo.net>2025-10-25 17:27:52 -0700
commitd952f0cafc8e90a6ebb826db491d9f18cf4dd1d7 (patch)
tree1a069e82fcbc24042abd8d90d2417018adee7499
parentae0e116d90cc9b2e7e268e497a7838bc756e2087 (diff)
downloadroseh.moe-d952f0cafc8e90a6ebb826db491d9f18cf4dd1d7.tar.zst
Use asspb instead of ini
-rw-r--r--go.mod3
-rw-r--r--go.sum4
-rw-r--r--internal/ini/ini.go51
-rw-r--r--roseh.moe.go69
4 files changed, 36 insertions, 91 deletions
diff --git a/go.mod b/go.mod
index 247f10d..6e43460 100644
--- a/go.mod
+++ b/go.mod
@@ -1,9 +1,10 @@
module roseh.moe/pkg/roseh.moe
-go 1.24.0
+go 1.25.1
require (
golang.org/x/term v0.35.0
+ roseh.moe/pkg/asspb v1.2.0
roseh.moe/pkg/wordlist v1.0.2
)
diff --git a/go.sum b/go.sum
index e2aacc7..5c6cc58 100644
--- a/go.sum
+++ b/go.sum
@@ -1,6 +1,10 @@
+github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
+github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
+roseh.moe/pkg/asspb v1.2.0 h1:uMfyC0f+TPmrIXQj0Nh2Xre9hbWI5otprRV9XCsjXB4=
+roseh.moe/pkg/asspb v1.2.0/go.mod h1:9ZcWy0yQFpw0xg+1s9Zklrat9wEpj4TGqpvX3AFsmxw=
roseh.moe/pkg/wordlist v1.0.2 h1:riB2RqCU5zXfCQjaPHYTXV/688FV9/Bp6Hnb0IAkP9c=
roseh.moe/pkg/wordlist v1.0.2/go.mod h1:2Jd7j6Qy5SElcrITJJNUcbxH9TPKYn0k+BJL3tsJdiY=
diff --git a/internal/ini/ini.go b/internal/ini/ini.go
deleted file mode 100644
index c546a52..0000000
--- a/internal/ini/ini.go
+++ /dev/null
@@ -1,51 +0,0 @@
-package ini
-
-import (
- "bufio"
- "errors"
- "io"
- "iter"
- "strings"
-)
-
-type Parser struct {
- Section string
- LineNumber int
-}
-
-type KeyVal struct {
- Key, Val string
-}
-
-func (p *Parser) Parse(r io.Reader) iter.Seq2[KeyVal, error] {
- return func(yield func(KeyVal, error) bool) {
- *p = Parser{}
- scanner := bufio.NewScanner(r)
- for scanner.Scan() {
- p.LineNumber++
- line := strings.TrimSpace(scanner.Text())
- if len(line) == 0 || strings.HasPrefix(line, "//") || strings.HasPrefix(line, ";") || strings.HasPrefix(line, "#") {
- continue
- }
- if strings.HasPrefix(line, "[") && strings.HasSuffix(line, "]") {
- p.Section = strings.TrimSpace(line[1 : len(line)-1])
- continue
- }
- key, val, ok := strings.Cut(line, "=")
- if !ok {
- if !yield(KeyVal{}, errors.New("invalid key-value pair")) {
- return
- }
- continue
- }
- key, val = strings.TrimSpace(key), strings.TrimSpace(val)
- if !yield(KeyVal{key, val}, nil) {
- return
- }
- }
- if err := scanner.Err(); err != nil {
- yield(KeyVal{}, err)
- return
- }
- }
-}
diff --git a/roseh.moe.go b/roseh.moe.go
index 481da6b..7f5056c 100644
--- a/roseh.moe.go
+++ b/roseh.moe.go
@@ -20,7 +20,7 @@ import (
"sync"
"time"
- "roseh.moe/pkg/roseh.moe/internal/ini"
+ "roseh.moe/pkg/asspb"
"roseh.moe/pkg/roseh.moe/internal/pwhash"
"roseh.moe/pkg/wordlist"
)
@@ -37,37 +37,31 @@ var (
var notepadPassword, secretKey []byte
func loadSecrets() error {
- f, err := os.Open(*secretsFile)
+ fileBytes, err := os.ReadFile(*secretsFile)
if err != nil {
return err
}
- defer f.Close()
- p := new(ini.Parser)
- for keyVal, err := range p.Parse(f) {
- if err != nil {
- return fmt.Errorf("%s:%d %s", *secretsFile, p.LineNumber, err)
- }
- switch keyVal.Key {
- case "notepad-password":
- notepadPassword, err = hex.AppendDecode(nil, []byte(keyVal.Val))
- if err != nil {
- return fmt.Errorf("%s:%d %s", *secretsFile, p.LineNumber, err)
- }
- case "secret-key":
- secretKey, err = hex.AppendDecode(nil, []byte(keyVal.Val))
- if err != nil {
- return fmt.Errorf("%s:%d %s", *secretsFile, p.LineNumber, err)
- }
- default:
- return fmt.Errorf("%s:%d unknown key", *secretsFile, p.LineNumber)
- }
+ var secretsConfig struct {
+ NotepadPassword string
+ SecretKey string
}
- if len(notepadPassword) == 0 {
+ if err := asspb.Unmarshal(fileBytes, &secretsConfig); err != nil {
+ return fmt.Errorf("%s: %s", *secretsFile, err)
+ }
+ if secretsConfig.NotepadPassword == "" {
return fmt.Errorf("%s: missing notepad-password", *secretsFile)
}
- if len(secretKey) == 0 {
+ if secretsConfig.SecretKey == "" {
return fmt.Errorf("%s: missing secret-key", *secretsFile)
}
+ notepadPassword, err = hex.AppendDecode(nil, []byte(secretsConfig.NotepadPassword))
+ if err != nil {
+ return fmt.Errorf("bad notepad password: %s", err)
+ }
+ secretKey, err = hex.AppendDecode(nil, []byte(secretsConfig.SecretKey))
+ if err != nil {
+ return fmt.Errorf("bad secret key: %s", err)
+ }
return nil
}
@@ -96,28 +90,25 @@ func loadConfig() (*serviceConfiguration, error) {
return oldConfig, nil
}
log.Printf("Reloading config file...")
- f, err := os.Open(*configFile)
+ fileBytes, err := os.ReadFile(*configFile)
if err != nil {
return nil, err
}
- defer f.Close()
+ var fileConfig struct {
+ Redirect []struct{ Package, Command, Redirect string }
+ }
+ if err := asspb.Unmarshal(fileBytes, &fileConfig); err != nil {
+ return nil, err
+ }
config := &serviceConfiguration{
packageRedirects: make(map[string]string),
commandRedirects: make(map[string]string),
}
- p := new(ini.Parser)
- for keyVal, err := range p.Parse(f) {
- if err != nil {
- log.Printf("Warning: %s:%d %s", *configFile, p.LineNumber, err)
- continue
- }
- switch p.Section {
- case "package-redirects":
- config.packageRedirects[keyVal.Key] = keyVal.Val
- case "command-redirects":
- config.commandRedirects[keyVal.Key] = keyVal.Val
- default:
- log.Printf("Warning: %s:%d unknown section", *configFile, p.LineNumber)
+ for _, redirect := range fileConfig.Redirect {
+ if redirect.Package != "" {
+ config.packageRedirects[redirect.Package] = redirect.Redirect
+ } else {
+ config.commandRedirects[redirect.Command] = redirect.Command
}
}
serviceConfigMu.Lock()