githubStatus is a http wrapper over [GetGithubRepoStatus]/[GetGithubUserStatus] depending upon whether `remote` query is passed. It redirects to the grantAccessURL if there is no access. It's implemented as a non-gRPC endpoint mounted directly on /github/post-auth-redirect.
(w http.ResponseWriter, r *http.Request)
| 941 | // It redirects to the grantAccessURL if there is no access. |
| 942 | // It's implemented as a non-gRPC endpoint mounted directly on /github/post-auth-redirect. |
| 943 | func (s *Server) githubStatus(w http.ResponseWriter, r *http.Request) { |
| 944 | ctx := r.Context() |
| 945 | // Check the request is made by an authenticated user |
| 946 | claims := auth.GetClaims(ctx) |
| 947 | if claims.OwnerType() != auth.OwnerTypeUser { |
| 948 | s.redirectLogin(w, r) |
| 949 | return |
| 950 | } |
| 951 | |
| 952 | var hasAccess bool |
| 953 | var grantAccessURL string |
| 954 | remote := r.URL.Query().Get("remote") |
| 955 | remote = normalizeGitRemote(remote) // Backwards compatibility |
| 956 | if remote == "" { |
| 957 | resp, err := s.GetGithubUserStatus(ctx, &adminv1.GetGithubUserStatusRequest{}) |
| 958 | if err != nil { |
| 959 | http.Error(w, fmt.Sprintf("failed to fetch user status: %s", err), http.StatusInternalServerError) |
| 960 | return |
| 961 | } |
| 962 | hasAccess = resp.HasAccess |
| 963 | grantAccessURL = resp.GrantAccessUrl |
| 964 | } else { |
| 965 | resp, err := s.GetGithubRepoStatus(ctx, &adminv1.GetGithubRepoStatusRequest{Remote: remote}) |
| 966 | if err != nil { |
| 967 | http.Error(w, fmt.Sprintf("failed to fetch github repo status: %s", err), http.StatusInternalServerError) |
| 968 | return |
| 969 | } |
| 970 | hasAccess = resp.HasAccess |
| 971 | grantAccessURL = resp.GrantAccessUrl |
| 972 | } |
| 973 | |
| 974 | if hasAccess { |
| 975 | http.Redirect(w, r, s.admin.URLs.GithubConnectSuccessUI(false), http.StatusTemporaryRedirect) |
| 976 | return |
| 977 | } |
| 978 | |
| 979 | redirectURL := s.admin.URLs.GithubConnectUI(grantAccessURL) |
| 980 | http.Redirect(w, r, redirectURL, http.StatusTemporaryRedirect) |
| 981 | } |
| 982 | |
| 983 | func (s *Server) userAuthGithubClient(ctx context.Context, code string) (*github.Client, *admin.GithubToken, error) { |
| 984 | oauthConf := &oauth2.Config{ |
nothing calls this directly
no test coverage detected