grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
The setting for controlling whether or not to publish is named publish, not publishing
2019-09-18, Gary Kramlich
48860d0159a2
The setting for controlling whether or not to publish is named publish, not publishing
package
commands
import
(
"fmt"
"path/filepath"
"github.com/gliderlabs/ssh"
log
"github.com/sirupsen/logrus"
"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
(
session
ssh
.
Session
,
username
string
)
error
{
if
!
access
.
CanRead
(
username
,
"/"
+
s
.
repoName
)
{
return
fmt
.
Errorf
(
"repository %q not found"
,
s
.
repoName
)
}
writeable
:=
access
.
CanWrite
(
username
,
"/"
+
s
.
repoName
)
if
err
:=
run
(
hg
.
Serve
(
s
.
repoPath
,
writeable
),
session
);
err
!=
nil
{
return
err
}
if
s
.
repoName
==
access
.
AdminRepo
()
{
log
.
Info
(
"admin repo updated, refreshing access control"
)
return
access
.
Refresh
()
}
return
nil
}