prm

package
v0.0.0-...-c70380f Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Overview

nolint:structcheck,unused

nolint:structcheck,unused

Index

Constants

View Source
const (
	PuppetCmdFlag      string      = "puppet"
	BackendCmdFlag     string      = "backend"
	PuppetVerCfgKey    string      = "puppetversion" // Should match Config struct key.
	BackendCfgKey      string      = "backend"       // Should match Config struct key.
	DefaultPuppetVer   string      = "7.15.0"
	DefaultBackend     BackendType = DOCKER
	ToolPathCfgKey     string      = "toolpath"
	ToolTimeoutCfgKey  string      = "toolTimeout"
	DefaultToolTimeout int         = 1800 // 30 minutes
)
View Source
const (
	ToolConfigName     = "prm-config"
	ToolConfigFileName = "prm-config.yml"
)

Variables

View Source
var (
	ErrDockerNotRunning = fmt.Errorf("docker is not running, please start the docker process")
)
View Source
var (
	ToolGroups = map[string][]ToolInst{

		"group/modules": {
			{Name: "puppetlabs/spec_cache"},
			{
				Name: "puppetlabs/spec_puppet",
				Args: []string{
					"spec_prep",
				},
			},
			{Name: "puppetlabs/spec_puppet"},
			{Name: "puppetlabs/rubocop"},
			{Name: "puppetlabs/puppet-lint"},
			{Name: "puppetlabs/puppet-syntax"},
			{Name: "puppetlabs/puppet-strings"},
		},
	}
)

Functions

func FormatStatus

func FormatStatus(status Status, outputType string) (statusMessage string, err error)

Types

type BackendI

type BackendI interface {
	GetTool(tool *Tool, prmConfig Config) error
	Validate(toolInfo ToolInfo, prmConfig Config, paths DirectoryPaths) (ValidateExitCode, string, error)
	Exec(tool *Tool, args []string, prmConfig Config, paths DirectoryPaths) (ToolExitCode, error)
	Status() BackendStatus
}

type BackendStatus

type BackendStatus struct {
	IsAvailable bool
	StatusMsg   string
}

The BackendStatus must report whether the backend is available and any useful status information; in the case of the backend being unavailable, report the error message to the user.

type BackendType

type BackendType string
const (
	DOCKER BackendType = "docker"
)

type BinaryConfig

type BinaryConfig struct {
	Name         string        `mapstructure:"name"`
	InstallSteps *InstallSteps `mapstructure:"install_steps"`
}

type CommonConfig

type CommonConfig struct {
	CanValidate         bool              `mapstructure:"can_validate"`
	NeedsWriteAccess    bool              `mapstructure:"needs_write_access"`
	UseScript           string            `mapstructure:"use_script"`
	RequiresGit         bool              `mapstructure:"requires_git"`
	DefaultArgs         []string          `mapstructure:"default_args"`
	HelpArg             string            `mapstructure:"help_arg"`
	SuccessExitCode     int               `mapstructure:"success_exit_code"`
	InterleaveStdOutErr bool              `mapstructure:"interleave_stdout"`
	OutputMode          *OutputModes      `mapstructure:"output_mode"`
	Env                 map[string]string `mapstructure:"env"`
}

type Config

type Config struct {
	PuppetVersion *semver.Version
	Backend       BackendType
	ToolPath      string
	Timeout       time.Duration
}

type ContainerConfig

type ContainerConfig struct {
	Name string `mapstructure:"name"`
	Tag  string `mapstructure:"tag"`
}

type ContainerOutput

type ContainerOutput struct {
	// contains filtered or unexported fields
}

type DirectoryPaths

type DirectoryPaths struct {
	// contains filtered or unexported fields
}

type Docker

type Docker struct {
	// We need to be able to mock the docker client in testing
	Client         DockerClientI
	Context        context.Context
	ContextCancel  func()
	ContextTimeout time.Duration
	AFS            *afero.Afero
	IOFS           *afero.IOFS
	AlwaysBuild    bool
}

func (*Docker) Exec

func (d *Docker) Exec(tool *Tool, args []string, prmConfig Config, paths DirectoryPaths) (ToolExitCode, error)

