Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: at_commons 4.0.0 uptake in at_Client #1192

Merged
merged 17 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1de43a3
at_commons 4.0.0 uptake in at_Client
purnimavenkatasubbu Jan 3, 2024
82ec47f
resolved merge conflicts
purnimavenkatasubbu Jan 4, 2024
85cbb24
fixed tests
purnimavenkatasubbu Jan 4, 2024
4343fe5
Merge remote-tracking branch 'origin/trunk' into update_atclient_depe…
sitaram-kalluri Jan 6, 2024
12ff4c9
fix: Update the version in at_client
sitaram-kalluri Jan 6, 2024
ed3b11d
Merge branch 'trunk' into update_atclient_dependencies
purnimavenkatasubbu Jan 8, 2024
ebe4008
fix: Remove at_client in melos.yaml
sitaram-kalluri Jan 8, 2024
7aa87ac
Merge remote-tracking branch 'origin/update_atclient_dependencies' in…
sitaram-kalluri Jan 8, 2024
504c9c0
Merge branch 'trunk' into update_atclient_dependencies
gkc Jan 8, 2024
1c20bce
fix: Update the null check condition in shared_key_decryption.dart
sitaram-kalluri Jan 9, 2024
cef5f61
Merge remote-tracking branch 'origin/update_atclient_dependencies' in…
sitaram-kalluri Jan 9, 2024
57cb917
feat: replace encryption util encryption methods with at_chops
murali-shris Jan 10, 2024
495696a
Revert "feat: replace encryption util encryption methods with at_chops"
murali-shris Jan 10, 2024
68aa6f4
fix: In delete method when atkey.namespace is unset default to namesp…
sitaram-kalluri Jan 10, 2024
894dc2f
Merge remote-tracking branch 'origin/update_atclient_dependencies' in…
sitaram-kalluri Jan 11, 2024
341a0a8
Merge branch 'trunk' into update_atclient_dependencies
sitaram-kalluri Jan 11, 2024
03e9ab0
resolved merge conflicts
purnimavenkatasubbu Jan 16, 2024
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
3 changes: 1 addition & 2 deletions melos.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: at_client_sdk

packages:
- packages/*
- packages/at_client_mobile
- packages/*/example

