Skip to content

Commit 0f73aab

Browse files
fix: drop FF for MDM authd cases (#838)
MDM doesn't support yet FF, this change unblocks the commands when CLI is using machine tokens.
1 parent 1da01ee commit 0f73aab

File tree

3 files changed

+36
-21
lines changed

3 files changed

+36
-21
lines changed

safety/auth/utils.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -167,28 +167,38 @@ def initialize(ctx: Any, refresh: bool = True) -> None:
167167
if not ctx.obj:
168168
ctx.obj = SafetyCLI()
169169

170-
for feature in FeatureType:
171-
value = get_config_setting(feature.name)
172-
if value is not None:
173-
current_values[feature] = str_to_bool(value)
174-
175-
if refresh:
176-
try:
177-
settings = ctx.obj.auth.platform.initialize() # type: ignore
178-
except Exception:
179-
LOG.info("Unable to initialize, continue with default values.")
170+
has_machine_token = (
171+
ctx.obj.auth
172+
and ctx.obj.auth.platform
173+
and ctx.obj.auth.platform.has_machine_token
174+
)
180175

181-
if settings:
176+
if not has_machine_token:
177+
for feature in FeatureType:
178+
value = get_config_setting(feature.name)
179+
if value is not None:
180+
current_values[feature] = str_to_bool(value)
181+
182+
if refresh:
183+
try:
184+
settings = ctx.obj.auth.platform.initialize() # type: ignore
185+
except Exception:
186+
LOG.info("Unable to initialize, continue with default values.")
187+
188+
if settings:
189+
for feature in FeatureType:
190+
server_value = str_to_bool(settings.get(feature.config_key))
191+
if server_value is not None:
192+
if (
193+
feature not in current_values
194+
or current_values[feature] != server_value
195+
):
196+
current_values[feature] = server_value
197+
198+
save_flags_config(current_values)
199+
else:
182200
for feature in FeatureType:
183-
server_value = str_to_bool(settings.get(feature.config_key))
184-
if server_value is not None:
185-
if (
186-
feature not in current_values
187-
or current_values[feature] != server_value
188-
):
189-
current_values[feature] = server_value
190-
191-
save_flags_config(current_values)
201+
current_values[feature] = True
192202

193203
for feature, value in current_values.items():
194204
if value is not None:

safety/system_scan/command.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
get_command_for,
1717
pass_safety_cli_obj,
1818
CommandType,
19+
FeatureType,
1920
)
2021
from safety.constants import (
2122
DEFAULT_EPILOG,
2223
CONTEXT_COMMAND_TYPE,
24+
CONTEXT_FEATURE_TYPE,
2325
EXIT_CODE_INVALID_AUTH_CREDENTIAL,
2426
get_required_config_setting,
2527
)
@@ -52,7 +54,7 @@
5254
"allow_extra_args": True,
5355
"ignore_unknown_options": True,
5456
CONTEXT_COMMAND_TYPE: CommandType.BETA,
55-
# CONTEXT_FEATURE_TYPE: FeatureType.PLATFORM, TODO: We're disabling this until we have feature flags working with the new MDM auth
57+
CONTEXT_FEATURE_TYPE: FeatureType.PLATFORM,
5658
},
5759
)
5860
@pass_safety_cli_obj

tests/auth/test_auth_utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test_initialize_with_no_session(
4040
mock_initialize = Mock(side_effect=InvalidCredentialError())
4141
mock_client = Mock()
4242
mock_client.initialize = mock_initialize
43+
mock_client.has_machine_token = False
4344
mock_auth = Mock()
4445
mock_auth.platform = mock_client
4546
mock_safety_cli.auth = mock_auth
@@ -68,6 +69,7 @@ def test_initialize_without_refresh(
6869
patch("safety.auth.utils.setattr") as mock_setattr,
6970
):
7071
mock_safety_cli = MockSafetyCLI.return_value
72+
mock_safety_cli.auth.platform.has_machine_token = False
7173

7274
initialize(ctx, refresh=False)
7375

@@ -111,6 +113,7 @@ def test_initialize_with_server_response(
111113
)
112114
mock_client = Mock()
113115
mock_client.initialize = mock_initialize
116+
mock_client.has_machine_token = False
114117
mock_auth = Mock()
115118
mock_auth.platform = mock_client
116119
mock_safety_cli.auth = mock_auth

0 commit comments

Comments
 (0)