MCPcopy
hub / github.com/harness/harness / getSanitizedMachineName

Function getSanitizedMachineName

cli/operations/server/config.go:224–271  ·  view source on GitHub ↗

getSanitizedMachineName gets the name of the machine and returns it in sanitized format.

()

Source from the content-addressed store, hash-verified

222
223// getSanitizedMachineName gets the name of the machine and returns it in sanitized format.
224func getSanitizedMachineName() (string, error) {
225 // use the hostname as default id of the instance
226 hostName, err := os.Hostname()
227 if err != nil {
228 return "", err
229 }
230
231 // Always cast to lower and remove all unwanted chars
232 // NOTE: this could theoretically lead to overlaps, then it should be passed explicitly
233 // NOTE: for k8s names/ids below modifications are all noops
234 // https://kubernetes.io/docs/concepts/overview/working-with-objects/names/
235
236 // The following code will:
237 // * remove invalid runes
238 // * remove diacritical marks (ie "smörgåsbord" to "smorgasbord")
239 // * lowercase A-Z to a-z
240 // * leave only a-z, 0-9, '-', '.' and replace everything else with '_'
241 hostName, _, err = transform.String(
242 transform.Chain(
243 norm.NFD,
244 runes.ReplaceIllFormed(),
245 runes.Remove(runes.In(unicode.Mn)),
246 runes.Map(
247 func(r rune) rune {
248 switch {
249 case 'A' <= r && r <= 'Z':
250 return r + 32
251 case 'a' <= r && r <= 'z':
252 return r
253 case '0' <= r && r <= '9':
254 return r
255 case r == '-', r == '.':
256 return r
257 default:
258 return '_'
259 }
260 },
261 ),
262 norm.NFC,
263 ),
264 hostName,
265 )
266 if err != nil {
267 return "", err
268 }
269
270 return hostName, nil
271}
272
273// ProvideDatabaseConfig loads the database config from the main config.
274func ProvideDatabaseConfig(config *types.Config) database.Config {

Callers 1

LoadConfigFunction · 0.85

Calls 3

RemoveMethod · 0.80
MapMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…