grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Move the /ssh/authorized_keys endpoint to /hgk/authorized_keys
2022-03-07, Gary Kramlich
bc46a398eba6
Move the /ssh/authorized_keys endpoint to /hgk/authorized_keys
package
access
import
(
"fmt"
"os"
"path"
"path/filepath"
"strings"
)
func
refreshHgWeb
()
error
{
fp
,
err
:=
os
.
OpenFile
(
hgwebConfigPath
,
os
.
O_WRONLY
|
os
.
O_TRUNC
,
0644
)
if
err
!=
nil
{
return
err
}
defer
fp
.
Close
()
fmt
.
Fprintf
(
fp
,
"[paths]\n"
)
absReposPath
,
err
:=
filepath
.
Abs
(
ReposPath
())
if
err
!=
nil
{
return
err
}
// walk the reposPath, looking for .hg directories, when one is found,
// check if it is publicly readable, and if so, add it to the config file.
filepath
.
Walk
(
absReposPath
,
func
(
filename
string
,
info
os
.
FileInfo
,
err
error
)
error
{
// check if we're looking at a directory
if
!
info
.
IsDir
()
{
return
nil
}
// check if it is a .hg directory
if
!
strings
.
HasSuffix
(
info
.
Name
(),
".hg"
)
{
return
nil
}
// figure out the repo path that we will be checking against the casbin
// stuff. That means it needs to be the exact path of the repo and not
// include the parent directory.
repoPath
:=
path
.
Dir
(
filename
)
relativeRepoPath
:=
strings
.
TrimPrefix
(
repoPath
,
absReposPath
)
// check if it's publicly readable
if
CanRead
(
"public"
,
relativeRepoPath
)
{
fmt
.
Fprintf
(
fp
,
"%s = %s\n"
,
relativeRepoPath
,
repoPath
)
}
return
filepath
.
SkipDir
})
return
nil
}