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

Function NewStaticAuth

auth/static.go:16–58  ·  view source on GitHub ↗
(param_url *url.URL, logger *clog.CondLogger)

Source from the content-addressed store, hash-verified

14)
15
16func NewStaticAuth(param_url *url.URL, logger *clog.CondLogger) (*BasicAuth, error) {
17 values, err := url.ParseQuery(param_url.RawQuery)
18 if err != nil {
19 return nil, err
20 }
21 username := values.Get("username")
22 if username == "" {
23 return nil, errors.New("\"username\" parameter is missing from auth config URI")
24 }
25 password := values.Get("password")
26 if password == "" {
27 return nil, errors.New("\"password\" parameter is missing from auth config URI")
28 }
29 hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.MinCost)
30 if err != nil {
31 return nil, err
32 }
33 buf := bytes.NewBufferString(username)
34 buf.WriteByte(':')
35 buf.Write(hashedPassword)
36
37 f, err := htpasswd.NewFromReader(buf, htpasswd.DefaultSystems, func(parseError error) {
38 logger.Error("static auth: password entry parse error: %v", err)
39 })
40 if err != nil {
41 return nil, fmt.Errorf("can't instantiate pwFile: %w", err)
42 }
43
44 ba := &BasicAuth{
45 hiddenDomain: strings.ToLower(values.Get("hidden_domain")),
46 logger: logger,
47 stopChan: make(chan struct{}),
48 }
49 ba.pw.Store(&pwFile{file: f})
50 if nextAuth := values.Get("else"); nextAuth != "" {
51 nap, err := NewAuth(nextAuth, logger)
52 if err != nil {
53 return nil, fmt.Errorf("chained auth provider construction failed: %w", err)
54 }
55 ba.next = nap
56 }
57 return ba, nil
58}

Callers 1

NewAuthFunction · 0.85

Calls 5

NewAuthFunction · 0.85
ErrorfMethod · 0.80
GetMethod · 0.45
WriteMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected