-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(builds): Add regex pattern support for KDF download
Add regex pattern support for KDF downloads to resolve the issue where some platforms have both the “mm2” and “kdf” files listed for backwards compatibility.
- Loading branch information
Showing
5 changed files
with
129 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 67 additions & 36 deletions
103
...s/komodo_wallet_build_transformer/lib/src/steps/models/api/api_build_platform_config.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,88 @@ | ||
import 'package:komodo_wallet_build_transformer/src/steps/models/api/api_file_matching_config.dart'; | ||
|
||
/// Configuration for a specific platform's API build settings. | ||
/// | ||
/// This class contains the configuration needed to download and verify API | ||
/// binaries for a specific platform (e.g., 'web', 'macos', 'windows', etc.). | ||
class ApiBuildPlatformConfig { | ||
/// Creates a new [ApiBuildPlatformConfig] with required parameters. | ||
/// | ||
/// The [matchingConfig] specifies how to identify the correct API file. | ||
/// [validZipSha256Checksums] contains the list of valid SHA256 checksums for | ||
/// verification. | ||
/// [path] specifies where the API files should be stored. | ||
ApiBuildPlatformConfig({ | ||
required this.matchingKeyword, | ||
required this.matchingConfig, | ||
required this.validZipSha256Checksums, | ||
required this.path, | ||
}); | ||
}) : assert( | ||
validZipSha256Checksums.isNotEmpty, | ||
'At least one valid checksum must be provided', | ||
); | ||
|
||
/// Creates an instance of [ApiBuildPlatformConfig] from a JSON object. | ||
/// Creates a [ApiBuildPlatformConfig] from a JSON map. | ||
/// | ||
/// Throws an [ArgumentError] if the object does not match the expected | ||
/// structure. | ||
/// The JSON must contain either 'matching_keyword' or 'matching_pattern', | ||
/// 'valid_zip_sha256_checksums' as a non-empty list, and a 'path' string. | ||
/// Throws a [FormatException] if the JSON is invalid. | ||
factory ApiBuildPlatformConfig.fromJson(Map<String, dynamic> json) { | ||
if (!json.containsKey('matching_keyword')) { | ||
throw ArgumentError('missing matching_keyword'); | ||
} | ||
|
||
if (!json.containsKey('valid_zip_sha256_checksums')) { | ||
throw ArgumentError('missing valid_zip_sha256_checksums'); | ||
throw FormatException( | ||
'Missing required field: valid_zip_sha256_checksums', | ||
json.toString(), | ||
); | ||
} | ||
|
||
if (!json.containsKey('path')) { | ||
throw ArgumentError('missing path'); | ||
throw FormatException('Missing required field: path', json.toString()); | ||
} | ||
|
||
if (!json.containsKey('matching_keyword') && | ||
!json.containsKey('matching_pattern')) { | ||
throw FormatException( | ||
'Either matching_keyword or matching_pattern must be provided', | ||
json.toString(), | ||
); | ||
} | ||
|
||
final checksums = json['valid_zip_sha256_checksums']; | ||
if (checksums is! List || checksums.isEmpty) { | ||
throw FormatException( | ||
'valid_zip_sha256_checksums must be a non-empty list', | ||
json.toString(), | ||
); | ||
} | ||
|
||
final matchingConfig = ApiFileMatchingConfig( | ||
matchingKeyword: json['matching_keyword'] as String?, | ||
matchingPattern: json['matching_pattern'] as String?, | ||
); | ||
|
||
return ApiBuildPlatformConfig( | ||
matchingKeyword: json['matching_keyword'] as String, | ||
validZipSha256Checksums: | ||
List<String>.from(json['valid_zip_sha256_checksums'] as List), | ||
matchingConfig: matchingConfig, | ||
validZipSha256Checksums: List<String>.from(checksums), | ||
path: json['path'] as String, | ||
); | ||
} | ||
|
||
String matchingKeyword; | ||
List<String> validZipSha256Checksums; | ||
String path; | ||
/// Configuration for matching the correct API file | ||
final ApiFileMatchingConfig matchingConfig; | ||
|
||
Map<String, dynamic> toJson() { | ||
return { | ||
'matching_keyword': matchingKeyword, | ||
'valid_zip_sha256_checksums': validZipSha256Checksums, | ||
'path': path, | ||
}; | ||
} | ||
/// List of valid SHA256 checksums for the API zip file | ||
/// | ||
/// Multiple checksums can be valid at the same time to support different | ||
/// versions or variations of the API. | ||
final List<String> validZipSha256Checksums; | ||
|
||
ApiBuildPlatformConfig copyWith({ | ||
String? matchingKeyword, | ||
List<String>? validZipSha256Checksums, | ||
String? path, | ||
}) { | ||
return ApiBuildPlatformConfig( | ||
matchingKeyword: matchingKeyword ?? this.matchingKeyword, | ||
validZipSha256Checksums: | ||
validZipSha256Checksums ?? this.validZipSha256Checksums, | ||
path: path ?? this.path, | ||
); | ||
} | ||
/// Path where the API files should be stored | ||
/// | ||
/// This path is relative to the project's artifact output directory. | ||
final String path; | ||
|
||
/// Converts the configuration to a JSON map. | ||
Map<String, dynamic> toJson() => { | ||
...matchingConfig.toJson(), | ||
'valid_zip_sha256_checksums': validZipSha256Checksums, | ||
'path': path, | ||
}; | ||
} |
44 changes: 44 additions & 0 deletions
44
...es/komodo_wallet_build_transformer/lib/src/steps/models/api/api_file_matching_config.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/// Configuration for matching API files using either a simple keyword or regex pattern. | ||
class ApiFileMatchingConfig { | ||
ApiFileMatchingConfig({ | ||
this.matchingKeyword, | ||
this.matchingPattern, | ||
}) : assert( | ||
matchingKeyword != null || matchingPattern != null, | ||
'Either matchingKeyword or matchingPattern must be provided', | ||
); | ||
|
||
factory ApiFileMatchingConfig.fromJson(Map<String, dynamic> json) { | ||
return ApiFileMatchingConfig( | ||
matchingKeyword: json['matching_keyword'] as String?, | ||
matchingPattern: json['matching_pattern'] as String?, | ||
); | ||
} | ||
|
||
/// Simple substring to match in the filename | ||
final String? matchingKeyword; | ||
|
||
/// Regular expression pattern to match against the filename | ||
final String? matchingPattern; | ||
|
||
/// Checks if the given input string matches either the keyword or pattern | ||
bool matches(String input) { | ||
if (matchingPattern != null) { | ||
try { | ||
final regex = RegExp(matchingPattern!); | ||
return regex.hasMatch(input); | ||
} catch (e) { | ||
throw FormatException( | ||
'Invalid regex pattern: $matchingPattern', | ||
e.toString(), | ||
); | ||
} | ||
} | ||
return matchingKeyword != null && input.contains(matchingKeyword!); | ||
} | ||
|
||
Map<String, dynamic> toJson() => { | ||
if (matchingKeyword != null) 'matching_keyword': matchingKeyword, | ||
if (matchingPattern != null) 'matching_pattern': matchingPattern, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters