MCPcopy
hub / github.com/keploy/keploy / startNativeAgent

Method startNativeAgent

pkg/platform/http/agent.go:867–1027  ·  view source on GitHub ↗

startNativeAgent starts the keploy agent as a native process

(ctx context.Context, opts models.SetupOptions)

Source from the content-addressed store, hash-verified

865
866// startNativeAgent starts the keploy agent as a native process
867func (a *AgentClient) startNativeAgent(ctx context.Context, opts models.SetupOptions) error {
868
869 // Get the errgroup from context
870 grp, ok := ctx.Value(models.ErrGroupKey).(*errgroup.Group)
871 if !ok {
872 return fmt.Errorf("failed to get errorgroup from the context")
873 }
874
875 keployBin, err := utils.GetCurrentBinaryPath()
876 if err != nil {
877 utils.LogError(a.logger, err, "failed to get current keploy binary path")
878 return err
879 }
880
881 // Build args (binary is passed separately to utils)
882 args := []string{
883 "agent",
884 "--port", strconv.Itoa(int(opts.AgentPort)),
885 "--proxy-port", strconv.Itoa(int(opts.ProxyPort)),
886 "--dns-port", strconv.Itoa(int(opts.DnsPort)),
887 "--client-pid", strconv.Itoa(int(os.Getpid())),
888 "--mode", string(opts.Mode),
889 }
890
891 extraArgs := opts.ExtraArgs
892 if len(extraArgs) > 0 {
893 args = append(args, extraArgs...)
894 }
895 if a.conf.Debug {
896 args = append(args, "--debug")
897 }
898 if a.conf.Record.Synchronous {
899 args = append(args, "--sync")
900 }
901 // Forward the operator's --disable-mapping (root-level config) so
902 // the native agent process — even though it inherits the same
903 // keploy.yml via --config-path — sees an explicit override on
904 // invocations where the host CLI mutated the in-memory config
905 // after viper load (e.g. --disable-mapping=false on the test
906 // subcommand path that drove this agent start).
907 args = append(args, fmt.Sprintf("--disable-mapping=%t", a.conf.DisableMapping))
908 if a.conf.Record.EnableSampling > 0 {
909 args = append(args, fmt.Sprintf("--enable-sampling=%d", a.conf.Record.EnableSampling))
910 }
911 if opts.EnableTesting {
912 args = append(args, "--enable-testing")
913 }
914 if opts.GlobalPassthrough {
915 args = append(args, "--global-passthrough")
916 }
917 if opts.CapturePackets {
918 args = append(args, "--capture-packets")
919 }
920 if opts.OpportunisticTLSIntercept {
921 args = append(args, "--opportunistic-tls-intercept")
922 }
923 if opts.ChannelBindingShim {
924 args = append(args, "--channel-binding-shim")

Callers 1

startAgentMethod · 0.95

Calls 9

requestAgentStopMethod · 0.95
GetCurrentBinaryPathFunction · 0.92
LogErrorFunction · 0.92
AreSudoCredentialsCachedFunction · 0.92
RecoverFunction · 0.92
DebugMethod · 0.65
WaitMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected