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

feat:add apollo configuration to load env file #11210

Merged
merged 16 commits into from
Dec 9, 2024
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
fix:ruff check error
  • Loading branch information
huanshare committed Dec 2, 2024
commit 0faeb24aea5401a3cd9cb9c39bc27fa6a43178cc
20 changes: 14 additions & 6 deletions api/extensions/configuration/apollo/apollo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@
from pathlib import Path

from extensions.configuration.apollo.python_3x import http_request, makedirs_wrapper
from extensions.configuration.apollo.util import init_ip, CONFIGURATIONS, get_value_from_dict, \
no_key_cache_key, NOTIFICATION_ID, NAMESPACE_NAME, url_encode_wrapper, signature
from extensions.configuration.apollo.util import (
CONFIGURATIONS,
NAMESPACE_NAME,
NOTIFICATION_ID,
get_value_from_dict,
init_ip,
no_key_cache_key,
signature,
url_encode_wrapper,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -66,7 +74,7 @@ def get_json_from_net(self, namespace='application'):
else:
return None
except Exception as e:
logger.error(str(e))
logger.exception("an error occurred in get_json_from_net")
return None

def get_value(self, key, default_val=None, namespace='application'):
Expand Down Expand Up @@ -100,8 +108,8 @@ def get_value(self, key, default_val=None, namespace='application'):
self._set_local_cache_none(namespace, key)
return default_val
except Exception as e:
logger.error("get_value has error, [key is %s], [namespace is %s], [error is %s], ",
key, namespace, e)
logger.exception("get_value has error, [key is %s], [namespace is %s]",
key, namespace)
return default_val

# Set the key of a namespace to none, and do not set default val
Expand Down Expand Up @@ -267,7 +275,7 @@ def _do_heart_beat(self, namespace):
else:
return None
except Exception as e:
logger.error(str(e))
logger.exception("an error occurred in _do_heart_beat")
return None

def get_all_dicts(self, namespace):
Expand Down
2 changes: 1 addition & 1 deletion api/extensions/configuration/apollo_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def load_config_to_env_file(self):
# Retrieve the existing environment variables from the .env file
existing_vars = {}
if os.path.exists(env_path):
with open(env_path, 'r') as f:
with open(env_path) as f:
for line in f:
key, value = line.strip().split('=', 1)
existing_vars[key.strip()] = value.strip()
Expand Down