Browse code

Generate plugin types from the swagger spec.

Signed-off-by: Daniel Nephin <dnephin@docker.com>

Daniel Nephin authored on 2016/10/06 05:25:09
Showing 9 changed files
... ...
@@ -1118,11 +1118,15 @@ definitions:
1118 1118
 
1119 1119
   PluginMount:
1120 1120
     type: "object"
1121
+    x-nullable: false
1122
+    required: [Name, Description, Settable, Source, Destination, Type, Options]
1121 1123
     properties:
1122 1124
       Name:
1123 1125
         type: "string"
1126
+        x-nullable: false
1124 1127
       Description:
1125 1128
         type: "string"
1129
+        x-nullable: false
1126 1130
       Settable:
1127 1131
         type: "array"
1128 1132
         items:
... ...
@@ -1131,8 +1135,10 @@ definitions:
1131 1131
         type: "string"
1132 1132
       Destination:
1133 1133
         type: "string"
1134
+        x-nullable: false
1134 1135
       Type:
1135 1136
         type: "string"
1137
+        x-nullable: false
1136 1138
       Options:
1137 1139
         type: "array"
1138 1140
         items:
... ...
@@ -1140,11 +1146,15 @@ definitions:
1140 1140
 
1141 1141
   PluginDevice:
1142 1142
     type: "object"
1143
+    required: [Name, Description, Settable, Path]
1144
+    x-nullable: false
1143 1145
     properties:
1144 1146
       Name:
1145 1147
         type: "string"
1148
+        x-nullable: false
1146 1149
       Description:
1147 1150
         type: "string"
1151
+        x-nullable: false
1148 1152
       Settable:
1149 1153
         type: "array"
1150 1154
         items:
... ...
@@ -1152,22 +1162,61 @@ definitions:
1152 1152
       Path:
1153 1153
         type: "string"
1154 1154
 
1155
+  PluginEnv:
1156
+    type: "object"
1157
+    x-nullable: false
1158
+    required: [Name, Description, Settable, Value]
1159
+    properties:
1160
+      Name:
1161
+        x-nullable: false
1162
+        type: "string"
1163
+      Description:
1164
+        x-nullable: false
1165
+        type: "string"
1166
+      Settable:
1167
+        type: "array"
1168
+        items:
1169
+          type: "string"
1170
+      Value:
1171
+        type: "string"
1172
+
1173
+  PluginInterfaceType:
1174
+    type: "object"
1175
+    x-nullable: false
1176
+    required: [Prefix, Capability, Version]
1177
+    properties:
1178
+      Prefix:
1179
+        type: "string"
1180
+        x-nullable: false
1181
+      Capability:
1182
+        type: "string"
1183
+        x-nullable: false
1184
+      Version:
1185
+        type: "string"
1186
+        x-nullable: false
1187
+
1155 1188
   Plugin:
1156 1189
     description: "A plugin for the Remote API"
1157 1190
     type: "object"
1191
+    required: [Config, Enabled, Manifest, Name, Tag]
1158 1192
     properties:
1159 1193
       Id:
1160 1194
         type: "string"
1161 1195
       Name:
1162 1196
         type: "string"
1197
+        x-nullable: false
1163 1198
       Tag:
1164 1199
         type: "string"
1200
+        x-nullable: false
1165 1201
       Enabled:
1166 1202
         description: "True when the plugin is running. False when the plugin is not running, only installed."
1167 1203
         type: "boolean"
1204
+        x-nullable: false
1168 1205
       Config:
1169 1206
         description: "Settings that can be modified by users."
1170 1207
         type: "object"
1208
+        x-nullable: false
1209
+        required: [Args, Devices, Env, Mounts]
1171 1210
         properties:
1172 1211
           Mounts:
1173 1212
             type: "array"
... ...
@@ -1188,40 +1237,67 @@ definitions:
1188 1188
       Manifest:
1189 1189
         description: "The manifest of a plugin."
1190 1190
         type: "object"
