github.com/telepresenceio/telepresence/v2@v2.20.0-pro.6.0.20240517030216-236ea954e789/pkg/authenticator/exec.go (about) 1 package authenticator 2 3 import ( 4 "bytes" 5 "context" 6 "fmt" 7 8 clientcmdapi "k8s.io/client-go/tools/clientcmd/api" 9 10 "github.com/telepresenceio/telepresence/v2/pkg/dos" 11 "github.com/telepresenceio/telepresence/v2/pkg/proc" 12 ) 13 14 type execCredentialBinary struct{} 15 16 func (e execCredentialBinary) Resolve( 17 ctx context.Context, 18 execConfig *clientcmdapi.ExecConfig, 19 ) ([]byte, error) { 20 var buf bytes.Buffer 21 22 cmd := proc.CommandContext(ctx, execConfig.Command, execConfig.Args...) 23 cmd.Stdout = &buf 24 cmd.Stderr = dos.Stderr(ctx) 25 cmd.DisableLogging = true 26 cmd.Env = dos.Environ(ctx) 27 if len(execConfig.Env) > 0 { 28 em := dos.FromEnvPairs(cmd.Env) 29 for _, ev := range execConfig.Env { 30 em[ev.Name] = ev.Value 31 } 32 cmd.Env = em.Environ() 33 } 34 35 if err := cmd.Run(); err != nil { 36 return nil, fmt.Errorf("failed to run host command: %w", err) 37 } 38 39 return buf.Bytes(), nil 40 }