Skip to content

Commit

Permalink
Merge branch 'master' of github.com:cryptoadvance/specter-desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim Neunert committed May 27, 2022
2 parents 050edb9 + 337dec9 commit 2f0f743
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 6 deletions.
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ def run(self):
"init_catalog": babel.init_catalog,
"update_catalog": babel.update_catalog,
},
entry_points="""
[console_scripts]
specter=cryptoadvance.specter.cli:entry_point
""",
)
3 changes: 3 additions & 0 deletions src/cryptoadvance/specter/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ class BaseConfig(object):
SPECTER_URL_PREFIX = "/spc"
# This enables the isolated_client-extensions, SECURITY-CRITICAL
SESSION_COOKIE_PATH = SPECTER_URL_PREFIX
# should be "strong" until you're running specter behind a loadbalancer which accesses specter with more than one IP
SESSION_PROTECTION = os.getenv("SESSION_PROTECTION", "strong")
SESSION_PROTECTION = None if SESSION_PROTECTION == "none" else SESSION_PROTECTION
# The prefix for extensions which get access to the session cookie
EXT_URL_PREFIX = "/spc/ext"
# The prefix for extensions which don't get access to the session cookie (if SPECTER_URL_PREFIX isn't compromised)
Expand Down
1 change: 1 addition & 0 deletions src/cryptoadvance/specter/rpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def multi(self, calls: list, **kwargs):
if kwargs.get("no_wait"):
# Used for rpc calls that don't immediately return (e.g. rescanblockchain) so we don't
# expect any data back anyway. __getattr__ expects a list of formatted json.
self.trace_call_after(url, payload, timeout)
return [{"error": None, "result": None}]

logger.error(
Expand Down
2 changes: 1 addition & 1 deletion src/cryptoadvance/specter/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def init_app(app: SpecterFlask, hwibridge=False, specter=None):
)

login_manager = LoginManager()
login_manager.session_protection = "strong"
login_manager.session_protection = app.config.get("SESSION_PROTECTION", "strong")
login_manager.init_app(app) # Enable Login
login_manager.login_view = "auth_endpoint.login" # Enable redirects if unauthorized
app.config["SESSION_COOKIE_SAMESITE"] = "Strict"
Expand Down
23 changes: 22 additions & 1 deletion src/cryptoadvance/specter/server_endpoints/controller.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ..services.callbacks import flask_before_request
import random, traceback
from time import time
from flask_wtf.csrf import CSRFError
Expand Down Expand Up @@ -158,10 +159,15 @@ def selfcheck():

@app.before_request
def slow_request_detection_start():
""" """
g.start = time()


@app.before_request
def execute_service_manager_hook():
"""inform extensions about the request"""
app.specter.service_manager.execute_ext_callbacks(flask_before_request, request)


@app.after_request
def slow_request_detection_stop(response):
try:
Expand Down Expand Up @@ -214,3 +220,18 @@ def index():
@app.route(f"{app.config['SPECTER_URL_PREFIX']}/")
def index_prefix():
return redirect(url_for("welcome_endpoint.index"))


@app.route("/healthz/liveness")
def liveness():
return {"message": "i am alive"}


@app.route("/healthz/readyness")
def readyness():
try:
# Probably improvable:
app.specter.check()
except Exception as e:
return {"message": "i am not ready"}, 500
return {"message": "i am ready"}
5 changes: 5 additions & 0 deletions src/cryptoadvance/specter/services/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@
SPECTER_PERSISTENCE_CALLBACK_ASYNC.
"""
specter_persistence_callback = "specter_persistence_callback"

"""
Will get called before every request via the Flask's @app.before_request
"""
flask_before_request = "flask_before_request"
4 changes: 4 additions & 0 deletions src/cryptoadvance/specter/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,10 @@ def add_service(self, service_id: str, autosave: bool = True):
if autosave:
self.save_info()

def has_service(self, service_id: str) -> bool:
"""Returns true if the User has that service"""
return service_id in self._services

def remove_service(self, service_id: str, autosave: bool = True):
"""Remove a Service from the User. Only updates what is listed in the sidebar."""
if service_id in self.services:
Expand Down
6 changes: 2 additions & 4 deletions tests/test_node_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,8 @@ def test_fetch_wallet_addresses_for_mining(caplog, wallets_filled_data_folder):
caplog.set_level(logging.DEBUG, logger="cryptoadvance.specter")
# Todo: instantiate a specter-testwallet
addresses = fetch_wallet_addresses_for_mining("bitcoin", wallets_filled_data_folder)
assert addresses == [
"bcrt1q4h86vfanswhsle63hw2muv9h5a45cg2878uez5",
"bcrt1qcatuhg0gll3h7py4cmn53rjjn9xlsqfwj3zcej",
]
assert "bcrt1q4h86vfanswhsle63hw2muv9h5a45cg2878uez5" in addresses
assert "bcrt1q4h86vfanswhsle63hw2muv9h5a45cg2878uez5" in addresses


@pytest.mark.slow
Expand Down

0 comments on commit 2f0f743

Please sign in to comment.