tangled
alpha
login
or
join now
back
round
0
view raw
guard: read the motd from a file
#382
merged
opened by
ptr.pet
5 months ago
targeting
master
from
[deleted fork]
: master
Signed-off-by: dusk
y.bera003.06@protonmail.com
Change-Id: kvuxwxxzvvqtvypqzlotlwkqmuttqwun
options
unified
split
Changed files
+18
-2
guard
guard.go
+18
-2
guard/guard.go
···
2
3
import (
4
"context"
0
5
"fmt"
6
"log/slog"
7
"net/http"
···
43
Usage: "internal API endpoint",
44
Value: "http://localhost:5444",
45
},
0
0
0
0
0
46
},
47
}
48
}
···
54
gitDir := cmd.String("git-dir")
55
logPath := cmd.String("log-path")
56
endpoint := cmd.String("internal-api")
0
57
58
logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
59
if err != nil {
···
149
"fullPath", fullPath,
150
"client", clientIP)
151
0
0
0
0
0
0
0
0
0
152
if gitCommand == "git-upload-pack" {
153
-
fmt.Fprintf(os.Stderr, "\x02%s\n", "Welcome to this knot!")
154
} else {
155
-
fmt.Fprintf(os.Stderr, "%s\n", "Welcome to this knot!")
156
}
157
158
gitCmd := exec.Command(gitCommand, fullPath)
···
2
3
import (
4
"context"
5
+
"errors"
6
"fmt"
7
"log/slog"
8
"net/http"
···
44
Usage: "internal API endpoint",
45
Value: "http://localhost:5444",
46
},
47
+
&cli.StringFlag{
48
+
Name: "motd-file",
49
+
Usage: "path to message of the day file",
50
+
Value: "/home/git/motd",
51
+
},
52
},
53
}
54
}
···
60
gitDir := cmd.String("git-dir")
61
logPath := cmd.String("log-path")
62
endpoint := cmd.String("internal-api")
63
+
motdFile := cmd.String("motd-file")
64
65
logFile, err := os.OpenFile(logPath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
66
if err != nil {
···
156
"fullPath", fullPath,
157
"client", clientIP)
158
159
+
var motd string
160
+
if motdRaw, err := os.ReadFile(motdFile); err != nil {
161
+
if !errors.Is(err, os.ErrNotExist) {
162
+
l.Error("failed to read motd file", "error", err)
163
+
}
164
+
motd = "Welcome to this knot!\n"
165
+
} else {
166
+
motd = string(motdRaw)
167
+
}
168
if gitCommand == "git-upload-pack" {
169
+
fmt.Fprintf(os.Stderr, "\x02%s", motd)
170
} else {
171
+
fmt.Fprintf(os.Stderr, "%s", motd)
172
}
173
174
gitCmd := exec.Command(gitCommand, fullPath)