Add an admin repos command line argument
--- a/access/access.go Tue May 07 22:41:21 2019 -0500
+++ b/access/access.go Mon Jul 22 22:12:09 2019 -0500
@@ -34,7 +34,6 @@
@@ -113,7 +112,7 @@
- a.users[user] = make(map[string]Perm)
+ a.users[user] = map[string]Perm{} a.users[user][pattern] = perm
@@ -248,13 +247,18 @@
// New initializes access strucuture, if any error is
// returned it will be I/O errors reading or parsing
-func New(reposPath string) (*Access, error) {
- accessFile = filepath.Join(reposPath, "hgkeeper", AccessFile)
- keysDir = filepath.Join(reposPath, "hgkeeper", KeysDir)
- a.users = make(map[string]map[string]Perm)
- a.keys = make(map[string]string)
+func New(reposPath, adminRepo string) (*Access, error) { + accessFile = filepath.Join(reposPath, adminRepo, AccessFile) + keysDir = filepath.Join(reposPath, adminRepo, KeysDir) + log.Errorf("accessFile: %q", accessFile) + log.Errorf("keysDir: %q", keysDir) + users: map[string]map[string]Perm{}, + keys: map[string]string{}, --- a/access/access_test.go Tue May 07 22:41:21 2019 -0500
+++ b/access/access_test.go Mon Jul 22 22:12:09 2019 -0500
@@ -1,77 +1,79 @@
- _ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/assert"
+// var keysData = []string{ +func TestAccessControlLoadSimple(t *testing.T) {
-var keysData = []string{
-// func TestAccessControlLoadSimple(t *testing.T) {
-// assert := assert.New(t)
+ ac, err := loadAccessControl(strings.NewReader(data)) -// ac, err := loadAccessControl(strings.NewReader(data))
-// Init: []string{"admin"},
-// Read: []string{"everyone"},
-// Read: []string{"admin"},
-// ac.Patterns["hgkeeper"],
+ Init: []string{"admin"}, + Read: []string{"everyone"}, + Read: []string{"admin"}, + ac.Patterns["hgkeeper"], func TestIsPublic(t *testing.T) {
@@ -83,8 +85,6 @@
for _, v := range tests {
- if e := isPublic([]byte(v.u)); e != v.expect {
- t.Fatalf("isPublic(%s): expected: %v got: %v", v.u, v.expect, e)
+ assert.Equal(t, v.expect, isPublic([]byte(v.u))) --- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/globals/globals.go Mon Jul 22 22:12:09 2019 -0500
@@ -0,0 +1,6 @@
+ ReposPath string `kong:"flag,name='repos-path',env='HGK_REPOS_PATH',default='repos',help='the directory where the repositories are stored'"` + AdminRepo string `kong:"flag,name='admin-repo',env='HGK_ADMIN_REPO',default='hgkeeper',help='the name of the admin repo to create/use'"` --- a/main.go Tue May 07 22:41:21 2019 -0500
+++ b/main.go Mon Jul 22 22:12:09 2019 -0500
@@ -6,14 +6,15 @@
"github.com/alecthomas/kong"
log "github.com/sirupsen/logrus"
+ "bitbucket.org/rw_grim/hgkeeper/globals" "bitbucket.org/rw_grim/hgkeeper/serve"
"bitbucket.org/rw_grim/hgkeeper/setup"
- ReposPath string `kong:"flag,name='repos-path',default='repos',help='the directory where the repository are stored'"`
- Serve serve.Command `kong:"cmd,help='run the ssh server'"`
- Setup setup.Command `kong:"cmd,help='inital setup for the server'"`
+ Serve serve.Command `kong:"cmd,help='run the ssh server'"` + Setup setup.Command `kong:"cmd,help='inital setup for the server'"` @@ -34,6 +35,6 @@
- err := ctx.Run(cmd.ReposPath)
+ err := ctx.Run(&cmd.Globals) --- a/serve/command.go Tue May 07 22:41:21 2019 -0500
+++ b/serve/command.go Mon Jul 22 22:12:09 2019 -0500
@@ -1,16 +1,17 @@
+ "bitbucket.org/rw_grim/hgkeeper/globals" "bitbucket.org/rw_grim/hgkeeper/ssh"
- SSHAddr string `kong:"flag,name='ssh-listen-addr',short='l',help='what address to listen on',default=':22222'"`
- SSHHostKeysPath string `kong:"flag,name='ssh-host-keys-path',short='H',help='the path where host keys are kept',default='host-keys'"`
+ SSHAddr string `kong:"flag,name='ssh-listen-addr',env='HGK_SSH_LISTEN_ADDR',short='l',help='what address to listen on',default=':22222'"` + SSHHostKeysPath string `kong:"flag,name='ssh-host-keys-path',env='HGK_SSH_HOST_KEYS_PATH',short='H',help='the path where host keys are kept',default='host-keys'"` -func (c *Command) Run(reposPath string) error {
- s, err := ssh.NewServer(c.SSHHostKeysPath, reposPath)
+func (c *Command) Run(g *globals.Globals) error { + s, err := ssh.NewServer(c.SSHHostKeysPath, g.ReposPath, g.AdminRepo) --- a/setup/command.go Tue May 07 22:41:21 2019 -0500
+++ b/setup/command.go Mon Jul 22 22:12:09 2019 -0500
@@ -6,12 +6,13 @@
+ log "github.com/sirupsen/logrus" + "bitbucket.org/rw_grim/hgkeeper/globals" "bitbucket.org/rw_grim/hgkeeper/hg"
- AdminRepo string `kong:"flag,name='admin-repo',default='hgkeeper',help='the name of the admin repo to create'"`
accessYmlFilename = "access.yml"
@@ -68,9 +69,12 @@
-func (c *Command) createAdminRepo(reposPath string) error {
- path := filepath.Join(reposPath, c.AdminRepo)
+func (c *Command) createAdminRepo(reposPath, adminRepo string) error { + log.Errorf("reposPath: %q", reposPath) + log.Errorf("adminRepo: %q", adminRepo) + path := filepath.Join(reposPath, adminRepo) + log.Infof("creating %q", path) if err := runCmd(hg.Init(path)); err != nil {
@@ -107,8 +111,8 @@
-func (c *Command) Run(reposPath string) error {
- if err := c.createAdminRepo(reposPath); err != nil {
+func (c *Command) Run(g *globals.Globals) error { + if err := c.createAdminRepo(g.ReposPath, g.AdminRepo); err != nil { --- a/ssh/server.go Tue May 07 22:41:21 2019 -0500
+++ b/ssh/server.go Mon Jul 22 22:12:09 2019 -0500
@@ -17,7 +17,7 @@
-func NewServer(hostKeysPath, reposPath string) (*Server, error) {
+func NewServer(hostKeysPath, reposPath, adminRepo string) (*Server, error) { @@ -30,7 +30,7 @@
if err = s.setHostKeysPath(hostKeysPath); err != nil {
- if s.a, err = access.New(s.reposPath); err != nil {
+ if s.a, err = access.New(s.reposPath, adminRepo); err != nil { @@ -127,6 +127,7 @@
+ log.Warnf("running %#v\n", cmd) if err := cmd.run(conn, serverConn, req); err != nil {
log.Warnf("%s command %q failed: %v", serverConn.RemoteAddr(), rawCmd, err)