iotcs.messaging.client.storage module

class iotcs.messaging.client.storage.StorageAuthenticationResponse

Bases: object

Encapsulates the cloud storage service the authentication response.

Create a StorageAuthenticationResponse instance.

AUTH_TOKEN_HEADER = 'X-Auth-Token'
FIELD_AUTH_TOKEN = 'authToken'
FIELD_CONTENTLENGTH = 'content-length'
FIELD_CONTENTTYPE = 'content-type'
FIELD_DATE = 'date'
FIELD_HEADERS = 'headers'
FIELD_HOST = 'host'
FIELD_OCIAUTH_TOKEN = 'Authorization'
FIELD_OCISTORAGE_CONTAINER_URL = 'storageUrl'
FIELD_REQUEST_TARGET = '(request-target)'
FIELD_STORAGE_CONTAINER_URL = 'storageContainerUrl'
FIELD_XCONTENTSHA256 = 'x-content-sha256'
classmethod fromJson(jsonObject)

Return a StorageAuthenticationResponse instance.

Parameters:jsonObject – a json formatted oci object storage authentication response
Raises:NetworkException if jsonObject is not a valid storage authentication response
Returns:a StorageAuthenticationResponse instance
getHeaders(headers=None)
getIsoci()
getObjectName()
classmethod getRequestJson(object=None, method=None, storageurl=None, headers=None)
Parameters:
  • object
  • method
  • storageurl
Parma headers:
Returns:

getStorageContainerUrl()

Return the storageContainerUrl.

Returns:the storage container url
headers
isoci
objectname
setHeaders(headers)
setIsoci(isoci)
setObjectName(objectname)
setServicePath(servicePath)

Set the storage service path.

storageContainerUrl
toJson()

Return a json object for this instance.

Returns:a json object
class iotcs.messaging.client.storage.StorageConnection

Bases: iotcs.common.Closeable

A class to represent a connection to the Storage Cloud Service.

The StorageConnection transfers content to the Storage Cloud Service. StorageConnection is used by the client internally.

classmethod computeSHA256(file)
Parameters:file – path-like object
Returns:the base64 encoded sha for file as a str
classmethod isStorageCloudURI(stringuri)
sync(storageObject)

Synchronize content with the Storage Cloud Service.

Parameters:storageObject – The StorageObject that identifies the content.
Raises:OSerror – if there is an I/O exception raised by the runtime, or a failure reported by the storage cloud
Raises:SecurityException if there is an exception establishing a secure connection to the storage cloud
Raises:ArgumentException if the storageObject does not return an input stream or an output stream
class iotcs.messaging.client.storage.StorageConnectionBase(secureConnection)

Bases: iotcs.messaging.client.storage.StorageConnection

A class to transfer content to and from the Storage Cloud Service.

There is one StorageConnection instance per client.

Create a StorageConnectionBase instance.

Parameters:secureConnection – a :class`.SecureConection` instance
CLASSIC_STORAGE_METADATAPREFIX = 'X-Object-Meta-'
CLASSIC_STORAGE_PREFIX = '/v1/'
class DownloadTuple(status, headers)

Bases: tuple

Create new instance of DownloadTuple(status, headers)

headers

Alias for field number 1

status

Alias for field number 0

class HeadTuple(status, date, length, contentType, encoding)

Bases: tuple

Create new instance of HeadTuple(status, date, length, contentType, encoding)

contentType

Alias for field number 3

date

Alias for field number 1

encoding

Alias for field number 4

length

Alias for field number 2

status

Alias for field number 0

OBJECT_STORAGE_METADATAPREFIX = 'opc-meta-'
OCI_OBJECT_STORAGE_NAMESPACE_PARAMETER = '/n/'
OCI_OBJECT_STORAGE_OBJECT_PARAMETER = '/o/'
authToken
authTokenLockclosed
close()

Close the connection.

closedLockstorage_http
createStorageObject(clientId=None, name=None, contentType=None, storageUrl=None)

Create a StorageObject.

If any of clientId, name, or contentType are not None, storageUrl is ignored.

If storageUrl is not None, clientId, name, and contentType are ignored.

Information about the transfer of storageObject is obtained from a HEAD HTTP requrest and retried if _RETRY_LIMIT times. See config and the congifuration property in storage_connection_retry_limit in section media_storage.

Parameters:
  • clientId
  • name
  • contentType
  • storageUrl
Raises:

SecurityException if storageUrl does not start with container url.

Raises:

ArgumentException if storageUral is None or empty or invalid

getObjectNameFromURL(storagecloudurl)
getStorageAuthenticationResponse(clientid=None, name=None, storageurl=None, storageobject=None, headers=None)
getStorageContainerUrl()

Return the cloud storage service container url.

The storage cloud service container url is obtained from the StorageAuthenticationResponse in the process of authenticating. An authentication is attempted if the connection had not authenticated previously.

