cmd

package
v0.0.259 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2023 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package cmd provides the command line interface for the notary.

Index

Constants

This section is empty.

Variables

View Source
var NotaryInfoCommand = &cli.Command{
	Name:        "notary-info",
	Description: "learn how to use notary cli",
	Action: func(c *cli.Context) error {
		fmt.Println(string(markdown.Render(help, termsize.Width(), 6)))
		return nil
	},
}

NotaryInfoCommand gets info about using the notary agent.

View Source
var NotaryRunCommand = &cli.Command{
	Name:        "notary-run",
	Description: "runs the notary service",
	Flags:       []cli.Flag{configFlag, metricsPortFlag, debugFlag},
	Action: func(c *cli.Context) error {
		metricsProvider, err := metrics.NewFromEnv(c.Context, metadata.BuildInfo())
		if err != nil {
			return fmt.Errorf("failed to create metrics handler: %w", err)
		}

		notaryConfig, notaryDB, err := createNotaryParameters(c.Context, c, metricsProvider)
		if err != nil {
			return fmt.Errorf("failed to create notary parameters: %w", err)
		}

		var baseOmniRPCClient omnirpcClient.RPCClient
		if debugFlag.IsSet() {
			baseOmniRPCClient = omnirpcClient.NewOmnirpcClient(notaryConfig.BaseOmnirpcURL, metricsProvider, omnirpcClient.WithCaptureReqRes())
		} else {
			baseOmniRPCClient = omnirpcClient.NewOmnirpcClient(notaryConfig.BaseOmnirpcURL, metricsProvider)
		}

		var shouldRetryAtomic atomic.Bool
		shouldRetryAtomic.Store(true)

		for shouldRetryAtomic.Load() {
			shouldRetryAtomic.Store(false)

			g, _ := errgroup.WithContext(c.Context)

			notary, err := notary.NewNotary(c.Context, notaryConfig, baseOmniRPCClient, notaryDB, metricsProvider)
			if err != nil {
				return fmt.Errorf("failed to create notary: %w", err)
			}

			g.Go(func() error {
				err = notary.Start(c.Context)
				if err != nil {
					shouldRetryAtomic.Store(true)

					log.Errorf("Error running notary, will sleep for a minute and retry: %v", err)
					time.Sleep(60 * time.Second)
					return fmt.Errorf("failed to create notary: %w", err)
				}

				return nil
			})

			g.Go(func() error {
				err := api.Start(c.Context, uint16(c.Uint(metricsPortFlag.Name)))
				if err != nil {
					return fmt.Errorf("failed to start api: %w", err)
				}

				return nil
			})

			if err := g.Wait(); err != nil {
				return fmt.Errorf("failed to run notary: %w", err)
			}
		}

		return nil
	},
}

NotaryRunCommand runs the notary.

Functions

func InitNotaryDB added in v0.0.216

func InitNotaryDB(parentCtx context.Context, database string, path string, tablePrefix string, handler metrics.Handler) (_ db.NotaryDB, err error)

InitNotaryDB initializes a database given a database type and path.

func Start

func Start(args []string, buildInfo config.BuildInfo)

Start starts the command line.

Types

This section is empty.

Jump to

Keyboard shortcuts

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