storj/pkg/satellite/satelliteweb/satelliteql/utils.go
Yaroslav Vorobiov 175e25f93a
Satellite graphql: take authorized user id if no id was provided in iput (#828)
satellite graphql: take authorized user id if no id was provided by client
2018-12-11 17:54:45 +02:00

28 lines
652 B
Go

// Copyright (C) 2018 Storj Labs, Inc.
// See LICENSE for copying information.
package satelliteql
import (
"github.com/graphql-go/graphql"
"github.com/skyrings/skyring-common/tools/uuid"
"storj.io/storj/pkg/satellite"
)
// uuidIDAuthFallback returns auth user id if no id argument provided
func uuidIDAuthFallback(p graphql.ResolveParams, field string) (*uuid.UUID, error) {
// if client passed id - parse it and return
if idStr, ok := p.Args[field].(string); ok {
return uuid.Parse(idStr)
}
// else get id of authorized user
auth, err := satellite.GetAuth(p.Context)
if err != nil {
return nil, err
}
return &auth.User.ID, nil
}