Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

feat: implement functionality to create credential GitHub apps#63635

Merged
BolajiOlajide merged 34 commits into
mainfrom
bahrmichael/2024-07-03-batch-changes
Jul 5, 2024
Merged

feat: implement functionality to create credential GitHub apps#63635
BolajiOlajide merged 34 commits into
mainfrom
bahrmichael/2024-07-03-batch-changes

Conversation

@bahrmichael

@bahrmichael bahrmichael commented Jul 4, 2024

Copy link
Copy Markdown
Contributor

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

  • Manual testing

Changelog

@cla-bot cla-bot Bot added the cla-signed label Jul 4, 2024
Comment thread internal/batches/service/service.go Fixed
Comment thread internal/batches/service/service.go
@bahrmichael bahrmichael changed the title feat: complete batch changes github app flow for user credentials feat: implement functionality to create credential GitHub apps Jul 4, 2024
Comment thread cmd/frontend/internal/batches/resolvers/credential.go Outdated
Comment thread cmd/frontend/internal/batches/resolvers/errors.go
Comment on lines +7 to +9
"github.com/sourcegraph/sourcegraph/internal/batches/sources"
ghstore "github.com/sourcegraph/sourcegraph/internal/github_apps/store"
"github.com/sourcegraph/sourcegraph/lib/pointers"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering what the source (or tool) of truth is. I just ran sg lint --fix format and that didn't update imports.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, golangci-lint is what usually does this on vscode, but I haven't found a way to do it on GoLand.
CleanShot 2024-07-04 at 18 19 21@2x

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CleanShot 2024-07-04 at 18 29 41@2x

https://plugins.jetbrains.com/plugin/12496-go-linter

I was able to get it working with this.

Comment thread cmd/frontend/internal/batches/resolvers/resolver.go Outdated
Comment thread cmd/frontend/internal/githubapp/httpapi.go
}

redirectURL := generateRedirectURL(&stateDetails.Domain, &installationID, &app.ID, &app.Name, nil)
if kind == ghtypes.UserCredentialGitHubAppKind {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll need to replicate this for Site Credentials, this only works for user credentials right now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, but not tested (apart from existing CI)

Comment thread internal/batches/service/service.go
Comment thread internal/batches/sources/sources.go Outdated
Comment thread internal/github_apps/store/store.go Outdated
Comment thread internal/batches/service/service.go Fixed
Comment on lines +1890 to +1920
// 🚨 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

Code that highlight SECURITY in comment has changed. Please review the code for changes. The changes might be sensitive.
@bahrmichael bahrmichael requested a review from BolajiOlajide July 5, 2024 09:02
@bahrmichael bahrmichael marked this pull request as ready for review July 5, 2024 09:03

@BolajiOlajide BolajiOlajide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple of comments and this should be good to go.

Comment thread cmd/frontend/internal/batches/resolvers/credential.go
Comment thread cmd/frontend/internal/batches/resolvers/credential.go Outdated
Comment thread cmd/frontend/internal/githubapp/httpapi.go Outdated
Comment thread cmd/frontend/internal/githubapp/parser.go Outdated
Comment thread internal/batches/service/service.go Outdated
Comment thread internal/batches/service/service.go
Comment thread internal/batches/sources/sources.go Outdated
bahrmichael and others added 6 commits July 5, 2024 13:31
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>
@BolajiOlajide BolajiOlajide requested a review from a team July 5, 2024 11:36
@BolajiOlajide BolajiOlajide merged commit 73881ae into main Jul 5, 2024
@BolajiOlajide BolajiOlajide deleted the bahrmichael/2024-07-03-batch-changes branch July 5, 2024 13:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants