MCPcopy Index your code
hub / github.com/oauth2-proxy/oauth2-proxy / LoadAuthenticatedEmailsFile

Method LoadAuthenticatedEmailsFile

validator.go:48–74  ·  view source on GitHub ↗

LoadAuthenticatedEmailsFile loads the authenticated emails file from disk and parses the contents as CSV

()

Source from the content-addressed store, hash-verified

46// LoadAuthenticatedEmailsFile loads the authenticated emails file from disk
47// and parses the contents as CSV
48func (um *UserMap) LoadAuthenticatedEmailsFile() {
49 r, err := os.Open(um.usersFile)
50 if err != nil {
51 logger.Fatalf("failed opening authenticated-emails-file=%q, %s", um.usersFile, err)
52 }
53 defer func(c io.Closer) {
54 cerr := c.Close()
55 if cerr != nil {
56 logger.Fatalf("Error closing authenticated emails file: %s", cerr)
57 }
58 }(r)
59 csvReader := csv.NewReader(r)
60 csvReader.Comma = ','
61 csvReader.Comment = '#'
62 csvReader.TrimLeadingSpace = true
63 records, err := csvReader.ReadAll()
64 if err != nil {
65 logger.Errorf("error reading authenticated-emails-file=%q, %s", um.usersFile, err)
66 return
67 }
68 updated := make(map[string]bool)
69 for _, r := range records {
70 address := strings.ToLower(strings.TrimSpace(r[0]))
71 updated[address] = true
72 }
73 atomic.StorePointer(&um.m, unsafe.Pointer(&updated)) // #nosec G103
74}
75
76func newValidatorImpl(domains []string, usersFile string,
77 done <-chan bool, onUpdate func()) func(string) bool {

Callers 1

NewUserMapFunction · 0.95

Calls 3

FatalfFunction · 0.92
ErrorfFunction · 0.92
CloseMethod · 0.65

Tested by

no test coverage detected