chore: actually validate API key privileges and refs

This commit is contained in:
2023-05-29 22:13:25 +02:00
parent edf1485cd2
commit a46895081e
2 changed files with 27 additions and 3 deletions
+6 -3
View File
@@ -74,11 +74,10 @@ func (r *mutationResolver) AddAPIKey(ctx context.Context, input *model.InputAPIK
// UpdateSubGraph is the resolver for the updateSubGraph field.
func (r *mutationResolver) UpdateSubGraph(ctx context.Context, input model.InputSubGraph) (*model.SubGraph, error) {
orgId := middleware.OrganizationFromContext(ctx)
key, err := middleware.ApiKeyFromContext(ctx)
name, err := r.apiKeyCanAccessRef(ctx, input.Ref, true)
if err != nil {
return nil, err
}
apiKey := r.Cache.ApiKeyByKey(key)
subGraphId := r.Cache.SubGraphId(orgId, input.Ref, input.Service)
subGraph := &domain.SubGraph{}
if subGraphId != "" {
@@ -115,7 +114,7 @@ func (r *mutationResolver) UpdateSubGraph(ctx context.Context, input model.Input
Url: input.URL,
WSUrl: input.WsURL,
Sdl: input.Sdl,
Initiator: apiKey.Name,
Initiator: name,
})
if err != nil {
return nil, err
@@ -133,6 +132,10 @@ func (r *queryResolver) Organizations(ctx context.Context) ([]*model.Organizatio
// Supergraph is the resolver for the supergraph field.
func (r *queryResolver) Supergraph(ctx context.Context, ref string, isAfter *string) (model.Supergraph, error) {
orgId := middleware.OrganizationFromContext(ctx)
_, err := r.apiKeyCanAccessRef(ctx, ref, false)
if err != nil {
return nil, err
}
after := ""
if isAfter != nil {
after = *isAfter