a2conf

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 17 Imported by: 2

README

a2conf

Parse and manipulate with apache2 config using augeas library

Installation

go get r2dtools/a2conf

Example

import (
	"encoding/json"
	"fmt"

	"github.com/r2dtools/a2conf"
)

func main() {
	configurator, err := a2conf.GetApacheConfigurator(nil)

	if err != nil {
		panic(fmt.Sprintf("could not create apache configurator: %v", err))
	}

	vhosts, err := configurator.GetVhosts()

	if err != nil {
		panic(fmt.Sprintf("could not get virtual hosts: %v", err))
	}

	jsonVhosts, _ := json.Marshal(vhosts)
	fmt.Printf("vhsosts: %v", string(jsonVhosts))
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetAugPath

func GetAugPath(fullPath string) string

GetAugPath returns Augeas path for the file full path

Types

type ApacheConfigurator

type ApacheConfigurator interface {
	GetParser() *Parser
	GetVhosts() ([]*entity.VirtualHost, error)
	Save() error
	DeployCertificate(serverName, certPath, certKeyPath, chainPath, fullChainPath string) error
	EnableSite(vhost *entity.VirtualHost) error
	PrepareHTTPSModules(temp bool) error
	EnableModule(module string, temp bool) error
	EnsurePortIsListening(port string, https bool) error
	GetSuitableVhosts(serverName string, createIfNoSsl bool) ([]*entity.VirtualHost, error)
	FindSuitableVhosts(serverName string) ([]*entity.VirtualHost, error)
	CheckConfiguration() bool
	RestartWebServer() error
	SetLogger(logger logger.Logger)
	Commit() error
	Rollback() error
}

ApacheConfigurator manipulates with apache configs

func GetApacheConfigurator

func GetApacheConfigurator(options map[string]string) (ApacheConfigurator, error)

GetApacheConfigurator returns ApacheConfigurator instance

type Parser

type Parser struct {
	Augeas       augeas.Augeas
	ApacheCtl    *apache.Ctl
	ServerRoot   string
	VHostRoot    string
	ConfigRoot   string
	СonfigListen string

	Paths map[string][]string

	Modules map[string]bool
	// contains filtered or unexported fields
}

Parser ia a wrapper under the augeas to work with httpd config

func GetParser

func GetParser(apachectl *apache.Ctl, version, serverRoot, vhostRoot string) (*Parser, error)

GetParser creates parser instance

func (*Parser) AddDirective

func (p *Parser) AddDirective(augConfPath string, directive string, args []string) error

AddDirective adds directive to the end of the file given by augConfPath

func (*Parser) AddDirectiveToIfModSSL

func (p *Parser) AddDirectiveToIfModSSL(augConfPath string, directive string, args []string) error

AddDirectiveToIfModSSL adds directive to the end of the file given by augConfPath within IfModule ssl block

func (*Parser) AddInclude

func (p *Parser) AddInclude(mainConfigPath string, inclPath string) error

AddInclude adds Include directive for a configuration file

func (*Parser) AddModule

func (p *Parser) AddModule(name string)

AddModule shortcut for updating parser modules.

func (*Parser) Close

func (p *Parser) Close()

Close closes the Parser instance and frees any storage associated with it.

func (*Parser) CreateIfModule

func (p *Parser) CreateIfModule(augConfPath string, mod string, begining bool) (string, error)

CreateIfModule creates a new <IfMod mod> and returns its path

func (*Parser) ExcludeDirectives

func (p *Parser) ExcludeDirectives(matches []string) ([]string, error)

ExcludeDirectives excludes directives that are not loaded into the configuration.

func (*Parser) FindDirective

func (p *Parser) FindDirective(directive, arg, start string, exclude bool) ([]string, error)

FindDirective finds directive in configuration directive - directive to look for arg - directive value. If empty string then all directives should be considrered start - Augeas path that should be used to begin looking for the directive exclude - whether or not to exclude directives based on variables and enabled modules

func (*Parser) GetArg

func (p *Parser) GetArg(match string) (string, error)

GetArg returns argument value and interprets result

func (*Parser) GetAugeasError

func (p *Parser) GetAugeasError(errorsToExclude []string) error

GetAugeasError return Augeas errors

func (*Parser) GetIfModule

func (p *Parser) GetIfModule(augConfPath string, mod string, begining bool) (string, error)

GetIfModule returns the path to <IfModule mod> and creates one if it does not exist

func (*Parser) GetRootAugPath

func (p *Parser) GetRootAugPath() (string, error)

GetRootAugPath returns Augeas path of the root configuration

func (*Parser) GetUnsavedFiles

func (p *Parser) GetUnsavedFiles() ([]string, error)

GetUnsavedFiles returns unsaved paths

func (*Parser) IsFilenameExistInCurrentPaths

func (p *Parser) IsFilenameExistInCurrentPaths(filename string) bool

IsFilenameExistInCurrentPaths checks if the file path is parsed by current Augeas parser config

func (*Parser) IsFilenameExistInOriginalPaths

func (p *Parser) IsFilenameExistInOriginalPaths(filename string) bool

IsFilenameExistInOriginalPaths checks if the file path is parsed by existing Apache config

func (*Parser) ParseFile

func (p *Parser) ParseFile(fPath string) error

ParseFile parses file with Auegause

func (*Parser) ResetModules

func (p *Parser) ResetModules() error

ResetModules resets the loaded modules list

func (*Parser) Save

func (p *Parser) Save(reverter *Reverter) error

Save saves all chages to the reconfiguratiob files

func (*Parser) SetBeforeDomReloadCallback

func (p *Parser) SetBeforeDomReloadCallback(callback func(unsavedFiles []string))

SetBeforeDomReloadCallback sets callback that will be executed before augeas dom load/reload It can be used to makes sure that all Augeas dom changes are written to files to avoid loss of configuration directives when doing additional augeas parsing, causing a possible augeas.load() resulting dom reset

func (*Parser) UpdateDefines

func (p *Parser) UpdateDefines() error

UpdateDefines Updates the map of known variables in the configuration

func (*Parser) UpdateIncludes

func (p *Parser) UpdateIncludes() error

UpdateIncludes gets includes from httpd process, and add them to DOM if needed

func (*Parser) UpdateModules

func (p *Parser) UpdateModules() error

UpdateModules gets loaded modules from httpd process, and add them to DOM

func (*Parser) UpdateRuntimeVariables

func (p *Parser) UpdateRuntimeVariables() error

UpdateRuntimeVariables Updates Includes, Defines and Includes from httpd config dump data

type Reverter

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

Reverter reverts change back for configuration files of virtual hosts

func (*Reverter) AddFileToDeletion

func (r *Reverter) AddFileToDeletion(filePath string)

AddFileToDeletion marks file to delete on rollback

func (*Reverter) AddSiteConfigToDisable

func (r *Reverter) AddSiteConfigToDisable(siteConfigName string)

AddSiteConfigToDisable marks apache site config as needed to be disabled on rollback

func (*Reverter) BackupFile

func (r *Reverter) BackupFile(filePath string) error

BackupFile makes file backup. The file content will be restored on rollback.

func (*Reverter) BackupFiles

func (r *Reverter) BackupFiles(filePaths []string) error

BackupFiles makes files backups

func (*Reverter) Commit

func (r *Reverter) Commit() error

Commit commits changes. All *.back files will be removed.

func (*Reverter) Rollback

func (r *Reverter) Rollback() error

Rollback rollback all changes

func (*Reverter) SetLogger

func (r *Reverter) SetLogger(logger logger.Logger)

SetLogger sets logger

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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