MCPcopy Create free account
hub / github.com/SenseUnit/dumbproxy / NewBasicFileAuth

Function NewBasicFileAuth

auth/basic.go:34–76  ·  view source on GitHub ↗
(param_url *url.URL, logger *clog.CondLogger)

Source from the content-addressed store, hash-verified

32}
33
34func NewBasicFileAuth(param_url *url.URL, logger *clog.CondLogger) (*BasicAuth, error) {
35 values, err := url.ParseQuery(param_url.RawQuery)
36 if err != nil {
37 return nil, err
38 }
39 filename := values.Get("path")
40 if filename == "" {
41 return nil, errors.New("\"path\" parameter is missing from auth config URI")
42 }
43
44 auth := &BasicAuth{
45 hiddenDomain: strings.ToLower(values.Get("hidden_domain")),
46 pwFilename: filename,
47 logger: logger,
48 stopChan: make(chan struct{}),
49 }
50
51 if err := auth.reload(); err != nil {
52 return nil, fmt.Errorf("unable to load initial password list: %w", err)
53 }
54
55 reloadInterval := 15 * time.Second
56 if reloadIntervalOption := values.Get("reload"); reloadIntervalOption != "" {
57 parsedInterval, err := time.ParseDuration(reloadIntervalOption)
58 if err != nil {
59 logger.Warning("unable to parse reload interval: %v. using default value.", err)
60 }
61 reloadInterval = parsedInterval
62 }
63 if reloadInterval > 0 {
64 go auth.reloadLoop(reloadInterval)
65 }
66 if nextAuth := values.Get("else"); nextAuth != "" {
67 nap, err := NewAuth(nextAuth, logger)
68 if err != nil {
69 defer auth.Close()
70 return nil, fmt.Errorf("chained auth provider construction failed: %w", err)
71 }
72 auth.next = nap
73 }
74
75 return auth, nil
76}
77
78func (auth *BasicAuth) reload() error {
79 var oldModTime time.Time

Callers 1

NewAuthFunction · 0.85

Calls 7

reloadMethod · 0.95
reloadLoopMethod · 0.95
CloseMethod · 0.95
NewAuthFunction · 0.85
ErrorfMethod · 0.80
GetMethod · 0.45
WarningMethod · 0.45

Tested by

no test coverage detected