2018-12-11 15:54:45 +00:00
|
|
|
// Copyright (C) 2018 Storj Labs, Inc.
|
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package consoleql
|
2018-12-11 15:54:45 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2018-12-11 15:54:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2019-01-15 13:03:24 +00:00
|
|
|
auth, err := console.GetAuth(p.Context)
|
2018-12-11 15:54:45 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return &auth.User.ID, nil
|
|
|
|
}
|