feat: implement functionality to create credential GitHub apps#63635
Conversation
| "github.com/sourcegraph/sourcegraph/internal/batches/sources" | ||
| ghstore "github.com/sourcegraph/sourcegraph/internal/github_apps/store" | ||
| "github.com/sourcegraph/sourcegraph/lib/pointers" |
There was a problem hiding this comment.
These imports aren't properly sorted.
It's one of the weirdness I encountered with Goland, I haven't found a way to integrate golangci-lint.
There was a problem hiding this comment.
I'm wondering what the source (or tool) of truth is. I just ran sg lint --fix format and that didn't update imports.
There was a problem hiding this comment.
| } | ||
|
|
||
| redirectURL := generateRedirectURL(&stateDetails.Domain, &installationID, &app.ID, &app.Name, nil) | ||
| if kind == ghtypes.UserCredentialGitHubAppKind { |
There was a problem hiding this comment.
You'll need to replicate this for Site Credentials, this only works for user credentials right now.
There was a problem hiding this comment.
Done, but not tested (apart from existing CI)
| // 🚨 SECURITY: Check that a site credential can only be created | ||
| // by a site-admin. | ||
| if err := auth.CheckCurrentUserIsSiteAdmin(ctx, s.store.DatabaseDB()); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| if as == "" { | ||
| return nil, errors.New("authentication strategy must be specified") | ||
| } | ||
|
|
||
| // Throw error documented in schema.graphql. | ||
| existing, err := s.store.GetSiteCredential(ctx, store.GetSiteCredentialOpts{ | ||
| ExternalServiceType: args.ExternalServiceType, | ||
| ExternalServiceID: args.ExternalServiceURL, | ||
| }) | ||
| if err != nil && err != store.ErrNoResults { | ||
| return nil, err | ||
| } | ||
| if existing != nil { | ||
| return nil, ErrDuplicateCredential{} | ||
| } | ||
|
|
||
| a, err := s.generateAuthenticatorForCredential(ctx, generateAuthenticatorForCredentialArgs{ | ||
| externalServiceType: args.ExternalServiceType, | ||
| externalServiceURL: args.ExternalServiceURL, | ||
| credential: args.Credential, | ||
| username: args.Username, | ||
| gitHubAppKind: args.GitHubAppKind, | ||
| githubAppID: args.GitHubAppID, | ||
| authenticationStrategy: as, | ||
| githubAppStore: s.store.GitHubAppsStore(), |
Check notice
Code scanning / Semgrep OSS
Semgrep Finding: security-semgrep-rules.semgrep-rules.generic.comment-tagging-rule
BolajiOlajide
left a comment
There was a problem hiding this comment.
Just a couple of comments and this should be good to go.
Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
Co-authored-by: Bolaji Olajide <25608335+BolajiOlajide@users.noreply.github.com>
Closes SRCH-663
This is a follow-up to previous PRs, where we added database fields to support the new github apps integration.
See initiative "Batch Changes using GitHub App auth" on linear.
Test plan
Changelog