Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config file #95

Merged
merged 7 commits into from
Mar 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated tests
  • Loading branch information
Jayy001 committed Mar 28, 2021
commit 19ad214e0a9289b490c48c039b0092d8441ff558
31 changes: 29 additions & 2 deletions search_that_hash/config_object.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import toml
from appdirs import *
import json
from loguru import logger
Expand All @@ -8,6 +7,7 @@

import logging
import coloredlogs
import os.path


def cli_config(kwargs):
Expand Down Expand Up @@ -40,7 +40,7 @@ def api_config(hashes: str, sth_api: str = None):


def default_config():
return {
config = {
"api_keys": {"STH": "rGFbPbSXMF5ldzid2eyA81i6aCa497Z25MNgi8sa"},
"hashcat": False,
"api": False,
Expand All @@ -52,6 +52,33 @@ def default_config():
"offline": False,
}

defults = {

"hashes_dot_org":"test",
"sth_api":"rGFbPbSXMF5ldzid2eyA81i6aCa497Z25MNgi8sa",
"hashcat_exe_name":"hashcat",
"hashcat_folder":""

}

appname = "Search-That-Hash"
appauthor = "HashPals"

config_json = user_data_dir(appname, appauthor) + "\\config.json"

if not os.path.isfile(config_json):
os.makedirs(user_data_dir(appname, appauthor))
with open(config_json, "w+") as file:
file.write(json.dumps(defults))
file.close()

with open(config_json) as json_file:
json_contents = json.load(json_file)
json_file.close()

config.update(json_contents)

return config

def create_hash_config(hashes):
# Gets the results from name-that-hash
Expand Down
11 changes: 10 additions & 1 deletion tests/main_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from search_that_hash import api
from click.testing import CliRunner

from appdirs import *
from search_that_hash.__main__ import main
import os.path


def test_it_works():
Expand Down Expand Up @@ -150,3 +151,11 @@ def test_cli_fail_on_grep(): # Fixes #63 issue
["-t", "jadjsjhd9239uh80dahjdah8isdh90wq90hj0j9fj9023j0-12j-j-0fasj0a", "-g"],
)
assert result.exit_code == 0

def test_config_is_there():
appname = "Search-That-Hash"
appauthor = "HashPals"

config_json = user_data_dir(appname, appauthor) + "\\config.json"

assert os.path.isfile(config_json) == True