laws

package
v0.0.0-...-d58b5d9 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: BSD-3-Clause Imports: 27 Imported by: 0

Documentation

Overview

Copyright © 2023 Iggy <iggy@theiggy.com>

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

  3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Package laws - Laws describe the state of the system

Package laws - Laws describe the state of the system

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFiles

func ParseFiles(path string) ([]*gograph.Vertex[*LawNode], error)

ParseFiles - parse a file or directory of yaml files to get the laws This is a total pain... either I screw myself on the logic by making everything a struct or I screw myself on the parsing by using maps and interfaces

Types

type AbsentMount

type AbsentMount struct {
	// Name       string
	Spec       string
	MountPoint string `yaml:"mount_point"`
	Type       string
	Options    string
	Freq       int64
	Pass       int64

	// CommonFields
	Name   string
	Before []string
	After  []string
}

func (*AbsentMount) Ensure

func (m *AbsentMount) Ensure(pretend bool) error

func (*AbsentMount) Exists

func (m *AbsentMount) Exists() (bool, error)

func (*AbsentMount) UnmarshalYAML

func (m *AbsentMount) UnmarshalYAML(value *yaml.Node) error

type Container

type Container struct {
	// Name          string
	Image         string
	Running       bool
	Volumes       map[string]string
	Environment   map[string]string
	Labels        map[string]string
	LogDriver     string
	Hostname      string
	Network       string // bridge|none|container:<name|id>|host|<network-name|network-id>
	HealthCheck   HealthCheckOpts
	Privileged    bool
	PublishAll    bool
	Publish       map[string]string
	RestartPolicy string // no|on-failure[:max-retries]|always|unless-stopped

	// CommonFields
	Name   string
	Before []string
	After  []string
}

Container - This is a struct for the container

func (*Container) Ensure

func (c *Container) Ensure(pretend bool) error

Ensure - run the container if it isn't running

func (*Container) IsRunning

func (c *Container) IsRunning() (bool, error)

IsRunning - This checks if the container is running

func (*Container) UnmarshalYAML

func (c *Container) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML - This fills in default values if they aren't specified

type FileChange

type FileChange struct {
	Search  string   `yaml:"search"`            // line to search for
	Replace string   `yaml:"replace,omitempty"` // line to replace with
	Done    string   `yaml:"done"`
	If      []string // should probably convert this into some template logic
	// contains filtered or unexported fields
}

func (*FileChange) Ensure

func (f *FileChange) Ensure(pretend bool) error

TODO handle \r's

func (*FileChange) UnmarshalYAML

func (f *FileChange) UnmarshalYAML(value *yaml.Node) error

type FileInsert

type FileInsert struct {

	// Name       string
	// MakeDir    bool `yaml:"make_dir"` // make the parent dir
	AfterLine  string
	BeforeLine string
	LineNum    int64
	Text       string
	// contains filtered or unexported fields
}

func (*FileInsert) Ensure

func (f *FileInsert) Ensure(pretend bool) error

func (*FileInsert) UnmarshalYAML

func (f *FileInsert) UnmarshalYAML(value *yaml.Node) error
type FileLink struct {
	Target   string `yaml:"target"` // the target of the link
	Symbolic bool   `yaml:"symbolic"`
	// contains filtered or unexported fields
}

func (*FileLink) Ensure

func (f *FileLink) Ensure(pretend bool) error

func (*FileLink) UnmarshalYAML

func (f *FileLink) UnmarshalYAML(value *yaml.Node) error

type FileTemplate

type FileTemplate struct {

	// Name         string      // file path
	// MakeDir      bool        `yaml:"make_dir"` // make the parent dir
	// User         string      // user/uid owner of the file
	// Group        string      // group/gid owner of the file
	// Mode         fs.FileMode // file mode TODO maybe default to 400?
	Text         string // text template
	TemplatePath string // path to a file to use instead of Text (unimpl)
	// contains filtered or unexported fields
}

