grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Use Go 1.22 and update dependencies
default
tip
2 months ago, aklitzing
f33f223bc8fe
Use Go 1.22 and update dependencies
Reviewed at https://reviews.imfreedom.org/r/2949/
package
authorized_keys
import
(
"fmt"
"strings"
"keep.imfreedom.org/grim/hgkeeper/access"
"keep.imfreedom.org/grim/hgkeeper/globals"
)
type
Command
struct
{
PubKey
string
`kong:"arg,help='The pubkey of the calling user'"`
HGKeeperExec
string
`kong:"flag,help='The path to hgkeeper executable',default='hgkeeper'"`
}
func
(
c
*
Command
)
Run
(
g
*
globals
.
Globals
)
error
{
if
err
:=
access
.
Setup
(
g
.
ReposPath
,
g
.
AdminRepo
,
g
.
LdapConfig
);
err
!=
nil
{
return
err
}
defer
access
.
Teardown
()
username
:=
access
.
UsernameFromPubkey
(
c
.
PubKey
)
if
username
==
""
{
return
fmt
.
Errorf
(
"username not found for pubkey: %s"
,
c
.
PubKey
)
}
options
:=
[]
string
{
fmt
.
Sprintf
(
"command=\"%s --repos-path='%s' once %s\""
,
c
.
HGKeeperExec
,
g
.
ReposPath
,
username
),
"restrict"
,
}
fmt
.
Printf
(
"%s %s"
,
strings
.
Join
(
options
,
","
),
c
.
PubKey
)
return
nil
}