go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/logindefs/logindefs.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package logindefs
     5  
     6  import (
     7  	"bufio"
     8  	"io"
     9  	"regexp"
    10  	"strings"
    11  )
    12  
    13  func Parse(r io.Reader) map[string]string {
    14  	res := map[string]string{}
    15  
    16  	// ignore line if it starts with a comment
    17  	logindefEntry := regexp.MustCompile(`^\s*([^#]\S+)\s+(\S+)\s*$`)
    18  
    19  	scanner := bufio.NewScanner(r)
    20  	for scanner.Scan() {
    21  		line := scanner.Text()
    22  		noWhitespace := strings.TrimSpace(line)
    23  
    24  		m := logindefEntry.FindStringSubmatch(noWhitespace)
    25  		if len(m) == 3 {
    26  			res[m[1]] = m[2]
    27  		}
    28  	}
    29  
    30  	return res
    31  }