func (*FileTemplate) Ensure

func (f *FileTemplate) Ensure(pretend bool) error

Ensure ensures that the file exists with the correct contents

func (*FileTemplate) Exists

func (f *FileTemplate) Exists() bool

Exists checks if the file exists

func (*FileTemplate) UnmarshalYAML

func (f *FileTemplate) UnmarshalYAML(value *yaml.Node) error

type Group

type Group struct {
	// Name   string
	GID    uint64
	System bool
	// CommonFields
	Name   string
	Before []string
	After  []string
}

Group - a group the system should have

func (*Group) Create

func (g *Group) Create() error

Create - create a group

func (*Group) Ensure

func (g *Group) Ensure(pretend bool) error

Ensure - check if the group exists

type HealthCheckOpts

type HealthCheckOpts struct {
	Enabled     bool
	Command     string
	Interval    string
	Retries     int
	StartPeriod string
	Timeout     string
}

HealthCheckOpts - This is a struct for the healthcheck options

type Law

type Law interface {
	Ensure(bool) error
}

type LawNode

type LawNode struct {
	Law   Law
	Group string
	Type  string
	Name  string
}

dep graph node that represents each law parsed from the laws yaml files i.e. each one represents a user, group, file, etc

type Laws3

type Laws3 struct {
	Users struct {
		Present []*User
	}
	Groups struct {
		Present []*Group
	}
	Packages struct {
		Installed []*Package
	}
	PackageRepos struct {
		Present []*PackageRepo
	} `yaml:"package_repos"`
	Containers struct {
		// FIXME revisit this naming
		Running []*Container
	}
	Scripts struct {
		Run []*Script
	}
	Files struct {
		Templates []*FileTemplate
		Inserts   []*FileInsert
		Changes   []*FileChange
		Links     []*FileLink
	}
	Mounts struct {
		Exists []*Mount
		Absent []*AbsentMount
	}
	Services struct {
		Enabled []*Service
	}
	SSH struct {
		AuthorizedKeys []*SSHKey `yaml:"authorized_keys"`
	} `yaml:"ssh"`
}

Laws - describe the state of the system TODO should really just turn this into a list of `Law`

type Laws struct {
	Users        []User
	Groups       []Group
	Packages     []Package
	PackageRepos []PackageRepo
	Containers   []Container
	Scripts      []Script
	Files        FileTemplate
	Mounts       []Mount
	Services     []Service
}

type Laws2 map[string]interface{}

type LogOpts

type LogOpts struct {
	Driver string // none|json-file|syslog|journald|gelf|fluentd|awslogs|splunk
	Opt    map[string]string
}

LogOpts - This is a struct for the log options

type Mount

type Mount struct {
	// Name       string
	Spec       string
	MountPoint string `yaml:"mount_point"`
	Type       string
	Options    string
	Freq       int64
	Pass       int64
	Present    bool

	// CommonFields
	Name   string
	Before []string
	After  []string
}

Mount is a mount point

func (*Mount) Ensure

func (m *Mount) Ensure(pretend bool) error

Ensure - ensure mount is setup TODO should probably mark fstab as managed by govern

func (*Mount) Exists

func (m *Mount) Exists() (bool, error)

Exists - check if mountpoint exists

func (*Mount) UnmarshalYAML

func (m *Mount) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the Unmarshaler interface

type Package

type Package struct {
	// Name    string
	Version   string `yaml:",omitempty"`
	Installed bool   `yaml:",omitempty"` // whether the package should be installed or removed

	// CommonFields
	Name   string
	Before []string
	After  []string
}

Package - package info

func (*Package) Ensure

func (p *Package) Ensure(pretend bool) error

Ensure - ensure a package is installed

func (*Package) Install

func (p *Package) Install() (string, error)

Install - install a package

func (*Package) IsInstalled

func (p *Package) IsInstalled() (bool, error)

