MCPcopy
hub / github.com/harness/harness / LoadConfig

Function LoadConfig

cli/operations/server/config.go:63–107  ·  view source on GitHub ↗

LoadConfig returns the system configuration from the host environment.

()

Source from the content-addressed store, hash-verified

61// LoadConfig returns the system configuration from the
62// host environment.
63func LoadConfig() (*types.Config, error) {
64 config := new(types.Config)
65 err := envconfig.Process("", config)
66 if err != nil {
67 return nil, err
68 }
69
70 config.InstanceID, err = getSanitizedMachineName()
71 if err != nil {
72 return nil, fmt.Errorf("unable to ensure that instance ID is set in config: %w", err)
73 }
74
75 err = backfillURLs(config)
76 if err != nil {
77 return nil, fmt.Errorf("failed to backfil urls: %w", err)
78 }
79
80 if config.Git.HookPath == "" {
81 executablePath, err := os.Executable()
82 if err != nil {
83 return nil, fmt.Errorf("failed to get path of current executable: %w", err)
84 }
85
86 config.Git.HookPath = executablePath
87 }
88
89 if config.Git.Root == "" {
90 homedir, err := os.UserHomeDir()
91 if err != nil {
92 return nil, err
93 }
94
95 newPath := filepath.Join(homedir, gitnessHomeDir)
96 config.Git.Root = newPath
97
98 oldPath := filepath.Join(homedir, ".gitrpc")
99 if _, err := os.Stat(oldPath); err == nil {
100 if err := os.Rename(oldPath, newPath); err != nil {
101 config.Git.Root = oldPath
102 }
103 }
104 }
105
106 return config, nil
107}
108
109//nolint:gocognit // refactor if required
110func backfillURLs(config *types.Config) error {

Callers 2

getDBFunction · 0.92
runMethod · 0.85

Calls 5

getSanitizedMachineNameFunction · 0.85
backfillURLsFunction · 0.85
JoinMethod · 0.80
StatMethod · 0.65
ErrorfMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…