See authenticate() See _getStorageAuthentication()

Returns:the cloud storage service container url
http
pathIsClassicObjectStore(path)
secureConnection
sync(storageObject)

Synchronize content with the Storage Cloud Service.

Parameters:storageObject – The StorageObject that identifies the content.
Raises:TransportException – if there is an I/O exception raised by the runtime, or a failure reported by the storage cloud
Raises:SecurityException if there is an exception establishing a secure connection to the storage cloud
Raises:ArgumentException if the storageObject does not return an input stream or an output stream
class iotcs.messaging.client.storage.StorageObject(uri, name, mimetype, encoding, date, length)

Bases: iotcs.messaging.client.client.ExternalObject

StorageObject provides information about content in cloud storage.

Create a StorageObject instance.

Parameters:
  • uri – the full URL of the object in the Storage Cloud
  • name – the object name used in the Storage Cloud
  • mimetype – the object’s content type or None
  • encoding – the object’s encoding or None
  • date – the the object’s last modified date
  • length – the object’s length in bytes
date
encoding
getContentType()

Return the mime type of the content.

See IANA Media Types # noqa: E501 :return: The mime-type of the content

getCustomMetadata()

This method return unmodifiable copy of metadata. :return: a dict of metadata. It may be empty.

getDate()

Return the date and time the content was created or last modified.

Return the date and time the content was created or last modified in the cloud storage in ISO 8601 format. This may be None if the content has not been uploaded.

Returns:The date the content was last modified in cloud storage in ISO 8601 format, or None if the content has not been uploaded.
getEncoding()

Return the compression scheme of the content.

Returns:the compression scheme of the content, or None if the content is not compressed
getInputStream()

Called by the library to obtain the input stream when uploading content.

Returns:The input stream for the content being uploaded
getLength()

Return the length of the content in bytes.

This is the number of bytes required to upload or download the content.

Returns:The length of the content, or -1 if unknown
getName()

Return the the name of this object in the storage cloud.

It is the name and path of the file that was uploaded to the storage cloud.

:return the name of this object in the storage cloud

getOutputStream()

Return outputStream for downloaded content.

Called by the library to obtain the output stream when downloading content :return: The output stream for the content being downloaded

inputStream
length
metadata
mimetype
name
outputStream
setAttributes(date, length)

Set meta data date, and length.

Parameters:
  • date – the last modified date
  • length – the object’s length
setCustomMetadata(key, value)

Sets the metadata for the StorageObject.

All metdata will be added to Storage Cloud Service as custom metadata with the X-Object-Meta-KeyName header. :param key: The metadata key :param value: The metadata value :raises: Argument if the key or value is None or empty

setInputStream(inputStream)

Set an input stream for content to be uploaded.

The implementation allows for either the input stream to be set, or the output stream to be set, but not both. If`inputStream` parameter is not None the output stream will be set to None.

Parameters:inputStream – A stream from which the content will be read
Raises:StateException – if a transfer is currently in progress
setOutputStream(outputStream)

Set an output stream downloaded content.

The implementation allows for either the input stream to be set, or the output stream to be set, but not both. If outputStream is not None the input stream will be set to None.

Parameters:outputStream – A stream to which the content will be written
Raises:StateException – if a transfer is currently in progress
sync()

Synchronize content with the Storage Cloud Service.

Raises:IOError – if there is an I/O exception raised by the runtime,

or a failure reported by the storage cloud :raises SecurityException: if there is an exception establishing a secure connection to the storage cloud :raises StateException: if the StorageObject does not have an input stream or output stream set.

class iotcs.messaging.client.storage.StorageObjectDelegate(storageConnection, uri, name, contentType, contentEncoding, dateOfLastModification, length)

Bases: iotcs.messaging.client.storage.StorageObject

StorageObjectDelegate provides a storage connection and number of transferred bytes. # noqa: E501

See messaging.client.StorageObject See messaging.client.StorageConnection

Create a StorageObjectDelegate instance.

Parameters:
  • storageConnection – the cloud storage service connection
  • uri – the full URL of the object in the Storage Cloud
  • name – the object name used in the Storage Cloud
  • mimetype – the object’s content type or None
  • encoding – the object’s encoding or None
  • date – the the object’s last modified date
  • length – the object’s length in bytes
isCancelled()

Cancel any pending transfer.

setAttributes(date, length)

Set meta data date and length.

Parameters:
  • date – the last modified date
  • length – the number of transferred bytes
setTransferredBytes(transferredBytes)

Set the number of bytes transferred.

Parameters:transferredBytes – the number of bytes transferred
storageConnection
sync()

Synchronize content with the Storage Cloud Service.

Raises:IOError – if there is an I/O exception raised by the runtime,

or a failure reported by the storage cloud :raises SecurityException: if there is an exception establishing a secure connection to the storage cloud :raises StateException: if the StorageObject does not have an input stream or output stream set.

transferredBytes