IsInstalled - check if a package is installed true/false whether a package is installed err = nil if we know what distro we are on

func (*Package) UnmarshalYAML

func (p *Package) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML - This fills in default values if they aren't specified

type PackageRepo

type PackageRepo struct {
	// Name     string
	Key      string `yaml:"key"` // (gpg|etc) key to fetch and load into the system store
	Contents string // the repo URL usually
	// CommonFields
	Name   string // unique identifier, not used in the actual repo
	Before []string
	After  []string
}

PackageRepo describes a package repository

func (*PackageRepo) Ensure

func (r *PackageRepo) Ensure(pretend bool) error

func (*PackageRepo) UnmarshalYAML

func (r *PackageRepo) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the Unmarshaler interface

type RetryOpts

type RetryOpts struct {
	Attempts uint // how many times to try to apply the law
	Until    bool // ??? copied from Salt, probably not necessary
	Interval uint // how long to wait between tries
	Splay    uint // how much variance to add to the interval, useful for thundering herd type scenarios
}

RetryOpts - retry options

type Root

type Root struct {
	Name string
}

func (*Root) Ensure

func (r *Root) Ensure(bool) error

Ensure - just to fulfill the interface

type SSHKey

type SSHKey struct {
	Name   string
	Key    string
	User   string
	Before []string
	After  []string
}

func (*SSHKey) Ensure

func (k *SSHKey) Ensure(pretend bool) error

type Script

type Script struct {
	// Name       string
	Shell      string
	Script     string
	Env        []string
	Args       []string
	WorkingDir string
	Creates    []string
	RunAs      string
	// CommonFields
	Name   string
	Before []string
	After  []string
}

Script is a script to run

func (*Script) Run

func (s *Script) Run(pretend bool) error

Run - run the script

func (*Script) UnmarshalYAML

func (s *Script) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML implements the Unmarshaler interface.

type Service

type Service struct {
	// Name       string
	State      string `yaml:",omitempty"`
	Persistent bool   `yaml:",omitempty"`
	RunLevel   string `yaml:",omitempty"`

	// CommonFields
	Name   string
	Before []string
	After  []string
}

Service - package info

func (*Service) CurrentState

func (s *Service) CurrentState() string

CurrentState - get current state of service

func (*Service) Ensure

func (s *Service) Ensure(pretend bool) error

FIXME changing the runlevel doesn't update the service Ensure - ensure service is in desired state

func (*Service) UnmarshalYAML

func (s *Service) UnmarshalYAML(value *yaml.Node) error

type User

type User struct {
	// Name           string   “                       // the user's name
	UID            uint64   `yaml:",omitempty"`      // the user's UID, uint64 matches
	GID            uint64   `yaml:",omitempty"`      // The primary group ID
	Fullname       string   ``                       // part of the GECOS string
	Password       string   ``                       // the encrypted password
	HomeDir        string   ``                       // the user's $HOME
	Shell          string   ``                       // the system shell
	System         bool     ``                       // whether this is a system user or not
	Exists         bool     ``                       // Whether the user should exist on the system or not
	ExtraGroups    []string ``                       // required extra group names
	OptionalGroups []string `yaml:"optional_groups"` // if these groups exist already, add the user to them, otherwise ignore
	// CommonFields            //`yaml:",inline"` // CommonFields `yaml:"commonfields,inline"` // fields that are supported for everything, mostly dep related
	Name   string
	Before []string
	After  []string
}

User - a user the system should have

func (*User) Create

func (u *User) Create()

Create - create the user

func (*User) Ensure

func (u *User) Ensure(pretend bool) error

Ensure - ensure the user exists, if not create it

func (*User) GetPassword

func (u *User) GetPassword() (string, error)

GetPassword - Get the password for the user Common internet wisdom says I should be talking to pam, but Alpine doesn't use pam

func (*User) UnmarshalYAML

func (u *User) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML - This fills in default values if they aren't specified

Jump to

Keyboard shortcuts

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