1191
+        x-nullable: false
1192
+        required:
1193
+          - ManifestVersion
1194
+          - Description
1195
+          - Documentation
1196
+          - Interface
1197
+          - Entrypoint
1198
+          - Workdir
1199
+          - Network
1200
+          - Capabilities
1201
+          - Mounts
1202
+          - Devices
1203
+          - Env
1204
+          - Args
1191 1205
         properties:
1192 1206
           ManifestVersion:
1193 1207
             type: "string"
1208
+            x-nullable: false
1194 1209
           Description:
1195 1210
             type: "string"
1211
+            x-nullable: false
1196 1212
           Documentation:
1197 1213
             type: "string"
1214
+            x-nullable: false
1198 1215
           Interface:
1199 1216
             description: "The interface between Docker and the plugin"
1217
+            x-nullable: false
1200 1218
             type: "object"
1219
+            required: [Types, Socket]
1201 1220
             properties:
1202 1221
               Types:
1203 1222
                 type: "array"
1204 1223
                 items:
1205
-                  type: "string"
1224
+                  $ref: "#/definitions/PluginInterfaceType"
1206 1225
               Socket:
1207 1226
                 type: "string"
1227
+                x-nullable: false
1208 1228
           Entrypoint:
1209 1229
             type: "array"
1210 1230
             items:
1211 1231
               type: "string"
1212 1232
           Workdir:
1213 1233
             type: "string"
1234
+            x-nullable: false
1214 1235
           User:
1215 1236
             type: "object"
1237
+            x-nullable: false
1216 1238
             properties:
1217 1239
               UID:
1218 1240
                 type: "integer"
1241
+                format: "uint32"
1219 1242
               GID:
1220 1243
                 type: "integer"
1244
+                format: "uint32"
1221 1245
           Network:
1222 1246
             type: "object"
1247
+            x-nullable: false
1248
+            required: [Type]
1223 1249
             properties:
1224 1250
               Type:
1251
+                x-nullable: false
1225 1252
                 type: "string"
1226 1253
           Capabilities:
1227 1254
             type: "array"
... ...
@@ -1236,24 +1312,19 @@ definitions:
1236 1236
             items:
1237 1237
               $ref: "#/definitions/PluginDevice"
1238 1238
           Env:
1239
-            type: "object"
1240
-            properties:
1241
-              Name:
1242
-                type: "string"
1243
-              Description:
1244
-                type: "string"
1245
-              Settable:
1246
-                type: "array"
1247
-                items:
1248
-                  type: "string"
1249
-              Value:
1250
-                type: "string"
1239
+            type: "array"
1240
+            items:
1241
+              $ref: "#/definitions/PluginEnv"
1251 1242
           Args:
1252 1243
             type: "object"
1244
+            x-nullable: false
1245
+            required: [Name, Description, Settable, Value]
1253 1246
             properties:
1254 1247
               Name:
1248
+                x-nullable: false
1255 1249
                 type: "string"
1256 1250
               Description:
1251
+                x-nullable: false
1257 1252
                 type: "string"
1258 1253
               Settable:
1259 1254
                 type: "array"
