github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/pkg/config/remoteconfig/config.go (about) 1 package remoteconfig 2 3 import ( 4 "path/filepath" 5 6 "github.com/ddev/ddev/pkg/build" 7 "github.com/ddev/ddev/pkg/config/remoteconfig/internal" 8 ) 9 10 // Local is the struct defining the local source. 11 type Local struct { 12 Path string 13 } 14 15 // Remote is the struct defining the remote source. 16 type Remote struct { 17 Owner string 18 Repo string 19 Ref string 20 Filepath string 21 } 22 23 // Config is the struct defining the RemoteConfig config. 24 type Config struct { 25 Local Local 26 Remote Remote 27 28 UpdateInterval int 29 TickerInterval int 30 } 31 32 // getLocalSourceFileName returns the filename of the local storage. 33 func (c *Config) getLocalSourceFileName() string { 34 return filepath.Join(c.Local.Path, localFileName) 35 } 36 37 // getRemoteSourceOwner returns the owner to be used for the remote 38 // config download from GitHub, the global config overwrites the default. 39 func (c *Config) getRemoteSourceOwner(remoteConfig *internal.RemoteConfig) string { 40 if c.Remote.Owner != "" { 41 return c.Remote.Owner 42 } 43 44 if remoteConfig.Remote.Owner != "" { 45 return remoteConfig.Remote.Owner 46 } 47 48 return build.RemoteConfigRemoteSourceOwner 49 } 50 51 // getRemoteSourceRepo returns the repo to be used for the remote 52 // config download from GitHub, the global config overwrites the default. 53 func (c *Config) getRemoteSourceRepo(remoteConfig *internal.RemoteConfig) string { 54 if c.Remote.Repo != "" { 55 return c.Remote.Repo 56 } 57 58 if remoteConfig.Remote.Repo != "" { 59 return remoteConfig.Remote.Repo 60 } 61 62 return build.RemoteConfigRemoteSourceRepo 63 } 64 65 // getRemoteSourceRef returns the ref to be used for the remote 66 // config download from GitHub, the global config overwrites the default. 67 func (c *Config) getRemoteSourceRef(remoteConfig *internal.RemoteConfig) string { 68 if c.Remote.Ref != "" { 69 return c.Remote.Ref 70 } 71 72 if remoteConfig.Remote.Ref != "" { 73 return remoteConfig.Remote.Ref 74 } 75 76 return build.RemoteConfigRemoteSourceRef 77 } 78 79 // getRemoteSourceFilepath returns the filepath to be used for the remote 80 // config download from GitHub, the global config overwrites the default. 81 func (c *Config) getRemoteSourceFilepath(remoteConfig *internal.RemoteConfig) string { 82 if c.Remote.Filepath != "" { 83 return c.Remote.Filepath 84 } 85 86 if remoteConfig.Remote.Filepath != "" { 87 return remoteConfig.Remote.Filepath 88 } 89 90 return build.RemoteConfigRemoteSourceFilepath 91 }