func (*Docker) GetTool

func (d *Docker) GetTool(tool *Tool, prmConfig Config) error

func (*Docker) ImageName

func (d *Docker) ImageName(tool *Tool, prmConfig Config) string

Creates a unique name for the image based on the tool and the PRM configuration

func (*Docker) Status

func (d *Docker) Status() BackendStatus

Check to see if the Docker runtime is available: if so, return true and info about Docker on this node; if not, return false and the error message

func (*Docker) Validate

func (d *Docker) Validate(toolInfo ToolInfo, prmConfig Config, paths DirectoryPaths) (ValidateExitCode, string, error)

type DockerClientI

type DockerClientI interface {
	// All docker client functions must be noted here so they can be mocked
	ContainerCreate(ctx context.Context, config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string) (container.ContainerCreateCreatedBody, error)
	ContainerLogs(ctx context.Context, container string, options types.ContainerLogsOptions) (io.ReadCloser, error)
	ContainerRemove(ctx context.Context, containerID string, options types.ContainerRemoveOptions) error
	ContainerStart(ctx context.Context, containerID string, options types.ContainerStartOptions) error
	ContainerWait(ctx context.Context, containerID string, condition container.WaitCondition) (<-chan container.ContainerWaitOKBody, <-chan error)
	ImageBuild(ctx context.Context, buildContext io.Reader, options types.ImageBuildOptions) (types.ImageBuildResponse, error)
	ImageList(ctx context.Context, options types.ImageListOptions) ([]types.ImageSummary, error)
	ImageRemove(ctx context.Context, imageID string, options types.ImageRemoveOptions) ([]types.ImageDeleteResponseItem, error)
	ServerVersion(context.Context) (types.Version, error)
	ContainerStop(ctx context.Context, containerID string, timeout *time.Duration) error
}

type ExecExitCode

type ExecExitCode int64
const (
	EXEC_SUCCESS ExecExitCode = iota
	EXEC_FAILURE
	EXEC_ERROR
)

type GemConfig

type GemConfig struct {
	Name          []string                      `mapstructure:"name"`
	Executable    string                        `mapstructure:"executable"`
	BuildTools    bool                          `mapstructure:"build_tools"`
	Compatibility map[float32]map[string]string `mapstructure:"compatibility"`
}

type Group

type Group struct {
	ID    string     `yaml:"id"`
	Tools []ToolInst `yaml:"tools"`
}

type InstallSteps

type InstallSteps struct {
	Windows string `mapstructure:"windows"`
	Darwin  string `mapstructure:"darwin"`
	Linux   string `mapstructure:"linux"`
}

type OutputModes

type OutputModes struct {
	Json  string `mapstructure:"json"`
	Yaml  string `mapstructure:"yaml"`
	Junit string `mapstructure:"junit"`
}

type OutputSettings

type OutputSettings struct {
	ResultsView string // Either "terminal" or "file"
	OutputDir   string // Directory to write log file to
}

type PluginConfig

type PluginConfig struct {
	install.ConfigParams `mapstructure:",squash"`
	Display              string `mapstructure:"display"`
	UpstreamProjUrl      string `mapstructure:"upstream_project_url"`
}

type Pool

type Pool[T any] struct {
	Tasks []*Task[T]
	// contains filtered or unexported fields
}

Pool is a worker group that runs a number of tasks at a configured concurrency.

func CreateWorkerPool

func CreateWorkerPool[T any](tasks []*Task[T], workerCount int) *Pool[T]

func (*Pool[T]) Run

func (p *Pool[T]) Run()

Run runs all work within the pool and blocks until it's finished.

type Prm

type Prm struct {
	AFS           *afero.Afero
	IOFS          *afero.IOFS
	RunningConfig Config
	CodeDir       string
	CacheDir      string
	Cache         map[string]*Tool
	Backend       BackendI
}

func (*Prm) EnsureCacheDirExists

func (p *Prm) EnsureCacheDirExists() error

func (*Prm) Exec

func (p *Prm) Exec(tool *Tool, args []string) error

Executes a tool with the given arguments, against the codeDir.

func (*Prm) FilterFiles

