Skip to content

Commit 467066b

Browse files
committed
tools/geneos: consolidate the various almost-identical file import loops, rename component file lists and refactor previous internal ImportFiles to Filename type
1 parent 85d5f73 commit 467066b

File tree

9 files changed

+31
-69
lines changed

9 files changed

+31
-69
lines changed

tools/geneos/cmd/add.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import (
3535
var addCmdTemplate, addCmdBase, addCmdKeyfileCRC string
3636
var addCmdStart, addCmdLogs bool
3737
var addCmdPort uint16
38-
var addCmdImportFiles instance.ImportFiles
38+
var addCmdImportFiles instance.Filename
3939
var addCmdKeyfile string
4040

4141
var addCmdExtras = instance.SetConfigValues{}
@@ -195,12 +195,7 @@ func AddInstance(ct *geneos.Component, addCmdExtras instance.SetConfigValues, it
195195
i.Load()
196196
i.Rebuild(true)
197197

198-
for _, importfile := range addCmdImportFiles {
199-
if _, err = geneos.ImportSource(i.Host(), i.Home(), importfile); err != nil && err != geneos.ErrExists {
200-
return err
201-
}
202-
}
203-
err = nil
198+
_ = instance.ImportFiles(i, addCmdImportFiles...)
204199

205200
fmt.Printf("%s added, port %d\n", i, cf.GetInt("port"))
206201

tools/geneos/cmd/deploy.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var deployCmdSigningBundle, deployCmdInstanceBundle string
4343
var deployCmdPort uint16
4444
var deployCmdArchive, deployCmdVersion, deployCmdOverride string
4545
var deployCmdPassword *config.Plaintext
46-
var deployCmdImportFiles instance.ImportFiles
46+
var deployCmdImportFiles instance.Filename
4747
var deployCmdKeyfile string
4848
var deployCmdExtras = instance.SetConfigValues{}
4949

@@ -388,12 +388,7 @@ var deployCmd = &cobra.Command{
388388
log.Debug().Msgf("home is now %s", i.Home())
389389
i.Rebuild(true)
390390

391-
for _, importfile := range deployCmdImportFiles {
392-
if _, err = geneos.ImportSource(i.Host(), i.Home(), importfile); err != nil && err != geneos.ErrExists {
393-
return err
394-
}
395-
}
396-
err = nil
391+
_ = instance.ImportFiles(i, deployCmdImportFiles...)
397392

398393
fmt.Printf("%s added, port %d\n", i, cf.GetInt("port"))
399394

tools/geneos/cmd/import.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,7 @@ func importInstance(i geneos.Instance, params ...any) (resp *instance.Response)
137137
log.Fatal().Msg("no file/url provided")
138138
}
139139

140-
for _, source := range sources {
141-
if _, resp.Err = geneos.ImportSource(i.Host(), i.Home(), source); resp.Err != nil && resp.Err != geneos.ErrExists {
142-
return
143-
}
144-
}
140+
_ = instance.ImportFiles(i, sources...)
145141
resp.Err = nil
146142
return
147143
}

tools/geneos/internal/component/ac2/ac2.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var AC2 = geneos.Component{
8181
GetPID: pidCheckFn,
8282
}
8383

84-
var ac2Files = []string{
84+
var initialFiles = []string{
8585
// "ActiveConsole.gci",
8686
// "log4j2.properties",
8787
// "defaultws.dwx",
@@ -199,13 +199,7 @@ func (n *AC2s) Add(tmpl string, port uint16) (err error) {
199199
return
200200
}
201201

202-
for _, source := range ac2Files {
203-
if _, err = geneos.ImportSource(n.Host(), n.Home(), source); err != nil && err != geneos.ErrExists {
204-
return
205-
}
206-
}
207-
err = nil
208-
202+
_ = instance.ImportFiles(n, initialFiles...)
209203
return
210204
}
211205

tools/geneos/internal/component/ca3/ca3.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ const (
9393

9494
var ca3jarRE = regexp.MustCompile(`^` + ca3prefix + `(.+)` + ca3suffix)
9595

96-
var ca3Files = []string{
96+
var initialFiles = []string{
9797
"collection-agent.yml",
9898
"logback.xml",
9999
}
@@ -210,14 +210,7 @@ func (n *CA3s) Add(tmpl string, port uint16) (err error) {
210210
return
211211
}
212212

213-
for _, source := range ca3Files {
214-
if _, err = geneos.ImportSource(n.Host(), n.Home(), source); err != nil && err != geneos.ErrExists {
215-
return
216-
}
217-
}
218-
err = nil
219-
220-
// default config XML etc.
213+
_ = instance.ImportFiles(n, initialFiles...)
221214
return
222215
}
223216

tools/geneos/internal/component/ssoagent/ssoagent.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ func factory(name string) geneos.Instance {
142142
// list of file patterns to copy?
143143
// from WebBins + WebBase + /config
144144

145-
// ssoagentFiles is a list of files to import from the "read-only"
145+
// initialFiles is a list of files to import from the "read-only"
146146
// package.
147147
//
148148
// `config/=config/file` means import file into config/ with no name
149149
// change
150-
var ssoagentFiles = []string{
150+
var initialFiles = []string{
151151
"conf",
152152
}
153153

@@ -226,14 +226,7 @@ func (s *SSOAgents) Add(tmpl string, port uint16) (err error) {
226226
return
227227
}
228228

229-
for _, source := range ssoagentFiles {
230-
if _, err = geneos.ImportSource(s.Host(), s.Home(), source); err != nil && !errors.Is(err, geneos.ErrExists) {
231-
log.Warn().Err(err).Msgf("source file %q may not exist", source)
232-
return
233-
}
234-
}
235-
err = nil
236-
229+
_ = instance.ImportFiles(s, initialFiles...)
237230
return
238231
}
239232

tools/geneos/internal/component/webserver/webserver.go

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,15 @@ func factory(name string) geneos.Instance {
145145
// list of file patterns to copy?
146146
// from WebBins + WebBase + /config
147147

148-
// webserverFiles is a list of files to import from the "read-only"
148+
// initialFiles is a list of files to import from the "read-only"
149149
// package.
150150
//
151151
// `config/=config/file` means import file into config/ with no name
152152
// change
153-
var webserverFiles = []string{
153+
var initialFiles = []string{
154+
"config",
154155
"config/config.xml=config/config.xml.min.tmpl",
155-
"config/=config/log4j.properties",
156-
"config/=config/log4j2.properties",
157-
"config/=config/logging.properties",
158-
"config/=config/login.conf",
159-
"config/=config/security.properties",
160-
"config/=config/security.xml",
161-
"config/=config/sso.properties",
162-
"config/=config/users.properties",
163-
"cacerts=JRE/lib/security/cacerts",
156+
"JRE/lib/security/cacerts",
164157
}
165158

166159
// interface method set
@@ -243,13 +236,7 @@ func (w *Webservers) Add(tmpl string, port uint16) (err error) {
243236
return
244237
}
245238

246-
for _, source := range webserverFiles {
247-
if _, err = geneos.ImportSource(w.Host(), w.Home(), source); err != nil && err != geneos.ErrExists {
248-
return
249-
}
250-
}
251-
err = nil
252-
239+
_ = instance.ImportFiles(w, initialFiles...)
253240
return
254241
}
255242

tools/geneos/internal/instance/instance.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,3 +411,12 @@ func SplitName(in string, defaultHost *geneos.Host) (ct *geneos.Component, name
411411
}
412412
return
413413
}
414+
415+
func ImportFiles(s geneos.Instance, files ...string) (err error) {
416+
for _, source := range files {
417+
if _, err = geneos.ImportSource(s.Host(), s.Home(), source); err != nil {
418+
return
419+
}
420+
}
421+
return
422+
}

tools/geneos/internal/instance/values.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -574,18 +574,18 @@ func (i *UnsetVars) Type() string {
574574
return "SETTING"
575575
}
576576

577-
// ImportFiles fulfils the Var interface for pflag
578-
type ImportFiles []string
577+
// Filename fulfils the Var interface for pflag
578+
type Filename []string
579579

580-
func (i *ImportFiles) String() string {
580+
func (i *Filename) String() string {
581581
return ""
582582
}
583583

584-
func (i *ImportFiles) Set(value string) error {
584+
func (i *Filename) Set(value string) error {
585585
*i = append(*i, value)
586586
return nil
587587
}
588588

589-
func (i *ImportFiles) Type() string {
589+
func (i *Filename) Type() string {
590590
return "[DEST=]PATH|URL"
591591
}

0 commit comments

Comments
 (0)