grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Add `go 1.11` to the bottom of go.mod and run `go mod tidy`
2019-09-10, Gary Kramlich
21e7408ca1a0
Add `go 1.11` to the bottom of go.mod and run `go mod tidy`
package
access
import
(
"sync"
)
const
(
modelFilename
=
"model.conf"
policyFilename
=
"policy.csv"
)
var
(
accessLock
sync
.
Mutex
)
// Refresh will try to reload the casbin model and policies followed by SSH
// keys. If there is an error it's possible that the casbin model and polcies
// could have been updated but the ssh keys were not.
func
Refresh
(
adminRepoPath
string
)
error
{
accessLock
.
Lock
()
defer
accessLock
.
Unlock
()
if
err
:=
refreshEnforcer
(
adminRepoPath
);
err
!=
nil
{
return
err
}
if
err
:=
refreshKeys
(
adminRepoPath
);
err
!=
nil
{
return
err
}
return
nil
}
func
check
(
user
,
repo
,
action
string
)
bool
{
return
enforcer
.
Enforce
(
user
,
repo
,
action
)
}
func
CanRead
(
user
,
repo
string
)
bool
{
return
check
(
user
,
repo
,
"read"
)
}
func
CanWrite
(
user
,
repo
string
)
bool
{
return
check
(
user
,
repo
,
"write"
)
}
func
CanInit
(
user
,
repo
string
)
bool
{
return
check
(
user
,
repo
,
"init"
)
}