policy

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseXmlPolicy

type BaseXmlPolicy struct {
	PolicyId []PolicyId `xml:"PolicyId"`
}

BaseXmlPolicy represents the value of a base policy in XML.

func (*BaseXmlPolicy) Byte

func (p *BaseXmlPolicy) Byte() []byte

Byte @see Policy.Byte.

func (*BaseXmlPolicy) File

func (p *BaseXmlPolicy) File() string

File @see Policy.File.

func (*BaseXmlPolicy) HasParent

func (p *BaseXmlPolicy) HasParent() bool

HasParent @see Policy.HasParent.

func (*BaseXmlPolicy) Id

func (p *BaseXmlPolicy) Id() string

Id @see Policy.Id.

func (*BaseXmlPolicy) Parent

func (p *BaseXmlPolicy) Parent() Policy

Parent @see Policy.Parent.

type Builder

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

Builder is a type that represents a content builder. It is used to read, process, and write content.

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new instance of Builder and initializes it with empty File and Processed contents.

func (*Builder) Len

func (b *Builder) Len() int

Len returns the length of the content.Source map in the Builder instance.

func (*Builder) Process

func (b *Builder) Process(c map[string]string) error

Process processes the content of the Builder instance by replacing variables with their corresponding values. It takes a map of variables and their values as input. The method returns an error if there is nothing to process or if there are any errors encountered during the variable replacement.

func (*Builder) Read

func (b *Builder) Read(from string) error

Read reads files from a specified directory and populates the Builder's source field. The absolute path to the directory is passed as the 'from' parameter. If the provided path is not absolute, an error is returned. The method first calls the Reset() method to set the Builder instance to its initial state. Then, it sets the source root field to the provided path. It uses filepath.WalkDir to walk through the files and directories in the source root directory. For each file with the extension ".xml", it reads the file contents using os.ReadFile. The file path is modified by removing the root directory path. The modified path and file contents are stored in the Builder's source map. If any errors occur during the file reading or path modification, the method returns the error. Finally, the method returns the error encountered during the filepath.WalkDir operation, if any.

func (*Builder) Reset

func (b *Builder) Reset()

Reset sets the Builder instance back to an initial state, with empty source root and empty content fields.

func (*Builder) Result

func (b *Builder) Result() content.Processed

Result returns the processed content of the Builder instance. It returns a map[string][]byte where the key is the file path and the value is the processed content. If the Builder instance has not been processed yet, an empty map is returned.

func (*Builder) Write

func (b *Builder) Write(to string) error

Write writes the processed content to the specified directory. It creates directories as needed and writes the content files. The "to" parameter must be an absolute path. If "to" is not absolute, it returns an error with a message indicating that the path must be absolute. If there is no content to write, it returns an error with a message indicating that there is nothing to write. It returns an error if any error occurs during directory creation or file writing.

type Policy

type Policy interface {
	Id() string
	HasParent() bool
	Parent() Policy
	File() string
	Byte() []byte
}

Policy is an interface that represents a policy.

func New

func New(f string) (Policy, error)

New reads the XML file specified by the string f and returns a new Policy object using xml.Unmarshal. As a basic check, New ensures that the id of the policy is not empty.

type PolicyId

type PolicyId struct {
	Value string `xml:",chardata"`
}

PolicyId represents the value of a policy ID in XML.

type Tree

type Tree []Policy

Tree is a type that represents a collection of policies.

func (*Tree) Batches

func (t *Tree) Batches() [][]Policy

Batches returns the policies organized into batches. Each batch is a slice of policies. It determines the batches by traversing the tree and appending policies to each batch. The resulting batches are returned as a two-dimensional slice.

Example usage:

tree := Tree{}
batches := tree.Batches()

Result:

batches: [][]Policy

func (*Tree) Read

func (t *Tree) Read(from string) error

Read reads policies from the specified absolute path and adds them to the Tree. It recursively searches for XML files in the specified directory and its subdirectories. Each XML file found is parsed as a Policy using the New method. If a Policy with the same ID already exists in the Tree, an error is returned. The Tree is modified by appending the new Policies. The method returns an error if any file or parsing error occurs during the process.

type XmlPolicy

type XmlPolicy struct {
	PolicyId      string           `xml:"PolicyId,attr"`
	BaseXmlPolicy []*BaseXmlPolicy `xml:"BasePolicy"`
	// contains filtered or unexported fields
}

XmlPolicy represents the value of a policy in XML, used to be unmarshalled by xml.Unmarshal.

func (*XmlPolicy) Byte

func (p *XmlPolicy) Byte() []byte

Byte @see Policy.Byte.

func (*XmlPolicy) File

func (p *XmlPolicy) File() string

File @see Policy.File.

func (*XmlPolicy) HasParent

func (p *XmlPolicy) HasParent() bool

HasParent @see Policy.HasParent.

func (*XmlPolicy) Id

func (p *XmlPolicy) Id() string

Id @see Policy.Id.

func (*XmlPolicy) Parent

func (p *XmlPolicy) Parent() Policy

Parent @see Policy.Parent.

func (*XmlPolicy) Valid

func (p *XmlPolicy) Valid() bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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