- tests/*
7 changes: 7 additions & 0 deletions packages/at_client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 3.0.73
- build[deps]: Upgraded dependencies for the following packages:
- at_commons to v4.0.0
- at_utils to v3.0.16
- at_lookup to v3.0.44
- at_chops to v1.0.7
- at_persistence_secondary_server to v3.0.60
## 3.0.72
- chore: Minor change to allow us to support dart
versions both before and after 3.2.0 specifically for this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class AtCollectionMethodImpl {
_logger.finest('Self key to be used : $atKey');
var atOperationItemStatus = AtOperationItemStatus(
atSign: atKey.sharedBy ?? '',
key: atKey.key ?? '',
key: atKey.key,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Earlier, the AtKey.key is a nullable variable, but the named argument "key" does not accept NULL value. Hence defaulted to empty string in case of null. In at_commons-4.0.0, the AtKey.key is prefixed with late and "?" (which denotes that variable can be null) is removed because key can never be null in AtKey,

complete: false,
operation: Operation.save);
try {
Expand Down Expand Up @@ -76,7 +76,7 @@ class AtCollectionMethodImpl {
_logger.finest('Update shared key $sharedKey');
var atOperationItemStatus = AtOperationItemStatus(
atSign: sharedKey.sharedWith ?? '',
key: sharedKey.key ?? '',
key: sharedKey.key,
complete: false,
operation: Operation.share);
try {
Expand Down Expand Up @@ -133,7 +133,7 @@ class AtCollectionMethodImpl {

var atOperationItemStatus = AtOperationItemStatus(
atSign: atSign,
key: selfKey.key ?? '',
key: selfKey.key,
complete: false,
operation: Operation.share);

Expand Down Expand Up @@ -164,7 +164,7 @@ class AtCollectionMethodImpl {

yield AtOperationItemStatus(
atSign: selfAtKey.sharedWith ?? '',
key: selfAtKey.key ?? '',
key: selfAtKey.key,
complete: isSelfKeyDeleted,
operation: Operation.delete);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ class AtCollectionMethodImpl {
for (var sharedKey in sharedAtKeys) {
var atOperationItemStatus = AtOperationItemStatus(
atSign: sharedKey.sharedWith ?? '',
key: sharedKey.key ?? '',
key: sharedKey.key,
complete: false,
operation: Operation.unshare);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ class DefaultKeyMaker implements KeyMaker {
return AtKey()
..key = '$keyId.$collectionName.atcollectionmodel.$namespace'
..metadata = Metadata()
..metadata!.ccd = objectLifeCycleOptions?.cascadeDelete ?? true
..metadata!.ttl = objectLifeCycleOptions?.timeToLive?.inMilliseconds
..metadata!.ttb = objectLifeCycleOptions?.timeToBirth?.inMilliseconds
..metadata.ccd = objectLifeCycleOptions?.cascadeDelete ?? true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In at_commons-> AtKey, updated the "metadata" field from nullable field (removed "?"). With the change, the field is defaulted to Metadata instance - "Metadata metadata = Metadata();"

..metadata.ttl = objectLifeCycleOptions?.timeToLive?.inMilliseconds
..metadata.ttb = objectLifeCycleOptions?.timeToBirth?.inMilliseconds
..sharedBy = _getAtClient().getCurrentAtSign();
}

Expand All @@ -36,10 +36,10 @@ class DefaultKeyMaker implements KeyMaker {
..key = '$keyId.$collectionName.atcollectionmodel.$namespace'
..sharedWith = sharedWith
..metadata = Metadata()
..metadata!.ttr = ttrInSeconds ?? -1
..metadata!.ccd = objectLifeCycleOptions?.cascadeDelete ?? true
..metadata!.ttl = objectLifeCycleOptions?.timeToLive?.inMilliseconds
..metadata!.ttb = objectLifeCycleOptions?.timeToBirth?.inMilliseconds
..metadata.ttr = ttrInSeconds ?? -1
..metadata.ccd = objectLifeCycleOptions?.cascadeDelete ?? true
..metadata.ttl = objectLifeCycleOptions?.timeToLive?.inMilliseconds
..metadata.ttb = objectLifeCycleOptions?.timeToBirth?.inMilliseconds
..sharedBy = _getAtClient().getCurrentAtSign();
}
}
64 changes: 20 additions & 44 deletions packages/at_client/lib/src/client/at_client_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -294,23 +294,13 @@ class AtClientImpl implements AtClient, AtSignChangeListener {

Future<bool> _delete(AtKey atKey,
{DeleteRequestOptions? deleteRequestOptions}) async {
// If metadata is null, initialize metadata
atKey.metadata ??= Metadata();
String keyWithNamespace;
if (atKey.metadata!.namespaceAware) {
keyWithNamespace = AtClientUtil.getKeyWithNameSpace(atKey, _preference!);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the namespace fixing no longer required?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By assigning atKey directly to the verb builder, key construction utilizes AtKey.toString(), appending the namespace to the key. For the key we do not want namespace to be appended, leaving the namespace fields unset or initializing them to an empty string will suffice.

However, when the user doesn't set a namespace for the AtKey, the earlier practice involved appending the namespace from the AtClientPreferences when namespaceAware is set to "true" is missing here. Will add the code where if atKey.namespace is null or empty and namespaceAware is true, then set the namespace from AtClientPreference.namespace

} else {
keyWithNamespace = atKey.key!;
}
atKey.sharedBy ??= _atSign;
var builder = DeleteVerbBuilder()
..isLocal = atKey.isLocal
..isCached = atKey.metadata!.isCached
..isPublic =
(atKey.metadata!.isPublic == null) ? false : atKey.metadata!.isPublic!
..sharedWith = atKey.sharedWith
..atKey = keyWithNamespace
..sharedBy = atKey.sharedBy;
// When namespace is not set in AtKey.namespace, default it to namespace from
// AtClientPreferences
if (atKey.metadata.namespaceAware) {
atKey.namespace ??= preference?.namespace;
}
var builder = DeleteVerbBuilder()..atKey = atKey;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fields of AtKey are now substituted with AtKey instances in all verb builders. The atKey object is directly assigned, and the code responsible for assigning fields of atKey has been removed

var secondary = getSecondary();
if (deleteRequestOptions != null &&
deleteRequestOptions.useRemoteAtServer) {
Expand Down Expand Up @@ -441,10 +431,8 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
Future<AtResponse> putText(AtKey atKey, String value,
{PutRequestOptions? putRequestOptions}) async {
try {
// Set the default metadata if not already set.
atKey.metadata ??= Metadata();
// Setting metadata.isBinary to false for putText
atKey.metadata!.isBinary = false;
atKey.metadata.isBinary = false;
return await _putInternal(atKey, value, putRequestOptions);
} on AtException catch (e) {
throw AtExceptionManager.createException(e);
Expand All @@ -456,10 +444,8 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
Future<AtResponse> putBinary(AtKey atKey, List<int> value,
{PutRequestOptions? putRequestOptions}) async {
try {
// Set the default metadata if not already set.
atKey.metadata ??= Metadata();
// Setting metadata.isBinary to true for putBinary
atKey.metadata!.isBinary = true;
atKey.metadata.isBinary = true;
// Base2e15.encode method converts the List<int> type to String.
return await _putInternal(
atKey, Base2e15.encode(value), putRequestOptions);
Expand All @@ -470,7 +456,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener {

@visibleForTesting
ensureLowerCase(AtKey atKey) {
if ((atKey.key != null && upperCaseRegex.hasMatch(atKey.key!)) ||
if (upperCaseRegex.hasMatch(atKey.key) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Atkey.key is modified as a non null variable in at_commons, removed the non-null assertion operator

(atKey.namespace != null &&
upperCaseRegex.hasMatch(atKey.namespace!))) {
_logger.finer('AtKey: ${atKey.toString()} previously contained upper case'
Expand All @@ -487,12 +473,12 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
if (atKey.sharedBy.isNull) {
atKey.sharedBy = _atSign;
}
if (atKey.metadata!.namespaceAware) {
if (atKey.metadata.namespaceAware) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Atkey.metadata is modified as a non null variable (defaulted to "Metadata()"), removed the non-null assertion operator

atKey.namespace ??= preference?.namespace;
}

if (preference!.atProtocolEmitted >= Version(2, 0, 0)) {
atKey.metadata!.ivNonce ??= EncryptionUtil.generateIV();
atKey.metadata.ivNonce ??= EncryptionUtil.generateIV();
}
ensureLowerCase(atKey);

Expand Down Expand Up @@ -521,7 +507,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener {

//Get encryptionPrivateKey for public key to signData
String? encryptionPrivateKey;
if (atKey.metadata!.isPublic != null && atKey.metadata!.isPublic! == true) {
if (atKey.metadata.isPublic == true) {
encryptionPrivateKey = await _localSecondary?.getEncryptionPrivateKey();
}
// Transform put request
Expand All @@ -543,7 +529,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
}
// Execute the verb builder
var putResponse = await secondary.executeVerb(verbBuilder,
sync: SyncUtil.shouldSync(atKey.key!));
sync: SyncUtil.shouldSync(atKey.key));
// If putResponse is null or empty, return AtResponse with isError set to true
if (putResponse == null || putResponse.isEmpty) {
return AtResponse()..isError = true;
Expand Down Expand Up @@ -579,27 +565,17 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
@override
Future<bool> putMeta(AtKey atKey) async {
var updateKey = atKey.key;
var metadata = atKey.metadata!;
var metadata = atKey.metadata;
if (metadata.namespaceAware) {
updateKey = _getKeyWithNamespace(atKey.key!);
updateKey = _getKeyWithNamespace(atKey.key);
}
var sharedWith = atKey.sharedWith;
var builder = UpdateVerbBuilder();
builder
..atKey = updateKey
..sharedBy = _atSign
..sharedWith = sharedWith
..ttl = metadata.ttl
..ttb = metadata.ttb
..ttr = metadata.ttr
..ccd = metadata.ccd
..isBinary = metadata.isBinary
..isEncrypted = metadata.isEncrypted
..dataSignature = metadata.dataSignature
..atKey = atKey
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fields of AtKey are now substituted with AtKey instances in all verb builders. The atKey object is directly assigned, and the code responsible for assigning fields of atKey has been removed

..operation = AtConstants.updateMeta;

var updateMetaResult = await getSecondary()
.executeVerb(builder, sync: SyncUtil.shouldSync(updateKey!));
.executeVerb(builder, sync: SyncUtil.shouldSync(updateKey));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since Atkey.key is modified as a non null variable in at_commons, removed the non-null assertion operator

return updateMetaResult != null;
}

Expand Down Expand Up @@ -768,9 +744,9 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
..key = key
..sharedWith = sharedWithAtSign
..metadata = Metadata()
..metadata!.ttr = -1
..metadata.ttr = -1
// file transfer key will be deleted after 30 days
..metadata!.ttl = 2592000000
..metadata.ttl = 2592000000
..sharedBy = _atSign;

var notificationResult = await notificationService.notify(
Expand Down Expand Up @@ -949,7 +925,7 @@ class AtClientImpl implements AtClient, AtSignChangeListener {
PriorityEnum? priority,
StrategyEnum? strategy,
int? latestN,
String? notifier = SYSTEM,
String? notifier = AtConstants.system,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced the use of legacy at_constants (which are now removed from at_commons -4.0.0) with new references to new AtConstants file

bool isDedicated = false}) async {
AtKeyValidators.get().validate(
atKey.toString(),
Expand Down
39 changes: 4 additions & 35 deletions packages/at_client/lib/src/client/local_secondary.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,46 +69,15 @@ class LocalSecondary implements Secondary {
var updateKey = builder.buildKey();
switch (builder.operation) {
case AtConstants.updateMeta:
var metadata = Metadata();
metadata
..ttl = builder.ttl
..ttb = builder.ttb
..ttr = builder.ttr
..ccd = builder.ccd
..isBinary = builder.isBinary
..isEncrypted = builder.isEncrypted
..sharedKeyEnc = builder.sharedKeyEncrypted
..pubKeyCS = builder.pubKeyChecksum
..encoding = builder.encoding
..encKeyName = builder.encKeyName
..encAlgo = builder.encAlgo
..ivNonce = builder.ivNonce
..skeEncKeyName = builder.skeEncKeyName
..skeEncAlgo = builder.skeEncAlgo;
var atMetadata = AtMetaData.fromCommonsMetadata(metadata);
var atMetadata =
AtMetaData.fromCommonsMetadata(builder.atKey.metadata);
updateResult = await keyStore!.putMeta(updateKey, atMetadata);
break;
default:
var atData = AtData();
atData.data = builder.value;
var metadata = Metadata();
metadata
..ttl = builder.ttl
..ttb = builder.ttb
..ttr = builder.ttr
..ccd = builder.ccd
..isBinary = builder.isBinary
..isEncrypted = builder.isEncrypted
..dataSignature = builder.dataSignature
..sharedKeyEnc = builder.sharedKeyEncrypted
..pubKeyCS = builder.pubKeyChecksum
..encoding = builder.encoding
..encKeyName = builder.encKeyName
..encAlgo = builder.encAlgo
..ivNonce = builder.ivNonce
..skeEncKeyName = builder.skeEncKeyName
..skeEncAlgo = builder.skeEncAlgo;
var atMetadata = AtMetaData.fromCommonsMetadata(metadata);
var atMetadata =
AtMetaData.fromCommonsMetadata(builder.atKey.metadata);
updateResult = await keyStore!.putAll(updateKey, atData, atMetadata);
break;
}
Expand Down
36 changes: 16 additions & 20 deletions packages/at_client/lib/src/client/verb_builder_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ class LookUpBuilderManager {
{GetRequestOptions? getRequestOptions}) {
// If isPublic is true in metadata, the key is a public key, return PLookupVerbHandler.
if (atKey.sharedBy != currentAtSign &&
(atKey.metadata != null &&
atKey.metadata!.isPublic! &&
!atKey.metadata!.isCached)) {
(atKey.metadata.isPublic && !atKey.metadata.isCached)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since AtKey.metadata is not null and boolean fields in Metadata have default values instead of null, removed the null check and non null assertion operator

final plookUpVerbBuilder = PLookupVerbBuilder()
..atKey = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference)
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy)
..atKey = (AtKey()
..key = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference)
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy))
..operation = 'all';
if (getRequestOptions != null && getRequestOptions.bypassCache == true) {
plookUpVerbBuilder.bypassCache = true;
Expand All @@ -24,12 +23,11 @@ class LookUpBuilderManager {
}
// If sharedBy is not equal to currentAtSign and isCached is false, return LookupVerbHandler
if (atKey.sharedBy != currentAtSign &&
(atKey.metadata != null &&
!atKey.metadata!.isCached &&
!atKey.metadata!.isPublic!)) {
(!atKey.metadata.isCached && !atKey.metadata.isPublic)) {
final lookupVerbBuilder = LookupVerbBuilder()
..atKey = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference)
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy)
..atKey = (AtKey()
..key = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference)
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy))
..auth = true
..operation = 'all';
if (getRequestOptions != null && getRequestOptions.bypassCache == true) {
Expand All @@ -38,16 +36,14 @@ class LookUpBuilderManager {
return lookupVerbBuilder;
}
return LLookupVerbBuilder()
..atKey = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference)
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy)
..sharedWith = AtClientUtil.fixAtSign(atKey.sharedWith)
..isPublic = (atKey.metadata != null && atKey.metadata?.isPublic != null)
? atKey.metadata!.isPublic!
: false
..isCached = (atKey.metadata != null && atKey.metadata?.isCached != null)
? atKey.metadata!.isCached
: false
..isLocal = atKey.isLocal
..atKey = (AtKey()
..key = AtClientUtil.getKeyWithNameSpace(atKey, atClientPreference)
..sharedBy = AtClientUtil.fixAtSign(atKey.sharedBy)
..sharedWith = AtClientUtil.fixAtSign(atKey.sharedWith)
..metadata = (Metadata()
..isPublic = atKey.metadata.isPublic
..isCached = atKey.metadata.isCached)
..isLocal = atKey.isLocal)
..operation = 'all';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class AtKeyDecryptionManager {
// Eg: currentAtSign is @bob and _phone.wavi@bob (or) phone@bob (or) @bob:phone@bob
if (((atKey.sharedWith == null || atKey.sharedWith == currentAtSign) &&
atKey.sharedBy == currentAtSign) ||
atKey.key!.startsWith('_')) {
atKey.key.startsWith('_')) {
return SelfKeyDecryption(_atClient);
}
// Returns LocalKeyDecryption to for the keys present in local storage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class LocalKeyDecryption extends AbstractAtKeyEncryption
exceptionScenario: ExceptionScenario.fetchEncryptionKeys);
}
InitialisationVector iV;
if (atKey.metadata?.ivNonce != null) {
iV = AtChopsUtil.generateIVFromBase64String(atKey.metadata!.ivNonce!);
if (atKey.metadata.ivNonce != null) {
iV = AtChopsUtil.generateIVFromBase64String(atKey.metadata.ivNonce!);
} else {
iV = AtChopsUtil.generateIVLegacy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class SelfKeyDecryption implements AtKeyDecryption {
}

InitialisationVector iV;
if (atKey.metadata?.ivNonce != null) {
iV = AtChopsUtil.generateIVFromBase64String(atKey.metadata!.ivNonce!);
if (atKey.metadata.ivNonce != null) {
iV = AtChopsUtil.generateIVFromBase64String(atKey.metadata.ivNonce!);
} else {
iV = AtChopsUtil.generateIVLegacy();
}
Expand Down
Loading