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)
| 178 | // |
| 179 | // If the input string is empty, the error will be ErrNoAuth. |
| 180 | func 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. |
no outgoing calls