2019-01-24 16:26:36 +00:00
|
|
|
// Copyright (C) 2019 Storj Labs, Inc.
|
2018-11-26 10:47:23 +00:00
|
|
|
// See LICENSE for copying information.
|
|
|
|
|
2019-01-15 13:03:24 +00:00
|
|
|
package consoleql
|
2018-11-26 10:47:23 +00:00
|
|
|
|
|
|
|
import (
|
2021-08-02 23:06:15 +01:00
|
|
|
"strconv"
|
2019-04-04 15:56:20 +01:00
|
|
|
"time"
|
|
|
|
|
2018-11-26 10:47:23 +00:00
|
|
|
"github.com/graphql-go/graphql"
|
2019-01-08 14:05:14 +00:00
|
|
|
|
2021-08-02 23:06:15 +01:00
|
|
|
"storj.io/common/memory"
|
2019-11-15 14:27:44 +00:00
|
|
|
"storj.io/storj/satellite/accounting"
|
2019-01-15 13:03:24 +00:00
|
|
|
"storj.io/storj/satellite/console"
|
2018-11-26 10:47:23 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-08-11 15:50:01 +01:00
|
|
|
// ProjectType is a graphql type name for project.
|
2019-01-24 16:26:36 +00:00
|
|
|
ProjectType = "project"
|
2020-08-11 15:50:01 +01:00
|
|
|
// ProjectInputType is a graphql type name for project input.
|
2019-01-24 16:26:36 +00:00
|
|
|
ProjectInputType = "projectInput"
|
2021-08-02 23:06:15 +01:00
|
|
|
// ProjectLimitType is a graphql type name for project limit.
|
|
|
|
ProjectLimitType = "projectLimit"
|
2020-08-11 15:50:01 +01:00
|
|
|
// ProjectUsageType is a graphql type name for project usage.
|
2019-04-04 15:56:20 +01:00
|
|
|
ProjectUsageType = "projectUsage"
|
2021-01-21 18:19:37 +00:00
|
|
|
// ProjectsCursorInputType is a graphql input type name for projects cursor.
|
|
|
|
ProjectsCursorInputType = "projectsCursor"
|
|
|
|
// ProjectsPageType is a graphql type name for projects page.
|
|
|
|
ProjectsPageType = "projectsPage"
|
2019-05-16 11:43:46 +01:00
|
|
|
// BucketUsageCursorInputType is a graphql input
|
2020-08-11 15:50:01 +01:00
|
|
|
// type name for bucket usage cursor.
|
2019-05-16 11:43:46 +01:00
|
|
|
BucketUsageCursorInputType = "bucketUsageCursor"
|
2020-08-11 15:50:01 +01:00
|
|
|
// BucketUsageType is a graphql type name for bucket usage.
|
2019-05-16 11:43:46 +01:00
|
|
|
BucketUsageType = "bucketUsage"
|
2023-06-08 04:30:01 +01:00
|
|
|
// BucketUsagePageType is a graphql type name for bucket usage page.
|
2019-05-16 11:43:46 +01:00
|
|
|
BucketUsagePageType = "bucketUsagePage"
|
2023-06-08 04:30:01 +01:00
|
|
|
// ProjectMembersAndInvitationsPageType is a graphql type name for a page of project members and invitations.
|
|
|
|
ProjectMembersAndInvitationsPageType = "projectMembersAndInvitationsPage"
|
2020-08-11 15:50:01 +01:00
|
|
|
// ProjectMembersCursorInputType is a graphql type name for project members.
|
2019-08-12 11:22:32 +01:00
|
|
|
ProjectMembersCursorInputType = "projectMembersCursor"
|
2023-06-08 04:30:01 +01:00
|
|
|
// APIKeysPageType is a graphql type name for api keys page.
|
2019-09-12 15:19:30 +01:00
|
|
|
APIKeysPageType = "apiKeysPage"
|
2020-08-11 15:50:01 +01:00
|
|
|
// APIKeysCursorInputType is a graphql type name for api keys.
|
2019-09-12 15:19:30 +01:00
|
|
|
APIKeysCursorInputType = "apiKeysCursor"
|
2023-01-04 19:18:12 +00:00
|
|
|
// FieldPublicID is a field name for "publicId".
|
|
|
|
FieldPublicID = "publicId"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldOwnerID is a field name for "ownerId".
|
2019-10-22 12:12:49 +01:00
|
|
|
FieldOwnerID = "ownerId"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldName is a field name for "name".
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldName = "name"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldBucketName is a field name for "bucket name".
|
2019-05-16 11:43:46 +01:00
|
|
|
FieldBucketName = "bucketName"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldDescription is a field name for description.
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldDescription = "description"
|
2023-06-08 04:30:01 +01:00
|
|
|
// FieldMembersAndInvitations is field name for members and invitations.
|
|
|
|
FieldMembersAndInvitations = "membersAndInvitations"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldAPIKeys is a field name for api keys.
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldAPIKeys = "apiKeys"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldUsage is a field name for usage rollup.
|
2019-04-04 15:56:20 +01:00
|
|
|
FieldUsage = "usage"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldBucketUsages is a field name for bucket usages.
|
2019-05-16 11:43:46 +01:00
|
|
|
FieldBucketUsages = "bucketUsages"
|
2021-08-02 23:06:15 +01:00
|
|
|
// FieldStorageLimit is a field name for the storage limit.
|
|
|
|
FieldStorageLimit = "storageLimit"
|
|
|
|
// FieldBandwidthLimit is a field name for bandwidth limit.
|
|
|
|
FieldBandwidthLimit = "bandwidthLimit"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldStorage is a field name for storage total.
|
2019-04-04 15:56:20 +01:00
|
|
|
FieldStorage = "storage"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldEgress is a field name for egress total.
|
2019-04-04 15:56:20 +01:00
|
|
|
FieldEgress = "egress"
|
2021-10-20 23:54:34 +01:00
|
|
|
// FieldSegmentCount is a field name for segments count.
|
|
|
|
FieldSegmentCount = "segmentCount"
|
2021-10-28 16:50:06 +01:00
|
|
|
// FieldObjectCount is a field name for objects count.
|
|
|
|
FieldObjectCount = "objectCount"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldPageCount is a field name for total page count.
|
2019-05-16 11:43:46 +01:00
|
|
|
FieldPageCount = "pageCount"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldCurrentPage is a field name for current page number.
|
2019-05-16 11:43:46 +01:00
|
|
|
FieldCurrentPage = "currentPage"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldTotalCount is a field name for bucket usage count total.
|
2019-05-16 11:43:46 +01:00
|
|
|
FieldTotalCount = "totalCount"
|
2021-01-21 18:19:37 +00:00
|
|
|
// FieldMemberCount is a field name for number of project members.
|
|
|
|
FieldMemberCount = "memberCount"
|
|
|
|
// FieldProjects is a field name for projects.
|
|
|
|
FieldProjects = "projects"
|
2020-08-11 15:50:01 +01:00
|
|
|
// FieldProjectMembers is a field name for project members.
|
2019-08-12 11:22:32 +01:00
|
|
|
FieldProjectMembers = "projectMembers"
|
2023-06-08 04:30:01 +01:00
|
|
|
// FieldProjectInvitations is a field name for project member invitations.
|
|
|
|
FieldProjectInvitations = "projectInvitations"
|
2020-08-11 15:50:01 +01:00
|
|
|
// CursorArg is an argument name for cursor.
|
2019-05-16 11:43:46 +01:00
|
|
|
CursorArg = "cursor"
|
2020-08-11 15:50:01 +01:00
|
|
|
// PageArg ia an argument name for page number.
|
2019-05-16 11:43:46 +01:00
|
|
|
PageArg = "page"
|
2020-08-11 15:50:01 +01:00
|
|
|
// LimitArg is argument name for limit.
|
2019-01-24 16:26:36 +00:00
|
|
|
LimitArg = "limit"
|
2020-08-11 15:50:01 +01:00
|
|
|
// OffsetArg is argument name for offset.
|
2019-01-24 16:26:36 +00:00
|
|
|
OffsetArg = "offset"
|
2020-08-11 15:50:01 +01:00
|
|
|
// SearchArg is argument name for search.
|
2019-01-24 16:26:36 +00:00
|
|
|
SearchArg = "search"
|
2020-08-11 15:50:01 +01:00
|
|
|
// OrderArg is argument name for order.
|
2019-01-24 16:26:36 +00:00
|
|
|
OrderArg = "order"
|
2020-08-11 15:50:01 +01:00
|
|
|
// OrderDirectionArg is argument name for order direction.
|
2019-08-12 11:22:32 +01:00
|
|
|
OrderDirectionArg = "orderDirection"
|
2020-08-11 15:50:01 +01:00
|
|
|
// SinceArg marks start of the period.
|
2019-04-04 15:56:20 +01:00
|
|
|
SinceArg = "since"
|
2020-08-11 15:50:01 +01:00
|
|
|
// BeforeArg marks end of the period.
|
2019-04-04 15:56:20 +01:00
|
|
|
BeforeArg = "before"
|
2018-11-26 10:47:23 +00:00
|
|
|
)
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// graphqlProject creates *graphql.Object type representation of satellite.ProjectInfo.
|
2019-04-04 15:56:20 +01:00
|
|
|
func graphqlProject(service *console.Service, types *TypeCreator) *graphql.Object {
|
2018-11-26 10:47:23 +00:00
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
2019-01-24 16:26:36 +00:00
|
|
|
Name: ProjectType,
|
2018-11-26 10:47:23 +00:00
|
|
|
Fields: graphql.Fields{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldID: &graphql.Field{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2023-01-04 19:18:12 +00:00
|
|
|
FieldPublicID: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldName: &graphql.Field{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-10-22 12:12:49 +01:00
|
|
|
FieldOwnerID: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldDescription: &graphql.Field{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldCreatedAt: &graphql.Field{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
2021-01-21 18:19:37 +00:00
|
|
|
FieldMemberCount: &graphql.Field{
|
|
|
|
Type: graphql.Int,
|
|
|
|
},
|
2023-06-08 04:30:01 +01:00
|
|
|
FieldMembersAndInvitations: &graphql.Field{
|
|
|
|
Type: types.projectMembersAndInvitationsPage,
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
CursorArg: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(types.projectMembersCursor),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2023-06-08 09:49:53 +01:00
|
|
|
project, _ := p.Source.(*console.Project)
|
|
|
|
|
|
|
|
_, err := console.GetUser(p.Context)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
cursor := cursorArgsToProjectMembersCursor(p.Args[CursorArg].(map[string]interface{}))
|
|
|
|
page, err := service.GetProjectMembersAndInvitations(p.Context, project.ID, cursor)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var users []projectMember
|
|
|
|
for _, member := range page.ProjectMembers {
|
|
|
|
user, err := service.GetUser(p.Context, member.MemberID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
users = append(users, projectMember{
|
|
|
|
User: user,
|
|
|
|
JoinedAt: member.CreatedAt,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
projectMembersPage := projectMembersPage{
|
|
|
|
ProjectMembers: users,
|
|
|
|
ProjectInvitations: page.ProjectInvitations,
|
|
|
|
TotalCount: page.TotalCount,
|
|
|
|
Offset: page.Offset,
|
|
|
|
Limit: page.Limit,
|
|
|
|
Order: int(page.Order),
|
|
|
|
OrderDirection: int(page.OrderDirection),
|
|
|
|
Search: page.Search,
|
|
|
|
CurrentPage: page.CurrentPage,
|
|
|
|
PageCount: page.PageCount,
|
|
|
|
}
|
|
|
|
return projectMembersPage, nil
|
2018-12-10 11:38:42 +00:00
|
|
|
},
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldAPIKeys: &graphql.Field{
|
2019-09-12 15:19:30 +01:00
|
|
|
Type: types.apiKeyPage,
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
CursorArg: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(types.apiKeysCursor),
|
|
|
|
},
|
|
|
|
},
|
2018-12-27 15:30:15 +00:00
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
2019-01-15 13:03:24 +00:00
|
|
|
project, _ := p.Source.(*console.Project)
|
2018-12-27 15:30:15 +00:00
|
|
|
|
2019-09-12 15:19:30 +01:00
|
|
|
cursor := cursorArgsToAPIKeysCursor(p.Args[CursorArg].(map[string]interface{}))
|
|
|
|
page, err := service.GetAPIKeys(p.Context, project.ID, cursor)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
apiKeysPage := apiKeysPage{
|
|
|
|
APIKeys: page.APIKeys,
|
|
|
|
TotalCount: page.TotalCount,
|
|
|
|
Offset: page.Offset,
|
|
|
|
Limit: page.Limit,
|
|
|
|
Order: int(page.Order),
|
|
|
|
OrderDirection: int(page.OrderDirection),
|
|
|
|
Search: page.Search,
|
|
|
|
CurrentPage: page.CurrentPage,
|
|
|
|
PageCount: page.PageCount,
|
|
|
|
}
|
|
|
|
|
|
|
|
return apiKeysPage, err
|
2018-12-27 15:30:15 +00:00
|
|
|
},
|
|
|
|
},
|
2019-04-04 15:56:20 +01:00
|
|
|
FieldUsage: &graphql.Field{
|
|
|
|
Type: types.projectUsage,
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
SinceArg: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.DateTime),
|
|
|
|
},
|
|
|
|
BeforeArg: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.DateTime),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
project, _ := p.Source.(*console.Project)
|
|
|
|
|
|
|
|
since := p.Args[SinceArg].(time.Time)
|
|
|
|
before := p.Args[BeforeArg].(time.Time)
|
|
|
|
|
2019-09-04 16:02:39 +01:00
|
|
|
usage, err := service.GetProjectUsage(p.Context, project.ID, since, before)
|
|
|
|
if err != nil {
|
2020-01-20 13:02:44 +00:00
|
|
|
return nil, err
|
2019-09-04 16:02:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return usage, nil
|
2019-04-04 15:56:20 +01:00
|
|
|
},
|
|
|
|
},
|
2019-05-16 11:43:46 +01:00
|
|
|
FieldBucketUsages: &graphql.Field{
|
|
|
|
Type: types.bucketUsagePage,
|
|
|
|
Args: graphql.FieldConfigArgument{
|
|
|
|
BeforeArg: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.DateTime),
|
|
|
|
},
|
|
|
|
CursorArg: &graphql.ArgumentConfig{
|
|
|
|
Type: graphql.NewNonNull(types.bucketUsageCursor),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
|
|
|
project, _ := p.Source.(*console.Project)
|
|
|
|
|
|
|
|
before := p.Args[BeforeArg].(time.Time)
|
|
|
|
cursor := fromMapBucketUsageCursor(p.Args[CursorArg].(map[string]interface{}))
|
|
|
|
|
2019-09-04 16:02:39 +01:00
|
|
|
page, err := service.GetBucketTotals(p.Context, project.ID, cursor, before)
|
|
|
|
if err != nil {
|
2020-01-20 13:02:44 +00:00
|
|
|
return nil, err
|
2019-09-04 16:02:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return page, nil
|
2019-05-16 11:43:46 +01:00
|
|
|
},
|
|
|
|
},
|
2018-11-26 10:47:23 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// graphqlProjectInput creates graphql.InputObject type needed to create/update satellite.Project.
|
2018-11-26 10:47:23 +00:00
|
|
|
func graphqlProjectInput() *graphql.InputObject {
|
|
|
|
return graphql.NewInputObject(graphql.InputObjectConfig{
|
2019-01-24 16:26:36 +00:00
|
|
|
Name: ProjectInputType,
|
2018-11-26 10:47:23 +00:00
|
|
|
Fields: graphql.InputObjectConfigFieldMap{
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldName: &graphql.InputObjectFieldConfig{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
2019-01-24 16:26:36 +00:00
|
|
|
FieldDescription: &graphql.InputObjectFieldConfig{
|
2018-11-26 10:47:23 +00:00
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-08-02 23:06:15 +01:00
|
|
|
// graphqlProjectLimit creates graphql.InputObject type needed to create/update satellite.Project.
|
|
|
|
func graphqlProjectLimit() *graphql.InputObject {
|
|
|
|
return graphql.NewInputObject(graphql.InputObjectConfig{
|
|
|
|
Name: ProjectLimitType,
|
|
|
|
Fields: graphql.InputObjectConfigFieldMap{
|
|
|
|
FieldStorageLimit: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
FieldBandwidthLimit: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-21 18:19:37 +00:00
|
|
|
// graphqlBucketUsageCursor creates bucket usage cursor graphql input type.
|
|
|
|
func graphqlProjectsCursor() *graphql.InputObject {
|
|
|
|
return graphql.NewInputObject(graphql.InputObjectConfig{
|
|
|
|
Name: ProjectsCursorInputType,
|
|
|
|
Fields: graphql.InputObjectConfigFieldMap{
|
|
|
|
LimitArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
PageArg: &graphql.InputObjectFieldConfig{
|
|
|
|
Type: graphql.NewNonNull(graphql.Int),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// graphqlBucketUsageCursor creates bucket usage cursor graphql input type.
|
2019-05-16 11:43:46 +01:00
|
|
|
func graphqlBucketUsageCursor() *graphql.InputObject {
|
|
|
|
return graphql.NewInputObject(graphql.InputObjectConfig{
|
|
|
|
Name: BucketUsageCursorInputType,
|
|
|
|
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),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// graphqlBucketUsage creates bucket usage grapqhl type.
|
2019-05-16 11:43:46 +01:00
|
|
|
func graphqlBucketUsage() *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: BucketUsageType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
FieldBucketName: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
FieldStorage: &graphql.Field{
|
|
|
|
Type: graphql.Float,
|
|
|
|
},
|
|
|
|
FieldEgress: &graphql.Field{
|
|
|
|
Type: graphql.Float,
|
|
|
|
},
|
2021-10-28 16:50:06 +01:00
|
|
|
FieldObjectCount: &graphql.Field{
|
|
|
|
Type: graphql.Float,
|
|
|
|
},
|
2021-10-20 23:54:34 +01:00
|
|
|
FieldSegmentCount: &graphql.Field{
|
2019-05-16 11:43:46 +01:00
|
|
|
Type: graphql.Float,
|
|
|
|
},
|
|
|
|
SinceArg: &graphql.Field{
|
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
|
|
|
BeforeArg: &graphql.Field{
|
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-01-21 18:19:37 +00:00
|
|
|
// graphqlProjectsPage creates a projects page graphql object.
|
|
|
|
func graphqlProjectsPage(types *TypeCreator) *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: ProjectsPageType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
FieldProjects: &graphql.Field{
|
|
|
|
Type: graphql.NewList(types.project),
|
|
|
|
},
|
|
|
|
LimitArg: &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
|
|
|
// graphqlBucketUsagePage creates bucket usage page graphql object.
|
2019-05-16 11:43:46 +01:00
|
|
|
func graphqlBucketUsagePage(types *TypeCreator) *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: BucketUsagePageType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
FieldBucketUsages: &graphql.Field{
|
|
|
|
Type: graphql.NewList(types.bucketUsage),
|
|
|
|
},
|
|
|
|
SearchArg: &graphql.Field{
|
|
|
|
Type: graphql.String,
|
|
|
|
},
|
|
|
|
LimitArg: &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
|
|
|
// graphqlProjectUsage creates project usage graphql type.
|
2019-04-04 15:56:20 +01:00
|
|
|
func graphqlProjectUsage() *graphql.Object {
|
|
|
|
return graphql.NewObject(graphql.ObjectConfig{
|
|
|
|
Name: ProjectUsageType,
|
|
|
|
Fields: graphql.Fields{
|
|
|
|
FieldStorage: &graphql.Field{
|
|
|
|
Type: graphql.Float,
|
|
|
|
},
|
|
|
|
FieldEgress: &graphql.Field{
|
|
|
|
Type: graphql.Float,
|
|
|
|
},
|
2021-10-28 16:50:06 +01:00
|
|
|
FieldObjectCount: &graphql.Field{
|
|
|
|
Type: graphql.Float,
|
|
|
|
},
|
2021-10-20 23:54:34 +01:00
|
|
|
FieldSegmentCount: &graphql.Field{
|
2019-04-04 15:56:20 +01:00
|
|
|
Type: graphql.Float,
|
|
|
|
},
|
|
|
|
SinceArg: &graphql.Field{
|
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
|
|
|
BeforeArg: &graphql.Field{
|
|
|
|
Type: graphql.DateTime,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2020-07-16 15:18:02 +01:00
|
|
|
// fromMapProjectInfo creates console.ProjectInfo from input args.
|
2019-01-15 13:03:24 +00:00
|
|
|
func fromMapProjectInfo(args map[string]interface{}) (project console.ProjectInfo) {
|
2019-01-24 16:26:36 +00:00
|
|
|
project.Name, _ = args[FieldName].(string)
|
|
|
|
project.Description, _ = args[FieldDescription].(string)
|
2018-11-26 10:47:23 +00:00
|
|
|
|
|
|
|
return
|
|
|
|
}
|
2019-05-16 11:43:46 +01:00
|
|
|
|
2021-08-02 23:06:15 +01:00
|
|
|
// fromMapProjectInfoProjectLimits creates console.ProjectInfo from input args.
|
2021-08-24 22:12:07 +01:00
|
|
|
func fromMapProjectInfoProjectLimits(projectInfo, projectLimits map[string]interface{}) (project console.ProjectInfo, err error) {
|
2021-08-02 23:06:15 +01:00
|
|
|
project.Name, _ = projectInfo[FieldName].(string)
|
|
|
|
project.Description, _ = projectInfo[FieldDescription].(string)
|
2021-08-24 22:12:07 +01:00
|
|
|
storageLimit, err := strconv.Atoi(projectLimits[FieldStorageLimit].(string))
|
|
|
|
if err != nil {
|
|
|
|
return project, err
|
|
|
|
}
|
2021-08-02 23:06:15 +01:00
|
|
|
project.StorageLimit = memory.Size(storageLimit)
|
2021-08-24 22:12:07 +01:00
|
|
|
bandwidthLimit, err := strconv.Atoi(projectLimits[FieldBandwidthLimit].(string))
|
|
|
|
if err != nil {
|
|
|
|
return project, err
|
|
|
|
}
|
2021-08-02 23:06:15 +01:00
|
|
|
project.BandwidthLimit = memory.Size(bandwidthLimit)
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-21 18:19:37 +00:00
|
|
|
// fromMapProjectsCursor creates console.ProjectsCursor from input args.
|
|
|
|
func fromMapProjectsCursor(args map[string]interface{}) (cursor console.ProjectsCursor) {
|
|
|
|
cursor.Limit = args[LimitArg].(int)
|
|
|
|
cursor.Page = args[PageArg].(int)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// fromMapBucketUsageCursor creates accounting.BucketUsageCursor from input args.
|
2019-11-15 14:27:44 +00:00
|
|
|
func fromMapBucketUsageCursor(args map[string]interface{}) (cursor accounting.BucketUsageCursor) {
|
2019-05-16 11:43:46 +01:00
|
|
|
limit, _ := args[LimitArg].(int)
|
|
|
|
page, _ := args[PageArg].(int)
|
|
|
|
|
|
|
|
cursor.Limit = uint(limit)
|
|
|
|
cursor.Page = uint(page)
|
|
|
|
cursor.Search, _ = args[SearchArg].(string)
|
|
|
|
return
|
|
|
|
}
|
2019-08-12 11:22:32 +01:00
|
|
|
|
|
|
|
func cursorArgsToProjectMembersCursor(args map[string]interface{}) console.ProjectMembersCursor {
|
|
|
|
limit, _ := args[LimitArg].(int)
|
|
|
|
page, _ := args[PageArg].(int)
|
|
|
|
order, _ := args[OrderArg].(int)
|
|
|
|
orderDirection, _ := args[OrderDirectionArg].(int)
|
|
|
|
|
|
|
|
var cursor console.ProjectMembersCursor
|
|
|
|
|
|
|
|
cursor.Limit = uint(limit)
|
|
|
|
cursor.Page = uint(page)
|
|
|
|
cursor.Order = console.ProjectMemberOrder(order)
|
2019-09-12 15:19:30 +01:00
|
|
|
cursor.OrderDirection = console.OrderDirection(orderDirection)
|
|
|
|
cursor.Search, _ = args[SearchArg].(string)
|
|
|
|
|
|
|
|
return cursor
|
|
|
|
}
|
|
|
|
|
|
|
|
func cursorArgsToAPIKeysCursor(args map[string]interface{}) console.APIKeyCursor {
|
|
|
|
limit, _ := args[LimitArg].(int)
|
|
|
|
page, _ := args[PageArg].(int)
|
|
|
|
order, _ := args[OrderArg].(int)
|
|
|
|
orderDirection, _ := args[OrderDirectionArg].(int)
|
|
|
|
|
|
|
|
var cursor console.APIKeyCursor
|
|
|
|
|
|
|
|
cursor.Limit = uint(limit)
|
|
|
|
cursor.Page = uint(page)
|
|
|
|
cursor.Order = console.APIKeyOrder(order)
|
|
|
|
cursor.OrderDirection = console.OrderDirection(orderDirection)
|
2019-08-12 11:22:32 +01:00
|
|
|
cursor.Search, _ = args[SearchArg].(string)
|
|
|
|
|
|
|
|
return cursor
|
|
|
|
}
|