Skip to content

Commit

Permalink
Merge branch 'trunk' into dependabot/github_actions/github/codeql-act…
Browse files Browse the repository at this point in the history
…ion-2.22.3
  • Loading branch information
cpswan authored Oct 16, 2023
2 parents 837ff6b + df224da commit a3fd980
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 57 deletions.
2 changes: 2 additions & 0 deletions packages/at_persistence_secondary_server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.0.58
- fix: Modify "lastCommittedSequenceNumberWithRegex" to return highest commitId among enrolled namespaces
## 3.0.57
- fix: Refactor commit log keystore to optimize memory usage
## 3.0.56
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ class AtCompactionStatsServiceImpl implements AtCompactionStatsService {
///changes the value of [compactionStatsKey] to match the AtLogType being processed
void _getKey() {
if (_atCompaction is AtCommitLog) {
compactionStatsKey = commitLogCompactionKey;
compactionStatsKey = AtConstants.commitLogCompactionKey;
}
if (_atCompaction is AtAccessLog) {
compactionStatsKey = accessLogCompactionKey;
compactionStatsKey = AtConstants.accessLogCompactionKey;
}
if (_atCompaction is AtNotificationKeystore) {
compactionStatsKey = notificationCompactionKey;
compactionStatsKey = AtConstants.notificationCompactionKey;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,10 @@ class AtCommitLog extends BaseAtCommitLog {

/// Returns the latest committed sequence number with regex
@server
Future<int?> lastCommittedSequenceNumberWithRegex(String regex) async {
return await _commitLogKeyStore.lastCommittedSequenceNumberWithRegex(regex);
Future<int?> lastCommittedSequenceNumberWithRegex(String regex,
{List<String>? enrolledNamespace}) async {
return await _commitLogKeyStore.lastCommittedSequenceNumberWithRegex(regex,
enrolledNamespace: enrolledNamespace);
}

/// Returns the first committed sequence number
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ class CommitLogKeyStore extends BaseCommitLogKeyStore {
}

/// Returns the latest committed sequence number with regex
Future<int?> lastCommittedSequenceNumberWithRegex(String regex) async {
Future<int?> lastCommittedSequenceNumberWithRegex(String regex,
{List<String>? enrolledNamespace}) async {
var lastCommittedEntry = (getBox() as Box).values.lastWhere(
(entry) => (_acceptKey(entry.atKey, regex)),
(entry) => (_acceptKey(entry.atKey, regex,
enrolledNamespace: enrolledNamespace)),
orElse: () => NullCommitEntry());
var lastCommittedSequenceNum =
(lastCommittedEntry != null) ? lastCommittedEntry.key : null;
Expand Down Expand Up @@ -177,19 +179,41 @@ class CommitLogKeyStore extends BaseCommitLogKeyStore {
}
}

bool _acceptKey(String atKey, String regex) {
return _isRegexMatches(atKey, regex) || _isSpecialKey(atKey);
bool _acceptKey(String atKey, String regex,
{List<String>? enrolledNamespace}) {
return _isNamespaceAuthorised(atKey, enrolledNamespace) &&
(_isRegexMatches(atKey, regex) || _isSpecialKey(atKey));
}

bool _isNamespaceAuthorised(String atKey, List<String>? enrolledNamespace) {
// This is work-around for : https://github.com/atsign-foundation/at_server/issues/1570
if (atKey.toLowerCase() == 'configkey') {
return true;
}
String? keyNamespace = AtKey.fromString(atKey).namespace;
// If enrolledNamespace is null or keyNamespace is null, fallback to
// existing behaviour - the key is authorized for the client to receive. So return true.
if (enrolledNamespace == null ||
enrolledNamespace.isEmpty ||
(keyNamespace == null || keyNamespace.isEmpty)) {
return true;
}
if (enrolledNamespace.contains('*') ||
enrolledNamespace.contains(keyNamespace)) {
return true;
}
return false;
}

bool _isRegexMatches(String atKey, String regex) {
return RegExp(regex).hasMatch(atKey);
}

bool _isSpecialKey(String atKey) {
return atKey.contains(AT_ENCRYPTION_SHARED_KEY) ||
return atKey.contains(AtConstants.atEncryptionSharedKey) ||
atKey.startsWith('public:') ||
atKey.contains(AT_PKAM_SIGNATURE) ||
atKey.contains(AT_SIGNING_PRIVATE_KEY);
atKey.contains(AtConstants.atPkamSignature) ||
atKey.contains(AtConstants.atSigningPrivateKey);
}

/// Returns the latest commitEntry of the key.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,21 +136,21 @@ class AtMetaData extends HiveObject {
map['refreshAt'] = refreshAt?.toUtc().toString();
map['status'] = status;
map['version'] = version;
map[AT_TTL] = ttl;
map[AT_TTB] = ttb;
map[AT_TTR] = ttr;
map[CCD] = isCascade;
map[IS_BINARY] = isBinary;
map[IS_ENCRYPTED] = isEncrypted;
map[PUBLIC_DATA_SIGNATURE] = dataSignature;
map[SHARED_KEY_ENCRYPTED] = sharedKeyEnc;
map[SHARED_WITH_PUBLIC_KEY_CHECK_SUM] = pubKeyCS;
map[ENCODING] = encoding;
map[ENCRYPTING_KEY_NAME] = encKeyName;
map[ENCRYPTING_ALGO] = encAlgo;
map[IV_OR_NONCE] = ivNonce;
map[SHARED_KEY_ENCRYPTED_ENCRYPTING_KEY_NAME] = skeEncKeyName;
map[SHARED_KEY_ENCRYPTED_ENCRYPTING_ALGO] = skeEncAlgo;
map[AtConstants.ttl] = ttl;
map[AtConstants.ttb] = ttb;
map[AtConstants.ttr] = ttr;
map[AtConstants.ccd] = isCascade;
map[AtConstants.isBinary] = isBinary;
map[AtConstants.isEncrypted] = isEncrypted;
map[AtConstants.publicDataSignature] = dataSignature;
map[AtConstants.sharedKeyEncrypted] = sharedKeyEnc;
map[AtConstants.sharedWithPublicKeyCheckSum] = pubKeyCS;
map[AtConstants.encoding] = encoding;
map[AtConstants.encryptingKeyName] = encKeyName;
map[AtConstants.encryptingAlgo] = encAlgo;
map[AtConstants.ivOrNonce] = ivNonce;
map[AtConstants.sharedKeyEncryptedEncryptingKeyName] = skeEncKeyName;
map[AtConstants.sharedKeyEncryptedEncryptingAlgo] = skeEncAlgo;
return map;
}

Expand Down Expand Up @@ -178,33 +178,33 @@ class AtMetaData extends HiveObject {
: (json['version'] == null)
? 0
: json['version'];
ttl = (json[AT_TTL] is String)
? int.parse(json[AT_TTL])
: (json[AT_TTL] == null)
ttl = (json[AtConstants.ttl] is String)
? int.parse(json[AtConstants.ttl])
: (json[AtConstants.ttl] == null)
? null
: json[AT_TTL];
ttb = (json[AT_TTB] is String)
? int.parse(json[AT_TTB])
: (json[AT_TTB] == null)
: json[AtConstants.ttl];
ttb = (json[AtConstants.ttb] is String)
? int.parse(json[AtConstants.ttb])
: (json[AtConstants.ttb] == null)
? null
: json[AT_TTB];
ttr = (json[AT_TTR] is String)
? int.parse(json[AT_TTR])
: (json[AT_TTR] == null)
: json[AtConstants.ttb];
ttr = (json[AtConstants.ttr] is String)
? int.parse(json[AtConstants.ttr])
: (json[AtConstants.ttr] == null)
? null
: json[AT_TTR];
isCascade = json[CCD];
isBinary = json[IS_BINARY];
isEncrypted = json[IS_ENCRYPTED];
dataSignature = json[PUBLIC_DATA_SIGNATURE];
sharedKeyEnc = json[SHARED_KEY_ENCRYPTED];
pubKeyCS = json[SHARED_WITH_PUBLIC_KEY_CHECK_SUM];
encoding = json[ENCODING];
encKeyName = json[ENCRYPTING_KEY_NAME];
encAlgo = json[ENCRYPTING_ALGO];
ivNonce = json[IV_OR_NONCE];
skeEncKeyName = json[SHARED_KEY_ENCRYPTED_ENCRYPTING_KEY_NAME];
skeEncAlgo = json[SHARED_KEY_ENCRYPTED_ENCRYPTING_ALGO];
: json[AtConstants.ttr];
isCascade = json[AtConstants.ccd];
isBinary = json[AtConstants.isBinary];
isEncrypted = json[AtConstants.isEncrypted];
dataSignature = json[AtConstants.publicDataSignature];
sharedKeyEnc = json[AtConstants.sharedKeyEncrypted];
pubKeyCS = json[AtConstants.sharedWithPublicKeyCheckSum];
encoding = json[AtConstants.encoding];
encKeyName = json[AtConstants.encryptingKeyName];
encAlgo = json[AtConstants.encryptingAlgo];
ivNonce = json[AtConstants.ivOrNonce];
skeEncKeyName = json[AtConstants.sharedKeyEncryptedEncryptingKeyName];
skeEncAlgo = json[AtConstants.sharedKeyEncryptedEncryptingAlgo];

return this;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/at_persistence_secondary_server/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: at_persistence_secondary_server
description: A Dart library with the implementation classes for the persistence layer of the secondary server.
version: 3.0.57
version: 3.0.58
repository: https://github.com/atsign-foundation/at_server
homepage: https://docs.atsign.com/

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Future<void> main() async {
// Get Compaction Stats
AtData? atData = await secondaryPersistenceStore!
.getSecondaryKeyStore()
?.get(at_commons.commitLogCompactionKey);
?.get(at_commons.AtConstants.commitLogCompactionKey);

// Assert Compaction Stats
var decodedData = jsonDecode(atData!.data!) as Map;
Expand Down Expand Up @@ -110,7 +110,7 @@ Future<void> main() async {
await atCompactionStatsServiceImpl.handleStats(atCompactionStats);
AtData? atData = await secondaryPersistenceStore!
.getSecondaryKeyStore()
?.get(at_commons.accessLogCompactionKey);
?.get(at_commons.AtConstants.accessLogCompactionKey);
var data = (atData?.data);
var decodedData = jsonDecode(data!) as Map;
expect(decodedData["deletedKeysCount"], '3');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,12 @@ void main() async {
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
await commitLogKeystore.getBox().add(CommitEntry(
'test_key_false_$i', CommitOp.UPDATE, DateTime.now()));
'test_key_false_$i.wavi@alice',
CommitOp.UPDATE,
DateTime.now()));
} else {
await commitLogKeystore.getBox().add(CommitEntry(
'test_key_false_$i', CommitOp.UPDATE, DateTime.now())
'test_key_false_$i.wavi@alice', CommitOp.UPDATE, DateTime.now())
..commitId = i);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ void main() async {
var keyStore = keyStoreManager.getSecondaryKeyStore()!;
var atData = AtData();
atData.data = '123';
final result = await keyStore.put(AT_PKAM_PRIVATE_KEY, atData);
final result = await keyStore.put(AtConstants.atPkamPrivateKey, atData);
expect(result, isA<int>());
});

Expand Down

0 comments on commit a3fd980

Please sign in to comment.