2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-12-27 15:30:15 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package consoleql
|
2018-12-27 15:30:15 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/graphql-go/graphql"
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2018-12-27 15:30:15 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-08-11 15:50:01 +01:00
|
|
|
// APIKeyInfoType is graphql type name for api key.
|
2019-01-24 16:26:36 +00:00
|
|
|
APIKeyInfoType = "keyInfo"
|
|
|
|
// CreateAPIKeyType is graphql type name for createAPIKey struct
|
2020-08-11 15:50:01 +01:00
|
|
|
// which incapsulates the actual key and it's info.
|
2019-01-24 16:26:36 +00:00
|
|
|
CreateAPIKeyType = "graphqlCreateAPIKey"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldKey is field name for the actual key in createAPIKey.
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldKey = "key"
|
2018-12-27 15:30:15 +00:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// graphqlAPIKeyInfo creates satellite.APIKeyInfo graphql object.
|
2018-12-27 15:30:15 +00:00
|
|
|
func graphqlAPIKeyInfo() *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
2019-01-24 16:26:36 +00:00
|
|
|
Name: APIKeyInfoType,
|
2018-12-27 15:30:15 +00:00
|
|
|
Fields: graphql.Fields{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldID: &graphql.Field{
|
2018-12-27 15:30:15 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldProjectID: &graphql.Field{
|
2018-12-27 15:30:15 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldName: &graphql.Field{
|
2018-12-27 15:30:15 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldCreatedAt: &graphql.Field{
|
2018-12-27 15:30:15 +00:00
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// graphqlCreateAPIKey creates createAPIKey graphql object.
|
2019-04-04 15:56:20 +01:00
|
|
|
func graphqlCreateAPIKey(types *TypeCreator) *graphql.Object {
|
2018-12-27 15:30:15 +00:00
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
2019-01-24 16:26:36 +00:00
|
|
|
Name: CreateAPIKeyType,
|
2018-12-27 15:30:15 +00:00
|
|
|
Fields: graphql.Fields{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldKey: &graphql.Field{
|
2018-12-27 15:30:15 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
APIKeyInfoType: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: types.apiKeyInfo,
|
2018-12-27 15:30:15 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2019-09-12 15:19:30 +01:00
|
|
|
func graphqlAPIKeysCursor() *graphql.InputObject {
|
|
|
|
return graphql.NewInputObject(graphql.InputObjectConfig{
|
|
|
|
Name: APIKeysCursorInputType,
|
|
|
|
Fields: graphql.InputObjectConfigFieldMap{
|
|
|
|
SearchArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.String),
|
|
|
|
},
|
|
|
|
LimitArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
PageArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
OrderArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
OrderDirectionArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func graphqlAPIKeysPage(types *TypeCreator) *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: APIKeysPageType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
FieldAPIKeys: &graphql.Field{
|
|
|
|
Type: graphql.NewList(types.apiKeyInfo),
|
|
|
|
},
|
|
|
|
SearchArg: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
LimitArg: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
OrderArg: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
OrderDirectionArg: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
OffsetArg: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
FieldPageCount: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
FieldCurrentPage: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
FieldTotalCount: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// createAPIKey holds macaroon.APIKey and console.APIKeyInfo.
|
2018-12-27 15:30:15 +00:00
|
|
|
type createAPIKey struct {
|
2019-05-24 17:51:27 +01:00
|
|
|
Key string
|
2019-01-15 13:03:24 +00:00
|
|
|
KeyInfo *console.APIKeyInfo
|
2018-12-27 15:30:15 +00:00
|
|
|
}
|
2019-09-12 15:19:30 +01:00
|
|
|
|
|
|
|
type apiKeysPage struct {
|
|
|
|
APIKeys []console.APIKeyInfo
|
|
|
|
|
|
|
|
Search string
|
|
|
|
Limit uint
|
|
|
|
Order int
|
|
|
|
OrderDirection int
|
|
|
|
Offset uint64
|
|
|
|
|
|
|
|
PageCount uint
|
|
|
|
CurrentPage uint
|
|
|
|
TotalCount uint64
|
|
|
|
}
|