Browse Source

authorization options (#41)

Signed-off-by: R4SAS <r4sas@i2pmail.org>
pull/45/head
R4SAS 2 years ago
parent
commit
46149f868b
Signed by: r4sas
GPG Key ID: 66F6C87B98EBCFE2
  1. 4
      README.md
  2. 12
      README.rst
  3. 10
      pbincli/api.py
  4. 23
      pbincli/cli.py

4
README.md

@ -58,6 +58,10 @@ proxy=http://127.0.0.1:3128
| no_check_certificate | False | True / False | | no_check_certificate | False | True / False |
| no_insecure_warning | False | True / False | | no_insecure_warning | False | True / False |
| compression | zlib | zlib / none | | compression | zlib | zlib / none |
| auth | None | `basic`, `custom` |
| auth_user | None | Basic authorization username |
| auth_pass | None | Basic authorization password |
| auth_custom | None | Custom authorization headers in JSON format, like `{'Authorization': 'Bearer token'}` |
# Usage # Usage

12
README.rst

@ -116,6 +116,18 @@ List of OPTIONS available
* - compression * - compression
- zlib - zlib
- zlib / none - zlib / none
* - auth
- None
- ``basic``\ , ``custom``
* - auth_user
- None
- Basic authorization username
* - auth_pass
- None
- Basic authorization password
* - auth_custom
- None
- Custom authorization headers in JSON format, like ``{'Authorization': 'Bearer token'}``
Usage Usage

10
pbincli/api.py

@ -32,6 +32,16 @@ class PrivateBin:
self.session, self.proxy = _config_requests(settings) self.session, self.proxy = _config_requests(settings)
if settings['auth']:
if settings['auth'] == 'basic' and settings['auth_user'] and settings['auth_pass']:
self.session.auth = (settings['auth_user'], settings['auth_pass'])
elif settings['auth'] == 'custom' and settings['auth_custom']:
from json import loads as json_loads
auth = json_loads(settings['auth_custom'])
self.headers.update(auth)
else:
PBinCLIError("Incorrect authorization configuration")
def post(self, request): def post(self, request):
result = self.session.post( result = self.session.post(
url = self.server, url = self.server,

23
pbincli/cli.py

@ -69,6 +69,12 @@ def main():
send_parser.add_argument("--no-check-certificate", default=argparse.SUPPRESS, action="store_true", help="Disable certificate validation") send_parser.add_argument("--no-check-certificate", default=argparse.SUPPRESS, action="store_true", help="Disable certificate validation")
send_parser.add_argument("--no-insecure-warning", default=argparse.SUPPRESS, action="store_true", send_parser.add_argument("--no-insecure-warning", default=argparse.SUPPRESS, action="store_true",
help="Suppress InsecureRequestWarning (only with --no-check-certificate)") help="Suppress InsecureRequestWarning (only with --no-check-certificate)")
## Authorization options
send_parser.add_argument("--auth", default=argparse.SUPPRESS, action="store",
choices=["basic", "custom"], help="Server authorization method (default: none)")
send_parser.add_argument("--auth-user", default=argparse.SUPPRESS, help="Basic authorization username")
send_parser.add_argument("--auth-pass", default=argparse.SUPPRESS, help="Basic authorization password")
send_parser.add_argument("--auth-custom", default=argparse.SUPPRESS, help="Custom authorization header in JSON format")
## ##
send_parser.add_argument("-L", "--mirrors", default=argparse.SUPPRESS, help="Comma-separated list of mirrors of service with scheme (default: None)") send_parser.add_argument("-L", "--mirrors", default=argparse.SUPPRESS, help="Comma-separated list of mirrors of service with scheme (default: None)")
send_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output") send_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output")
@ -88,6 +94,12 @@ def main():
get_parser.add_argument("--no-check-certificate", default=argparse.SUPPRESS, action="store_true", help="Disable certificate validation") get_parser.add_argument("--no-check-certificate", default=argparse.SUPPRESS, action="store_true", help="Disable certificate validation")
get_parser.add_argument("--no-insecure-warning", default=argparse.SUPPRESS, action="store_true", get_parser.add_argument("--no-insecure-warning", default=argparse.SUPPRESS, action="store_true",
help="Suppress InsecureRequestWarning (only with --no-check-certificate)") help="Suppress InsecureRequestWarning (only with --no-check-certificate)")
## Authorization options
get_parser.add_argument("--auth", default=argparse.SUPPRESS, action="store",
choices=["basic", "custom"], help="Server authorization method (default: none)")
get_parser.add_argument("--auth-user", default=argparse.SUPPRESS, help="Basic authorization username")
get_parser.add_argument("--auth-pass", default=argparse.SUPPRESS, help="Basic authorization password")
get_parser.add_argument("--auth-custom", default=argparse.SUPPRESS, help="Custom authorization header in JSON format")
## ##
get_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output") get_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output")
get_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output") get_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output")
@ -102,6 +114,11 @@ def main():
delete_parser.add_argument("--no-check-certificate", default=argparse.SUPPRESS, action="store_true", help="Disable certificate validation") delete_parser.add_argument("--no-check-certificate", default=argparse.SUPPRESS, action="store_true", help="Disable certificate validation")
delete_parser.add_argument("--no-insecure-warning", default=argparse.SUPPRESS, action="store_true", delete_parser.add_argument("--no-insecure-warning", default=argparse.SUPPRESS, action="store_true",
help="Suppress InsecureRequestWarning (only with --no-check-certificate)") help="Suppress InsecureRequestWarning (only with --no-check-certificate)")
delete_parser.add_argument("--auth", default=argparse.SUPPRESS, action="store",
choices=["basic", "custom"], help="Server authorization method (default: none)")
delete_parser.add_argument("--auth-user", default=argparse.SUPPRESS, help="Basic authorization username")
delete_parser.add_argument("--auth-pass", default=argparse.SUPPRESS, help="Basic authorization password")
delete_parser.add_argument("--auth-custom", default=argparse.SUPPRESS, help="Custom authorization header in JSON format")
## ##
delete_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output") delete_parser.add_argument("-v", "--verbose", default=False, action="store_true", help="Enable verbose output")
delete_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output") delete_parser.add_argument("-d", "--debug", default=False, action="store_true", help="Enable debug output")
@ -128,7 +145,11 @@ def main():
'output': None, 'output': None,
'no_check_certificate': False, 'no_check_certificate': False,
'no_insecure_warning': False, 'no_insecure_warning': False,
'compression': None 'compression': None,
'auth': None,
'auth_user': None,
'auth_pass': None,
'auth_custom': None
} }
# Configuration preference order: # Configuration preference order:

Loading…
Cancel
Save