Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Rebagliati committed Jun 9, 2021
2 parents 5a55b02 + 9aca75d commit 253d5f6
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG/current/fix_cmd2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix to use cmd2 2.0 and update requirements
1 change: 1 addition & 0 deletions CHANGELOG/current/show_message_of_expired_license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Show message if license is expired
1 change: 1 addition & 0 deletions CHANGELOG/current/update_to_v3_api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[MOD] Change to V3 api of faraday
4 changes: 4 additions & 0 deletions faraday_cli/api_client/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ class Invalid2FA(Exception):

class MissingConfig(Exception):
pass


class ExpiredLicense(Exception):
pass
5 changes: 4 additions & 1 deletion faraday_cli/api_client/faraday_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
InvalidCredentials,
Invalid2FA,
MissingConfig,
ExpiredLicense,
)
from simple_rest_client.api import API

Expand Down Expand Up @@ -66,7 +67,9 @@ def hanlde(self, *args, **kwargs):
raise Exception(f"{e}")
except NotFoundError:
raise
except ClientError:
except ClientError as e:
if e.response.status_code == 402:
raise ExpiredLicense("Your Faraday license is expired")
raise
except Exception as e:
raise Exception(f"Unknown error: {type(e)} - {e}")
Expand Down
52 changes: 26 additions & 26 deletions faraday_cli/api_client/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
class LoginResource(Resource):
actions = {
"auth": {"method": "POST", "url": "login"},
"whoami": {"method": "GET", "url": "v2/whoami"},
"get_token": {"method": "GET", "url": "v2/token/"},
"validate": {"method": "GET", "url": "v2/preferences/"},
"whoami": {"method": "GET", "url": "v3/whoami"},
"get_token": {"method": "GET", "url": "v3/token"},
"validate": {"method": "GET", "url": "v3/preferences"},
"second_factor": {"method": "POST", "url": "confirmation"},
}

Expand All @@ -19,66 +19,66 @@ class ConfigResource(Resource):

class WorkspaceResource(Resource):
actions = {
"list": {"method": "GET", "url": "v2/ws/"},
"get": {"method": "GET", "url": "v2/ws/{}/"},
"create": {"method": "POST", "url": "v2/ws/"},
"delete": {"method": "DELETE", "url": "v2/ws/{}/"},
"list": {"method": "GET", "url": "v3/ws"},
"get": {"method": "GET", "url": "v3/ws/{}"},
"create": {"method": "POST", "url": "v3/ws"},
"delete": {"method": "DELETE", "url": "v3/ws/{}"},
}


class BulkCreateResource(Resource):
actions = {"create": {"method": "POST", "url": "v2/ws/{}/bulk_create/"}}
actions = {"create": {"method": "POST", "url": "v3/ws/{}/bulk_create"}}


class HostResource(Resource):
actions = {
"list": {"method": "GET", "url": "v2/ws/{}/hosts/"},
"get": {"method": "GET", "url": "v2/ws/{}/hosts/{}/"},
"create": {"method": "POST", "url": "v2/ws/{}/hosts/"},
"delete": {"method": "DELETE", "url": "v2/ws/{}/hosts/{}/"},
"list": {"method": "GET", "url": "v3/ws/{}/hosts"},
"get": {"method": "GET", "url": "v3/ws/{}/hosts/{}"},
"create": {"method": "POST", "url": "v3/ws/{}/hosts"},
"delete": {"method": "DELETE", "url": "v3/ws/{}/hosts/{}"},
"get_services": {
"method": "GET",
"url": "v2/ws/{}/hosts/{}/services/",
"url": "v3/ws/{}/hosts/{}/services",
},
"get_vulns": {"method": "GET", "url": "v2/ws/{}/vulns/"},
"get_vulns": {"method": "GET", "url": "v3/ws/{}/vulns"},
}


class ServiceResource(Resource):
actions = {
"list": {"method": "GET", "url": "v2/ws/{}/services/"},
"get": {"method": "GET", "url": "v2/ws/{}/services/{}/"},
"list": {"method": "GET", "url": "v3/ws/{}/services"},
"get": {"method": "GET", "url": "v3/ws/{}/services/{}"},
}


class VulnResource(Resource):
actions = {
"list": {"method": "GET", "url": "v2/ws/{}/vulns/"},
"filter": {"method": "GET", "url": "v2/ws/{}/vulns/filter"},
"list": {"method": "GET", "url": "v3/ws/{}/vulns"},
"filter": {"method": "GET", "url": "v3/ws/{}/vulns/filter"},
}


class CredentialResource(Resource):
actions = {
"list": {"method": "GET", "url": "v2/ws/{}/credential/"},
"list": {"method": "GET", "url": "v3/ws/{}/credential"},
}


class AgentResource(Resource):
actions = {
"list": {"method": "GET", "url": "v2/ws/{}/agents/"},
"get": {"method": "GET", "url": "v2/ws/{}/agents/{}/"},
"run": {"method": "POST", "url": "v2/ws/{}/agents/{}/run/"},
"list": {"method": "GET", "url": "v3/ws/{}/agents"},
"get": {"method": "GET", "url": "v3/ws/{}/agents/{}"},
"run": {"method": "POST", "url": "v3/ws/{}/agents/{}/run"},
}


class ExecutiveReportResource(Resource):
actions = {
"list_templates": {
"method": "GET",
"url": "v2/ws/{}/reports/listTemplates/",
"url": "v3/ws/{}/reports/listTemplates",
},
"generate": {"method": "POST", "url": "v2/ws/{}/reports/"},
"status": {"method": "GET", "url": "v2/ws/{}/reports/{}/"},
"download": {"method": "GET", "url": "v2/ws/{}/reports/{}/download/"},
"generate": {"method": "POST", "url": "v3/ws/{}/reports"},
"status": {"method": "GET", "url": "v3/ws/{}/reports/{}"},
"download": {"method": "GET", "url": "v3/ws/{}/reports/{}/download"},
}
24 changes: 19 additions & 5 deletions faraday_cli/shell/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,16 +257,30 @@ def postcmd(self, stop, line):
def send_to_faraday(ws, data):
spinner = Halo(text="Sending", text_color="green", spinner="dots")
spinner.start()
self.api_client.bulk_create(ws, data)
spinner.stop()
try:
self.api_client.bulk_create(ws, data)
except Exception as e:
spinner.stop()
return str(e)
else:
spinner.stop()
return None

while not self.data_queue.empty():
data = self.data_queue.get()
message = f"{self.emojis['arrow_up']} Sending data to workspace: {data['workspace']}" # noqa: E501
self.poutput(style(message, fg="green"))
send_to_faraday(data["workspace"], data["json_data"])
self.poutput(style(f"{self.emojis['check']} Done", fg="green"))

upload_error = send_to_faraday(
data["workspace"], data["json_data"]
)
if upload_error is not None:
self.poutput(
style(f"\n{self.emojis['cross']} {upload_error}", fg="red")
)
else:
self.poutput(
style(f"\n{self.emojis['check']} Done", fg="green")
)
return Cmd.postcmd(self, stop, line)

def update_prompt(self) -> None:
Expand Down

0 comments on commit 253d5f6

Please sign in to comment.