grim/hgkeeper

Parents 2930b0a69048
Children b3b134a272ad
Set the environment variable HGK_USERNAME when we spawn hg so that hooks can know who has authenticated
--- a/hg/hg.go Tue Jun 08 16:51:39 2021 -0500
+++ b/hg/hg.go Thu Oct 28 02:15:42 2021 -0500
@@ -19,7 +19,7 @@
writeable bool
}
-func (c *Command) Setup(repoName string) error {
+func (c *Command) Setup(repoName, username string) error {
hgrc, err := createHgrc(c.writeable)
if err != nil {
return err
@@ -39,6 +39,7 @@
c.cmd.Env = append(
os.Environ(),
"HGRCPATH="+strings.Join(rcs, string(filepath.ListSeparator)),
+ "HGK_USERNAME="+username,
)
return nil
@@ -53,8 +54,8 @@
}
}
-func (c *Command) Exec(repoName string) (string, error) {
- c.Setup(repoName)
+func (c *Command) Exec(repoName, username string) (string, error) {
+ c.Setup(repoName, username)
defer c.Teardown()
raw, err := c.Cmd().CombinedOutput()
@@ -62,8 +63,8 @@
return string(raw), err
}
-func (c *Command) ExecPiped(repoName string, stdin io.Reader, stdout, stderr io.Writer) error {
- if err := c.Setup(repoName); err != nil {
+func (c *Command) ExecPiped(repoName, username string, stdin io.Reader, stdout, stderr io.Writer) error {
+ if err := c.Setup(repoName, username); err != nil {
return err
}
defer c.Teardown()
--- a/hg/hgweb.go Tue Jun 08 16:51:39 2021 -0500
+++ b/hg/hgweb.go Thu Oct 28 02:15:42 2021 -0500
@@ -10,7 +10,7 @@
)
func TemplatesDir() (string, error) {
- templatesDir, err := Config("web.templates").Exec("")
+ templatesDir, err := Config("web.templates").Exec("", "")
if err != nil || templatesDir == "" {
if err != nil {
--- a/once/command.go Tue Jun 08 16:51:39 2021 -0500
+++ b/once/command.go Thu Oct 28 02:15:42 2021 -0500
@@ -23,7 +23,7 @@
hgcmd := hg.Serve(filepath.Join(reposPath, repoPath), writeable)
- return hgcmd.ExecPiped(repoPath, os.Stdin, os.Stdout, os.Stderr)
+ return hgcmd.ExecPiped(repoPath, c.User, os.Stdin, os.Stdout, os.Stderr)
}
func (c *Command) init(reposPath, repoPath string) error {
@@ -33,7 +33,7 @@
hgcmd := hg.Init(filepath.Join(reposPath, repoPath))
- return hgcmd.ExecPiped(repoPath, os.Stdin, os.Stdout, os.Stderr)
+ return hgcmd.ExecPiped(repoPath, c.User, os.Stdin, os.Stdout, os.Stderr)
}
func (c *Command) Run(g *globals.Globals) error {
--- a/ssh/commands/init.go Tue Jun 08 16:51:39 2021 -0500
+++ b/ssh/commands/init.go Thu Oct 28 02:15:42 2021 -0500
@@ -28,7 +28,7 @@
return fmt.Errorf("access denied")
}
- if err := run(i.repoPath, hg.Init(i.repoPath), session); err != nil {
+ if err := run(i.repoPath, username, hg.Init(i.repoPath), session); err != nil {
return err
}
--- a/ssh/commands/run.go Tue Jun 08 16:51:39 2021 -0500
+++ b/ssh/commands/run.go Thu Oct 28 02:15:42 2021 -0500
@@ -6,6 +6,6 @@
"keep.imfreedom.org/grim/hgkeeper/hg"
)
-func run(repoPath string, hgCmd *hg.Command, session ssh.Session) error {
- return hgCmd.ExecPiped(repoPath, session, session, session.Stderr())
+func run(repoPath, username string, hgCmd *hg.Command, session ssh.Session) error {
+ return hgCmd.ExecPiped(repoPath, username, session, session, session.Stderr())
}
--- a/ssh/commands/serve.go Tue Jun 08 16:51:39 2021 -0500
+++ b/ssh/commands/serve.go Thu Oct 28 02:15:42 2021 -0500
@@ -31,7 +31,7 @@
writeable := access.CanWrite(username, "/"+s.repoName)
hgcmd := hg.Serve(s.repoPath, writeable)
- if err := run(s.repoName, hgcmd, session); err != nil {
+ if err := run(s.repoName, username, hgcmd, session); err != nil {
return err
}