Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if config comes from pipe and stat size is > 0 #306

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Commander interface {
ConfigSet(string, []string) error
ConfigUnset(string, []string) error
ConfigPull(string, bool, bool) error
ConfigPush(string, string) error
ConfigPush(string, string, bool) error
DomainsList(string, int) error
DomainsAdd(string, string) error
DomainsRemove(string, string) error
Expand Down
14 changes: 11 additions & 3 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,20 +235,28 @@ func (d *DeisCmd) ConfigPull(appID string, interactive bool, overwrite bool) err
}

// ConfigPush pushes an app's config from a file.
func (d *DeisCmd) ConfigPush(appID, fileName string) error {
func (d *DeisCmd) ConfigPush(appID, fileName string, verbose bool) error {
stat, err := os.Stdin.Stat()

if err != nil {
return err
}

var contents []byte

if (stat.Mode() & os.ModeCharDevice) == 0 {
if ((stat.Mode()&os.ModeNamedPipe) != 0 || stat.Size() > 0) && fileName == ".no-file" {
if verbose {
d.Println("Getting input from stdin")
}
buffer := new(bytes.Buffer)
buffer.ReadFrom(os.Stdin)
contents = buffer.Bytes()
} else {
if verbose {
d.Println("Not getting input from stdin")
}
if fileName == ".no-file" {
fileName = ".env"
}
contents, err = ioutil.ReadFile(fileName)

if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions parser/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,11 @@ Usage: deis config:push [options]

Options:
-a --app=<app>
the uniquely identifiable name for the application.
The uniquely identifiable name for the application.
-p <path>, --path=<path>
a path leading to an environment file [default: .env]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for giving you bad advice here about checking filepath first. I completely forgot about the .env default. It would be nice if we didn't have to go down this route, as it feels a little hacky.

So much for the easy solution 😄. I guess we do need to find the correct Sdin mode. If I have some time I'll help you experiment with this this week.

As for similar code in config:pull, here it is. It uses Stout, which means that redirecting a bash scripts output would likely run into similar issues to this.

Thanks so much for working on this and I apologize again for giving you bad advice 😢!

A path leading to an environment file [default: .no-file]
-v --verbose
Show debug output
`

args, err := docopt.Parse(usage, argv, true, "", false, true)
Expand All @@ -189,6 +191,7 @@ Options:

app := safeGetValue(args, "--app")
path := safeGetValue(args, "--path")
verbose := args["--verbose"].(bool)

return cmdr.ConfigPush(app, path)
return cmdr.ConfigPush(app, path, verbose)
}
2 changes: 1 addition & 1 deletion parser/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (d FakeDeisCmd) ConfigPull(string, bool, bool) error {
return errors.New("config:pull")
}

func (d FakeDeisCmd) ConfigPush(string, string) error {
func (d FakeDeisCmd) ConfigPush(string, string, bool) error {
return errors.New("config:push")
}

Expand Down