pythongoogle-cloud-datastoregoogle-cloud-pythongcloud-python

Creating a Datastore Entry results in encrypted properties when viewing with the browser


I manage to create or modify a datastore entity fine with google.cloud.datastore in python, but when I log in into my Cloud Platform project in the browser and check the entry, it looks like all of its properties are encrypted (They look like "Rm9vIEJhcg==" and such - If I create it from the browser I can see the normally).

I am authenticating with a service account identity's json file:

self.client = datastore.Client()
self.client = self.client.from_service_account_json(cert_file.json)

The service account has "editor" permissions on the whole project. Changing it to "Owner", which is the one set for the gmail account I use to log in, doesn't fix the issues.

I create the entity like this:

with self.datastore.client.transaction():
    entity = Entity(Key("key", project="project"))
    entity["property"] = "data"
    self.datastore.client.put(entity)

Any way to make it so the entry I modify with the python library are readable from the browser site?


Solution

  • The value is not really encrypted, rather encoded with Base64. The reason for this is the value is stored as a Blob (raw bytes), instead of Text/Character String. The Console displays Blob fields in Base64 format. The value, Rm9vIEJhcg==, when decoded with Base64, is Foo Bar.

    I don't have much knowledge in Python, but take a look at the Note from the official documentation:

    When saving an entity to the backend, values which are “text” (unicode in Python2, str in Python3) will be saved using the ‘text_value’ field, after being encoded to UTF-8. When retrieved from the back-end, such values will be decoded to “text” again. Values which are “bytes” (str in Python2, bytes in Python3), will be saved using the ‘blob_value’ field, without any decoding / encoding step.

    Depending on the version of Python you are using, adjust the data type for your data and the issue should be resolved.