-
Notifications
You must be signed in to change notification settings - Fork 6
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
Removing tf show output when streaming logs #104
Changes from 4 commits
4c43399
613394e
404e40e
1b78cff
12b3873
2987b22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,6 +38,8 @@ import ( | |
"github.com/runatlantis/atlantis/server/logging" | ||
) | ||
|
||
var LogStreamingValidCmds = [...]string{"init", "plan", "apply"} | ||
|
||
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_terraform_client.go Client | ||
|
||
type Client interface { | ||
|
@@ -442,11 +444,16 @@ func (c *DefaultClient) RunCommandAsync(ctx models.ProjectCommandContext, path s | |
|
||
// Asynchronously copy from stdout/err to outCh. | ||
go func() { | ||
s := bufio.NewScanner(stdout) | ||
for s.Scan() { | ||
message := s.Text() | ||
outCh <- Line{Line: message} | ||
c.projectCmdOutputHandler.Send(ctx, message) | ||
// Don't stream terraform show output to outCh | ||
cmds := strings.Split(tfCmd, " ") | ||
// OverrideTF used for testing with non terraform commands. | ||
if c.overrideTF != "" || isValidCommand(cmds[1]) { | ||
s := bufio.NewScanner(stdout) | ||
for s.Scan() { | ||
message := s.Text() | ||
outCh <- Line{Line: message} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to always run. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True! Thanks for the catch :) I've made the change you suggested. |
||
c.projectCmdOutputHandler.Send(ctx, message) | ||
} | ||
} | ||
wg.Done() | ||
}() | ||
|
@@ -558,6 +565,15 @@ func generateRCFile(tfeToken string, tfeHostname string, home string) error { | |
return nil | ||
} | ||
|
||
func isValidCommand(cmd string) bool { | ||
for _, validCmd := range LogStreamingValidCmds { | ||
if validCmd == cmd { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func getVersion(tfBinary string) (*version.Version, error) { | ||
versionOutBytes, err := exec.Command(tfBinary, "version").Output() // #nosec | ||
versionOutput := string(versionOutBytes) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to actually only allow plan and apply specifically instead of just having a deny list?
Upstream has support for using
terraform version
. and we might want to eventually supportterraform import
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I think it makes sense to have an allow list for better control over what's being streamed to the web UI. I've added a
LogStreamingValidCmds
withinit
,plan
, andapply
commands for now. We can add more commands as we go :)