-
-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Included in the changes: - create a new /api root package to hold all API code, migrate /graphql in there - git API handlers all use the cache instead of the repo directly - git API handlers are now tested - git API handlers now require a "repo" mux parameter - lots of untangling of API/handlers/middleware - less code in commands/webui.go
- Loading branch information
1 parent
bf3fede
commit d1231bf
Showing
54 changed files
with
474 additions
and
309 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Package auth contains helpers for managing identities within the GraphQL API. | ||
package auth | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/MichaelMure/git-bug/cache" | ||
"github.com/MichaelMure/git-bug/entity" | ||
) | ||
|
||
// identityCtxKey is a unique context key, accessible only in this package. | ||
var identityCtxKey = &struct{}{} | ||
|
||
// CtxWithUser attaches an Identity to a context. | ||
func CtxWithUser(ctx context.Context, userId entity.Id) context.Context { | ||
return context.WithValue(ctx, identityCtxKey, userId) | ||
} | ||
|
||
// UserFromCtx retrieves an IdentityCache from the context. | ||
// If there is no identity in the context, ErrNotAuthenticated is returned. | ||
// If an error occurs while resolving the identity (e.g. I/O error), then it will be returned. | ||
func UserFromCtx(ctx context.Context, r *cache.RepoCache) (*cache.IdentityCache, error) { | ||
id, ok := ctx.Value(identityCtxKey).(entity.Id) | ||
if !ok { | ||
return nil, ErrNotAuthenticated | ||
} | ||
return r.ResolveIdentity(id) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package auth | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/MichaelMure/git-bug/entity" | ||
) | ||
|
||
func Middleware(fixedUserId entity.Id) func(http.Handler) http.Handler { | ||
return func(next http.Handler) http.Handler { | ||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | ||
ctx := CtxWithUser(r.Context(), fixedUserId) | ||
next.ServeHTTP(w, r.WithContext(ctx)) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
//go:generate go run gen_graphql.go | ||
|
||
// Package graphql contains the root GraphQL http handler | ||
package graphql | ||
|
||
import ( | ||
"io" | ||
"net/http" | ||
|
||
"github.com/99designs/gqlgen/graphql/handler" | ||
|
||
"github.com/MichaelMure/git-bug/api/graphql/graph" | ||
"github.com/MichaelMure/git-bug/api/graphql/resolvers" | ||
"github.com/MichaelMure/git-bug/cache" | ||
) | ||
|
||
// Handler is the root GraphQL http handler | ||
type Handler struct { | ||
http.Handler | ||
io.Closer | ||
} | ||
|
||
func NewHandler(mrc *cache.MultiRepoCache) Handler { | ||
rootResolver := resolvers.NewRootResolver(mrc) | ||
config := graph.Config{Resolvers: rootResolver} | ||
h := handler.NewDefaultServer(graph.NewExecutableSchema(config)) | ||
|
||
return Handler{ | ||
Handler: h, | ||
Closer: rootResolver, | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.