MCPcopy
hub / github.com/perkeep/perkeep / FromConfig

Function FromConfig

pkg/auth/auth.go:180–198  ·  view source on GitHub ↗

FromConfig parses authConfig and accordingly sets up the AuthMode that will be used for all upcoming authentication exchanges. The supported modes are UserPass and DevAuth. UserPass requires an authConfig of the kind "userpass:joe:ponies". If the input string is empty, the error will be ErrNoAuth.

(authConfig string)

Source from the content-addressed store, hash-verified

178//
179// If the input string is empty, the error will be ErrNoAuth.
180func FromConfig(authConfig string) (AuthMode, error) {
181 if authConfig == "" {
182 return nil, ErrNoAuth
183 }
184 pieces := strings.SplitN(authConfig, ":", 2)
185 if len(pieces) < 1 {
186 return nil, fmt.Errorf("Invalid auth string: %q", authConfig)
187 }
188 authType := pieces[0]
189
190 if fn, ok := authConstructor[authType]; ok {
191 arg := ""
192 if len(pieces) == 2 {
193 arg = pieces[1]
194 }
195 return fn(arg)
196 }
197 return nil, fmt.Errorf("Unknown auth type: %q", authType)
198}
199
200// SetMode sets the given authentication mode as the only allowed one for
201// future requests. That is, it replaces all modes that were previously added.

Callers 6

SetupAuthMethod · 0.92
SetupAuthFromStringMethod · 0.92
checkValidAuthMethod · 0.92
newHandlerFunction · 0.92
FromEnvFunction · 0.85
TestFromConfigFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestFromConfigFunction · 0.68