This repository has been archived by the owner on Oct 2, 2022. It is now read-only.
generated from ContainerSSH/library-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathconfig_dockerrun.go
97 lines (84 loc) · 2.99 KB
/
config_dockerrun.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package docker
import (
"bytes"
"encoding/json"
"fmt"
"time"
"github.com/containerssh/log"
"gopkg.in/yaml.v3"
)
// Validate validates the docker run config
//goland:noinspection GoDeprecation
func (config DockerRunConfig) Validate() error {
if config.Host == "" {
return log.NewMessage(EConfigError, "empty Docker host provided")
}
if err := config.Config.Validate(); err != nil {
return fmt.Errorf("invalid dockerrun config (%w)", err)
}
return nil
}
//Deprecated: Switch to the more generic "docker" backend.
//goland:noinspection GoNameStartsWithPackageName,GoDeprecation
type DockerRunContainerConfig struct {
LaunchConfig `json:",inline,omitempty" yaml:",inline,omitempty"`
Subsystems map[string]string `json:"subsystems,omitempty" yaml:"subsystems,omitempty" comment:"Subsystem names and binaries map." default:"{\"sftp\":\"/usr/lib/openssh/sftp-server\"}"`
DisableCommand bool `json:"disableCommand,omitempty" yaml:"disableCommand,omitempty" comment:"Disable command execution passed from SSH"`
Timeout time.Duration `json:"timeout,omitempty" yaml:"timeout,omitempty" comment:"Timeout for pod creation" default:"60s"`
}
//goland:noinspection GoDeprecation
func (d *DockerRunContainerConfig) UnmarshalJSON(b []byte) error {
decoder := json.NewDecoder(bytes.NewReader(b))
tmp := &tmpDockerRunContainerConfig{}
if err := decoder.Decode(tmp); err != nil {
return err
}
d.DisableCommand = tmp.DisableCommand
if err := parseRawDuration(tmp.Timeout, &d.Timeout); err != nil {
return err
}
d.Subsystems = tmp.Subsystems
lc := LaunchConfig{}
decoder = json.NewDecoder(bytes.NewReader(b))
if err := decoder.Decode(&lc); err != nil {
return err
}
d.LaunchConfig = lc
return nil
}
//goland:noinspection GoDeprecation
func (d *DockerRunContainerConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
raw := &map[string]interface{}{}
if err := unmarshal(raw); err != nil {
return err
}
substructure, err := yaml.Marshal(raw)
if err != nil {
return err
}
tmp := &tmpDockerRunContainerConfig{}
if err = yaml.Unmarshal(substructure, tmp); err != nil {
return err
}
d.DisableCommand = tmp.DisableCommand
if err := parseRawDuration(tmp.Timeout, &d.Timeout); err != nil {
return err
}
d.Subsystems = tmp.Subsystems
lc := LaunchConfig{}
if err := unmarshal(&lc); err != nil {
return err
}
d.LaunchConfig = lc
return nil
}
// Validate validates the container config
//goland:noinspection GoDeprecation
func (d *DockerRunContainerConfig) Validate() error {
return d.LaunchConfig.Validate()
}
type tmpDockerRunContainerConfig struct {
Subsystems map[string]string `json:"subsystems" yaml:"subsystems" comment:"Subsystem names and binaries map." default:"{\"sftp\":\"/usr/lib/openssh/sftp-server\"}"`
DisableCommand bool `json:"disableCommand" yaml:"disableCommand" comment:"Disable command execution passed from SSH"`
Timeout interface{} `json:"timeout" yaml:"timeout" comment:"Timeout for pod creation" default:"60s"`
}