... ...
@@ -314,3 +314,12 @@ type TaskListOptions struct {
314 314
 type PluginRemoveOptions struct {
315 315
 	Force bool
316 316
 }
317
+
318
+// PluginInstallOptions holds parameters to install a plugin.
319
+type PluginInstallOptions struct {
320
+	Disabled              bool
321
+	AcceptAllPermissions  bool
322
+	RegistryAuth          string // RegistryAuth is the base64 encoded credentials for the registry
323
+	PrivilegeFunc         RequestPrivilegeFunc
324
+	AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
325
+}
... ...
@@ -1,168 +1,163 @@
1 1
 package types
2 2
 
3
-import (
4
-	"encoding/json"
5
-	"fmt"
6
-)
7
-
8
-// PluginInstallOptions holds parameters to install a plugin.
9
-type PluginInstallOptions struct {
10
-	Disabled              bool
11
-	AcceptAllPermissions  bool
12
-	RegistryAuth          string // RegistryAuth is the base64 encoded credentials for the registry
13
-	PrivilegeFunc         RequestPrivilegeFunc
14
-	AcceptPermissionsFunc func(PluginPrivileges) (bool, error)
3
+// This file was generated by the swagger tool.
4
+// Editing this file might prove futile when you re-run the swagger generate command
5
+
6
+// Plugin A plugin for the Remote API
7
+// swagger:model Plugin
8
+type Plugin struct {
9
+
10
+	// config
11
+	// Required: true
12
+	Config PluginConfig `json:"Config"`
13
+
14
+	// True when the plugin is running. False when the plugin is not running, only installed.
15
+	// Required: true
16
+	Enabled bool `json:"Enabled"`
17
+
18
+	// Id
19
+	ID string `json:"Id,omitempty"`
20
+
21
+	// manifest
22
+	// Required: true
23
+	Manifest PluginManifest `json:"Manifest"`
24
+
25
+	// name
26
+	// Required: true
27
+	Name string `json:"Name"`
28
+
29
+	// tag
30
+	// Required: true
31
+	Tag string `json:"Tag"`
15 32
 }
16 33
 
17
-// PluginConfig represents the values of settings potentially modifiable by a user
34
+// PluginConfigSettings that can be modified by users.
35
+// swagger:model PluginConfig
18 36
 type PluginConfig struct {
19
-	Mounts  []PluginMount
20
-	Env     []string
21
-	Args    []string
22
-	Devices []PluginDevice
23
-}
24 37
 
25
-// Plugin represents a Docker plugin for the remote API
26
-type Plugin struct {
27
-	ID   string `json:"Id,omitempty"`
28
-	Name string
29
-	Tag  string
30
-	// Enabled is true when the plugin is running, is false when the plugin is not running, only installed.
31
-	Enabled  bool
32
-	Config   PluginConfig
33
-	Manifest PluginManifest
34
-}
38
+	// args
39
+	// Required: true
40
+	Args []string `json:"Args"`
35 41
 
36
-// PluginsListResponse contains the response for the remote API
37
-type PluginsListResponse []*Plugin
38
-
39
-const (
40
-	authzDriver   = "AuthzDriver"
41
-	graphDriver   = "GraphDriver"
42
-	ipamDriver    = "IpamDriver"
43
-	networkDriver = "NetworkDriver"
44
-	volumeDriver  = "VolumeDriver"
45
-)
46
-
47
-// PluginInterfaceType represents a type that a plugin implements.
48
-type PluginInterfaceType struct {
49
-	Prefix     string // This is always "docker"
50
-	Capability string // Capability should be validated against the above list.
51
-	Version    string // Plugin API version. Depends on the capability
52
-}
42
+	// devices
43
+	// Required: true
44
+	Devices []PluginDevice `json:"Devices"`
53 45
 
54
-// UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType
55
-func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error {
56
-	versionIndex := len(p)
57
-	prefixIndex := 0
58
-	if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' {
59
-		return fmt.Errorf("%q is not a plugin interface type", p)
60
-	}
61
-	p = p[1 : len(p)-1]
62
-loop:
63
-	for i, b := range p {
64
-		switch b {
65
-		case '.':
66
-			prefixIndex = i
67
-		case '/':
68
-			versionIndex = i
69
-			break loop
70
-		}
71
-	}
72
-	t.Prefix = string(p[:prefixIndex])
73
-	t.Capability = string(p[prefixIndex+1 : versionIndex])
74
-	if versionIndex < len(p) {
75
-		t.Version = string(p[versionIndex+1:])
76
-	}
77
-	return nil
78
-}
46
+	// env
47
+	// Required: true
48
+	Env []string `json:"Env"`
79 49
 
80
-// MarshalJSON implements json.Marshaler for PluginInterfaceType
81
-func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) {
82
-	return json.Marshal(t.String())
50
+	// mounts
51
+	// Required: true
52
+	Mounts []PluginMount `json:"Mounts"`
83 53
 }
