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

added support for attended flag in middleware #754

Open
wants to merge 2 commits into
base: feat/multi-agent-middleware
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
41 changes: 39 additions & 2 deletions operate/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,16 @@ def _daemon(
@_operate.command(name="quickstart")
def qs_start(
config: Annotated[str, params.String(help="Quickstart config file path")],
attended: Annotated[str, params.String(help="Run in attended/unattended mode (default: true")] = "true",
) -> None:
"""Quickstart."""

# Validate boolean value
if attended.lower() not in ["true", "false"]:
print("Error: --attended only accepts true/false values")
return

os.environ["ATTENDED"] = attended.lower()
operate = OperateApp()
operate.setup()
run_service(operate=operate, config_path=config)
Expand All @@ -966,8 +974,15 @@ def qs_stop(
@_operate.command(name="terminate")
def qs_terminate(
config: Annotated[str, params.String(help="Quickstart config file path")],
attended: Annotated[str, params.String(help="Run in attended/unattended mode (default: true")] = "true",
) -> None:
"""Quickstart."""
"""Terminate service."""

if attended.lower() not in ["true", "false"]:
print("Error: --attended only accepts true/false values")
return

os.environ["ATTENDED"] = attended.lower()
operate = OperateApp()
operate.setup()
terminate_service(operate=operate, config_path=config)
Expand All @@ -976,8 +991,15 @@ def qs_terminate(
@_operate.command(name="claim")
def qs_claim(
config: Annotated[str, params.String(help="Quickstart config file path")],
attended: Annotated[str, params.String(help="Run in attended/unattended mode (default: true")] = "true",
) -> None:
"""Quickclaim staking rewards."""

if attended.lower() not in ["true", "false"]:
print("Error: --attended only accepts true/false values")
return

os.environ["ATTENDED"] = attended.lower()
operate = OperateApp()
operate.setup()
claim_staking_rewards(operate=operate, config_path=config)
Expand All @@ -986,16 +1008,31 @@ def qs_claim(
@_operate.command(name="reset-staking")
def qs_reset_staking(
config: Annotated[str, params.String(help="Quickstart config file path")],
attended: Annotated[str, params.String(help="Run in attended/unattended mode (default: true")] = "true",
) -> None:
"""Reset staking."""

if attended.lower() not in ["true", "false"]:
print("Error: --attended only accepts true/false values")
return

os.environ["ATTENDED"] = attended.lower()
operate = OperateApp()
operate.setup()
reset_staking(operate=operate, config_path=config)


@_operate.command(name="reset-password")
def qs_reset_password() -> None:
def qs_reset_password(
attended: Annotated[str, params.String(help="Run in attended/unattended mode (default: true")] = "true",
) -> None:
"""Reset password."""

if attended.lower() not in ["true", "false"]:
print("Error: --attended only accepts true/false values")
return

os.environ["ATTENDED"] = attended.lower()
operate = OperateApp()
operate.setup()
reset_password(operate=operate)
Expand Down
11 changes: 6 additions & 5 deletions operate/quickstart/claim_staking_rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from operate.constants import OPERATE_HOME, SAFE_WEBAPP_URL
from operate.operate_types import LedgerType
from operate.quickstart.run_service import ask_password_if_needed, configure_local_config, get_service, load_local_config
from operate.utils.common import print_section, print_title
from operate.utils.common import ask_yes_or_no, print_section, print_title

if TYPE_CHECKING:
from operate.cli import OperateApp
Expand All @@ -38,6 +38,7 @@

def claim_staking_rewards(operate: "OperateApp", config_path: str) -> None:
"""Claim staking rewards."""
attended = os.environ.get("ATTENDED", "true").lower() == "true"

with open(config_path, "r") as config_file:
template = json.load(config_file)
Expand All @@ -54,10 +55,10 @@ def claim_staking_rewards(operate: "OperateApp", config_path: str) -> None:
"This script will claim the OLAS staking rewards "
"accrued in the current staking contract and transfer them to your service safe."
)
_continue = input("Do you want to continue (yes/no)? ").strip().lower()

if _continue not in ("y", "yes"):
sys.exit(0)

if attended and not ask_yes_or_no("Do you want to continue?"):
print("Cancelled.")
return

print("")

Expand Down
20 changes: 15 additions & 5 deletions operate/quickstart/reset_password.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""Reset password."""

from getpass import getpass
import os
from typing import TYPE_CHECKING

from operate.account.user import UserAccount
Expand All @@ -33,6 +34,8 @@

def reset_password(operate: "OperateApp") -> None:
"""Reset password."""
attended = os.environ.get("ATTENDED", "true").lower() == "true"

print_title("Reset your password")

# check if agent was started before
Expand All @@ -42,11 +45,18 @@ def reset_password(operate: "OperateApp") -> None:

old_password = None
while old_password is None:
old_password = getpass("\nEnter local user account password [hidden input]: ")
if operate.user_account.is_valid(password=old_password):
break
old_password = None
print("Invalid password!")
if attended:
old_password = getpass("\nEnter local user account password [hidden input]: ")
else:
old_password = os.getenv("OLD_OPERATE_PASSWORD")
if not old_password:
raise ValueError("OLD_OPERATE_PASSWORD environment variable must be set in unattended mode")

if operate.user_account.is_valid(password=old_password):
break
old_password = None
if attended:
print("Invalid password!")

print_section("Update local user account")
new_password = ask_confirm_password()
Expand Down
7 changes: 5 additions & 2 deletions operate/quickstart/reset_staking.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"""Reset staking."""

import json
import os
from typing import TYPE_CHECKING

from operate.constants import OPERATE_HOME
Expand All @@ -33,6 +34,8 @@

def reset_staking(operate: "OperateApp", config_path: str) -> None:
"""Reset staking."""
attended = os.environ.get("ATTENDED", "true").lower() == "true"

with open(config_path, "r") as config_file:
template = json.load(config_file)

Expand All @@ -58,7 +61,7 @@ def reset_staking(operate: "OperateApp", config_path: str) -> None:
"until it has been staked for a minimum staking period in the current program.\n"
)

if not ask_yes_or_no(
if attended and not ask_yes_or_no(
"Please, ensure that your service is stopped (./stop_service.sh) before proceeding. "
"Do you want to continue?"
):
Expand Down Expand Up @@ -87,7 +90,7 @@ def reset_staking(operate: "OperateApp", config_path: str) -> None:
)
return

if not ask_yes_or_no("Service can be unstaked. Would you like to proceed with unstaking and reset?"):
if attended and not ask_yes_or_no("Service can be unstaked. Would you like to proceed with unstaking and reset?"):
print("Cancelled.")
return

Expand Down
Loading
Loading