a
    !f                     @   st   d Z dZdZdZdZdZdZdZdZd	Z	d
Z
dZdZdZdZdZdZdZdZdZdZdZdZdZG dd deZdS )zPubSub API IAM policy definitions

For allowed roles / permissions, see:
https://cloud.google.com/pubsub/access_control#permissions
zroles/ownerzroles/editorzroles/viewerzroles/pubsub.adminzroles/pubsub.editorzroles/pubsub.viewerzroles/pubsub.publisherzroles/pubsub.subscriberzpubsub.topics.consumezpubsub.topics.createzpubsub.topics.deletezpubsub.topics.getzpubsub.topics.getIamPolicyzpubsub.topics.listzpubsub.topics.setIamPolicyzpubsub.subscriptions.consumezpubsub.subscriptions.createzpubsub.subscriptions.deletezpubsub.subscriptions.getz!pubsub.subscriptions.getIamPolicyzpubsub.subscriptions.listz!pubsub.subscriptions.setIamPolicyzpubsub.subscriptions.updatec                   @   sv   e Zd ZdZdddZedd Zedd Zed	d
 Zedd Z	edd Z
edd Zedd Zdd ZdS )Policya\  Combined IAM Policy / Bindings.

    See:
    https://cloud.google.com/pubsub/reference/rest/Shared.Types/Policy
    https://cloud.google.com/pubsub/reference/rest/Shared.Types/Binding

    :type etag: string
    :param etag: ETag used to identify a unique of the policy

    :type version: int
    :param version: unique version of the policy
    Nc                 C   s8   || _ || _t | _t | _t | _t | _t | _d S )N)etagversionsetownerseditorsviewers
publisherssubscribers)selfr   r    r   R/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/pubsub/iam.py__init__n   s    zPolicy.__init__c                 C   s
   d| f S )zFactory method for a user member.

        :type email: string
        :param email: E-mail for this particular user.

        :rtype: string
        :returns: A member string corresponding to the given user.
        zuser:%sr   emailr   r   r   userw   s    
zPolicy.userc                 C   s
   d| f S )zFactory method for a service account member.

        :type email: string
        :param email: E-mail for this particular service account.

        :rtype: string
        :returns: A member string corresponding to the given service account.
        zserviceAccount:%sr   r   r   r   r   service_account   s    
zPolicy.service_accountc                 C   s
   d| f S )zFactory method for a group member.

        :type email: string
        :param email: An id or e-mail for this particular group.

        :rtype: string
        :returns: A member string corresponding to the given group.
        zgroup:%sr   r   r   r   r   group   s    
zPolicy.groupc                 C   s
   d| f S )zFactory method for a domain member.

        :type domain: string
        :param domain: The domain for this member.

        :rtype: string
        :returns: A member string corresponding to the given domain.
        z	domain:%sr   )domainr   r   r   r      s    
zPolicy.domainc                   C   s   dS )zFactory method for a member representing all users.

        :rtype: string
        :returns: A member string representing all users.
        ZallUsersr   r   r   r   r   	all_users   s    zPolicy.all_usersc                   C   s   dS )zFactory method for a member representing all authenticated users.

        :rtype: string
        :returns: A member string representing all authenticated users.
        ZallAuthenticatedUsersr   r   r   r   r   authenticated_users   s    zPolicy.authenticated_usersc                 C   s   | d}| d}| ||}| ddD ]}|d }t|d }|ttfv r^| j|O  _q*|ttfv rz| j|O  _q*|tt	fv r| j
|O  _
q*|tkr| j|O  _q*|tkr| j|O  _q*td|f q*|S )zCreate a policy from the resource returned from the API.

        :type resource: dict
        :param resource: resource returned from the ``getIamPolicy`` API.

        :rtype: :class:`Policy`
        :returns: the parsed policy
        r   r   bindingsr   rolememberszUnknown role: %s)getr   
OWNER_ROLEPUBSUB_ADMIN_ROLEr   EDITOR_ROLEPUBSUB_EDITOR_ROLEr   VIEWER_ROLEPUBSUB_VIEWER_ROLEr   PUBSUB_PUBLISHER_ROLEr   PUBSUB_SUBSCRIBER_ROLEr	   
ValueError)clsresourcer   r   policyZbindingr   r   r   r   r   from_api_repr   s$    



zPolicy.from_api_reprc                 C   s   i }| j dur| j |d< | jdur,| j|d< g }| jrL|tt| jd | jrh|tt| jd | jr|t	t| jd | j
r|tt| j
d | jr|tt| jd |r||d< |S )zConstruct a Policy resource.

        :rtype: dict
        :returns: a resource to be passed to the ``setIamPolicy`` API.
        Nr   r   )r   r   r   )r   r   r   appendr   sortedr   r   r   r   r   r    r	   r!   )r
   r$   r   r   r   r   to_api_repr   sN    



zPolicy.to_api_repr)NN)__name__
__module____qualname____doc__r   staticmethodr   r   r   r   r   r   classmethodr&   r)   r   r   r   r   r   a   s"   
	






r   N)r-   r   r   r   r   r   r   r    r!   ZPUBSUB_TOPICS_CONSUMEZPUBSUB_TOPICS_CREATEZPUBSUB_TOPICS_DELETEZPUBSUB_TOPICS_GETZPUBSUB_TOPICS_GET_IAM_POLICYZPUBSUB_TOPICS_LISTZPUBSUB_TOPICS_SET_IAM_POLICYZPUBSUB_SUBSCRIPTIONS_CONSUMEZPUBSUB_SUBSCRIPTIONS_CREATEZPUBSUB_SUBSCRIPTIONS_DELETEZPUBSUB_SUBSCRIPTIONS_GETZ#PUBSUB_SUBSCRIPTIONS_GET_IAM_POLICYZPUBSUB_SUBSCRIPTIONS_LISTZ#PUBSUB_SUBSCRIPTIONS_SET_IAM_POLICYZPUBSUB_SUBSCRIPTIONS_UPDATEobjectr   r   r   r   r   <module>   s0   