84 54
 
85
-// String implements fmt.Stringer for PluginInterfaceType
86
-func (t PluginInterfaceType) String() string {
87
-	return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version)
88
-}
55
+// PluginManifestThe manifest of a plugin.
56
+// swagger:model PluginManifest
57
+type PluginManifest struct {
89 58
 
90
-// PluginInterface describes the interface between Docker and plugin
91
-type PluginInterface struct {
92
-	Types  []PluginInterfaceType
93
-	Socket string
94
-}
59
+	// args
60
+	// Required: true
61
+	Args PluginManifestArgs `json:"Args"`
95 62
 
96
-// PluginSetting is to be embedded in other structs, if they are supposed to be
97
-// modifiable by the user.
98
-type PluginSetting struct {
99
-	Name        string
100
-	Description string
101
-	Settable    []string
102
-}
63
+	// capabilities
64
+	// Required: true
65
+	Capabilities []string `json:"Capabilities"`
103 66
 
104
-// PluginNetwork represents the network configuration for a plugin
105
-type PluginNetwork struct {
106
-	Type string
107
-}
67
+	// description
68
+	// Required: true
69
+	Description string `json:"Description"`
108 70
 
109
-// PluginMount represents the mount configuration for a plugin
110
-type PluginMount struct {
111
-	PluginSetting
112
-	Source      *string
113
-	Destination string
114
-	Type        string
115
-	Options     []string
116
-}
71
+	// devices
72
+	// Required: true
73
+	Devices []PluginDevice `json:"Devices"`
117 74
 
118
-// PluginEnv represents an environment variable for a plugin
119
-type PluginEnv struct {
120
-	PluginSetting
121
-	Value *string
122
-}
75
+	// documentation
76
+	// Required: true
77
+	Documentation string `json:"Documentation"`
123 78
 
124
-// PluginArgs represents the command line arguments for a plugin
125
-type PluginArgs struct {
126
-	PluginSetting
127
-	Value []string
128
-}
79
+	// entrypoint
80
+	// Required: true
81
+	Entrypoint []string `json:"Entrypoint"`
82
+
83
+	// env
84
+	// Required: true
85
+	Env []PluginEnv `json:"Env"`
86
+
87
+	// interface
88
+	// Required: true
89
+	Interface PluginManifestInterface `json:"Interface"`
90
+
91
+	// manifest version
92
+	// Required: true
93
+	ManifestVersion string `json:"ManifestVersion"`
129 94
 
130
-// PluginDevice represents a device for a plugin
131
-type PluginDevice struct {
132
-	PluginSetting
133
-	Path *string
95
+	// mounts
96
+	// Required: true
97
+	Mounts []PluginMount `json:"Mounts"`
98
+
99
+	// network
100
+	// Required: true
101
+	Network PluginManifestNetwork `json:"Network"`
102
+
103
+	// user
104
+	User PluginManifestUser `json:"User,omitempty"`
105
+
106
+	// workdir
107
+	// Required: true
108
+	Workdir string `json:"Workdir"`
134 109
 }
135 110
 
136
-// PluginUser represents the user for the plugin's process
137
-type PluginUser struct {
138
-	UID uint32 `json:"Uid,omitempty"`
139
-	GID uint32 `json:"Gid,omitempty"`
111
+// PluginManifestArgsplugin manifest args
112
+// swagger:model PluginManifestArgs
113
+type PluginManifestArgs struct {
114
+
115
+	// description
116
+	// Required: true
117
+	Description string `json:"Description"`
118
+
119
+	// name
120
+	// Required: true
121
+	Name string `json:"Name"`
122
+
123
+	// settable
124
+	// Required: true
125
+	Settable []string `json:"Settable"`
126
+
127
+	// value
128
+	// Required: true
129
+	Value []string `json:"Value"`
140 130
 }
141 131
 
142
-// PluginManifest represents the manifest of a plugin
143
-type PluginManifest struct {
144
-	ManifestVersion string
145
-	Description     string
146
-	Documentation   string
147
-	Interface       PluginInterface
148
-	Entrypoint      []string
149
-	Workdir         string
150
-	User            PluginUser `json:",omitempty"`
151
-	Network         PluginNetwork
152
-	Capabilities    []string
153
-	Mounts          []PluginMount
154
-	Devices         []PluginDevice
155
-	Env             []PluginEnv
156
-	Args            PluginArgs
132
+// PluginManifestInterfaceThe interface between Docker and the plugin
133
+// swagger:model PluginManifestInterface
134
+type PluginManifestInterface struct {
135
+
136
+	// socket
137
+	// Required: true
138
+	Socket string `json:"Socket"`
139
+
140
+	// types
141
+	// Required: true
142
+	Types []PluginInterfaceType `json:"Types"`
157 143
 }
158 144
 
159
-// PluginPrivilege describes a permission the user has to accept
160
-// upon installing a plugin.
161
-type PluginPrivilege struct {
162
-	Name        string
163
-	Description string
164
-	Value       []string
145
+// PluginManifestNetworkplugin manifest network
146
+// swagger:model PluginManifestNetwork
147
+type PluginManifestNetwork struct {
148
+
149
+	// type
150
+	// Required: true
151
+	Type string `json:"Type"`
165 152
 }
166 153
 
167
-// PluginPrivileges is a list of PluginPrivilege
168
-type PluginPrivileges []PluginPrivilege
154
+// PluginManifestUserplugin manifest user
155
+// swagger:model PluginManifestUser
156
+type PluginManifestUser struct {
157
+
158
+	// g ID
159
+	GID uint32 `json:"GID,omitempty"`
160
+
161
+	// UID
162
+	UID uint32 `json:"UID,omitempty"`
163
+}
169 164
new file mode 100644
... ...
@@ -0,0 +1,25 @@
0
+package types
1
+
2
+// This file was generated by the swagger tool.
3
+// Editing this file might prove futile when you re-run the swagger generate command
4
+
5
+// PluginDevice plugin device
6
+// swagger:model PluginDevice
7
+type PluginDevice struct {
8
+
9
+	// description
10
+	// Required: true
11
+	Description string `json:"Description"`
12
+
13
+	// name
14
+	// Required: true
15
+	Name string `json:"Name"`
16
+
17
+	// path
18
+	// Required: true
19
+	Path *string `json:"Path"`
20
+
21
+	// settable
22
+	// Required: true
23
+	Settable []string `json:"Settable"`
24
+}
0 25
new file mode 100644
... ...
@@ -0,0 +1,25 @@
0
+package types
1
+
2
+// This file was generated by the swagger tool.
3
+// Editing this file might prove futile when you re-run the swagger generate command
4
+
5
+// PluginEnv plugin env
6
+// swagger:model PluginEnv
7
+type PluginEnv struct {
8
+
9
+	// description
10
+	// Required: true
11
+	Description string `json:"Description"`
12
+
13
+	// name
14
+	// Required: true
15
+	Name string `json:"Name"`
16
+
17
+	// settable
18
+	// Required: true
19
+	Settable []string `json:"Settable"`
20
+
21
+	// value
22
+	// Required: true
23
+	Value *string `json:"Value"`
24
+}
0 25
new file mode 100644
... ...
@@ -0,0 +1,21 @@
0
+package types
1
+
2
+// This file was generated by the swagger tool.
3
+// Editing this file might prove futile when you re-run the swagger generate command
4
+
5
+// PluginInterfaceType plugin interface type
6
+// swagger:model PluginInterfaceType
7
+type PluginInterfaceType struct {
8
+
9
+	// capability
10
+	// Required: true
11
+	Capability string `json:"Capability"`
12
+
13
+	// prefix
14
+	// Required: true
15
+	Prefix string `json:"Prefix"`
16
+
17
+	// version
18
+	// Required: true
19
+	Version string `json:"Version"`
20
+}
0 21
new file mode 100644
... ...
@@ -0,0 +1,37 @@
0
+package types
1
+
2
+// This file was generated by the swagger tool.
3
+// Editing this file might prove futile when you re-run the swagger generate command
4
+
5
+// PluginMount plugin mount
6
+// swagger:model PluginMount
7
+type PluginMount struct {
8
+
9
+	// description
10
+	// Required: true
11
+	Description string `json:"Description"`
12
+
13
+	// destination
14
+	// Required: true
15
+	Destination string `json:"Destination"`
16
+
17
+	// name
18
+	// Required: true
19
+	Name string `json:"Name"`
20
+
21
+	// options
22
+	// Required: true
23
+	Options []string `json:"Options"`
24
+
25
+	// settable
26
+	// Required: true
27
+	Settable []string `json:"Settable"`
28
+
29
+	// source
30
+	// Required: true
31
+	Source *string `json:"Source"`
32
+
33
+	// type
34
+	// Required: true
35
+	Type string `json:"Type"`
36
+}
0 37
new file mode 100644
... ...
@@ -0,0 +1,64 @@
0
+package types
1
+
2
+import (
3
+	"encoding/json"
4
+	"fmt"
5
+)
6
+
7
+// PluginsListResponse contains the response for the remote API
8
+type PluginsListResponse []*Plugin
9
+
10
+const (
11
+	authzDriver   = "AuthzDriver"
12
+	graphDriver   = "GraphDriver"
13
+	ipamDriver    = "IpamDriver"
14
+	networkDriver = "NetworkDriver"
15
+	volumeDriver  = "VolumeDriver"
16
+)
17
+
18
+// UnmarshalJSON implements json.Unmarshaler for PluginInterfaceType
19
+func (t *PluginInterfaceType) UnmarshalJSON(p []byte) error {
20
+	versionIndex := len(p)
21
+	prefixIndex := 0
22
+	if len(p) < 2 || p[0] != '"' || p[len(p)-1] != '"' {
23
+		return fmt.Errorf("%q is not a plugin interface type", p)
24
+	}
25
+	p = p[1 : len(p)-1]
26
+loop:
27
+	for i, b := range p {
28
+		switch b {
29
+		case '.':
30
+			prefixIndex = i
31
+		case '/':
32
+			versionIndex = i
33
+			break loop
34
+		}
35
+	}
36
+	t.Prefix = string(p[:prefixIndex])
37
+	t.Capability = string(p[prefixIndex+1 : versionIndex])
38
+	if versionIndex < len(p) {
39
+		t.Version = string(p[versionIndex+1:])
40
+	}
41
+	return nil
42
+}
43
+
44
+// MarshalJSON implements json.Marshaler for PluginInterfaceType
45
+func (t *PluginInterfaceType) MarshalJSON() ([]byte, error) {
46
+	return json.Marshal(t.String())
47
+}
48
+
49
+// String implements fmt.Stringer for PluginInterfaceType
50
+func (t PluginInterfaceType) String() string {
51
+	return fmt.Sprintf("%s.%s/%s", t.Prefix, t.Capability, t.Version)
52
+}
53
+
54
+// PluginPrivilege describes a permission the user has to accept
55
+// upon installing a plugin.
56
+type PluginPrivilege struct {
57
+	Name        string
58
+	Description string
59
+	Value       []string
60
+}
61
+
62
+// PluginPrivileges is a list of PluginPrivilege
63
+type PluginPrivileges []PluginPrivilege
... ...
@@ -5,4 +5,5 @@ swagger generate model -f api/swagger.yaml \
5 5
     -t api -m types --skip-validator \
6 6
     -n Volume \
7 7
     -n Port \
8
-    -n ImageSummary
8
+    -n ImageSummary \
9
+    -n Plugin -n PluginDevice -n PluginMount -n PluginEnv -n PluginInterfaceType