Skip to content

[git] improved logging in GitHub token verification #4479

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

Merged
merged 1 commit into from
Jun 11, 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 components/gitpod-cli/cmd/git-token-validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,19 @@ var gitTokenValidator = &cobra.Command{
User: gitTokenValidatorOpts.User,
},
}
log.WithField("host", gitTokenValidatorOpts.Host).
WithField("repoURL", gitTokenValidatorOpts.RepoURL).
WithField("command", gitTokenValidatorOpts.GitCommand).
WithField("user", gitTokenValidatorOpts.User).
WithField("tokenScopes", gitTokenValidatorOpts.TokenScopes).
Info("guessing required token scopes")
guessedTokenScopes, err := client.GuessGitTokenScopes(ctx, params)
if err != nil {
log.WithError(err).Fatal("error guessing token scopes on server")
}
if guessedTokenScopes.Message != "" {
message := fmt.Sprintf("%s Please grant the necessary permissions.", guessedTokenScopes.Message)
log.WithField("guessedTokenScopes", guessedTokenScopes.Scopes).Info("insufficient permissions")
result, err := supervisor.NewNotificationServiceClient(supervisorConn).Notify(ctx,
&supervisor.NotifyRequest{
Level: supervisor.NotifyRequest_INFO,
Expand Down
3 changes: 3 additions & 0 deletions components/server/src/github/github-token-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { inject, injectable } from "inversify";
import { CheckWriteAccessResult, IGitTokenValidator, IGitTokenValidatorParams } from "../workspace/git-token-validator";
import { GitHubApiError, GitHubGraphQlEndpoint, GitHubRestApi, GitHubResult } from "./api";
import { log } from '@gitpod/gitpod-protocol/lib/util/logging';

@injectable()
export class GitHubTokenValidator implements IGitTokenValidator {
Expand All @@ -28,6 +29,7 @@ export class GitHubTokenValidator implements IGitTokenValidator {
if (GitHubApiError.is(error) && error.response?.status === 404) {
return { found: false };
}
log.error('Error getting repo information from GitHub', error, { repoFullName, parsedRepoName })
return { found: false, error };
}

Expand Down Expand Up @@ -61,6 +63,7 @@ export class GitHubTokenValidator implements IGitTokenValidator {
if (errors && errors[0] && (errors[0] as any)["type"] === "FORBIDDEN") {
writeAccessToRepo = false;
} else {
log.error('Error getting organization information from GitHub', error, { org: parsedRepoName.owner })
throw error;
}
}
Expand Down