file

package
v1.5.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearFolders

func ClearFolders(fileMgr ClearFoldersOSFileManager, paths []string) (removedFiles []string, e error)

ClearFolders removes all files in the given folders and returns the removed files' full paths.

func WriteFile added in v1.5.1

func WriteFile(fileMgr OSFileManager, file File) error

Types

type ClearFoldersOSFileManager

type ClearFoldersOSFileManager interface {
	// ReadDir returns the directory entries for the directory.
	ReadDir(dirname string) ([]os.DirEntry, error)
	// Remove removes the file with given name.
	Remove(name string) error
}

ClearFoldersOSFileManager is an interface that exposes File I/O operations for ClearFolders. Used for unit testing.

type File

type File struct {
	Path    string
	Content []byte
	Type    Type
}

File is a file that is part of NGINX configuration to be written to the file system.

type Manager

type Manager interface {
	// ReplaceFiles replaces the files on the file system with the given files removing any previous files.
	ReplaceFiles(files []File) error
}

Manager manages NGINX configuration files.

type ManagerImpl

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

ManagerImpl is an implementation of Manager. Note: It is not thread safe.

func NewManagerImpl

func NewManagerImpl(logger logr.Logger, osFileManager OSFileManager) *ManagerImpl

NewManagerImpl creates a new NewManagerImpl.

func (*ManagerImpl) ReplaceFiles

func (m *ManagerImpl) ReplaceFiles(files []File) error

ReplaceFiles replaces the files on the file system with the given files removing any previous files. It panics if a file type is unknown.

type OSFileManager

type OSFileManager interface {
	// ReadDir returns the directory entries for the directory.
	ReadDir(dirname string) ([]fs.DirEntry, error)
	// Remove file with given name.
	Remove(name string) error
	// Create file at the provided filepath.
	Create(name string) (*os.File, error)
	// Chmod sets the mode of the file.
	Chmod(file *os.File, mode os.FileMode) error
	// Write writes contents to the file.
	Write(file *os.File, contents []byte) error
	// Open opens the file.
	Open(name string) (*os.File, error)
	// Copy copies from src to dst.
	Copy(dst io.Writer, src io.Reader) error
}

OSFileManager is an interface that exposes File I/O operations for ManagerImpl. Used for unit testing.

type StdLibOSFileManager

type StdLibOSFileManager struct{}

StdLibOSFileManager wraps the standard library's file operations. Clients can define an interface with all or a subset StdLibOSFileManager methods and use it in their types or functions, so that they can be unit tested. It is expected that clients generate fakes.

func NewStdLibOSFileManager

func NewStdLibOSFileManager() *StdLibOSFileManager

func (*StdLibOSFileManager) Chmod

func (s *StdLibOSFileManager) Chmod(file *os.File, mode os.FileMode) error

Chmod wraps os.File.Chmod.

func (*StdLibOSFileManager) Copy added in v1.5.1

func (s *StdLibOSFileManager) Copy(dst io.Writer, src io.Reader) error

Copy wraps io.Copy.

func (*StdLibOSFileManager) Create

func (s *StdLibOSFileManager) Create(name string) (*os.File, error)

Create wraps os.Create.

func (*StdLibOSFileManager) Open added in v1.5.1

func (s *StdLibOSFileManager) Open(name string) (*os.File, error)

Open wraps os.Open.

func (*StdLibOSFileManager) ReadDir

func (s *StdLibOSFileManager) ReadDir(dirname string) ([]fs.DirEntry, error)

ReadDir wraps os.ReadDir.

func (*StdLibOSFileManager) Remove

func (s *StdLibOSFileManager) Remove(name string) error

Remove wraps os.Remove.

func (*StdLibOSFileManager) Write

func (s *StdLibOSFileManager) Write(file *os.File, contents []byte) error

Write wraps os.File.Write.

type Type

type Type int

Type is the type of File.

const (
	// TypeRegular is the type for regular configuration files.
	TypeRegular Type = iota
	// TypeSecret is the type for secret files.
	TypeSecret
)

func (Type) String

func (t Type) String() string

Directories

Path Synopsis
Code generated by counterfeiter.
Code generated by counterfeiter.

Jump to

Keyboard shortcuts

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