config

package
v0.0.0-...-3736fb9 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package config stores the policy configuration Go representation, a global variable called Policies that is for reading the Config as it is updated on disk and configuration validation to make sure errors don't slip in to the Config.

A configuration is stored in JSON and looks like:

{
	"Name": "SateliteDiskErase",
	"Policies": [
		{
			"Name": "restrictJobTypes",
			"Settings": {
				"AllowedJobs": [
				        "JTValidateDecom",
        				"JTDiskErase",
        				"JTSleep",
        				"JTGetTokenFromBucket"
				]
			}
		}
	]
}

...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

Init is called in main to initialize our reads of the policy file. It is called manually instead of init() to guarantee other init() statements are run first.

Types

type Config

type Config struct {
	// Workflows stored by name.
	Workflows map[string]Workflow
	// contains filtered or unexported fields
}

Config represents a policy config that is stored on disk.

type Policy

type Policy struct {
	// Name is the name of the policy type.
	Name string
	// Settings are the settings for that particular policy. We store this as
	// a RawMessage so that we can parse it into the typed version on a second pass.
	Settings json.RawMessage
	// SettingsTyped is the parsed version of the Settings. This is not stored in the Config.
	SettingsTyped policy.Settings `json:"-"`
}

Policy is the policy to apply to a Workflow.

type Reader

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

Reader is used to read the current policy configuration. The configuration is checked for updates every 10 seconds and if there is a valid configuration, it is updated. If not, an error is recorded. Once a Reader is returned by New(), it guarantees to always return a Config. If there is an error also returned, then the Config is the last known good Config.

var Policies *Reader

Policies provides the policy Reader that can be used to read the current policy.

func (*Reader) Read

func (r *Reader) Read() (Config, error)

Read reads the latest Config we have. If an error is returned, the Config will be valid, but it will be the last known good Config instead of the broken latest Config.

type Workflow

type Workflow struct {
	// Name is the name of the Workflow.
	Name string
	// Policies are the Policies to be applied to that Workflow.
	Policies []Policy
}

Workflow stores a Workflow name and the Policies for that Workflow.

Jump to

Keyboard shortcuts

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