o
    u´•dÑ  ã                   @   sj   d dl mZmZ d dlmZmZ d dlm	Z	 d dl
Z
d dlZd dlZd dlZd dlmZ G dd„ dƒZdS )é    )ÚcloudServiceDAO_pb2_grpcÚcloudServiceDAO_pb2)Úfortanix_pb2_grpcÚfortanix_pb2)ÚjsonifyN)ÚMessageToJsonc                   @   s<   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚFortanixzpython-fortanix-trcloud:8445zlocalhost:8443c           
   
   C   s  zlt | j d¡ƒdkrt | jd ¡nd}t |¡}|d }t | j d¡ƒdkr-| jd nd}t | j d¡ƒdkr>| jd nd}t | j d¡ƒdkrO| jd nd}t ||t 	|¡¡}t 
|||t |¡¡ dd	d
dœW S  tyˆ }	 zt|	ƒ ddddœW  Y d }	~	S d }	~	ww )NZdata_form_config_rr   ÚNOTFOUNDZemail_fortanixÚtenant_vcloudÚuser_vcloudZplanidz`Se genero satisfactoriamente el acceso al portal, se le hara llegar un correo con la invitacion.Tzalert-success)ÚmessageÚvalidÚclasszhOcurrio un error al generar el acceso al portal, puede intentarlo mas tarde o contactar a mesa de ayuda.Fzalert-danger)ÚlenÚformÚgetlistÚbase64Ú	b64decodeÚjsonÚloadsr   Ú
clnt_frtnxÚcredentials_srvfrtnxÚsave_subscriptionÚcredentials_daoÚ	ExceptionÚprint)
ÚrequestÚPATH_APPÚ	data_formZdtfrm_json_resultsÚemailr
   r   Úplan_idZrslt_clnt_frtnxÚe© r"   úK/home/gothic-suse/public_html/api_core_daas_miscambios/App/main/Fortanix.pyÚmain   s*   (
"""ýý€þzFortanix.mainc                 C   sH   t | d d dƒ�}| ¡ }W d   ƒ n1 sw   Y  t |¡}|S )Nz/App/certs/csharp_dao/úca.pemÚrb)ÚopenÚreadÚgrpcÚssl_channel_credentials)Úpath_appÚfpÚca_certÚcredsr"   r"   r#   r   -   s
   
ÿ
zFortanix.credentials_daoc                 C   s�   t  tj|¡}t |¡}tj|d�}| |¡}t	 
t|ƒ¡}t|ƒ tt|ƒƒ |d d d }	tjddt|ƒt|	ƒd�}
| |
¡}t|ƒ d S )N)Z	user_nameZusersr   Z	userVCDId)Úbackup_scheduled_idÚfirewall_idr    Úuser_id)r)   Úsecure_channelr   ÚHOST_SRV_DAOr   ZservicioDAOServiceStubr   ZGetUserVCDRequestZ
getUserVCDr   r   r   r   ÚtypeZSetContractedServicesRequestÚintZGetContractedServicesRequest)r   Zuser_vcdr    Ú
credentialÚcore_channelZstub_usrZreq_usrZres_usrZreusrZ
id_usr_vcdZreq_srv_contractZres_srv_contractr"   r"   r#   r   3   s    

ü
zFortanix.save_subscriptionc                 C   sR   t | d d dƒ�}| ¡ }W d   ƒ n1 sw   Y  t tjt |¡¡}|S )Nz/App/certs/python_fortanix/r%   r&   )r'   r(   r)   r2   r   ÚHOST_SRV_FRTNXr*   )r+   r,   r-   Zrecommendations_channelr"   r"   r#   r   G   s   
ÿÿzFortanix.credentials_srvfrtnxc                 C   s   ddddddœS )Nzacct.idzacct_role.idzgroup.idzgroup_role.idzuser.id)Zaccount_uidZaccount_role_uidZaccount_group_uidZaccount_group_role_uidZaccount_user_uid)Úpb2_grpcZConsumerStubÚpb2ZAccountToCreateZCreateAccountÚresZRoleToCreateÚidZCreateAccountRoleZGroupToCreateZCreateGroupZCreateGroupRoleZUserToCreateZ
CreateUser)r   ÚtenantÚcredentialsÚclientr   ÚresponseZacctZrequest_roleZresponse_roleZ	acct_roleZrequest_groupZresponse_groupÚgroupZrequest_groleZresponse_groleZ
group_roleZrequest_userZresponse_userÚuserr"   r"   r#   r   O   s   ûzFortanix.clnt_frtnxN)
Ú__name__Ú
__module__Ú__qualname__r8   r3   r$   r   r   r   r   r"   r"   r"   r#   r      s    r   )Z
csharp_daor   r   Zpython_fortanixr   r9   r   r:   Úflaskr   r)   r   r   ÚreZgoogle.protobuf.json_formatr   r   r"   r"   r"   r#   Ú<module>   s   