Skip to content

Commit

Permalink
refactor: fixing DeepSource issues
Browse files Browse the repository at this point in the history
  • Loading branch information
vishnu-deepsource committed Jul 28, 2023
1 parent 56e3037 commit fc43624
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion artifact/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,6 @@ func (h *Handler) HandleAutofix(c echo.Context) error {
return c.JSON(200, autofixArtifactsResponse)
}

func (h *Handler) HandleOptions(c echo.Context) error {
func (*Handler) HandleOptions(c echo.Context) error {
return c.NoContent(http.StatusOK)
}
2 changes: 1 addition & 1 deletion auth/oauth/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestGithub_GetToken(t *testing.T) {
return
}
w.Header().Set("Content-Type", "application/json")
w.Write([]byte(`{"access_token":"token","token_type":"bearer","scope":"repo,gist"}`))
_, _ = w.Write([]byte(`{"access_token":"token","token_type":"bearer","scope":"repo,gist"}`))
}))
defer server.Close()
serverURL, _ := url.Parse(server.URL)
Expand Down
4 changes: 3 additions & 1 deletion auth/oauth/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ func (h *Handler) HandleSession(c echo.Context) error {
}

code := ksuid.New().String()
h.store.SetAccessCode(code, user)
if err := h.store.SetAccessCode(code, user); err != nil {
return c.JSON(500, err.Error())
}

u := h.deepsource.Host.JoinPath(fmt.Sprintf("/accounts/runner/apps/%s/login/callback/bifrost/", req.AppID))
q := u.Query()
Expand Down
6 changes: 0 additions & 6 deletions auth/saml/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,3 @@ func NewSAMLMiddleware(ctx context.Context, opts *Opts, client *http.Client) (*s

return sp, err
}

func SAMLHandler() http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world"))
})
}
26 changes: 21 additions & 5 deletions auth/saml/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/deepsourcecorp/runner/auth/token"
"github.com/labstack/echo/v4"
"github.com/segmentio/ksuid"
"golang.org/x/exp/slog"
"golang.org/x/oauth2"
)

Expand Down Expand Up @@ -55,7 +56,10 @@ func (h *Handler) AuthorizationHandler() echo.HandlerFunc {
request.Parse(r)
if !h.runner.IsValidClientID(request.ClientID) {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("invalid client_id"))
if _, err := w.Write([]byte("invalid client_id")); err != nil {
slog.Error("error writing response", slog.Any("err", err))
return
}
return
}

Expand All @@ -72,7 +76,11 @@ func (h *Handler) AuthorizationHandler() echo.HandlerFunc {
session, ok := s.(samlsp.SessionWithAttributes)
if !ok {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte("unauthorized"))
if _, err := w.Write([]byte("unauthorized")); err != nil {
slog.Error("error writing response", slog.Any("err", err))
return
}

return
}
attr := session.GetAttributes()
Expand All @@ -85,7 +93,10 @@ func (h *Handler) AuthorizationHandler() echo.HandlerFunc {
accessToken, err := h.tokenService.GetAccessToken(user)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
if _, err := w.Write([]byte(err.Error())); err != nil {
slog.Error("error writing response", slog.Any("err", err))
return
}
return
}

Expand All @@ -101,7 +112,10 @@ func (h *Handler) AuthorizationHandler() echo.HandlerFunc {
refreshToken, err := h.tokenService.GetRefreshToken(user)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
if _, err := w.Write([]byte(err.Error())); err != nil {
slog.Error("error writing response", slog.Any("err", err))
return
}
return
}
http.SetCookie(w, &http.Cookie{
Expand Down Expand Up @@ -140,7 +154,9 @@ func (h *Handler) HandleSession(c echo.Context) error {
}

code := ksuid.New().String()
h.store.SetAccessCode(code, user)
if err := h.store.SetAccessCode(code, user); err != nil {
return c.JSON(400, err.Error())
}

u := h.deepsource.Host.JoinPath("/accounts/runner/apps/saml/login/callback/bifrost/")
q := u.Query()
Expand Down
2 changes: 1 addition & 1 deletion cmd/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (s *Server) Start() error {
return nil
}

func (s *Server) PrintBanner() {
func (*Server) PrintBanner() {
fmt.Println(fmt.Sprintf(Banner, Version))
}

Expand Down
4 changes: 2 additions & 2 deletions provider/github/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestAPIProxyFactory_NewClient(t *testing.T) {
}

func TestAPIProxy_GenerateJWT(t *testing.T) {
privateKey, _ := rsa.GenerateKey(rand.Reader, 512)
privateKey, _ := rsa.GenerateKey(rand.Reader, 2048)
app := &App{ID: "test-app-id", PrivateKey: privateKey}
proxy := &APIProxy{app: app}
token, err := proxy.GenerateJWT()
Expand Down Expand Up @@ -136,7 +136,7 @@ func TestAPIProxy_GenerateAccessToken(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(tc.responseStatus)
w.Write([]byte(tc.responseBody))
_, _ = w.Write([]byte(tc.responseBody))
}))
defer server.Close()

Expand Down

0 comments on commit fc43624

Please sign in to comment.