|
@@ -2,13 +2,14 @@ package secret
|
|
|
|
|
|
import (
|
|
import (
|
|
"fmt"
|
|
"fmt"
|
|
|
|
+ "io"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
- "os"
|
|
|
|
|
|
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"github.com/docker/docker/api/types/swarm"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/cli"
|
|
"github.com/docker/docker/cli/command"
|
|
"github.com/docker/docker/cli/command"
|
|
"github.com/docker/docker/opts"
|
|
"github.com/docker/docker/opts"
|
|
|
|
+ "github.com/docker/docker/pkg/system"
|
|
runconfigopts "github.com/docker/docker/runconfig/opts"
|
|
runconfigopts "github.com/docker/docker/runconfig/opts"
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/net/context"
|
|
"golang.org/x/net/context"
|
|
@@ -16,6 +17,7 @@ import (
|
|
|
|
|
|
type createOptions struct {
|
|
type createOptions struct {
|
|
name string
|
|
name string
|
|
|
|
+ file string
|
|
labels opts.ListOpts
|
|
labels opts.ListOpts
|
|
}
|
|
}
|
|
|
|
|
|
@@ -26,7 +28,7 @@ func newSecretCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
|
|
|
|
cmd := &cobra.Command{
|
|
cmd := &cobra.Command{
|
|
Use: "create [OPTIONS] SECRET",
|
|
Use: "create [OPTIONS] SECRET",
|
|
- Short: "Create a secret using stdin as content",
|
|
|
|
|
|
+ Short: "Create a secret from a file or STDIN as content",
|
|
Args: cli.ExactArgs(1),
|
|
Args: cli.ExactArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
createOpts.name = args[0]
|
|
createOpts.name = args[0]
|
|
@@ -35,6 +37,7 @@ func newSecretCreateCommand(dockerCli *command.DockerCli) *cobra.Command {
|
|
}
|
|
}
|
|
flags := cmd.Flags()
|
|
flags := cmd.Flags()
|
|
flags.VarP(&createOpts.labels, "label", "l", "Secret labels")
|
|
flags.VarP(&createOpts.labels, "label", "l", "Secret labels")
|
|
|
|
+ flags.StringVarP(&createOpts.file, "file", "f", "", "Read from a file or STDIN ('-')")
|
|
|
|
|
|
return cmd
|
|
return cmd
|
|
}
|
|
}
|
|
@@ -43,9 +46,23 @@ func runSecretCreate(dockerCli *command.DockerCli, options createOptions) error
|
|
client := dockerCli.Client()
|
|
client := dockerCli.Client()
|
|
ctx := context.Background()
|
|
ctx := context.Background()
|
|
|
|
|
|
- secretData, err := ioutil.ReadAll(os.Stdin)
|
|
|
|
|
|
+ if options.file == "" {
|
|
|
|
+ return fmt.Errorf("Please specify either a file name or STDIN ('-') with --file")
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var in io.Reader = dockerCli.In()
|
|
|
|
+ if options.file != "-" {
|
|
|
|
+ file, err := system.OpenSequential(options.file)
|
|
|
|
+ if err != nil {
|
|
|
|
+ return err
|
|
|
|
+ }
|
|
|
|
+ in = file
|
|
|
|
+ defer file.Close()
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ secretData, err := ioutil.ReadAll(in)
|
|
if err != nil {
|
|
if err != nil {
|
|
- return fmt.Errorf("Error reading content from STDIN: %v", err)
|
|
|
|
|
|
+ return fmt.Errorf("Error reading content from %q: %v", options.file, err)
|
|
}
|
|
}
|
|
|
|
|
|
spec := swarm.SecretSpec{
|
|
spec := swarm.SecretSpec{
|