grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Move from our custom yaml access setup to casbin
2019-09-09, Gary Kramlich
f82b7c397849
Move from our custom yaml access setup to casbin
package
commands
import
(
"fmt"
"path/filepath"
"golang.org/x/crypto/ssh"
"bitbucket.org/rw_grim/hgkeeper/access"
"bitbucket.org/rw_grim/hgkeeper/hg"
)
type
Serve
struct
{
repoPath
string
repoName
string
}
func
NewServe
(
reposPath
,
repoName
string
)
*
Serve
{
return
&
Serve
{
repoPath
:
filepath
.
Join
(
reposPath
,
repoName
),
repoName
:
repoName
,
}
}
func
(
s
*
Serve
)
Run
(
conn
ssh
.
Channel
,
serverConn
*
ssh
.
ServerConn
,
username
string
,
req
*
ssh
.
Request
)
error
{
if
!
access
.
CanRead
(
username
,
s
.
repoName
)
{
return
fmt
.
Errorf
(
"repository %q not found"
,
s
.
repoName
)
}
writeable
:=
access
.
CanWrite
(
username
,
s
.
repoName
)
return
run
(
hg
.
Serve
(
s
.
repoPath
,
writeable
),
conn
,
serverConn
,
req
)
}
func
(
s
*
Serve
)
String
()
string
{
return
"hg serve"
}