apidump

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:          "apidump",
	Short:        "Capture requests/responses from network traffic.",
	Long:         "Capture and store a sequence of requests/responses to a service by observing network traffic.",
	SilenceUsage: true,
	Args:         cobra.ExactArgs(0),
	RunE: func(cmd *cobra.Command, _ []string) error {
		traceTags, err := util.ParseTagsAndWarn(tagsFlag)
		if err != nil {
			return err
		}

		plugins, err := pluginloader.Load(pluginsFlag)
		if err != nil {
			return errors.Wrap(err, "failed to load plugins")
		}

		if !outFlag.IsSet() && serviceFlag == "" && postmanCollectionID == "" {
			return errors.New("exactly one of --out, --project or --collection must be specified")
		}

		if serviceFlag != "" {
			uri, err := akiuri.Parse(akiuri.Scheme + serviceFlag)
			if err != nil {
				return errors.Wrap(err, "bad project name")
			}
			outFlag.AkitaURI = &uri
		}

		if appendByTagFlag {
			if outFlag.AkitaURI == nil {
				return errors.New("\"append-by-tag\" can only be used with a cloud-based trace")
			}

			if outFlag.AkitaURI.ObjectName != "" {
				return errors.New("Cannot specify a trace name together with \"append-by-tag\"")
			}

			destURI, err := util.GetTraceURIByTags(rest.Domain,
				telemetry.GetClientID(),
				outFlag.AkitaURI.ServiceName,
				traceTags,
				"append-by-tag",
			)
			if err != nil {
				return err
			}
			if destURI.ObjectName != "" {
				outFlag.AkitaURI = &destURI
			}
		}

		traceRotateInterval := time.Duration(0)
		if outFlag.AkitaURI != nil {
			if traceRotateFlag != "" {
				if outFlag.AkitaURI.ObjectName != "" {
					return errors.New("Cannot specify trace rotation along with a specific trace.")
				}
				traceRotateInterval, err = time.ParseDuration(traceRotateFlag)
				if err != nil {
					return errors.Wrap(err, "Failed to parse trace rotation interval.")
				}
			} else {
				if outFlag.AkitaURI.ObjectName == "" {
					traceRotateInterval = apispec.DefaultTraceRotateInterval
				}
			}
		}

		if deploymentFlag == "" {
			deploymentFlag = apispec.DefaultDeployment
			if os.Getenv("AKITA_DEPLOYMENT") != "" {
				deploymentFlag = os.Getenv("AKITA_DEPLOYMENT")
			}
		} else if deploymentFlag == "-" {

			deploymentFlag = ""
		} else {
			if os.Getenv("AKITA_DEPLOYMENT") != "" && os.Getenv("AKITA_DEPLOYMENT") != deploymentFlag {
				printer.Stderr.Warningf("Deployment in environment variable %q overridden by the command line value %q.\n",
					os.Getenv("AKITA_DEPLOYMENT"),
					deploymentFlag,
				)
			}
		}

		if rateLimitFlag <= 0.0 {
			rateLimitFlag = 1000.0
		}

		if collectTCPAndTLSReports {
			if !parseTLSHandshakes {
				printer.Stderr.Warningf("Overriding parse-tls-handshakes=false because TLS report collection is enabled.\n")
				parseTLSHandshakes = true
			}
		}

		args := apidump.Args{
			ClientID:                telemetry.GetClientID(),
			Domain:                  rest.Domain,
			Out:                     outFlag,
			PostmanCollectionID:     postmanCollectionID,
			Tags:                    traceTags,
			SampleRate:              sampleRateFlag,
			WitnessesPerMinute:      rateLimitFlag,
			Interfaces:              interfacesFlag,
			Filter:                  filterFlag,
			PathExclusions:          pathExclusionsFlag,
			HostExclusions:          hostExclusionsFlag,
			PathAllowlist:           pathAllowlistFlag,
			HostAllowlist:           hostAllowlistFlag,
			ExecCommand:             execCommandFlag,
			ExecCommandUser:         execCommandUserFlag,
			Plugins:                 plugins,
			LearnSessionLifetime:    traceRotateInterval,
			Deployment:              deploymentFlag,
			StatsLogDelay:           statsLogDelay,
			TelemetryInterval:       telemetryInterval,
			ProcFSPollingInterval:   procFSPollingInterval,
			CollectTCPAndTLSReports: collectTCPAndTLSReports,
			ParseTLSHandshakes:      parseTLSHandshakes,
			MaxWitnessSize_bytes:    maxWitnessSize_bytes,
			DockerExtensionMode:     dockerExtensionMode,
			HealthCheckPort:         healthCheckPort,
		}
		if err := apidump.Run(args); err != nil {
			return cmderr.AkitaErr{Err: err}
		}
		return nil
	},
}

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL