storj/satellite/console/consoleweb/consoleql/apikey.go

138 lines
3.1 KiB
Go
Raw Normal View History

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.
package consoleql
2018-12-27 15:30:15 +00:00
import (
"github.com/graphql-go/graphql"
"storj.io/storj/satellite/console"
2018-12-27 15:30:15 +00:00
)
const (
2019-01-24 16:26:36 +00:00
// APIKeyInfoType is graphql type name for api key
APIKeyInfoType = "keyInfo"
// CreateAPIKeyType is graphql type name for createAPIKey struct
// which incapsulates the actual key and it's info
CreateAPIKeyType = "graphqlCreateAPIKey"
// FieldKey is field name for the actual key in createAPIKey
FieldKey = "key"
2018-12-27 15:30:15 +00:00
)
// graphqlAPIKeyInfo creates satellite.APIKeyInfo graphql object
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,
},
FieldPartnerID: &graphql.Field{
Type: graphql.String,
},
2018-12-27 15:30:15 +00: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
},
},
})
}
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,
},
},
})
}
// createAPIKey holds macaroon.APIKey and console.APIKeyInfo
2018-12-27 15:30:15 +00:00
type createAPIKey struct {
Key string
KeyInfo *console.APIKeyInfo
2018-12-27 15:30:15 +00:00
}
type apiKeysPage struct {
APIKeys []console.APIKeyInfo
Search string
Limit uint
Order int
OrderDirection int
Offset uint64
PageCount uint
CurrentPage uint
TotalCount uint64
}