This repository has been archived by the owner on Feb 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
svnconfig.go
96 lines (82 loc) · 2.52 KB
/
svnconfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
// Package svnconfig generates config files for SVN server.
package svnconfig
import (
"bytes"
"text/template"
"sigs.k8s.io/yaml"
)
var (
tmplAuthzSVNAccessFile = template.Must(template.New("AuthzSVNAccessFile").Parse(rawTmplAuthzSVNAccessFile))
tmplAuthUserFile = template.Must(template.New("AuthUserFile").Parse(rawTmplAuthUserFile))
)
// Generator generates configuration files for SVN server.
//
// NB: Generator assumes that all fields and parameters are VALIDATED ELSEWHERE and does not validate nor escape
// any fields. Be careful if you want to generate configuration files from untrusted source.
type Generator struct {
Repositories []Repository
Groups []Group
Users []User
}
// Repository is a definition of a repository.
type Repository struct {
Name string
Permissions []Permission
}
// Permission configurates permission to a specific repository.
type Permission struct {
Group string
Permission string
}
// Group is a definitions of a group.
type Group struct {
Name string
Users []string
}
// User is a definition of a user.
type User struct {
Name string
EncryptedPassword string
}
// ReposConfig is a special configuration structure that is used to create SVN repositories.
type ReposConfig struct {
Repositories []RepoEntry `json:"repositories"`
}
// RepoEntry is an entry for SVN repository.
type RepoEntry struct {
Name string `json:"name,omitempty"`
}
// AuthzSVNAccessFile is an authorization configuration file for mod_authz_svn.
//
// See https://svn.apache.org/repos/asf/subversion/trunk/subversion/mod_authz_svn/INSTALL for more details.
func (g *Generator) AuthzSVNAccessFile() (string, error) {
buf := bytes.NewBuffer(nil)
if err := tmplAuthzSVNAccessFile.Execute(buf, g); err != nil {
return "", err
}
return buf.String(), nil
}
// AuthUserFile is an authentication configuration file for mod_authn_file.
//
// See https://httpd.apache.org/docs/2.4/en/mod/mod_authn_file.html for more details.
func (g *Generator) AuthUserFile() (string, error) {
buf := bytes.NewBuffer(nil)
if err := tmplAuthUserFile.Execute(buf, g); err != nil {
return "", err
}
return buf.String(), nil
}
func (g *Generator) ReposConfig() (string, error) {
marshaled, err := yaml.Marshal(g.BuildReposConfig())
if err != nil {
return "", err
}
return string(marshaled), nil
}
func (g *Generator) BuildReposConfig() *ReposConfig {
repos := []RepoEntry{}
for _, r := range g.Repositories {
repos = append(repos, RepoEntry{Name: r.Name})
}
return &ReposConfig{Repositories: repos}
}