setup

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 10, 2020 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CantRunInteractiveCASetupErr = errors.New("EnsureCA: Could not resort to interactive CA setupnon-interactive frontend.")
View Source
var Command = &cli.Command{
	Name:  "setup",
	Usage: "Setup Komagome PKI",
	Flags: append(structflags.MustPopulateFlagsFromStruct(setup.Config{}),
		&cli.BoolFlag{
			Name:  "dump-template",
			Usage: "dump configuration template yaml without making actual changes",
		},
	),
	Action: func(c *cli.Context) error {
		env := action.GlobalEnvironment
		slog := env.Logger.Sugar()

		profile, err := env.Profile()
		if err != nil {
			return err
		}

		var cfg *Config
		if c.Bool("dump-template") || !c.Bool("no-default") {
			slog.Debugf("Constructing default config.")
			cfg = DefaultConfig(env)
		} else {
			slog.Debugf("Config is from scratch.")
			cfg = &Config{Setup: setup.EmptyConfig()}
		}

		if cfgbs, ok := c.App.Metadata["config"]; ok {
			if err := yaml.UnmarshalStrict(cfgbs.([]byte), cfg); err != nil {
				return err
			}
		}
		if err := structflags.PopulateStructFromCliContext(cfg, c); err != nil {
			return err
		}
		if c.Bool("dump-template") {
			if err := frontend.DumpTemplate(configTemplateText, cfg); err != nil {
				return err
			}
			return nil
		}

		mode := AllowNonInteractiveSetup
		if c.Bool("no-default") {
			mode = AllowNonInteractiveSetupAndRequireCompatibleConfig
		}
		if err := EnsureCA(env, cfg, profile, mode); err != nil {
			return err
		}

		return nil
	},
}

Functions

func EnsureCA

func EnsureCA(env *action.Environment, cfg *Config, profile *storage.Profile, mode EnsureCAMode) error

Types

type Config added in v0.1.0

type Config struct {
	Setup *setup.Config `yaml:"setup" flags:""`

	// This is here to avoid UnmarshalStrict throw error when noDefault was specified for ShouldLoadDefaults().
	XXX_NoDefault bool `yaml:"noDefault"`
}

func DefaultConfig added in v0.1.0

func DefaultConfig(env *action.Environment) *Config

func (*Config) Verify added in v0.1.0

func (c *Config) Verify(env *action.Environment) error

type EnsureCAMode added in v0.1.0

type EnsureCAMode int
const (
	DisallowNonInteractiveSetup EnsureCAMode = iota
	AllowNonInteractiveSetup
	AllowNonInteractiveSetupAndRequireCompatibleConfig
)

type IncompatibleCertErr added in v0.1.0

type IncompatibleCertErr struct {
	Wrap error
}

func (IncompatibleCertErr) Error added in v0.1.0

func (e IncompatibleCertErr) Error() string

func (IncompatibleCertErr) Is added in v0.1.0

func (IncompatibleCertErr) Is(target error) bool

func (IncompatibleCertErr) Unwrap added in v0.1.0

func (e IncompatibleCertErr) Unwrap() error

Jump to

Keyboard shortcuts

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