func (p *Prm) FilterFiles(ss []ToolConfig, test func(ToolConfig) bool) (ret []ToolConfig)

func (*Prm) FormatTools

func (*Prm) FormatTools(tools map[string]*Tool, jsonOutput string) (string, error)

FormatTools formats one or more templates to display on the console in table format or json format.

func (*Prm) GenerateDefaultCfg

func (p *Prm) GenerateDefaultCfg()

func (*Prm) GetDefaultToolPath

func (p *Prm) GetDefaultToolPath() (string, error)

func (*Prm) GetStatus

func (p *Prm) GetStatus() (status Status)

func (*Prm) GetValidationGroupFromFile

func (p *Prm) GetValidationGroupFromFile(selectedGroupID string) (Group, error)

func (*Prm) IsToolAvailable

func (p *Prm) IsToolAvailable(tool string) (*Tool, bool)

Check to see if the requested tool can be found installed. If installed read the tool configuration and return

func (*Prm) IsToolReady

func (p *Prm) IsToolReady(tool *Tool) bool

Check to see if the tool is ready to execute

func (*Prm) List

func (p *Prm) List(toolPath string, toolName string, onlyValidators bool) error

List lists all templates in a given path and parses their configuration. Does not return any errors from parsing invalid templates, but returns them as debug log events

func (*Prm) LoadConfig

func (p *Prm) LoadConfig() error

func (*Prm) Validate

func (p *Prm) Validate(toolsInfo []ToolInfo, workerCount int, settings OutputSettings) error

type PuppetConfig

type PuppetConfig struct {
	Enabled bool `mapstructure:"enabled"`
}

type PuppetVersion

type PuppetVersion struct {
	// contains filtered or unexported fields
}

type Status

type Status struct {
	PuppetVersion *semver.Version
	Backend       BackendType
	BackendStatus BackendStatus
}

type Task

type Task[T any] struct {
	// Output holds an error that occurred during a task. Its
	// result is only meaningful after Run has been called
	// for the pool that holds it.
	Name   string
	Output T
	// contains filtered or unexported fields
}

Task encapsulates a work item that should go in a work pool.

func CreateTask

func CreateTask[T any](name string, f func() T, output T) *Task[T]

func (*Task[T]) Run

func (t *Task[T]) Run(wg *sync.WaitGroup)

Run runs a Task and does appropriate accounting via a given sync.WorkGroup.

type Tool

type Tool struct {
	Stdout   io.Reader
	Stderr   io.Reader
	ExitCode ToolExitCode
	Cfg      ToolConfig
}

type ToolConfig

type ToolConfig struct {
	Path      string
	Plugin    *PluginConfig    `mapstructure:"plugin"`
	Gem       *GemConfig       `mapstructure:"gem"`
	Container *ContainerConfig `mapstructure:"container"`
	Binary    *BinaryConfig    `mapstructure:"binary"`
	Puppet    *PuppetConfig    `mapstructure:"puppet"`
	Common    CommonConfig     `mapstructure:"common"`
}

type ToolConfigInfo

type ToolConfigInfo struct {
	Plugin   PluginConfig `mapstructure:"plugin"`
	Defaults map[string]interface{}
}

ToolConfigInfo is the housing struct for marshaling YAML data

type ToolExitCode

type ToolExitCode int64
const (
	FAILURE ToolExitCode = iota
	SUCCESS
	TOOL_ERROR
	TOOL_NOT_FOUND
)

type ToolInfo

type ToolInfo struct {
	Tool *Tool
	Args []string
}

type ToolInst

type ToolInst struct {
	Name string   `yaml:"name"`
	Args []string `yaml:"args"`
}

This package contains ToolGroups, which defines what inidividual tools make up a specific ToolGroup.

This allows users to specify 'group/mygroup' and have PRM execute against a larger list of tools, without needing to define or understand what is being called.

type ValidateExitCode

type ValidateExitCode int64
const (
	VALIDATION_PASS ValidateExitCode = iota
	VALIDATION_FAILED
	VALIDATION_ERROR
)

type ValidateYmlContent

type ValidateYmlContent struct {
	Groups []Group `yaml:"groups"`
}

type ValidationOutput

type ValidationOutput struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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