MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / hasRepoAccess

Method hasRepoAccess

providers/github.go:255–288  ·  view source on GitHub ↗
(ctx context.Context, accessToken string)

Source from the content-addressed store, hash-verified

253}
254
255func (p *GitHubProvider) hasRepoAccess(ctx context.Context, accessToken string) error {
256 // https://developer.github.com/v3/repos/#get-a-repository
257
258 type permissions struct {
259 Pull bool `json:"pull"`
260 Push bool `json:"push"`
261 }
262
263 type repository struct {
264 Permissions permissions `json:"permissions"`
265 Private bool `json:"private"`
266 }
267
268 endpoint := p.makeGitHubAPIEndpoint("/repos/"+p.Repo, nil)
269
270 var repo repository
271 err := requests.New(endpoint.String()).
272 WithContext(ctx).
273 WithHeaders(makeGitHubHeader(accessToken)).
274 Do().
275 UnmarshalInto(&repo)
276
277 if err != nil {
278 return err
279 }
280
281 // Every user can implicitly pull from a public repo, so only grant access
282 // if they have push access or the repo is private and they can pull
283 if repo.Permissions.Push || (repo.Private && repo.Permissions.Pull) {
284 return nil
285 }
286
287 return errors.New("user doesn't have repository access")
288}
289
290func (p *GitHubProvider) hasUser(ctx context.Context, accessToken string) (bool, error) {
291 // https://developer.github.com/v3/users/#get-the-authenticated-user

Callers 1

checkRestrictionsMethod · 0.95

Calls 8

makeGitHubAPIEndpointMethod · 0.95
NewFunction · 0.92
makeGitHubHeaderFunction · 0.85
UnmarshalIntoMethod · 0.65
DoMethod · 0.65
WithHeadersMethod · 0.65
WithContextMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected