Skip to content
This repository was archived by the owner on Aug 1, 2020. It is now read-only.

Commit 287541b

Browse files
committed
some swarm types
1 parent 8002733 commit 287541b

File tree

4 files changed

+143
-69
lines changed

4 files changed

+143
-69
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ stages:
1818
artifacts:
1919
name: "$CI_JOB_NAME"
2020
paths:
21-
- /go/src/gitlab.com/klud/graphql-docker-api/cmd/gql-dkr
21+
- go/src/gitlab.com/klud/graphql-docker-api/cmd/gql-dkr/gql-dkr
2222
expire_in: 1 week
2323

2424
.images: &images

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# GraphQL Docker API [![pipeline status](https://gitlab.com/klud/graphql-docker-api/badges/master/pipeline.svg)](https://gitlab.com/klud/graphql-docker-api/commits/master) [![](https://images.microbadger.com/badges/version/klud/docker-gql.svg)](https://microbadger.com/images/klud/docker-gql "Get your own version badge on microbadger.com") [![](https://images.microbadger.com/badges/image/klud/docker-gql.svg)](https://microbadger.com/images/klud/docker-gql "Get your own image badge on microbadger.com") [![Go Report Card](https://goreportcard.com/badge/gitlab.com/klud/graphql-docker-api)](https://goreportcard.com/report/gitlab.com/klud/graphql-docker-api) [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE)
1+
# GraphQL Docker API
2+
3+
[![pipeline status](https://gitlab.com/klud/graphql-docker-api/badges/master/pipeline.svg)](https://gitlab.com/klud/graphql-docker-api/commits/master) [![](https://images.microbadger.com/badges/version/klud/docker-gql.svg)](https://microbadger.com/images/klud/docker-gql "Get your own version badge on microbadger.com") [![](https://images.microbadger.com/badges/image/klud/docker-gql.svg)](https://microbadger.com/images/klud/docker-gql "Get your own image badge on microbadger.com") [![Go Report Card](https://goreportcard.com/badge/gitlab.com/klud/graphql-docker-api)](https://goreportcard.com/report/gitlab.com/klud/graphql-docker-api) [![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](LICENSE)
24

35
<p align="center"> <img src="resources/docker-go-graphql.png" alt="Logo" width="400"></p>
46

@@ -108,6 +110,8 @@ klud/docker-gql
108110
* [GraphQL](http://graphql.org)
109111
* [Golang](https://golang.org/)
110112
* [Go GraphQL](https://github.com/graphql-go/graphql)
113+
* [Go GraphQL handler](https://github.com/graphql-go/handler)
114+
* [Gorilla handlers](https://github.com/gorilla/handlers)
111115

112116
---
113117
> Inspired by [rm3l/docker-api-graphql](https://github.com/rm3l/docker-api-graphql)

resources/schema/swarm.graphql

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ type SwarmSpec {
1212
caConfig: CaConfig
1313
dispatcher: DispatcherConfig
1414
encryptionConfig: EncryptionConfig
15-
labels: StringAnyMap
15+
# TBI
16+
# labels: StringAnyMap
1617
name: String
1718
orchestration: OrchestrationConfig
1819
raft: RaftConfig
@@ -41,7 +42,8 @@ type CaConfig {
4142
}
4243

4344
type ExternalCa {
44-
options: StringAnyMap
45+
caCert: string
46+
# options: StringAnyMap
4547
protocol: String
4648
url: String
4749
}
@@ -56,7 +58,8 @@ type TaskDefaults {
5658

5759
type Driver {
5860
name: String
59-
options: StringAnyMap
61+
# TBI
62+
# options: StringAnyMap
6063
}
6164

6265
type JoinTokens {

schema/swarm.go

Lines changed: 131 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@ var (
99
Name: "CaConfig",
1010
Fields: graphql.Fields{
1111
"externalCas": &graphql.Field{
12-
Type: externalCa,
13-
// This must return a externalCa slice
14-
// Resolver
12+
Type: graphql.NewList(externalCa),
13+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
14+
return swInfo.Cluster.Spec.CAConfig.ExternalCAs, nil
15+
},
1516
},
1617
"nodeCertExpiry": &graphql.Field{
17-
Type: graphql.Float,
18-
// Resolver
18+
Type: graphql.Int,
19+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
20+
return int32(swInfo.Cluster.Spec.CAConfig.NodeCertExpiry), nil
21+
},
1922
},
2023
},
2124
})
2225
dispatcherConfig = graphql.NewObject(graphql.ObjectConfig{
2326
Name: "DispatcherConfig",
2427
Fields: graphql.Fields{
2528
"heartbeatPeriod": &graphql.Field{
26-
Type: graphql.Float,
27-
// Resolver
29+
Type: graphql.Int,
30+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
31+
return int32(swInfo.Cluster.Spec.Dispatcher.HeartbeatPeriod), nil
32+
},
2833
},
2934
},
3035
})
@@ -33,20 +38,25 @@ var (
3338
Fields: graphql.Fields{
3439
"name": &graphql.Field{
3540
Type: graphql.String,
36-
// Resolver
37-
},
38-
"options": &graphql.Field{
39-
Type: stringAnyMap,
40-
// Resolver
41+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
42+
return swInfo.Cluster.Spec.TaskDefaults.LogDriver.Name, nil
43+
},
4144
},
45+
// TBI
46+
// "options": &graphql.Field{
47+
// Type: stringAnyMap,
48+
// // Resolver
49+
// },
4250
},
4351
})
4452
encryptionConfig = graphql.NewObject(graphql.ObjectConfig{
4553
Name: "EncryptionConfig",
4654
Fields: graphql.Fields{
4755
"autoLockManagers": &graphql.Field{
4856
Type: graphql.Boolean,
49-
// Resolver
57+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
58+
return swInfo.Cluster.Spec.EncryptionConfig.AutoLockManagers, nil
59+
},
5060
},
5161
},
5262
})
@@ -84,17 +94,37 @@ var (
8494
externalCa = graphql.NewObject(graphql.ObjectConfig{
8595
Name: "ExternalCa",
8696
Fields: graphql.Fields{
87-
"options": &graphql.Field{
88-
Type: stringAnyMap,
89-
// Resolver
97+
"caCert": &graphql.Field{
98+
Type: graphql.String,
99+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
100+
for _, exCa := range swInfo.Cluster.Spec.CAConfig.ExternalCAs {
101+
return exCa.CACert, nil
102+
}
103+
return nil, nil
104+
},
90105
},
106+
// TBI
107+
// "options": &graphql.Field{
108+
// Type: stringAnyMap,
109+
// // Resolver
110+
// },
91111
"protocols": &graphql.Field{
92112
Type: graphql.String,
93-
// Resolver
113+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
114+
for _, exCa := range swInfo.Cluster.Spec.CAConfig.ExternalCAs {
115+
return exCa.Protocol, nil
116+
}
117+
return nil, nil
118+
},
94119
},
95120
"url": &graphql.Field{
96121
Type: graphql.String,
97-
// Resolver
122+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
123+
for _, exCa := range swInfo.Cluster.Spec.CAConfig.ExternalCAs {
124+
return exCa.URL, nil
125+
}
126+
return nil, nil
127+
},
98128
},
99129
},
100130
})
@@ -277,7 +307,9 @@ var (
277307
Fields: graphql.Fields{
278308
"taskHistoryRetentionLimit": &graphql.Field{
279309
Type: graphql.Int,
280-
// Resolver
310+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
311+
return int32(*swInfo.Cluster.Spec.Orchestration.TaskHistoryRetentionLimit), nil
312+
},
281313
},
282314
},
283315
})
@@ -299,40 +331,59 @@ var (
299331
Fields: graphql.Fields{
300332
"electionTick": &graphql.Field{
301333
Type: graphql.Int,
302-
// Resolver
334+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
335+
return int32(swInfo.Cluster.Spec.Raft.ElectionTick), nil
336+
},
303337
},
304338
"heartbeatTick": &graphql.Field{
305339
Type: graphql.Int,
306-
// Resolver
340+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
341+
return int32(swInfo.Cluster.Spec.Raft.HeartbeatTick), nil
342+
},
307343
},
308344
"keepOldSnapshots": &graphql.Field{
309345
Type: graphql.Int,
310-
// Resolver
346+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
347+
return int32(*swInfo.Cluster.Spec.Raft.KeepOldSnapshots), nil
348+
},
311349
},
312350
"logEntriesForSlowFollowers": &graphql.Field{
313351
Type: graphql.Int,
314-
// Resolver
352+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
353+
return int32(swInfo.Cluster.Spec.Raft.LogEntriesForSlowFollowers), nil
354+
},
315355
},
316356
"snapshotInterval": &graphql.Field{
317357
Type: graphql.Int,
318-
// Resolver
358+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
359+
return int32(swInfo.Cluster.Spec.Raft.SnapshotInterval), nil
360+
},
361+
},
362+
},
363+
})
364+
remoteManager = graphql.NewObject(graphql.ObjectConfig{
365+
Name: "RemoteManager",
366+
Fields: graphql.Fields{
367+
"addr": &graphql.Field{
368+
Type: graphql.String,
369+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
370+
for _, peer := range swInfo.RemoteManagers {
371+
return peer.Addr, nil
372+
}
373+
return nil, nil
374+
},
375+
},
376+
"nodeId": &graphql.Field{
377+
Type: graphql.String,
378+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
379+
for _, peer := range swInfo.RemoteManagers {
380+
return peer.NodeID, nil
381+
}
382+
return nil, nil
383+
},
319384
},
320385
},
321386
})
322-
// TBI
323-
// remoteManager = graphql.NewObject(graphql.ObjectConfig{
324-
// Name: "RemoteManager",
325-
// Fields: graphql.Fields{
326-
// "addr": &graphql.Field{
327-
// Type: graphql.String,
328-
// // Resolver
329-
// },
330-
// "nodeId": &graphql.Field{
331-
// Type: graphql.String,
332-
// // Resolver
333-
// },
334-
// },
335-
// })
336387
resources = graphql.NewObject(graphql.ObjectConfig{
337388
Name: "Resources",
338389
Fields: graphql.Fields{
@@ -402,11 +453,12 @@ var (
402453
return swInfo.Cluster.RootRotationInProgress, nil
403454
},
404455
},
405-
// TBI
406-
// "swarmSpec": &graphql.Field{
407-
// Type: swarmSpec,
408-
// // Resolver
409-
// },
456+
"swarmSpec": &graphql.Field{
457+
Type: swarmSpec,
458+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
459+
return swInfo.Cluster.Spec, nil
460+
},
461+
},
410462
"tlsInfo": &graphql.Field{
411463
Type: tlsInfo,
412464
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
@@ -427,7 +479,6 @@ var (
427479
},
428480
},
429481
})
430-
431482
swarmInfo = graphql.NewObject(graphql.ObjectConfig{
432483
Name: "SwarmInfo",
433484
Fields: graphql.Fields{
@@ -479,13 +530,12 @@ var (
479530
return swInfo.Nodes, nil
480531
},
481532
},
482-
// TBI
483-
// "remoteManagers": &graphql.Field{
484-
// Type: graphql.NewList(remoteManager),
485-
// Resolve: func(p graphql.ResolveParams) (interface{}, error) {
486-
// return swInfo.RemoteManagers, nil
487-
// },
488-
// },
533+
"remoteManagers": &graphql.Field{
534+
Type: graphql.NewList(remoteManager),
535+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
536+
return swInfo.RemoteManagers, nil
537+
},
538+
},
489539
},
490540
})
491541
swarmNode = graphql.NewObject(graphql.ObjectConfig{
@@ -534,35 +584,50 @@ var (
534584
Fields: graphql.Fields{
535585
"caConfig": &graphql.Field{
536586
Type: caConfig,
537-
// Resolver
587+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
588+
return swInfo.Cluster.Spec.CAConfig, nil
589+
},
538590
},
539591
"dispatcher": &graphql.Field{
540592
Type: dispatcherConfig,
541-
// Resolver
593+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
594+
return swInfo.Cluster.Spec.Dispatcher, nil
595+
},
542596
},
543597
"encryptionConfig": &graphql.Field{
544598
Type: encryptionConfig,
545-
// Resolver
546-
},
547-
"labels": &graphql.Field{
548-
Type: stringAnyMap,
549-
// Resolver
599+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
600+
return swInfo.Cluster.Spec.EncryptionConfig, nil
601+
},
550602
},
603+
// TBI
604+
// "labels": &graphql.Field{
605+
// Type: stringAnyMap,
606+
// // Resolver
607+
// },
551608
"name": &graphql.Field{
552-
Type: graphql.DateTime,
553-
// Resolver
609+
Type: graphql.String,
610+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
611+
return swInfo.Cluster.Spec.Annotations.Name, nil
612+
},
554613
},
555614
"orchestration": &graphql.Field{
556615
Type: orchestrationConfig,
557-
// Resolver
616+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
617+
return swInfo.Cluster.Spec.Orchestration, nil
618+
},
558619
},
559620
"raft": &graphql.Field{
560621
Type: raftconfig,
561-
// Resolver
622+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
623+
return swInfo.Cluster.Spec.Raft, nil
624+
},
562625
},
563626
"taskDefaults": &graphql.Field{
564627
Type: taskDefaults,
565-
// Resolver
628+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
629+
return swInfo.Cluster.Spec.TaskDefaults, nil
630+
},
566631
},
567632
},
568633
})
@@ -582,7 +647,9 @@ var (
582647
Fields: graphql.Fields{
583648
"logDriver": &graphql.Field{
584649
Type: driver,
585-
// Resolver
650+
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
651+
return swInfo.Cluster.Spec.TaskDefaults.LogDriver, nil
652+
},
586653
},
587654
},
588655
})

0 commit comments

Comments
 (0)