Skip to content
Merged
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
9 changes: 6 additions & 3 deletions samcli/cli/global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def config_dir(self):
# Internal Environment variable to customize SAM CLI App Dir. Currently used only by integ tests.
app_dir = os.getenv("__SAM_CLI_APP_DIR")
self._config_dir = Path(app_dir) if app_dir else Path(click.get_app_dir('AWS SAM', force_posix=True))

return Path(self._config_dir)

@property
Expand Down Expand Up @@ -76,7 +75,7 @@ def installation_id(self):
try:
self._installation_id = self._get_or_set_uuid(INSTALLATION_ID_KEY)
return self._installation_id
except (ValueError, IOError):
except (ValueError, IOError, OSError):
return None

@property
Expand Down Expand Up @@ -112,7 +111,7 @@ def telemetry_enabled(self):
try:
self._telemetry_enabled = self._get_value(TELEMETRY_ENABLED_KEY)
return self._telemetry_enabled
except (ValueError, IOError) as ex:
except (ValueError, IOError, OSError) as ex:
LOG.debug("Error when retrieving telemetry_enabled flag", exc_info=ex)
return False

Expand Down Expand Up @@ -164,6 +163,10 @@ def _set_value(self, key, value):
return self._set_json_cfg(cfg_path, key, value, json_body)

def _create_dir(self):
"""
Creates configuration directory if it does not already exist, otherwise does nothing.
May raise an OSError if we do not have permissions to create the directory.
"""
self.config_dir.mkdir(mode=0o700, parents=True, exist_ok=True)

def _get_config_file_path(self, filename):
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/cli/test_global_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ def test_config_write_error(self):
installation_id = gc.installation_id
self.assertIsNone(installation_id)

def test_unable_to_create_dir(self):
m = mock_open()
m.side_effect = OSError("Permission DENIED")
gc = GlobalConfig()
with patch('samcli.cli.global_config.Path.mkdir', m):
installation_id = gc.installation_id
self.assertIsNone(installation_id)
telemetry_enabled = gc.telemetry_enabled
self.assertFalse(telemetry_enabled)

def test_setter_cannot_open_path(self):
m = mock_open()
m.side_effect = IOError("fail")
Expand Down