Comment 12 for bug 1799746

Revision history for this message
Corey Bryant (corey.bryant) wrote : Re: PY3: when uploading file as secret: TypeError: a bytes-like object is required, not 'str'

Which get_encoded() is getting called?

In barbican's store_secret() this line is called:

    opaque_data.OpaqueData(secret_dto.secret)

castellan/common/objects/opaque_data.py
---------------------------------------
class OpaqueData(managed_object.ManagedObject):
    """This class represents opaque data."""

    def __init__(self, data, name=None, created=None, id=None):
        """Create a new OpaqueData object.

        Expected type for data is a bytestring.
        """
        self._data = data
        super(OpaqueData, self).__init__(name=name, created=created, id=id)

    @property
    def format(self):
        """This method returns 'Opaque'."""
        return "Opaque"

    def get_encoded(self):
        """Returns the data in its original format."""
        return self._data

Ok OpaqueData.__init__() expects a bytestring for data so appears it should already be encoded when the object is initialized and get_encoded() should just return the already encoded string.