1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/vendor/github.com/docker/swarmkit/template/getter.go
Ying Li 4509a001df Re-vendor swarmkit. This includes the following fixes:
- https://github.com/docker/swarmkit/pull/2266 (support for templating Node.Hostname in docker executor)
- https://github.com/docker/swarmkit/pull/2281 (change restore action on objects to be update, not delete/create)
- https://github.com/docker/swarmkit/pull/2285 (extend watch queue with timeout and size limit)
- https://github.com/docker/swarmkit/pull/2253 (version-aware failure tracking in the scheduler)
- https://github.com/docker/swarmkit/pull/2275 (update containerd and port executor to container client library)
- https://github.com/docker/swarmkit/pull/2292 (rename some generic resources)
- https://github.com/docker/swarmkit/pull/2300 (limit the size of the external CA response)
- https://github.com/docker/swarmkit/pull/2301 (delete global tasks when the node running them is deleted)

Minor cleanups, dependency bumps, and vendoring:
- https://github.com/docker/swarmkit/pull/2271
- https://github.com/docker/swarmkit/pull/2279
- https://github.com/docker/swarmkit/pull/2283
- https://github.com/docker/swarmkit/pull/2282
- https://github.com/docker/swarmkit/pull/2274
- https://github.com/docker/swarmkit/pull/2296 (dependency bump of etcd, go-winio)

Signed-off-by: Ying Li <ying.li@docker.com>
2017-07-11 13:43:43 -07:00

100 lines
2.8 KiB
Go

package template
import (
"github.com/docker/swarmkit/agent/exec"
"github.com/docker/swarmkit/api"
"github.com/pkg/errors"
)
type templatedSecretGetter struct {
dependencies exec.DependencyGetter
t *api.Task
node *api.NodeDescription
}
// NewTemplatedSecretGetter returns a SecretGetter that evaluates templates.
func NewTemplatedSecretGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.SecretGetter {
return templatedSecretGetter{dependencies: dependencies, t: t, node: node}
}
func (t templatedSecretGetter) Get(secretID string) (*api.Secret, error) {
if t.dependencies == nil {
return nil, errors.New("no secret provider available")
}
secrets := t.dependencies.Secrets()
if secrets == nil {
return nil, errors.New("no secret provider available")
}
secret, err := secrets.Get(secretID)
if err != nil {
return secret, err
}
newSpec, err := ExpandSecretSpec(secret, t.node, t.t, t.dependencies)
if err != nil {
return secret, errors.Wrapf(err, "failed to expand templated secret %s", secretID)
}
secretCopy := *secret
secretCopy.Spec = *newSpec
return &secretCopy, nil
}
type templatedConfigGetter struct {
dependencies exec.DependencyGetter
t *api.Task
node *api.NodeDescription
}
// NewTemplatedConfigGetter returns a ConfigGetter that evaluates templates.
func NewTemplatedConfigGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.ConfigGetter {
return templatedConfigGetter{dependencies: dependencies, t: t, node: node}
}
func (t templatedConfigGetter) Get(configID string) (*api.Config, error) {
if t.dependencies == nil {
return nil, errors.New("no config provider available")
}
configs := t.dependencies.Configs()
if configs == nil {
return nil, errors.New("no config provider available")
}
config, err := configs.Get(configID)
if err != nil {
return config, err
}
newSpec, err := ExpandConfigSpec(config, t.node, t.t, t.dependencies)
if err != nil {
return config, errors.Wrapf(err, "failed to expand templated config %s", configID)
}
configCopy := *config
configCopy.Spec = *newSpec
return &configCopy, nil
}
type templatedDependencyGetter struct {
secrets exec.SecretGetter
configs exec.ConfigGetter
}
// NewTemplatedDependencyGetter returns a DependencyGetter that evaluates templates.
func NewTemplatedDependencyGetter(dependencies exec.DependencyGetter, t *api.Task, node *api.NodeDescription) exec.DependencyGetter {
return templatedDependencyGetter{
secrets: NewTemplatedSecretGetter(dependencies, t, node),
configs: NewTemplatedConfigGetter(dependencies, t, node),
}
}
func (t templatedDependencyGetter) Secrets() exec.SecretGetter {
return t.secrets
}
func (t templatedDependencyGetter) Configs() exec.ConfigGetter {
return t.configs
}