Skip to content
This repository was archived by the owner on Jun 2, 2023. It is now read-only.

Commit 7cf902b

Browse files
committed
implement admin access to github repo reports
1 parent 35ecbc6 commit 7cf902b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/api/app.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ func (a *App) buildDeps() {
207207
a.policies.activeSub = policy.NewActiveSubscription(a.trackedLog, a.gormDB)
208208
}
209209
if a.policies.repo == nil {
210-
a.policies.repo = policy.NewRepo(a.providerFactory, a.trackedLog, a.cache, a.authorizer)
210+
a.policies.repo = policy.NewRepo(a.providerFactory, a.cfg, a.trackedLog, a.cache, a.authorizer)
211211
}
212212
}
213213

pkg/api/policy/repo.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"time"
77

8+
"github.com/golangci/golangci-api/internal/shared/config"
9+
810
"github.com/golangci/golangci-api/internal/api/apierrors"
911
"github.com/golangci/golangci-api/pkg/api/auth"
1012
"github.com/golangci/golangci-api/pkg/api/request"
@@ -22,14 +24,16 @@ var ErrNoProviderRepoOrAccess = errors.New("no provider repo or access to it")
2224

2325
type Repo struct {
2426
pf providers.Factory
27+
cfg config.Config
2528
log logutil.Log
2629
cache cache.Cache
2730
authorizer *auth.Authorizer
2831
}
2932

30-
func NewRepo(pf providers.Factory, log logutil.Log, cache cache.Cache, authorizer *auth.Authorizer) *Repo {
33+
func NewRepo(pf providers.Factory, cfg config.Config, log logutil.Log, cache cache.Cache, authorizer *auth.Authorizer) *Repo {
3134
return &Repo{
3235
pf: pf,
36+
cfg: cfg,
3337
log: log,
3438
cache: cache,
3539
authorizer: authorizer,
@@ -87,8 +91,15 @@ func (r Repo) CanReadPrivateRepo(rc *request.AnonymousContext, repo models.Unive
8791
return apierrors.NewForbiddenError("NEED_PRIVATE_ACCESS_TOKEN_TO_ACCESS_PRIVATE_REPO")
8892
}
8993

94+
// TODO: make proper error if providers of repo and auth don't match
9095
if accessErr := r.CanRead(rc.Ctx, repo, au.Auth); accessErr != nil {
9196
if accessErr == ErrNoProviderRepoOrAccess {
97+
adminLogin := r.cfg.GetString("ADMIN_GITHUB_LOGIN")
98+
if adminLogin != "" && au.Auth.Provider == "github.com" && au.Auth.Login == adminLogin {
99+
r.log.Infof("Access repo %s as github admin user %s", repo.Owner(), repo.Repo(), adminLogin)
100+
return nil
101+
}
102+
92103
return apierrors.NewForbiddenError("NO_ACCESS_TO_PRIVATE_REPO_OR_DOESNT_EXIST")
93104
}
94105

0 commit comments

Comments
 (0)