Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Lint
Browse files Browse the repository at this point in the history
Signed-off-by: Olivier Gambier <olivier@docker.com>
  • Loading branch information
Olivier Gambier committed Nov 5, 2015
1 parent 24da8ad commit d2ada64
Show file tree
Hide file tree
Showing 53 changed files with 240 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -2,4 +2,4 @@ sudo: required
dist: trusty
language: bash
services: docker
script: USE_CONTAINER=true make dco fmt vet test-short test-long coverage-send
script: USE_CONTAINER=true make dco fmt lint vet test-short test-long coverage-send
4 changes: 2 additions & 2 deletions commands/commands.go
Expand Up @@ -475,7 +475,7 @@ func runActionWithContext(actionName string, c CommandLine) error {
// codegangsta/cli will not set the cert paths if the storage-path is set to
// something different so we cannot use the paths in the global options. le
// sigh.
func getCertPathInfoFromContext(c CommandLine) cert.CertPathInfo {
func getCertPathInfoFromContext(c CommandLine) cert.PathInfo {
caCertPath := c.GlobalString("tls-ca-cert")
caKeyPath := c.GlobalString("tls-ca-key")
clientCertPath := c.GlobalString("tls-client-cert")
Expand All @@ -497,7 +497,7 @@ func getCertPathInfoFromContext(c CommandLine) cert.CertPathInfo {
clientKeyPath = filepath.Join(mcndirs.GetMachineCertDir(), "key.pem")
}

return cert.CertPathInfo{
return cert.PathInfo{
CaCertPath: caCertPath,
CaPrivateKeyPath: caKeyPath,
ClientCertPath: clientCertPath,
Expand Down
36 changes: 18 additions & 18 deletions commands/config.go
Expand Up @@ -16,14 +16,14 @@ import (
// ErrCertInvalid for when the cert is computed to be invalid.
type ErrCertInvalid struct {
wrappedErr error
hostUrl string
hostURL string
}

func (e ErrCertInvalid) Error() string {
return fmt.Sprintf(`There was an error validating certificates for host %q: %s
You can attempt to regenerate them using 'docker-machine regenerate-certs name'.
Be advised that this will trigger a Docker daemon restart which will stop running containers.
`, e.hostUrl, e.wrappedErr)
`, e.hostURL, e.wrappedErr)
}

func cmdConfig(c CommandLine) error {
Expand Down Expand Up @@ -53,58 +53,58 @@ func cmdConfig(c CommandLine) error {
return nil
}

func runConnectionBoilerplate(h *host.Host, c CommandLine) (string, *auth.AuthOptions, error) {
func runConnectionBoilerplate(h *host.Host, c CommandLine) (string, *auth.Options, error) {
hostState, err := h.Driver.GetState()
if err != nil {
// TODO: This is a common operation and should have a commonly
// defined error.
return "", &auth.AuthOptions{}, fmt.Errorf("Error trying to get host state: %s", err)
return "", &auth.Options{}, fmt.Errorf("Error trying to get host state: %s", err)
}
if hostState != state.Running {
return "", &auth.AuthOptions{}, fmt.Errorf("%s is not running. Please start it in order to use the connection settings", h.Name)
return "", &auth.Options{}, fmt.Errorf("%s is not running. Please start it in order to use the connection settings", h.Name)
}

dockerHost, err := h.Driver.GetURL()
if err != nil {
return "", &auth.AuthOptions{}, fmt.Errorf("Error getting driver URL: %s", err)
return "", &auth.Options{}, fmt.Errorf("Error getting driver URL: %s", err)
}

if c.Bool("swarm") {
var err error
dockerHost, err = parseSwarm(dockerHost, h)
if err != nil {
return "", &auth.AuthOptions{}, fmt.Errorf("Error parsing swarm: %s", err)
return "", &auth.Options{}, fmt.Errorf("Error parsing swarm: %s", err)
}
}

u, err := url.Parse(dockerHost)
if err != nil {
return "", &auth.AuthOptions{}, fmt.Errorf("Error parsing URL: %s", err)
return "", &auth.Options{}, fmt.Errorf("Error parsing URL: %s", err)
}

authOptions := h.HostOptions.AuthOptions

if err := checkCert(u.Host, authOptions); err != nil {
return "", &auth.AuthOptions{}, fmt.Errorf("Error checking and/or regenerating the certs: %s", err)
return "", &auth.Options{}, fmt.Errorf("Error checking and/or regenerating the certs: %s", err)
}

return dockerHost, authOptions, nil
}

func checkCert(hostUrl string, authOptions *auth.AuthOptions) error {
valid, err := cert.ValidateCertificate(hostUrl, authOptions)
func checkCert(hostURL string, authOptions *auth.Options) error {
valid, err := cert.ValidateCertificate(hostURL, authOptions)
if !valid || err != nil {
return ErrCertInvalid{
wrappedErr: err,
hostUrl: hostUrl,
hostURL: hostURL,
}
}

return nil
}

// TODO: This could use a unit test.
func parseSwarm(hostUrl string, h *host.Host) (string, error) {
func parseSwarm(hostURL string, h *host.Host) (string, error) {
swarmOptions := h.HostOptions.SwarmOptions

if !swarmOptions.Master {
Expand All @@ -119,15 +119,15 @@ func parseSwarm(hostUrl string, h *host.Host) (string, error) {
swarmPort := parts[1]

// get IP of machine to replace in case swarm host is 0.0.0.0
mUrl, err := url.Parse(hostUrl)
mURL, err := url.Parse(hostURL)
if err != nil {
return "", fmt.Errorf("There was an error parsing the url: %s", err)
}

mParts := strings.Split(mUrl.Host, ":")
machineIp := mParts[0]
mParts := strings.Split(mURL.Host, ":")
machineIP := mParts[0]

hostUrl = fmt.Sprintf("tcp://%s:%s", machineIp, swarmPort)
hostURL = fmt.Sprintf("tcp://%s:%s", machineIP, swarmPort)

return hostUrl, nil
return hostURL, nil
}
14 changes: 7 additions & 7 deletions commands/config_test.go
Expand Up @@ -26,29 +26,29 @@ func (fcg FakeCertGenerator) GenerateCert(hosts []string, certFile, keyFile, caF
return nil
}

func (fcg FakeCertGenerator) ValidateCertificate(addr string, authOptions *auth.AuthOptions) (bool, error) {
func (fcg FakeCertGenerator) ValidateCertificate(addr string, authOptions *auth.Options) (bool, error) {
return fcg.fakeValidateCertificate.IsValid, fcg.fakeValidateCertificate.Err
}

func TestCheckCert(t *testing.T) {
errCertsExpired := errors.New("Certs have expired")

cases := []struct {
hostUrl string
authOptions *auth.AuthOptions
hostURL string
authOptions *auth.Options
valid bool
checkErr error
expectedErr error
}{
{"192.168.99.100:2376", &auth.AuthOptions{}, true, nil, nil},
{"192.168.99.100:2376", &auth.AuthOptions{}, false, nil, ErrCertInvalid{wrappedErr: nil, hostUrl: "192.168.99.100:2376"}},
{"192.168.99.100:2376", &auth.AuthOptions{}, false, errCertsExpired, ErrCertInvalid{wrappedErr: errCertsExpired, hostUrl: "192.168.99.100:2376"}},
{"192.168.99.100:2376", &auth.Options{}, true, nil, nil},
{"192.168.99.100:2376", &auth.Options{}, false, nil, ErrCertInvalid{wrappedErr: nil, hostURL: "192.168.99.100:2376"}},
{"192.168.99.100:2376", &auth.Options{}, false, errCertsExpired, ErrCertInvalid{wrappedErr: errCertsExpired, hostURL: "192.168.99.100:2376"}},
}

for _, c := range cases {
fcg := FakeCertGenerator{fakeValidateCertificate: &FakeValidateCertificate{c.valid, c.checkErr}}
cert.SetCertGenerator(fcg)
err := checkCert(c.hostUrl, c.authOptions)
err := checkCert(c.hostURL, c.authOptions)
assert.Equal(t, c.expectedErr, err)
}
}
10 changes: 5 additions & 5 deletions commands/create.go
Expand Up @@ -168,8 +168,8 @@ func cmdCreateInner(c CommandLine) error {
return fmt.Errorf("Error getting new host: %s", err)
}

h.HostOptions = &host.HostOptions{
AuthOptions: &auth.AuthOptions{
h.HostOptions = &host.Options{
AuthOptions: &auth.Options{
CertDir: mcndirs.GetMachineCertDir(),
CaCertPath: certInfo.CaCertPath,
CaPrivateKeyPath: certInfo.CaPrivateKeyPath,
Expand All @@ -179,17 +179,17 @@ func cmdCreateInner(c CommandLine) error {
ServerKeyPath: filepath.Join(mcndirs.GetMachineDir(), name, "server-key.pem"),
StorePath: filepath.Join(mcndirs.GetMachineDir(), name),
},
EngineOptions: &engine.EngineOptions{
EngineOptions: &engine.Options{
ArbitraryFlags: c.StringSlice("engine-opt"),
Env: c.StringSlice("engine-env"),
InsecureRegistry: c.StringSlice("engine-insecure-registry"),
Labels: c.StringSlice("engine-label"),
RegistryMirror: c.StringSlice("engine-registry-mirror"),
StorageDriver: c.String("engine-storage-driver"),
TlsVerify: true,
TLSVerify: true,
InstallURL: c.String("engine-install-url"),
},
SwarmOptions: &swarm.SwarmOptions{
SwarmOptions: &swarm.Options{
IsSwarm: c.Bool("swarm"),
Image: c.String("swarm-image"),
Master: c.Bool("swarm-master"),
Expand Down
2 changes: 1 addition & 1 deletion commands/ls.go
Expand Up @@ -36,7 +36,7 @@ type HostListItem struct {
DriverName string
State state.State
URL string
SwarmOptions *swarm.SwarmOptions
SwarmOptions *swarm.Options
}

func cmdLs(c CommandLine) error {
Expand Down

0 comments on commit d2ada64

Please sign in to comment.