Skip to content

Commit 011e905

Browse files
committed
[Fix] method/type comments & some bug fixes
1 parent e4f49da commit 011e905

File tree

1 file changed

+81
-73
lines changed

1 file changed

+81
-73
lines changed

plugin.go

Lines changed: 81 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,23 @@ type PluginPrivilege struct {
2020
Value []string `json:"Value,omitempty" yaml:"Value,omitempty" toml:"Value,omitempty"`
2121
}
2222

23-
// InstallPluginOptions .This is a TBD Comments.
23+
// InstallPluginOptions
2424
//
25-
// See https://goo.gl/kaOHGw for more details.
25+
// See https://goo.gl/C4t7Tz for more details.
2626
type InstallPluginOptions struct {
2727
Remote string
2828
Name string
29-
Plugins []PluginPrivilege
29+
Plugins []PluginPrivilege `qs:"-"`
30+
31+
Auth AuthConfiguration
32+
3033
Context context.Context
3134
}
3235

33-
// InstallPlugins returns a slice of containers matching the given criteria.
36+
// InstallPlugins installs a plugin or returns an error in case of failure.
3437
//
35-
// See https://goo.gl/kaOHGw for more details.
36-
func (c *Client) InstallPlugins(opts InstallPluginOptions, auth AuthConfiguration) error {
38+
// See https://goo.gl/C4t7Tz for more details.
39+
func (c *Client) InstallPlugins(opts InstallPluginOptions) error {
3740
params := make(url.Values)
3841
params.Set("remote", opts.Remote)
3942
if opts.Name != "" {
@@ -51,80 +54,80 @@ func (c *Client) InstallPlugins(opts InstallPluginOptions, auth AuthConfiguratio
5154
return nil
5255
}
5356

54-
// PluginSetting .This is a TBD Comments.
57+
// PluginSetting stores plugin settings.
5558
//
56-
// See https://goo.gl/kaOHGw for more details.
57-
type PluginSetting struct {
59+
// See https://goo.gl/C4t7Tz for more details.
60+
type PluginSettings struct {
5861
Env []string `json:"Env,omitempty" yaml:"Env,omitempty" toml:"Env,omitempty"`
5962
Args []string `json:"Args,omitempty" yaml:"Args,omitempty" toml:"Args,omitempty"`
6063
Devices []string `json:"Devices,omitempty" yaml:"Devices,omitempty" toml:"Devices,omitempty"`
6164
}
6265

63-
// PluginInterface .This is a TBD Comments.
66+
// PluginInterface stores plugin interface.
6467
//
65-
// See https://goo.gl/kaOHGw for more details.
68+
// See https://goo.gl/C4t7Tz for more details.
6669
type PluginInterface struct {
6770
Types []string `json:"Types,omitempty" yaml:"Types,omitempty" toml:"Types,omitempty"`
6871
Socket string `json:"Socket,omitempty" yaml:"Socket,omitempty" toml:"Socket,omitempty"`
6972
}
7073

71-
// PluginNetwork .This is a TBD Comments.
74+
// PluginNetwork stores plugin network type.
7275
//
73-
// See https://goo.gl/kaOHGw for more details.
76+
// See https://goo.gl/C4t7Tz for more details.
7477
type PluginNetwork struct {
7578
Type string `json:"Type,omitempty" yaml:"Type,omitempty" toml:"Type,omitempty"`
7679
}
7780

78-
// PluginLinux .This is a TBD Comments.
81+
// PluginLinux stores plugin linux setting.
7982
//
80-
// See https://goo.gl/kaOHGw for more details.
83+
// See https://goo.gl/C4t7Tz for more details.
8184
type PluginLinux struct {
8285
Capabilities []string `json:"Capabilities,omitempty" yaml:"Capabilities,omitempty" toml:"Capabilities,omitempty"`
8386
AllowAllDevices bool `json:"AllowAllDevices,omitempty" yaml:"AllowAllDevices,omitempty" toml:"AllowAllDevices,omitempty"`
8487
Devices []PluginLinuxDevices `json:"Devices,omitempty" yaml:"Devices,omitempty" toml:"Devices,omitempty"`
8588
}
8689

87-
// PluginLinuxDevices .This is a TBD Comments.
90+
// PluginLinuxDevices stores plugin linux device setting.
8891
//
89-
// See https://goo.gl/kaOHGw for more details.
92+
// See https://goo.gl/C4t7Tz for more details.
9093
type PluginLinuxDevices struct {
9194
Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
9295
Description string `json:"Documentation,omitempty" yaml:"Documentation,omitempty" toml:"Documentation,omitempty"`
9396
Settable []string `json:"Settable,omitempty" yaml:"Settable,omitempty" toml:"Settable,omitempty"`
9497
Path string `json:"Path,omitempty" yaml:"Path,omitempty" toml:"Path,omitempty"`
9598
}
9699

97-
// PluginEnv .This is a TBD Comments.
100+
// PluginEnv stores plugin environment.
98101
//
99-
// See https://goo.gl/kaOHGw for more details.
102+
// See https://goo.gl/C4t7Tz for more details.
100103
type PluginEnv struct {
101104
Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
102105
Description string `json:"Description,omitempty" yaml:"Description,omitempty" toml:"Description,omitempty"`
103106
Settable []string `json:"Settable,omitempty" yaml:"Settable,omitempty" toml:"Settable,omitempty"`
104107
Value string `json:"Value,omitempty" yaml:"Value,omitempty" toml:"Value,omitempty"`
105108
}
106109

107-
// PluginArgs .This is a TBD Comments.
110+
// PluginArgs stores plugin arguments.
108111
//
109-
// See https://goo.gl/kaOHGw for more details.
112+
// See https://goo.gl/C4t7Tz for more details.
110113
type PluginArgs struct {
111114
Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
112115
Description string `json:"Description,omitempty" yaml:"Description,omitempty" toml:"Description,omitempty"`
113116
Settable []string `json:"Settable,omitempty" yaml:"Settable,omitempty" toml:"Settable,omitempty"`
114117
Value []string `json:"Value,omitempty" yaml:"Value,omitempty" toml:"Value,omitempty"`
115118
}
116119

117-
// PluginUser .This is a TBD Comments.
120+
// PluginUser stores plugin user.
118121
//
119-
// See https://goo.gl/kaOHGw for more details.
122+
// See https://goo.gl/C4t7Tz for more details.
120123
type PluginUser struct {
121124
UID int32 `json:"UID,omitempty" yaml:"UID,omitempty" toml:"UID,omitempty"`
122125
GID int32 `json:"GID,omitempty" yaml:"GID,omitempty" toml:"GID,omitempty"`
123126
}
124127

125-
// PluginConfig .This is a TBD Comments.
128+
// PluginConfig stores plugin config.
126129
//
127-
// See https://goo.gl/kaOHGw for more details.
130+
// See https://goo.gl/C4t7Tz for more details.
128131
type PluginConfig struct {
129132
Description string `json:"Description,omitempty" yaml:"Description,omitempty" toml:"Description,omitempty"`
130133
Documentation string
@@ -140,23 +143,26 @@ type PluginConfig struct {
140143
Args PluginArgs `json:"Args,omitempty" yaml:"Args,omitempty" toml:"Args,omitempty"`
141144
}
142145

143-
// PluginDetail .This is a TBD Comments.
146+
// PluginDetail specify results from the ListPlugins function.
144147
//
145-
// See https://goo.gl/kaOHGw for more details.
148+
// See https://goo.gl/C4t7Tz for more details.
146149
type PluginDetail struct {
147150
ID string `json:"Id,omitempty" yaml:"Id,omitempty" toml:"Id,omitempty"`
148151
Name string `json:"Name,omitempty" yaml:"Name,omitempty" toml:"Name,omitempty"`
149152
Tag string `json:"Tag,omitempty" yaml:"Tag,omitempty" toml:"Tag,omitempty"`
150153
Active bool `json:"Active,omitempty" yaml:"Active,omitempty" toml:"Active,omitempty"`
151-
Settings PluginSetting `json:"Settings,omitempty" yaml:"Settings,omitempty" toml:"Settings,omitempty"`
154+
Settings PluginSettings `json:"Settings,omitempty" yaml:"Settings,omitempty" toml:"Settings,omitempty"`
152155
Config PluginConfig `json:"Config,omitempty" yaml:"Config,omitempty" toml:"Config,omitempty"`
153156
}
154157

155-
// ListPlugins .This is a TBD Comments.
158+
// ListPlugins returns pluginDetails or an error.
156159
//
157-
// See https://goo.gl/kaOHGw for more details.
158-
func (c *Client) ListPlugins() ([]PluginDetail, error) {
159-
resp, err := c.do("GET", "/plugins", doOptions{})
160+
// See https://goo.gl/C4t7Tz for more details.
161+
func (c *Client) ListPlugins(ctx context.Context) ([]PluginDetail, error) {
162+
resp, err := c.do("GET", "/plugins", doOptions{
163+
context:ctx,
164+
165+
})
160166
if err != nil {
161167
return nil, err
162168
}
@@ -168,11 +174,13 @@ func (c *Client) ListPlugins() ([]PluginDetail, error) {
168174
return pluginDetails, nil
169175
}
170176

171-
// GetPluginPrivileges .This is a TBD Comments.
177+
// GetPluginPrivileges returns pulginPrivileges or an error.
172178
//
173-
// See https://goo.gl/kaOHGw for more details.
174-
func (c *Client) GetPluginPrivileges(name string) ([]PluginPrivilege, error) {
175-
resp, err := c.do("GET", "/plugins/privileges?"+name, doOptions{})
179+
// See https://goo.gl/C4t7Tz for more details.
180+
func (c *Client) GetPluginPrivileges(name string,ctx context.Context) ([]PluginPrivilege, error) {
181+
resp, err := c.do("GET", "/plugins/privileges?remote="+name, doOptions{
182+
context:ctx,
183+
})
176184
if err != nil {
177185
return nil, err
178186
}
@@ -184,11 +192,13 @@ func (c *Client) GetPluginPrivileges(name string) ([]PluginPrivilege, error) {
184192
return pluginPrivileges, nil
185193
}
186194

187-
// InspectPlugins .This is a TBD Comments.
195+
// InspectPlugins returns a pluginDetail or an error.
188196
//
189-
// See https://goo.gl/kaOHGw for more details.
190-
func (c *Client) InspectPlugins(name string) (*PluginDetail, error) {
191-
resp, err := c.do("GET", "/plugins/"+name+"/json", doOptions{})
197+
// See https://goo.gl/C4t7Tz for more details.
198+
func (c *Client) InspectPlugins(name string, ctx context.Context) (*PluginDetail, error) {
199+
resp, err := c.do("GET", "/plugins/"+name+"/json", doOptions{
200+
context:ctx,
201+
})
192202
if err != nil {
193203
return nil, err
194204
}
@@ -207,22 +217,20 @@ func (c *Client) InspectPlugins(name string) (*PluginDetail, error) {
207217
return &pluginDetail, nil
208218
}
209219

210-
// RemovePluginOptions .This is a TBD Comments.
220+
// RemovePluginOptions specify parameters to the RemovePlugin function.
211221
//
212-
// See https://goo.gl/kaOHGw for more details.
222+
// See https://goo.gl/C4t7Tz for more details.
213223
type RemovePluginOptions struct {
214-
// The ID of the container.
224+
// The Name of the plugin.
215225
Name string `qs:"-"`
216226

217-
// A flag that indicates whether Docker should remove the plugin
218-
// even if it is currently used.
219227
Force bool `qs:"force"`
220228
Context context.Context
221229
}
222230

223-
// RemovePlugin .This is a TBD Comments.
231+
// RemovePlugin returns a PluginDetail or an error.
224232
//
225-
// See https://goo.gl/kaOHGw for more details.
233+
// See https://goo.gl/C4t7Tz for more details.
226234
func (c *Client) RemovePlugin(opts RemovePluginOptions) (*PluginDetail, error) {
227235
path := "/plugins/" + opts.Name + "?" + queryString(opts)
228236
resp, err := c.do("DELETE", path, doOptions{context: opts.Context})
@@ -244,20 +252,20 @@ func (c *Client) RemovePlugin(opts RemovePluginOptions) (*PluginDetail, error) {
244252
return &pluginDetail, nil
245253
}
246254

247-
// EnablePluginOptions .This is a TBD Comments.
255+
// EnablePluginOptions specify parameters to the EnablePlugin function.
248256
//
249-
// See https://goo.gl/kaOHGw for more details.
257+
// See https://goo.gl/C4t7Tz for more details.
250258
type EnablePluginOptions struct {
251-
// The ID of the container.
259+
// The Name of the plugin.
252260
Name string `qs:"-"`
253261
Timeout int64 `qs:"timeout"`
254262

255263
Context context.Context
256264
}
257265

258-
// EnablePlugin .This is a TBD Comments.
266+
// EnablePlugin enables plugin that opts point or returns an error.
259267
//
260-
// See https://goo.gl/kaOHGw for more details.
268+
// See https://goo.gl/C4t7Tz for more details.
261269
func (c *Client) EnablePlugin(opts EnablePluginOptions) error {
262270
path := "/plugins/" + opts.Name + "/enable?" + queryString(opts)
263271
resp, err := c.do("POST", path, doOptions{context: opts.Context})
@@ -269,19 +277,19 @@ func (c *Client) EnablePlugin(opts EnablePluginOptions) error {
269277
return nil
270278
}
271279

272-
// DisablePluginOptions .This is a TBD Comments.
280+
// DisablePluginOptions specify parameters to the DisablePlugin function.
273281
//
274-
// See https://goo.gl/kaOHGw for more details.
282+
// See https://goo.gl/C4t7Tz for more details.
275283
type DisablePluginOptions struct {
276-
// The ID of the container.
284+
// The Name of the plugin.
277285
Name string `qs:"-"`
278286

279287
Context context.Context
280288
}
281289

282-
// DisablePlugin .This is a TBD Comments.
290+
// DisablePlugin disables plugin that opts point or returns an error.
283291
//
284-
// See https://goo.gl/kaOHGw for more details.
292+
// See https://goo.gl/C4t7Tz for more details.
285293
func (c *Client) DisablePlugin(opts DisablePluginOptions) error {
286294
path := "/plugins/" + opts.Name + "/disable"
287295
resp, err := c.do("POST", path, doOptions{context: opts.Context})
@@ -293,23 +301,23 @@ func (c *Client) DisablePlugin(opts DisablePluginOptions) error {
293301
return nil
294302
}
295303

296-
// CreatePluginOptions .This is a TBD Comments.
304+
// CreatePluginOptions specify parameters to the CreatePlugin function.
297305
//
298-
// See https://goo.gl/kaOHGw for more details.
306+
// See https://goo.gl/C4t7Tz for more details.
299307
type CreatePluginOptions struct {
300-
// The Name of the container.
308+
// The Name of the plugin.
301309
Name string `qs:"name"`
302310
// Path to tar containing plugin
303311
Path string `qs:"-"`
304312

305313
Context context.Context
306314
}
307315

308-
// CreatePlugin .This is a TBD Comments.
316+
// CreatePlugin creates plugin that opts point or returns an error.
309317
//
310-
// See https://goo.gl/kaOHGw for more details.
318+
// See https://goo.gl/C4t7Tz for more details.
311319
func (c *Client) CreatePlugin(opts CreatePluginOptions) (string, error) {
312-
path := "/plugins/create?" + queryString(opts.Name)
320+
path := "/plugins/create?" + queryString(opts)
313321
resp, err := c.do("POST", path, doOptions{
314322
data: opts.Path,
315323
context: opts.Context})
@@ -324,19 +332,19 @@ func (c *Client) CreatePlugin(opts CreatePluginOptions) (string, error) {
324332
return string(containerNameBytes), nil
325333
}
326334

327-
// PushPluginOptions .This is a TBD Comments.
335+
// PushPluginOptions specify parameters to PushPlugin function.
328336
//
329-
// See https://goo.gl/kaOHGw for more details.
337+
// See https://goo.gl/C4t7Tz for more details.
330338
type PushPluginOptions struct {
331-
// The Name of the container.
339+
// The Name of the plugin.
332340
Name string
333341

334342
Context context.Context
335343
}
336344

337-
// PushPlugin .This is a TBD Comments.
345+
// PushPlugin pushes plugin that opts point or returns an error.
338346
//
339-
// See https://goo.gl/kaOHGw for more details.
347+
// See https://goo.gl/C4t7Tz for more details.
340348
func (c *Client) PushPlugin(opts PushPluginOptions) error {
341349
path := "/plugins/" + opts.Name + "/push"
342350
resp, err := c.do("POST", path, doOptions{context: opts.Context})
@@ -347,20 +355,20 @@ func (c *Client) PushPlugin(opts PushPluginOptions) error {
347355
return nil
348356
}
349357

350-
// ConfigurePluginOptions .This is a TBD Comments.
358+
// ConfigurePluginOptions specify parameters to the ConfigurePlugin
351359
//
352-
// See https://goo.gl/kaOHGw for more details.
360+
// See https://goo.gl/C4t7Tz for more details.
353361
type ConfigurePluginOptions struct {
354-
// The Name of the container.
362+
// The Name of the plugin.
355363
Name string `qs:"name"`
356364
Envs []string
357365

358366
Context context.Context
359367
}
360368

361-
// ConfigurePlugin .This is a TBD Comments.
369+
// ConfigurePlugin configures plugin that opts point or returns an error.
362370
//
363-
// See https://goo.gl/kaOHGw for more details.
371+
// See https://goo.gl/C4t7Tz for more details.
364372
func (c *Client) ConfigurePlugin(opts ConfigurePluginOptions) error {
365373
path := "/plugins/" + opts.Name + "/set"
366374
resp, err := c.do("POST", path, doOptions{

0 commit comments

Comments
 (0)