o ckF[R@sPddlmZddlmZddlmZddlmZddlm Z GdddeZ dS) )json)JSONResponseError)AWSAuthConnection) RegionInfo) exceptionsc seZdZdZdZdZdZeZe j e j e j e j e je je je jdZfddZdd Zd d Zd d ZddZddZddZ  d(ddZd(ddZ  d)ddZddZ d*ddZdd Zd!d"Z  d+d#d$Z! % d,d&d'Z"Z#S)-CognitoSyncConnectiona Amazon Cognito Sync Amazon Cognito Sync provides an AWS service and client library that enable cross-device syncing of application-related user data. High-level client libraries are available for both iOS and Android. You can use these libraries to persist data locally so that it's available even if the device is offline. Developer credentials don't need to be stored on the mobile device to access the service. You can use Amazon Cognito to obtain a normalized user ID and credentials. User data is persisted in a dataset that can store up to 1 MB of key-value pairs, and you can have up to 20 datasets per user identity. With Amazon Cognito Sync, the data stored for each identity is accessible only to credentials assigned to that identity. In order to use the Cognito Sync service, you need to make API calls using credentials retrieved with `Amazon Cognito Identity service`_. z 2014-06-30z us-east-1z$cognito-sync.us-east-1.amazonaws.com)LimitExceededExceptionResourceConflictExceptionInvalidConfigurationExceptionTooManyRequestsExceptionInvalidParameterExceptionResourceNotFoundExceptionInternalErrorExceptionNotAuthorizedExceptionc sP|d}|st||j|j}n|d=|j|d<tt|jdi|||_dS)Nregionhost) getrDefaultRegionNameDefaultRegionEndpointendpointsuperr__init__r)selfkwargsr __class__r:/usr/lib/python3/dist-packages/boto/cognito/sync/layer1.pyrAs   zCognitoSyncConnection.__init__cCsdgS)Nzhmac-v4r)rrrr_required_auth_capabilityLsz/CognitoSyncConnection._required_auth_capabilitycCd|||}|jd|ddS)a Deletes the specific dataset. The dataset will be deleted permanently, and the action can't be undone. Datasets that this dataset was merged with will no longer report the merge. Any consequent operation on this dataset will result in a ResourceNotFoundException. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type identity_id: string :param identity_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type dataset_name: string :param dataset_name: A string of up to 128 characters. Allowed characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.' (dot). ./identitypools/{0}/identities/{1}/datasets/{2}DELETEexpected_statusformat make_requestridentity_pool_id identity_id dataset_nameurirrrdelete_datasetOsz$CognitoSyncConnection.delete_datasetcCr)a6 Gets metadata about a dataset by identity and dataset name. The credentials used to make this API call need to have access to the identity data. With Amazon Cognito Sync, each identity has access only to its own data. You should use Amazon Cognito Identity service to retrieve the credentials necessary to make this API call. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type identity_id: string :param identity_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type dataset_name: string :param dataset_name: A string of up to 128 characters. Allowed characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.' (dot). r GETr"r#r%r(rrrdescribe_datasetlsz&CognitoSyncConnection.describe_datasetcCd|}|jd|ddS)ad Gets usage details (for example, data storage) about a particular identity pool. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. z/identitypools/{0}r.r"r#r%rr)r,rrrdescribe_identity_pool_usage z2CognitoSyncConnection.describe_identity_pool_usagecCsd||}|jd|ddS)aW Gets usage information for an identity, including number of datasets and data usage. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type identity_id: string :param identity_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. z!/identitypools/{0}/identities/{1}r.r"r#r%)rr)r*r,rrrdescribe_identity_usagesz-CognitoSyncConnection.describe_identity_usagecCr0)aa Gets the configuration settings of an identity pool. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. This is the ID of the pool for which to return a configuration. /identitypools/{0}/configurationr.r"r#r%r1rrrget_identity_pool_configurationr3z5CognitoSyncConnection.get_identity_pool_configurationNc CsTd||}i}i}i}|dur||d<|dur||d<|jd|dt|||dS)a6 Lists datasets for an identity. The credentials used to make this API call need to have access to the identity data. With Amazon Cognito Sync, each identity has access only to its own data. You should use Amazon Cognito Identity service to retrieve the credentials necessary to make this API call. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type identity_id: string :param identity_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type next_token: string :param next_token: A pagination token for obtaining the next page of results. :type max_results: integer :param max_results: The maximum number of results to be returned. z*/identitypools/{0}/identities/{1}/datasetsN nextToken maxResultsr.r"r$dataheadersparamsr&r'rdumps) rr)r* next_token max_resultsr,r<r; query_paramsrrr list_datasetss  z#CognitoSyncConnection.list_datasetscCsLd}i}i}i}|dur||d<|dur||d<|jd|dt|||dS)a; Gets a list of identity pools registered with Cognito. :type next_token: string :param next_token: A pagination token for obtaining the next page of results. :type max_results: integer :param max_results: The maximum number of results to be returned. z/identitypoolsNr7r8r.r"r9)r'rr>)rr?r@r,r<r;rArrrlist_identity_pool_usages   z.CognitoSyncConnection.list_identity_pool_usagec Csvd|||}i} i} i} |dur|| d<|dur|| d<|dur%|| d<|dur-|| d<|jd|dt| | | d S) aY Gets paginated records, optionally changed after a particular sync count for a dataset and identity. The credentials used to make this API call need to have access to the identity data. With Amazon Cognito Sync, each identity has access only to its own data. You should use Amazon Cognito Identity service to retrieve the credentials necessary to make this API call. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type identity_id: string :param identity_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type dataset_name: string :param dataset_name: A string of up to 128 characters. Allowed characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.' (dot). :type last_sync_count: long :param last_sync_count: The last server sync count for this record. :type next_token: string :param next_token: A pagination token for obtaining the next page of results. :type max_results: integer :param max_results: The maximum number of results to be returned. :type sync_session_token: string :param sync_session_token: A token containing a session ID, identity ID, and expiration. z6/identitypools/{0}/identities/{1}/datasets/{2}/recordsN lastSyncCountr7r8syncSessionTokenr.r"r9r=) rr)r*r+last_sync_countr?r@sync_session_tokenr,r<r;rArrr list_recordss$*  z"CognitoSyncConnection.list_recordsc Cs:d||}||d}i}i}|jd|dt|||dS)aq Registers a device to receive push sync notifications. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. Here, the ID of the pool that the identity belongs to. :type identity_id: string :param identity_id: The unique ID for this identity. :type platform: string :param platform: The SNS platform type (e.g. GCM, SDM, APNS, APNS_SANDBOX). :type token: string :param token: The push token. z&/identitypools/{0}/identity/{1}/device)PlatformTokenPOSTr"r9r=) rr)r*platformtokenr,r<r;rArrrregister_device:s   z%CognitoSyncConnection.register_devicecCsBd|}i}i}i}|dur||d<|jd|dt|||dS)a Sets the necessary configuration for push sync. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. This is the ID of the pool to modify. :type push_sync: dict :param push_sync: Configuration options to be applied to the identity pool. r5NPushSyncrKr"r9r=)rr) push_syncr,r<r;rArrrset_identity_pool_configurationXs   z5CognitoSyncConnection.set_identity_pool_configurationcC d||||}|jd|ddS)a Subscribes to receive notifications when a dataset is modified by another device. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. The ID of the pool to which the identity belongs. :type identity_id: string :param identity_id: Unique ID for this identity. :type dataset_name: string :param dataset_name: The name of the dataset to subcribe to. :type device_id: string :param device_id: The unique ID generated for this device by Cognito. @/identitypools/{0}/identities/{1}/datasets/{2}/subscriptions/{3}rKr"r#r%rr)r*r+ device_idr,rrrsubscribe_to_datasetrz*CognitoSyncConnection.subscribe_to_datasetcCrR)a Unsubscribe from receiving notifications when a dataset is modified by another device. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. The ID of the pool to which this identity belongs. :type identity_id: string :param identity_id: Unique ID for this identity. :type dataset_name: string :param dataset_name: The name of the dataset from which to unsubcribe. :type device_id: string :param device_id: The unique ID generated for this device by Cognito. rSr!r"r#r%rTrrrunsubscribe_from_datasetrWz.CognitoSyncConnection.unsubscribe_from_datasetc Cszd|||}d|i} i} i} |dur|| d<|dur|| d<|dur'|| d<|dur/|| d<|jd|dt| | | d S) a Posts updates to records and add and delete records for a dataset and user. The credentials used to make this API call need to have access to the identity data. With Amazon Cognito Sync, each identity has access only to its own data. You should use Amazon Cognito Identity service to retrieve the credentials necessary to make this API call. :type identity_pool_id: string :param identity_pool_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type identity_id: string :param identity_id: A name-spaced GUID (for example, us- east-1:23EC4050-6AEA-7089-A2DD-08002EXAMPLE) created by Amazon Cognito. GUID generation is unique within a region. :type dataset_name: string :param dataset_name: A string of up to 128 characters. Allowed characters are a-z, A-Z, 0-9, '_' (underscore), '-' (dash), and '.' (dot). :type device_id: string :param device_id: The unique ID generated for this device by Cognito. :type record_patches: list :param record_patches: A list of patch operations. :type sync_session_token: string :param sync_session_token: The SyncSessionToken returned by a previous call to ListRecords for this dataset and identity. :type client_context: string :param client_context: Intended to supply a device ID that will populate the `lastModifiedBy` field referenced in other methods. The `ClientContext` field is not yet implemented. r SyncSessionTokenNDeviceId RecordPatcheszx-amz-Client-ContextrKr"r9r=) rr)r*r+rGrUrecord_patchesclient_contextr,r<r;rArrrupdate_recordss$+  z$CognitoSyncConnection.update_recordsc Csx|duri}tj||||||d}t|d}|j|kr"|S|ddd} |j | |j } | |j|j |)N)r;r:r<zutf-8zx-amzn-ErrorType:r) rr'rloadsreaddecodestatus getheadersplit_faultsr ResponseErrorreason) rverbresourcer;r:r$r<responsebody error_type error_classrrrr's  z"CognitoSyncConnection.make_request)NN)NNNN)N)NNN)Nr_NN)$__name__ __module__ __qualname____doc__ APIVersionrrrrhrrr r r r r rrrgrrr-r/r2r4r6rBrCrHrNrQrVrXr^r' __classcell__rrrrrsP   ) ;  <rN) boto.compatrboto.exceptionrboto.connectionrboto.regioninforboto.cognito.syncrrrrrrs