-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2085 from atsign-foundation/2074-introducing-auto…
…-expiry-and-time-to-birth-features-for-apkam-keys fix: Introduce time duration for apkam keys to auto expire
- Loading branch information
Showing
23 changed files
with
613 additions
and
171 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
6 changes: 5 additions & 1 deletion
6
packages/at_secondary_server/lib/src/enroll/enroll_datastore_value.g.dart
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
packages/at_secondary_server/lib/src/enroll/enrollment_manager.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,82 @@ | ||
import 'dart:convert'; | ||
|
||
import 'package:at_commons/at_commons.dart'; | ||
import 'package:at_persistence_secondary_server/at_persistence_secondary_server.dart'; | ||
import 'package:at_secondary/src/constants/enroll_constants.dart'; | ||
import 'package:at_secondary/src/enroll/enroll_datastore_value.dart'; | ||
import 'package:at_secondary/src/server/at_secondary_impl.dart'; | ||
import 'package:at_secondary/src/utils/secondary_util.dart'; | ||
import 'package:at_utils/at_logger.dart'; | ||
|
||
/// Manages enrollment data in the secondary server. | ||
/// | ||
/// This class provides methods to retrieve and store enrollment data | ||
/// associated with a given enrollment ID. It interacts with the | ||
/// SecondaryKeyStore to persist and retrieve enrollment information. | ||
class EnrollmentManager { | ||
final SecondaryKeyStore _keyStore; | ||
|
||
final logger = AtSignLogger('AtSecondaryServer'); | ||
|
||
/// Creates an instance of [EnrollmentManager]. | ||
/// | ||
/// The [keyStore] is required to interact with the persistence layer. | ||
EnrollmentManager(this._keyStore); | ||
|
||
/// Retrieves the enrollment data for a given [enrollmentId]. | ||
/// | ||
/// This method constructs an enrollment key, fetches the corresponding | ||
/// data from the key store, and returns it as an [EnrollDataStoreValue]. | ||
/// If the key is not found, a [KeyNotFoundException] is thrown. | ||
/// | ||
/// If the retrieved enrollment data is no longer active, the status | ||
/// will be set to `expired`. | ||
/// | ||
/// Returns: | ||
/// An [EnrollDataStoreValue] containing the enrollment details. | ||
/// | ||
/// Throws: | ||
/// [KeyNotFoundException] if the enrollment key does not exist. | ||
Future<EnrollDataStoreValue> get(String enrollmentId) async { | ||
String enrollmentKey = buildEnrollmentKey(enrollmentId); | ||
try { | ||
AtData enrollData = await _keyStore.get(enrollmentKey); | ||
EnrollDataStoreValue enrollDataStoreValue = | ||
EnrollDataStoreValue.fromJson(jsonDecode(enrollData.data!)); | ||
|
||
if (!SecondaryUtil.isActiveKey(enrollData)) { | ||
enrollDataStoreValue.approval?.state = EnrollmentStatus.expired.name; | ||
} | ||
|
||
return enrollDataStoreValue; | ||
} on KeyNotFoundException { | ||
logger.severe('$enrollmentKey does not exist in the keystore'); | ||
rethrow; | ||
} | ||
} | ||
|
||
/// Constructs the enrollment key based on the provided [enrollmentId]. | ||
/// | ||
/// The key format combines the [enrollmentId], a new enrollment key pattern, | ||
/// and the current AtSign. | ||
/// | ||
/// Returns: | ||
/// A [String] representing the enrollment key. | ||
String buildEnrollmentKey(String enrollmentId) { | ||
return '$enrollmentId.$newEnrollmentKeyPattern.$enrollManageNamespace${AtSecondaryServerImpl.getInstance().currentAtSign}'; | ||
} | ||
|
||
/// Stores the enrollment data associated with the given [enrollmentId]. | ||
/// | ||
/// This method constructs an enrollment key and saves the provided [AtData] | ||
/// to the key store. The skipCommit is set to true, to prevent the enrollment | ||
/// data being synced to the client(s). | ||
/// | ||
/// Parameters: | ||
/// - [enrollmentId]: The ID associated with the enrollment. | ||
/// - [atData]: The [AtData] object to be stored. | ||
Future<void> put(String enrollmentId, AtData atData) async { | ||
String enrollmentKey = buildEnrollmentKey(enrollmentId); | ||
await _keyStore.put(enrollmentKey, atData, skipCommit: true); | ||
} | ||
} |
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
Oops, something went wrong.