This repository has been archived by the owner on Jun 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathroot.go
64 lines (53 loc) · 1.5 KB
/
root.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Package docker presents a filesystem hierarchy for Docker resources.
//
// It uses local socket access or the DOCKER environment variables to
// access the Docker daemon.
package docker
import (
"context"
"github.com/docker/docker/client"
"github.com/puppetlabs/wash/plugin"
)
// DOCKER ROOT
// Root of the Docker plugin
type Root struct {
plugin.EntryBase
resources []plugin.Entry
}
// Init for root
func (r *Root) Init(map[string]interface{}) error {
dockerCli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return err
}
r.EntryBase = plugin.NewEntry("docker")
r.DisableDefaultCaching()
r.resources = []plugin.Entry{
newContainersDir(dockerCli),
newVolumesDir(dockerCli),
}
return nil
}
// Schema returns the root's schema
func (r *Root) Schema() *plugin.EntrySchema {
return plugin.
NewEntrySchema(r, "docker").
SetDescription(rootDescription).
IsSingleton()
}
// ChildSchemas returns the root's child schema
func (r *Root) ChildSchemas() []*plugin.EntrySchema {
return []*plugin.EntrySchema{
(&containersDir{}).Schema(),
(&volumesDir{}).Schema(),
}
}
// List lists the types of resources the Docker plugin exposes.
func (r *Root) List(ctx context.Context) ([]plugin.Entry, error) {
return r.resources, nil
}
const rootDescription = `
This is the Docker plugin root. It lets you interact with Docker resources
like containers and volumes. These resources are found from the Docker socket
or via the DOCKER environment variables.
`