mirror of
https://git.vectorsigma.ru/public/atlantis.git
synced 2026-07-30 13:38:40 +00:00
* Adding policy_check support into yaml config * Added policy check model and runtime structs * Adding BuildPolicyCheckCommand to ProjectCommandBuilder * Return incorrectly deleted code * Remove BuildAutoPolicyPlanCommand from ProjectCommandBuilder * Split runAutoCommand into two functions runAutoPlanCommand - does what originally RunAutoplancommand was doing except now it returns CommandResult and []models.ProjectCommandContext runAutoPolicyCheckCommand - accepts CommandContext, CommandResult, and []models.ProjectCommandContext as arguments and runs PolicyCheckStep runner * Refactor RunCommentCommand * Remove BuildPolicyCheckCommand and rename StepCmdExec back to TerraformExec * Add policy step runner logic and conftest interfaces. * Add show step runner to policy check stage. * Adding models.PolicyCheckCommand to buildCtx This also means buildPlanAllCommands call buildCtx twice once with models.PlanCommand and once with models.PolicyCheckCommand * Adding new project_command_builder that supports policy_check * Refactoring PolicyCheck specific logic into a PolicyCheckProjectCommandBuilder * Moving events.CommandContext to models.CommandContext this will allow me to remove buildCtx method and move ProjectCommandContext creation into models package * Policy Owners might be different types, for that reason we are refactoring Owners into its own struct with specific keys defining different owner types Co-authored-by: Nish Krishnan <nishk@lyft.com> Co-authored-by: Nish Krishnan <nishkrishnan@users.noreply.github.com>
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package models
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"strings"
|
|
)
|
|
|
|
//go:generate pegomock generate -m --use-experimental-model-gen --package mocks -o mocks/mock_exec.go Exec
|
|
|
|
type Exec interface {
|
|
LookPath(file string) (string, error)
|
|
CombinedOutput(args []string, envs map[string]string, workdir string) (string, error)
|
|
}
|
|
|
|
type LocalExec struct{}
|
|
|
|
func (e LocalExec) LookPath(file string) (string, error) {
|
|
return exec.LookPath(file)
|
|
}
|
|
|
|
// CombinedOutput encapsulates creating a command and running it. We should think about
|
|
// how to flexibly add parameters here as this is meant to satisfy very simple usecases
|
|
// for more complex usecases we can add a Command function to this method which will
|
|
// allow us to edit a Cmd directly.
|
|
func (e LocalExec) CombinedOutput(args []string, envs map[string]string, workdir string) (string, error) {
|
|
formattedArgs := strings.Join(args, " ")
|
|
|
|
envVars := []string{}
|
|
for key, val := range envs {
|
|
envVars = append(envVars, fmt.Sprintf("%s=%s", key, val))
|
|
}
|
|
|
|
// TODO: move this os.Environ call out to the server so this
|
|
// can happen once at the beginning
|
|
envVars = append(envVars, os.Environ()...)
|
|
|
|
// honestly not entirely sure why we're using sh -c but it's used
|
|
// for the terraform binary so copying it for now
|
|
cmd := exec.Command("sh", "-c", formattedArgs)
|
|
cmd.Env = envVars
|
|
cmd.Dir = workdir
|
|
|
|
output, err := cmd.CombinedOutput()
|
|
|
|
return string(output), err
|
|
}
|