Skip to content

Commit e5e5e10

Browse files
planner: make path functions decoupled from planner and public
Reduce the surface area of the planner and group the path generation functions together under a public helper type. Signed-off-by: John Mulligan <[email protected]>
1 parent 8fe42ce commit e5e5e10

File tree

3 files changed

+57
-23
lines changed

3 files changed

+57
-23
lines changed

internal/planner/args.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (sp *Planner) dnsRegisterArgs() []string {
3535
if sp.DNSRegister() == DNSRegisterClusterIP {
3636
args = append(args, "--target=internal")
3737
}
38-
args = append(args, sp.serviceWatchJSONPath())
38+
args = append(args, sp.Paths().ServiceWatchJSON())
3939
return args
4040
}
4141

internal/planner/configuration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func (sp *Planner) Update() (changed bool, err error) {
9292
shareKey := smbcc.Key(sp.shareName())
9393
share, found := sp.ConfigState.Shares[shareKey]
9494
if !found {
95-
share = smbcc.NewSimpleShare(sp.sharePath())
95+
share = smbcc.NewSimpleShare(sp.Paths().Share())
9696
if !sp.SmbShare.Spec.Browseable {
9797
share.Options[smbcc.BrowseableParam] = smbcc.No
9898
}

internal/planner/paths.go

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,93 @@ import (
2020
"path"
2121
)
2222

23-
func (sp *Planner) sharePath() string {
24-
return path.Join("/mnt", string(sp.SmbShare.UID))
23+
// Paths for relevant files and dirs within the containers.
24+
type Paths struct {
25+
planner *Planner
2526
}
2627

27-
func (sp *Planner) containerConfigPath() string {
28-
cpath := path.Join(sp.containerConfigDir(), "config.json")
29-
if sp.UserSecuritySource().Configured {
30-
upath := path.Join(sp.usersConfigDir(), sp.usersConfigFileName())
31-
cpath += ":" + upath
28+
// Paths returns an instance of the Paths type for our intended configuration.
29+
func (planner *Planner) Paths() *Paths {
30+
return &Paths{planner}
31+
}
32+
33+
// Share path.
34+
func (p *Paths) Share() string {
35+
return path.Join("/mnt", string(p.planner.SmbShare.UID))
36+
}
37+
38+
// ContainerConfigs returns a slice containing all configuration
39+
// files that the samba-container should process.
40+
func (p *Paths) ContainerConfigs() []string {
41+
paths := []string{p.containerConfig()}
42+
if uc := p.usersConfig(); uc != "" {
43+
paths = append(paths, uc)
44+
}
45+
return paths
46+
}
47+
48+
func (p *Paths) containerConfig() string {
49+
return path.Join(p.ContainerConfigDir(), "config.json")
50+
}
51+
52+
func (p *Paths) usersConfig() string {
53+
if !p.planner.UserSecuritySource().Configured {
54+
return ""
3255
}
33-
return cpath
56+
return path.Join(p.UsersConfigDir(), p.UsersConfigBaseName())
3457
}
3558

36-
func (*Planner) containerConfigDir() string {
59+
// ContainerConfigDir absolute path.
60+
func (*Paths) ContainerConfigDir() string {
3761
return "/etc/container-config"
3862
}
3963

40-
func (*Planner) usersConfigFileName() string {
64+
// UsersConfigBaseName file name component.
65+
func (*Paths) UsersConfigBaseName() string {
4166
return "users.json"
4267
}
4368

44-
func (*Planner) usersConfigDir() string {
69+
// UsersConfigDir absolute path.
70+
func (*Paths) UsersConfigDir() string {
4571
return "/etc/container-users"
4672
}
4773

48-
func (*Planner) winbindSocketsDir() string {
74+
// WinbindSocketsDir absolute path.
75+
func (*Paths) WinbindSocketsDir() string {
4976
return "/run/samba/winbindd"
5077
}
5178

52-
func (*Planner) sambaStateDir() string {
79+
// SambaStateDir absolute path.
80+
func (*Paths) SambaStateDir() string {
5381
return "/var/lib/samba"
5482
}
5583

56-
func (*Planner) osRunDir() string {
84+
// OSRunDir absolute path.
85+
func (*Paths) OSRunDir() string {
5786
return "/run"
5887
}
5988

60-
func (*Planner) joinJSONSourceDir(index int) string {
89+
// JoinJSONSourceDir absolute path based on the given index value.
90+
func (*Paths) JoinJSONSourceDir(index int) string {
6191
return fmt.Sprintf("/var/tmp/join/%d", index)
6292
}
6393

64-
func (*Planner) joinJSONFileName() string {
94+
// JoinJSONBaseName file name component.
95+
func (*Paths) JoinJSONBaseName() string {
6596
return "join.json"
6697
}
6798

68-
func (sp *Planner) joinJSONSourcePath(index int) string {
69-
return path.Join(sp.joinJSONSourceDir(index), sp.joinJSONFileName())
99+
// JoinJSONSource absolute path based on the given index value.
100+
func (p *Paths) JoinJSONSource(index int) string {
101+
return path.Join(p.JoinJSONSourceDir(index), p.JoinJSONBaseName())
70102
}
71103

72-
func (*Planner) serviceWatchStateDir() string {
104+
// ServiceWatchStateDir absolute path.
105+
func (*Paths) ServiceWatchStateDir() string {
73106
return "/var/lib/svcwatch"
74107
}
75108

76-
func (sp *Planner) serviceWatchJSONPath() string {
77-
return path.Join(sp.serviceWatchStateDir(), "status.json")
109+
// ServiceWatchJSON file absolute path.
110+
func (p *Paths) ServiceWatchJSON() string {
111+
return path.Join(p.ServiceWatchStateDir(), "status.json")
78112
}

0 commit comments

Comments
 (0)