Skip to content

Fixing SSRC Typos and Minor Bugs #841

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

Merged
merged 46 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
8727e91
feat(firestore): Add Firestore Multi Database Support (#818)
jonathanedey Oct 24, 2024
2a8170f
[chore] Bump cachecontrol (#819)
jonathanedey Oct 24, 2024
d8d6aea
chore: Create dependabot.yml (#820)
lahirumaramba Oct 24, 2024
32e8dd2
feat: Support passing `google.auth` typed credentials in `initialize_…
jonathanedey Nov 4, 2024
be56a0f
chore: Add `X-Goog-Api-Client` metric header to requests (#826)
jonathanedey Nov 4, 2024
50ace23
feat(firestore): Upgrade `google-cloud-firestore` to support Firestor…
jonathanedey Nov 7, 2024
d3e2a63
[chore] Release 6.6.0 (#829)
jonathanedey Nov 7, 2024
1b131f0
[chore] Release 6.6.0 Take 2 (#830)
jonathanedey Nov 7, 2024
e377491
Adding script for Python Bug Bash
Dec 4, 2024
f9f0635
Changes for percent comparison
Dec 5, 2024
5f6f03e
Fixing semantic version issues with invalid version
Dec 8, 2024
ba678a9
Config values must retrun default values from invalid get operations
Dec 8, 2024
84ebe4c
Fixing typos
Dec 18, 2024
12fb2f1
Adding requirements set is master branch
Dec 18, 2024
d276c3e
Updating tolerance for percentage evaluation
Dec 18, 2024
f22ef5b
Removing dependency changes from fix branch
Dec 18, 2024
43ab91e
chore: Skip integration test for deprecated FCM API and bump pypy CI …
jonathanedey Dec 19, 2024
8ba819a
chore: Adding delayed response message for holidays (#842)
jonathanedey Dec 20, 2024
00dff8c
Updating ServerConfig methods
Jan 5, 2025
a08b91b
Updating ServerConfig methods
Jan 5, 2025
0ce187f
Revert "chore: Adding delayed response message for holidays (#842)" (…
jonathanedey Jan 6, 2025
0788d22
Updating comments and vars for readability
Jan 7, 2025
2faf53f
feat(firestore): Add Firestore Multi Database Support (#818)
jonathanedey Oct 24, 2024
7ff94da
[chore] Bump cachecontrol (#819)
jonathanedey Oct 24, 2024
f0c504b
chore: Create dependabot.yml (#820)
lahirumaramba Oct 24, 2024
464f442
feat: Support passing `google.auth` typed credentials in `initialize_…
jonathanedey Nov 4, 2024
746ea96
chore: Add `X-Goog-Api-Client` metric header to requests (#826)
jonathanedey Nov 4, 2024
75d1746
feat(firestore): Upgrade `google-cloud-firestore` to support Firestor…
jonathanedey Nov 7, 2024
80f6fe3
[chore] Release 6.6.0 (#829)
jonathanedey Nov 7, 2024
6d8223c
[chore] Release 6.6.0 Take 2 (#830)
jonathanedey Nov 7, 2024
45c9ad6
chore: Skip integration test for deprecated FCM API and bump pypy CI …
jonathanedey Dec 19, 2024
61833d5
chore: Adding delayed response message for holidays (#842)
jonathanedey Dec 20, 2024
6088f28
Revert "chore: Adding delayed response message for holidays (#842)" (…
jonathanedey Jan 6, 2025
e940950
Implementation for Fetching and Caching Server Side Remote Config (#825)
pijushcs Nov 15, 2024
ccb186a
Implementation for Evaluating Condition and Custom Signals Server Sid…
rathovarun1032 Nov 15, 2024
473d31f
Adding script for Python Bug Bash
Dec 4, 2024
7264d31
Changes for percent comparison
Dec 5, 2024
43a6862
Fixing semantic version issues with invalid version
Dec 8, 2024
0f50a95
Config values must retrun default values from invalid get operations
Dec 8, 2024
4bae22c
Fixing typos
Dec 18, 2024
797611b
Updating tolerance for percentage evaluation
Dec 18, 2024
55990cf
Removing dependency changes from fix branch
Dec 18, 2024
b4b4c1f
Updating ServerConfig methods
Jan 5, 2025
ced6140
Updating ServerConfig methods
Jan 5, 2025
40d0672
Updating comments and vars for readability
Jan 7, 2025
19a8156
Merge branch 'ssrc-bug-bash' of github.com:firebase/firebase-admin-py…
Jan 8, 2025
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
80 changes: 43 additions & 37 deletions firebase_admin/remote_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2017 Google Inc.
# Copyright 2024 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -185,21 +185,19 @@ def __init__(self, config_values):
self._config_values = config_values # dictionary of param key to values

def get_boolean(self, key):
return self.get_value(key).as_boolean()
return self._get_value(key).as_boolean()

def get_string(self, key):
return self.get_value(key).as_string()
return self._get_value(key).as_string()

def get_int(self, key):
return self.get_value(key).as_int()
return self._get_value(key).as_int()

def get_float(self, key):
return self.get_value(key).as_float()
return self._get_value(key).as_float()

def get_value(self, key):
if self._config_values[key]:
return self._config_values[key]
return _Value('static')
def _get_value(self, key):
return self._config_values.get(key, _Value('static'))


class _RemoteConfigService:
Expand Down Expand Up @@ -421,11 +419,11 @@ def evaluate_percent_condition(self, percent_condition,

hash64 = self.hash_seeded_randomization_id(string_to_hash)
instance_micro_percentile = hash64 % (100 * 1000000)
if percent_operator == PercentConditionOperator.LESS_OR_EQUAL:
if percent_operator == PercentConditionOperator.LESS_OR_EQUAL.value:
return instance_micro_percentile <= norm_micro_percent
if percent_operator == PercentConditionOperator.GREATER_THAN:
if percent_operator == PercentConditionOperator.GREATER_THAN.value:
return instance_micro_percentile > norm_micro_percent
if percent_operator == PercentConditionOperator.BETWEEN:
if percent_operator == PercentConditionOperator.BETWEEN.value:
return norm_percent_lower_bound < instance_micro_percentile <= norm_percent_upper_bound
logger.warning("Unknown percent operator: %s", percent_operator)
return False
Expand Down Expand Up @@ -454,10 +452,10 @@ def evaluate_custom_signal_condition(self, custom_signal_condition,
Returns:
True if the condition is met, False otherwise.
"""
custom_signal_operator = custom_signal_condition.get('custom_signal_operator') or {}
custom_signal_key = custom_signal_condition.get('custom_signal_key') or {}
custom_signal_operator = custom_signal_condition.get('customSignalOperator') or {}
custom_signal_key = custom_signal_condition.get('customSignalKey') or {}
target_custom_signal_values = (
custom_signal_condition.get('target_custom_signal_values') or {})
custom_signal_condition.get('targetCustomSignalValues') or {})

if not all([custom_signal_operator, custom_signal_key, target_custom_signal_values]):
logger.warning("Missing operator, key, or target values for custom signal condition.")
Expand All @@ -471,71 +469,71 @@ def evaluate_custom_signal_condition(self, custom_signal_condition,
logger.warning("Custom signal value not found in context: %s", custom_signal_key)
return False

if custom_signal_operator == CustomSignalOperator.STRING_CONTAINS:
if custom_signal_operator == CustomSignalOperator.STRING_CONTAINS.value:
return self._compare_strings(target_custom_signal_values,
actual_custom_signal_value,
lambda target, actual: target in actual)
if custom_signal_operator == CustomSignalOperator.STRING_DOES_NOT_CONTAIN:
if custom_signal_operator == CustomSignalOperator.STRING_DOES_NOT_CONTAIN.value:
return not self._compare_strings(target_custom_signal_values,
actual_custom_signal_value,
lambda target, actual: target in actual)
if custom_signal_operator == CustomSignalOperator.STRING_EXACTLY_MATCHES:
if custom_signal_operator == CustomSignalOperator.STRING_EXACTLY_MATCHES.value:
return self._compare_strings(target_custom_signal_values,
actual_custom_signal_value,
lambda target, actual: target.strip() == actual.strip())
if custom_signal_operator == CustomSignalOperator.STRING_CONTAINS_REGEX:
if custom_signal_operator == CustomSignalOperator.STRING_CONTAINS_REGEX.value:
return self._compare_strings(target_custom_signal_values,
actual_custom_signal_value,
re.search)

# For numeric operators only one target value is allowed.
if custom_signal_operator == CustomSignalOperator.NUMERIC_LESS_THAN:
if custom_signal_operator == CustomSignalOperator.NUMERIC_LESS_THAN.value:
return self._compare_numbers(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r < 0)
if custom_signal_operator == CustomSignalOperator.NUMERIC_LESS_EQUAL:
if custom_signal_operator == CustomSignalOperator.NUMERIC_LESS_EQUAL.value:
return self._compare_numbers(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r <= 0)
if custom_signal_operator == CustomSignalOperator.NUMERIC_EQUAL:
if custom_signal_operator == CustomSignalOperator.NUMERIC_EQUAL.value:
return self._compare_numbers(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r == 0)
if custom_signal_operator == CustomSignalOperator.NUMERIC_NOT_EQUAL:
if custom_signal_operator == CustomSignalOperator.NUMERIC_NOT_EQUAL.value:
return self._compare_numbers(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r != 0)
if custom_signal_operator == CustomSignalOperator.NUMERIC_GREATER_THAN:
if custom_signal_operator == CustomSignalOperator.NUMERIC_GREATER_THAN.value:
return self._compare_numbers(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r > 0)
if custom_signal_operator == CustomSignalOperator.NUMERIC_GREATER_EQUAL:
if custom_signal_operator == CustomSignalOperator.NUMERIC_GREATER_EQUAL.value:
return self._compare_numbers(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r >= 0)

# For semantic operators only one target value is allowed.
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_LESS_THAN:
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_LESS_THAN.value:
return self._compare_semantic_versions(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r < 0)
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_LESS_EQUAL:
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_LESS_EQUAL.value:
return self._compare_semantic_versions(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r <= 0)
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_EQUAL:
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_EQUAL.value:
return self._compare_semantic_versions(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r == 0)
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_NOT_EQUAL:
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_NOT_EQUAL.value:
return self._compare_semantic_versions(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r != 0)
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_GREATER_THAN:
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_GREATER_THAN.value:
return self._compare_semantic_versions(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r > 0)
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_GREATER_EQUAL:
if custom_signal_operator == CustomSignalOperator.SEMANTIC_VERSION_GREATER_EQUAL.value:
return self._compare_semantic_versions(target_custom_signal_values[0],
actual_custom_signal_value,
lambda r: r >= 0)
Expand Down Expand Up @@ -593,9 +591,9 @@ def _compare_versions(self, version1, version2, predicate_fn) -> bool:
"""Compares two semantic version strings.

Args:
version1: The first semantic version string.
version2: The second semantic version string.
predicate_fn: A function that takes an integer and returns a boolean.
version1: The first semantic version string.
version2: The second semantic version string.
predicate_fn: A function that takes an integer and returns a boolean.

Returns:
bool: The result of the predicate function.
Expand All @@ -608,6 +606,8 @@ def _compare_versions(self, version1, version2, predicate_fn) -> bool:
v2_parts.extend([0] * (max_length - len(v2_parts)))

for part1, part2 in zip(v1_parts, v2_parts):
if any((part1 < 0, part2 < 0)):
raise ValueError
if part1 < part2:
return predicate_fn(-1)
if part1 > part2:
Expand Down Expand Up @@ -674,7 +674,7 @@ def as_string(self) -> str:
"""Returns the value as a string."""
if self.source == 'static':
return self.DEFAULT_VALUE_FOR_STRING
return self.value
return str(self.value)

def as_boolean(self) -> bool:
"""Returns the value as a boolean."""
Expand All @@ -686,13 +686,19 @@ def as_int(self) -> float:
"""Returns the value as a number."""
if self.source == 'static':
return self.DEFAULT_VALUE_FOR_INTEGER
return self.value
try:
return int(self.value)
except ValueError:
return self.DEFAULT_VALUE_FOR_INTEGER

def as_float(self) -> float:
"""Returns the value as a number."""
if self.source == 'static':
return self.DEFAULT_VALUE_FOR_FLOAT_NUMBER
return float(self.value)
try:
return float(self.value)
except ValueError:
return self.DEFAULT_VALUE_FOR_FLOAT_NUMBER

def get_source(self) -> ValueSource:
"""Returns the source of the value."""
Expand Down
Loading
Loading