Skip to content

Commit

Permalink
Validate UDID for register-device action
Browse files Browse the repository at this point in the history
  • Loading branch information
artemii-yanushevskyi committed Jul 7, 2023
1 parent da398fc commit 21ade45
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
14 changes: 9 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ Version 0.40.5
-------------

**Features**
- Introduce `app-store-connect register-devices-from-file` action to bulk-register devices from a file with UDIDs
- Add short flags for `app-store-connect register-device` action
- Introduce `app-store-connect register-devices-from-file` action to bulk-register devices from a file with UDIDs.
- Update `app-store-connect register-device` to support short flags:
- `-n` flag for specifying the device name,
- `-u` flag for specifying the device UDID.
- Validate device UDID argument for `app-store-connect register-device` action.

**Development**
- Introduce a new action method `AppStoreConnect.register_devices_from_file`
- Introduce a new action method `AppStoreConnect.register_devices_from_file`.
- Validate UDID argument for `AppStoreConnect.register_device`.

**Documentation**
- Document `app-store-connect register-devices-from-file` action
- Document short flags for `app-store-connect register-device`
- Document `app-store-connect register-devices-from-file` action.
- Document short flags for `app-store-connect register-device`.

Version 0.40.4
-------------
Expand Down
10 changes: 8 additions & 2 deletions src/codemagic/tools/app_store_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ def register_device(
"""
Register a new device for app development
"""
if not self._is_device_udid_valid(device_udid):
raise AppStoreConnectError(f'Invalid device UDID: {device_udid}')

return self._create_resource(
self.api_client.devices,
should_print,
Expand All @@ -528,13 +531,12 @@ def register_devices_from_file(
"""
registered_devices = []
device_udid_lines = [udid.strip() for udid in device_udids_path.read_text().split('\n')]
udid_pattern = re.compile(r'^[a-fA-F0-9]{8}-[a-fA-F0-9]{16}$')

for line, device_udid in enumerate(device_udid_lines):
if not device_udid:
continue

if udid_pattern.match(device_udid) is None:
if not self._is_device_udid_valid(device_udid):
self.logger.warning(Colors.YELLOW(f'Invalid device UDID on line {line + 1}: {device_udid!r}'))
continue

Expand Down Expand Up @@ -1240,6 +1242,10 @@ def _save_certificates(
) -> List[pathlib.Path]:
return [self._save_certificate(c, private_key, p12_container_password) for c in certificates]

@staticmethod
def _is_device_udid_valid(device_udid: str) -> bool:
return re.match(r'^[a-fA-F0-9]{8}-[a-fA-F0-9]{16}$', device_udid) is not None


if __name__ == '__main__':
AppStoreConnect.invoke_cli()

0 comments on commit 21ade45

Please sign in to comment.