Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag for not fetching permissions (FlatPermissions) #491

Merged
merged 2 commits into from
Oct 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/drone-server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,13 @@ var flags = []cli.Flag{
//
// remote parameters
//
cli.BoolFlag{
Name: "flat-permissions",
Usage: "no remote call for permissions should be made",
EnvVar: "WOODPECKER_FLAT_PERMISSIONS",
Hidden: true,
// temporary workaround for v0.14.x to not hit api rate limits
},
cli.BoolFlag{
EnvVar: "DRONE_GITHUB,WOODPECKER_GITHUB",
Name: "github",
Expand Down
3 changes: 3 additions & 0 deletions cmd/drone-server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,9 @@ func setupEvilGlobals(c *cli.Context, v store.Store, r remote.Remote) {

// prometheus
droneserver.Config.Prometheus.AuthToken = c.String("prometheus-auth-token")

// temporary workaround for v0.14.x to not hit api rate limits
droneserver.Config.FlatPermissions = c.Bool("flat-permissions")
}

type authorizer struct {
Expand Down
1 change: 1 addition & 0 deletions server/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ var Config = struct {
Networks []string
Privileged []string
}
FlatPermissions bool // temporary workaround for v0.14.x to not hit api rate limits
}{}

type RPC struct {
Expand Down
21 changes: 16 additions & 5 deletions server/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (s *syncer) SetFilter(fn FilterFunc) {
s.match = fn
}

func (s *syncer) Sync(user *model.User) error {
func (s *syncer) Sync(user *model.User, flatPermissions bool) error {
unix := time.Now().Unix() - (3601) // force immediate expiration. note 1 hour expiration is hard coded at the moment
repos, err := s.remote.Repos(user)
if err != nil {
Expand All @@ -81,10 +81,21 @@ func (s *syncer) Sync(user *model.User) error {
Pull: true,
Synced: unix,
}
remotePerm, err := s.remote.Perm(user, repo.Owner, repo.Name)
if err == nil && remotePerm != nil {
perm.Push = remotePerm.Push
perm.Admin = remotePerm.Admin
// temporary workaround for v0.14.x to not hit api rate limits
if flatPermissions {
if repo.Perm != nil {
perm.Push = repo.Perm.Push
perm.Admin = repo.Perm.Admin
} else {
perm.Push = true
perm.Admin = true
}
} else {
remotePerm, err := s.remote.Perm(user, repo.Owner, repo.Name)
if err == nil && remotePerm != nil {
perm.Push = remotePerm.Push
perm.Admin = remotePerm.Admin
}
}
perms = append(perms, &perm)
}
Expand Down
4 changes: 2 additions & 2 deletions server/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func GetFeed(c *gin.Context) {
perms: store.FromContext(c),
match: NamespaceFilter(config.OwnersWhitelist),
}
if err := sync.Sync(user); err != nil {
if err := sync.Sync(user, Config.FlatPermissions); err != nil {
logrus.Debugf("sync error: %s: %s", user.Login, err)
} else {
logrus.Debugf("sync complete: %s", user.Login)
Expand Down Expand Up @@ -99,7 +99,7 @@ func GetRepos(c *gin.Context) {
match: NamespaceFilter(config.OwnersWhitelist),
}

if err := sync.Sync(user); err != nil {
if err := sync.Sync(user, Config.FlatPermissions); err != nil {
logrus.Debugf("sync error: %s: %s", user.Login, err)
} else {
logrus.Debugf("sync complete: %s", user.Login)
Expand Down