Skip to content

Commit

Permalink
running black
Browse files Browse the repository at this point in the history
  • Loading branch information
Dor.M committed Aug 21, 2023
1 parent cd1b0e5 commit 36c6594
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 160 deletions.
4 changes: 2 additions & 2 deletions movai_core_shared/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
CONFIG_REGEX,
TIMEOUT_PROCESS_SIGINT,
TIMEOUT_PROCESS_SIGTERM,
INTERNAL_DOMAIN
INTERNAL_DOMAIN,
)
from movai_core_shared.envvars import (
MOVAI_STDOUT_VERBOSITY_LEVEL,
Expand Down Expand Up @@ -90,7 +90,7 @@
ENVIRON_GDNODE_INJECT,
REST_SCOPES,
SCOPES_TO_TRACK,
)
)

from movai_core_shared.exceptions import (
MovaiException,
Expand Down
5 changes: 5 additions & 0 deletions movai_core_shared/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from pkg_resources import get_distribution
from movai_core_shared.envvars import REDIS_MASTER_HOST


def is_manager() -> bool:
"""Identify if this robot is the manager host machine.
Expand All @@ -21,6 +22,7 @@ def is_manager() -> bool:
"""
return REDIS_MASTER_HOST in (None, "redis-master")


def is_enteprise() -> bool:
"""Check the existence of the movai_core_enterprise package.
Expand All @@ -29,10 +31,12 @@ def is_enteprise() -> bool:
"""
try:
import movai_core_enterprise

return True
except ImportError:
return False


def create_principal_name(domain_name: str, account_name: str) -> str:
"""build principal name -> "account_name@domain_name
Expand All @@ -46,6 +50,7 @@ def create_principal_name(domain_name: str, account_name: str) -> str:
principal_name = f"{account_name}@{domain_name}"
return principal_name


def get_ip_address() -> str:
"""Returns the host(container) ip address.
Expand Down
12 changes: 6 additions & 6 deletions movai_core_shared/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""
from os import getpid

#system
# system
PID = getpid()

# Constants
Expand Down Expand Up @@ -112,32 +112,32 @@
OPERATOR_ROLE = "OPERATOR"
DEPLOYER_ROLE = "DEPLOYER"

#permissions
# permissions
READ_PERMISSION = "read"
UPDATE_PERMISSION = "update"
CREATE_PERMISSION = "create"
DELETE_PERMISSION = "delete"
EXECUTE_PERMISSION = "execute"
RESET_PERMISSION = "reset"

#container_names
# container_names
INFLUXDB_HOST = "influxdb"
MESSAGE_SERVER_HOST = "message-server"


#inluxdb DB names:
# inluxdb DB names:
LOGS_INFLUX_DB = "logs"
METRICS_INFLUX_DB = "metrics"
STRESS_INFLUX_DB = "stress"
INFLUXDB_DB_NAMES = [LOGS_INFLUX_DB, METRICS_INFLUX_DB, STRESS_INFLUX_DB]

#inluxdb measurements names:
# inluxdb measurements names:
SYSLOG_MEASUREMENT = "syslog"
LOGS_MEASUREMENT = "app_logs"
METRICS_MEASUREMENT = "metric_logs"
STRESS_MEASUREMENT = "stress_logs"

#Message-Server msgs types:
# Message-Server msgs types:
LOGS_HANDLER_MSG_TYPE = "logs"
SYSLOGS_HANDLER_MSG_TYPE = "syslog"
LOGS_QUERY_HANDLER_MSG_TYPE = "logs_query"
Expand Down
1 change: 1 addition & 0 deletions movai_core_shared/core/base_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from movai_core_shared.logger import Log


class BaseCommand(ABC):
"""Base Class for the various tools commands."""

Expand Down
4 changes: 2 additions & 2 deletions movai_core_shared/core/secure.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import secrets


def generate_secret_bytes(length: int=32) -> bytes:
def generate_secret_bytes(length: int = 32) -> bytes:
"""The function generates a unique secret in bytes format,
Args:
Expand All @@ -21,7 +21,7 @@ def generate_secret_bytes(length: int=32) -> bytes:
return secrets.token_bytes(length)


def generate_secret_string(length: int=32) -> bytes:
def generate_secret_string(length: int = 32) -> bytes:
"""The function generates a unique secret in bytes format,
Args:
Expand Down
17 changes: 8 additions & 9 deletions movai_core_shared/core/securepassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def password_checker(func):
Args:
func (callable): The function to be decorated
"""

def inner(*args, **kwargs):
"""This function is encapsulates the decorated function and
add the validation of the password.
Expand All @@ -46,17 +47,17 @@ def inner(*args, **kwargs):
LOGGER.error(error_msg)
raise PasswordASCIIFormatError(error_msg)
return func(*args, **kwargs)

return inner


class SecurePassword:
"""A class for securing password by encryption or hashing.
"""
"""A class for securing password by encryption or hashing."""

def __init__(self, secret: str = None) -> None:
if secret is None:
secret = generate_secret_string(32)
key = urlsafe_b64encode(secret[:32].encode('ascii'))
key = urlsafe_b64encode(secret[:32].encode("ascii"))
self.cipher_suite = Fernet(key)

def encrypt_password(self, plain_text: str) -> bytes:
Expand All @@ -68,7 +69,7 @@ def encrypt_password(self, plain_text: str) -> bytes:
Returns:
bytes: the cipher text of the encrypted password.
"""
cipher_text = self.cipher_suite.encrypt(plain_text.encode('ascii'))
cipher_text = self.cipher_suite.encrypt(plain_text.encode("ascii"))
return cipher_text

def decrypt_password(self, cipher_text: bytes) -> str:
Expand All @@ -81,7 +82,7 @@ def decrypt_password(self, cipher_text: bytes) -> str:
string: A plain text of the encrypted password.
"""
plain_text = self.cipher_suite.decrypt(cipher_text)
return plain_text.decode('ascii')
return plain_text.decode("ascii")

@staticmethod
def create_salt() -> str:
Expand Down Expand Up @@ -112,10 +113,8 @@ def create_hash(password: str, salt: str) -> bytes:
bytes: a secure hash (message digest) of the password.
"""
hash = binascii.hexlify(
hashlib.pbkdf2_hmac("sha256",
password.encode("ascii"),
salt,
100000))
hashlib.pbkdf2_hmac("sha256", password.encode("ascii"), salt, 100000)
)
return hash

@staticmethod
Expand Down
68 changes: 32 additions & 36 deletions movai_core_shared/envvars.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,18 @@

# Setting for logging verbosity levels
# Will be set only once at startup
MOVAI_STDOUT_VERBOSITY_LEVEL = int(
os.getenv("MOVAI_STDOUT_VERBOSITY_LEVEL", str(DEBUG))
)
MOVAI_FLEET_LOGS_VERBOSITY_LEVEL = int(
os.getenv("MOVAI_FLEET_LOGS_VERBOSITY_LEVEL", str(DEBUG))
)
MOVAI_STDOUT_VERBOSITY_LEVEL = int(os.getenv("MOVAI_STDOUT_VERBOSITY_LEVEL", str(DEBUG)))
MOVAI_FLEET_LOGS_VERBOSITY_LEVEL = int(os.getenv("MOVAI_FLEET_LOGS_VERBOSITY_LEVEL", str(DEBUG)))
MOVAI_LOG_FILE = os.getenv("MOVAI_LOG_FILE", "/opt/mov.ai/app/movai.log")
# default as NOTSET that will turn off the output for the addition log file
MOVAI_LOGFILE_VERBOSITY_LEVEL = int(
os.getenv("MOVAI_LOGFILE_VERBOSITY_LEVEL", str(NOTSET))
)
MOVAI_GENERAL_VERBOSITY_LEVEL = int(
os.getenv("MOVAI_GENERAL_VERBOSITY_LEVEL", str(DEBUG))
)
LOG_HTTP_HOST = os.environ.get('LOG_HTTP_HOST', 'http://health-node:8081')
MOVAI_LOGFILE_VERBOSITY_LEVEL = int(os.getenv("MOVAI_LOGFILE_VERBOSITY_LEVEL", str(NOTSET)))
MOVAI_GENERAL_VERBOSITY_LEVEL = int(os.getenv("MOVAI_GENERAL_VERBOSITY_LEVEL", str(DEBUG)))
LOG_HTTP_HOST = os.environ.get("LOG_HTTP_HOST", "http://health-node:8081")

# Read variables from current environment
APP_PATH = os.getenv("APP_PATH")
APP_LOGS = os.getenv("APP_LOGS")
SYSLOG_ENABLED = os.getenv("SYSLOG_ENABLED", 'False').lower() in ('true', '1', 't')
SYSLOG_ENABLED = os.getenv("SYSLOG_ENABLED", "False").lower() in ("true", "1", "t")
LD_LIBRARY_PATH = os.getenv("LD_LIBRARY_PATH")
MOVAI_HOME = os.getenv("MOVAI_HOME")
PATH = os.getenv("PATH")
Expand Down Expand Up @@ -59,7 +51,11 @@
MOVAI_ZMQ_TIMEOUT_MS = int(os.getenv("MOVAI_ZMQ_TIMEOUT_MS", "1000"))
LOG_STREAMER_BIND_IP = os.getenv("LOG_STREAMER_BIND_IP", "0.0.0.0")
LOG_STREAMER_BIND_ADDR = f"tcp://{LOG_STREAMER_BIND_IP}:{MESSAGE_SERVER_PORT}"
MESSAGE_SERVER_DEBUG_MODE = os.getenv("MESSAGE_SERVER_DEBUG_MODE", 'False').lower() in ('true', '1', 't')
MESSAGE_SERVER_DEBUG_MODE = os.getenv("MESSAGE_SERVER_DEBUG_MODE", "False").lower() in (
"true",
"1",
"t",
)

# DBWriter environment variables
DBWRITER_EMPTY_THREASHOULD = int(os.getenv("DBWRITER_EMPTY_THREASHOULD", "1000"))
Expand Down Expand Up @@ -122,31 +118,31 @@
"Configuration",
"Annotation",
"Layout",
"GraphicScene"
"GraphicScene",
]

#LDAP vars
LDAP_SEARCH_TIME_LIMIT = int(os.getenv('LDAP_SEARCH_TIME_LIMIT', "10"))
LDAP_POOLING_LOOP_TIMEOUT = int(os.getenv('LDAP_POOLING_LOOP_TIMEOUT', "5"))
LDAP_CONNECTION_RECEIVE_TIMEOUT = int(os.getenv('LDAP_CONNECTION_RECEIVE_TIMEOUT', "5"))
LDAP_KEY_LENGTH = int(os.getenv('LDAP_KEY_LENGTH', "32"))
# LDAP vars
LDAP_SEARCH_TIME_LIMIT = int(os.getenv("LDAP_SEARCH_TIME_LIMIT", "10"))
LDAP_POOLING_LOOP_TIMEOUT = int(os.getenv("LDAP_POOLING_LOOP_TIMEOUT", "5"))
LDAP_CONNECTION_RECEIVE_TIMEOUT = int(os.getenv("LDAP_CONNECTION_RECEIVE_TIMEOUT", "5"))
LDAP_KEY_LENGTH = int(os.getenv("LDAP_KEY_LENGTH", "32"))

#Token Vars
DEFAULT_JWT_ACCESS_DELTA_SECS = int(os.getenv('DEFAULT_JWT_ACCESS_DELTA_SECS', "3600"))
DEFAULT_JWT_REFRESH_DELTA_DAYS = int(os.getenv('DEFAULT_JWT_REFRESH_DELTA_DAYS', "7"))
# Token Vars
DEFAULT_JWT_ACCESS_DELTA_SECS = int(os.getenv("DEFAULT_JWT_ACCESS_DELTA_SECS", "3600"))
DEFAULT_JWT_REFRESH_DELTA_DAYS = int(os.getenv("DEFAULT_JWT_REFRESH_DELTA_DAYS", "7"))

#General Vars
# General Vars

DEFAULT_ROLE_NAME = os.getenv('DEFAULT_ROLE_NAME', ADMIN_ROLE)
FLEET_NAME = os.getenv('FLEET_NAME', "movai")
DEVICE_NAME = os.getenv('DEVICE_NAME', "UNDEFINED_ROBOT_NAME")
SERVICE_NAME = os.getenv('HOSTNAME', socket.gethostname())
DEFAULT_ROLE_NAME = os.getenv("DEFAULT_ROLE_NAME", ADMIN_ROLE)
FLEET_NAME = os.getenv("FLEET_NAME", "movai")
DEVICE_NAME = os.getenv("DEVICE_NAME", "UNDEFINED_ROBOT_NAME")
SERVICE_NAME = os.getenv("HOSTNAME", socket.gethostname())

#SMTP Vars
SMTP_EMAIL = os.getenv('SMTP_EMAIL', "[email protected]")
SMTP_HOST = os.getenv('SMTP_HOST')
SMTP_PORT = int(os.getenv('SMTP_PORT', '587'))
SMTP_USER = os.getenv('SMTP_USER')
SMTP_PASS = os.getenv('SMTP_PASS')
# SMTP Vars
SMTP_EMAIL = os.getenv("SMTP_EMAIL", "[email protected]")
SMTP_HOST = os.getenv("SMTP_HOST")
SMTP_PORT = int(os.getenv("SMTP_PORT", "587"))
SMTP_USER = os.getenv("SMTP_USER")
SMTP_PASS = os.getenv("SMTP_PASS")

AWS_ACCESS_KEY = os.getenv('AWS_ACCESS_KEY', "")
AWS_ACCESS_KEY = os.getenv("AWS_ACCESS_KEY", "")
Loading

0 comments on commit 36c6594

Please sign in to comment.