Skip to content

Commit

Permalink
Merge pull request #1284 from jeffreyhuang23/issue-1200
Browse files Browse the repository at this point in the history
Fixed issue #1200 (buildctl: add --tlsdir)
  • Loading branch information
AkihiroSuda authored Dec 13, 2019
2 parents 6e62650 + 783a723 commit 1dfd864
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
41 changes: 38 additions & 3 deletions cmd/buildctl/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ package common
import (
"context"
"net/url"
"os"
"path/filepath"
"time"

"github.com/moby/buildkit/client"
opentracing "github.com/opentracing/opentracing-go"
"github.com/pkg/errors"
"github.com/urfave/cli"
)

Expand All @@ -21,9 +24,41 @@ func ResolveClient(c *cli.Context) (*client.Client, error) {
}
serverName = uri.Hostname()
}
caCert := c.GlobalString("tlscacert")
cert := c.GlobalString("tlscert")
key := c.GlobalString("tlskey")

var caCert string
var cert string
var key string

tlsDir := c.GlobalString("tlsdir")

if tlsDir != "" {
// Look for ca.pem and, if it exists, set caCert to that
// Look for cert.pem and, if it exists, set key to that
// Look for key.pem and, if it exists, set tlsDir to that
for _, v := range [3]string{"ca.pem", "cert.pem", "key.pem"} {
file := filepath.Join(tlsDir, v)
if _, err := os.Stat(file); err == nil {
switch v {
case "ca.pem":
caCert = file
case "cert.pem":
cert = file
case "key.pem":
key = file
}
} else {
return nil, err
}
}

if c.GlobalString("tlscacert") != "" || c.GlobalString("tlscert") != "" || c.GlobalString("tlskey") != "" {
return nil, errors.New("cannot specify tlsdir and tlscacert/tlscert/tlskey at the same time")
}
} else {
caCert = c.GlobalString("tlscacert")
cert = c.GlobalString("tlscert")
key = c.GlobalString("tlskey")
}

opts := []client.ClientOpt{client.WithFailFast()}

Expand Down
5 changes: 5 additions & 0 deletions cmd/buildctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ func main() {
Usage: "client key",
Value: "",
},
cli.StringFlag{
Name: "tlsdir",
Usage: "directory containing CA certificate, client certificate, and client key",
Value: "",
},
cli.IntFlag{
Name: "timeout",
Usage: "timeout backend connection after value seconds",
Expand Down

0 comments on commit 1dfd864

Please sign in to comment.