-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
159 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from .base import AuthPlugin | ||
from .manager import PluginManager | ||
from .builtin import BasicAuthPlugin, DigestAuthPlugin | ||
|
||
|
||
plugin_manager = PluginManager() | ||
plugin_manager.register(BasicAuthPlugin) | ||
plugin_manager.register(DigestAuthPlugin) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
class AuthPlugin(object): | ||
""" | ||
Base auth plugin class. | ||
See <https://github.com/jkbr/httpie-ntlm> for an example auth plugin. | ||
""" | ||
|
||
# The value that should be passed to --auth-type | ||
# to use this auth plugin. Eg. "my-auth" | ||
auth_type = None | ||
|
||
# The name of the plugin, eg. "My auth". | ||
name = None | ||
|
||
# Optional short description. Will be be shown in the help | ||
# under --auth-type. | ||
description = None | ||
|
||
# This be set automatically once the plugin has been loaded. | ||
package_name = None | ||
|
||
def get_auth(self, username, password): | ||
""" | ||
Return a ``requests.auth.AuthBase`` subclass instance. | ||
""" | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import requests.auth | ||
|
||
from .base import AuthPlugin | ||
|
||
|
||
class BuiltinAuthPlugin(AuthPlugin): | ||
|
||
package_name = '(builtin)' | ||
|
||
|
||
class BasicAuthPlugin(BuiltinAuthPlugin): | ||
|
||
name = 'Basic HTTP auth' | ||
auth_type = 'basic' | ||
|
||
def get_auth(self, username, password): | ||
return requests.auth.HTTPBasicAuth(username, password) | ||
|
||
|
||
class DigestAuthPlugin(BuiltinAuthPlugin): | ||
|
||
name = 'Digest HTTP auth' | ||
auth_type = 'digest' | ||
|
||
def get_auth(self, username, password): | ||
return requests.auth.HTTPDigestAuth(username, password) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from pkg_resources import iter_entry_points | ||
|
||
|
||
ENTRY_POINT_NAMES = [ | ||
'httpie.plugins.auth.v1' | ||
] | ||
|
||
|
||
class PluginManager(object): | ||
|
||
def __init__(self): | ||
self._plugins = [] | ||
|
||
def __iter__(self): | ||
return iter(self._plugins) | ||
|
||
def register(self, plugin): | ||
self._plugins.append(plugin) | ||
|
||
def get_auth_plugins(self): | ||
return list(self._plugins) | ||
|
||
def get_auth_plugin_mapping(self): | ||
return dict((plugin.auth_type, plugin) for plugin in self) | ||
|
||
def get_auth_plugin(self, auth_type): | ||
return self.get_auth_plugin_mapping()[auth_type] | ||
|
||
def load_installed_plugins(self): | ||
|
||
for entry_point_name in ENTRY_POINT_NAMES: | ||
for entry_point in iter_entry_points(entry_point_name): | ||
plugin = entry_point.load() | ||
plugin.package_name = entry_point.dist.key | ||
self.register(entry_point.load()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
looking good