Skip to content

Commit

Permalink
2.5.0: More interactive Malwarecage.login()
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed May 16, 2019
1 parent 8f5f28d commit 503c5fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from distutils.core import setup

setup(name="mwdblib",
version="2.4.0.2",
version="2.5.0",
description="malwaredb API bindings for Python",
author="psrok1",
package_dir={'mwdblib': 'src'},
Expand Down
18 changes: 17 additions & 1 deletion src/core.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import getpass
import itertools
import json

Expand All @@ -9,6 +10,12 @@
from .config import MalwarecageConfig
from .blob import MalwarecageBlob

try:
import __builtin__
user_input = getattr(__builtin__, "raw_input")
except ImportError:
user_input = input


class Malwarecage(object):
"""
Expand All @@ -35,7 +42,7 @@ class Malwarecage(object):
def __init__(self, api=None, api_key=None):
self.api = api or MalwarecageAPI(api_key=api_key)

def login(self, username, password):
def login(self, username=None, password=None):
"""
Performs user authentication using provided username and password.
Expand All @@ -48,12 +55,21 @@ def login(self, username, password):
.. versionadded:: 2.4.0
Malwarecage tries to reauthenticate on first Unauthorized exception
.. versionadded:: 2.5.0
username and password arguments are optional. If one of the credentials is not provided via arguments,
user will be asked for it.
:param username: User name
:type username: str
:param password: Password
:type password: str
:raises: requests.exceptions.HTTPError
"""
if username is None:
# Py2 compatibility
username = user_input("Username: ")
if password is None:
password = getpass.getpass("Password: ")
self.api.login(username, password)

def _recent(self, endpoint, query=None):
Expand Down
8 changes: 5 additions & 3 deletions src/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,12 @@ def add_child(self, child):
"""
Adds reference to child with current object as parent
:param child: Object
:type child: MalwarecageObject
:param child: Object or object identifier (sha256)
:type child: MalwarecageObject or str
"""
self.api.put("object/{parent}/child/{child}".format(parent=self.id, child=child.id))
if not isinstance(child, str):
child = child.id
self.api.put("object/{parent}/child/{child}".format(parent=self.id, child=child))
if "children" in self.data:
del self.data["children"]

Expand Down

0 comments on commit 503c5fe

Please sign in to comment.