Skip to content
This repository has been archived by the owner on Oct 2, 2022. It is now read-only.

Commit

Permalink
0.9.6: Added Validate() for DockerRun
Browse files Browse the repository at this point in the history
This release adds a `Validate()` method for the DockerRun backend.
  • Loading branch information
Janos Pasztor committed Dec 30, 2020
1 parent c18fcb9 commit d572234
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 0.9.6: Added Validate() for DockerRun

This release adds a `Validate()` method for the DockerRun backend.

## 0.9.5: Metrics integration

This release integrates the [metrics library](https://github.com/containerssh/metrics) and adds two parameters to `New` and `NewDockerRun` methods:
Expand Down
20 changes: 19 additions & 1 deletion config_dockerrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,24 @@ package docker
import (
"bytes"
"encoding/json"
"fmt"
"time"

"gopkg.in/yaml.v3"
)

//goland:noinspection GoNameStartsWithPackageName
// Validate validates the docker run config
//goland:noinspection GoDeprecation
func (config DockerRunConfig) Validate() error {
if config.Host == "" {
return fmt.Errorf("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 {
Expand Down Expand Up @@ -71,6 +83,12 @@ func (d *DockerRunContainerConfig) UnmarshalYAML(unmarshal func(interface{}) err
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"`
Expand Down
4 changes: 3 additions & 1 deletion config_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ func (c ExecutionConfig) Validate() error {
if err := c.ImagePullPolicy.Validate(); err != nil {
return err
}

if err := c.Launch.Validate(); err != nil {
return err
}
if err := c.Mode.Validate(); err != nil {
return err
}
Expand Down
12 changes: 12 additions & 0 deletions config_launch.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package docker
import (
"bytes"
"encoding/json"
"fmt"

"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/network"
Expand Down Expand Up @@ -79,3 +80,14 @@ func (l *LaunchConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
l.ContainerName = tmp.ContainerName
return nil
}

// Validate validates the launch configuration.
func (l *LaunchConfig) Validate() error {
if l.ContainerConfig == nil {
return fmt.Errorf("no container config provided")
}
if l.ContainerConfig.Image == "" {
return fmt.Errorf("no image name provided")
}
return nil
}
1 change: 1 addition & 0 deletions factory_dockerrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
)

// NewDockerRun creates a new NetworkConnectionHandler based on the deprecated "dockerrun" config structure.
// Deprecated: use New instead
//goland:noinspection GoDeprecation
func NewDockerRun(
client net.TCPAddr,
Expand Down

0 comments on commit d572234

Please sign in to comment.