atsign-foundation / at_client_sdk

The Dart implementation of atSDK used for implementing Atsign's technology into other software
https://pub.dev/publishers/atsign.org/packages
BSD 3-Clause "New" or "Revised" License
1.46k stars 31 forks source link

Failure to store public data within atsign #345

Closed danielgoncalves25 closed 2 years ago

danielgoncalves25 commented 2 years ago

Describe the bug I am trying to store data within my atsign and make that data public for everyone. I am getting error code AT0003 Invalid syntax.

To Reproduce This is the code where im creating the AtKey object and setting its attributes.

    var metaData = Metadata()..isPublic = true;

    var atKey = AtKey()
      ..key = nameController.text
      ..metadata = metaData
      ..namespace = NAMESPACE
      ..sharedWith = atSign;

    var success = await atClientManager.atClient
        .put(atKey, json.encode(articleJson), isDedicated: true);

Screenshots

error DIY

Smartphone (please complete the following information):

Were you using an @‎application when the bug was found?

Additional context Data is successful stored but not whenever I set isPublic attribute to true.

cconstab commented 2 years ago

@danielgoncalves25 sorry this is a little tricky and the error is not useful, we will raise a an enhancement ticket to make both of those a thing of the past...

But to the answer I will provide an example from one of my apps. In my case I am also adding some other metadata so the key times out after an hour..

The catch is that for public data you have to say isPublic, isEncrypted and share with null

Let us know if that fixes your problem...

var metaData = Metadata()
    ..isPublic = true
    ..isEncrypted = false
    ..namespaceAware = true
    // // one minute
    // ..ttl = 60000 ;
    // One Hour
    ..ttl = 3600000;

  var key = AtKey()
    ..key = 'public.' + hamradio.radioName
    ..sharedBy = currentAtsign
    ..sharedWith = null
    ..metadata = metaData;

   await atClient.put(key, jsonEncode(publichamradio));
nickelskevin commented 2 years ago

Also - you can remove isDedicated as it is being deprecated. /// Starting version 3.0.0 [isDedicated] is deprecated

nickelskevin commented 2 years ago

Will categorize this as an enhancement request as follows: We should consider adding additional information for Invalid syntax errors.

gkc commented 2 years ago

1) isPublic and isEncrypted are effectively inverses of each other. We should change code to enforce that and deprecate one of them (I’d suggest deprecating isEncrypted - this is an implicit developer expectation that things are always encrypted unless isPublic is set) 2) sharedWith is fully irrelevant when isPublic is true. We should either (a) actively prevent that combination or (b) just silently set sharedWith to null when isPublic is true, and explain in documentation. (a) is cleaner but is a breaking change; so I suggest (b), with a WARNing logged also

ksanty commented 2 years ago

@cconstab I put you on this issue card. Please update if I got it wrong. :)

cconstab commented 2 years ago

Not something I was going to fix in the code but I did answer the original question. Jagan/Murali/GKC this needs you guys to agree an approach to make the enhancement.. Might be worth opening a new ticket if this one is too confusing..

gkc commented 2 years ago

Hi @danielgoncalves25 - see cconstab's suggestion above which should help you resolve your problem.

Have opened feature request #364 for a better API, and feature requests #365 and #366 for better guidance / protections when using the existing API

cconstab commented 2 years ago

Closing this ticket but noting that #364 was opened