o
    gi                     @   sd   d dl Z d dlZd dlZd dlZddlmZ ddlmZ ddlmZ ddlm	Z	 G dd de
ZdS )	    N   )	constants)errors)create_environment_dict)find_executablec                   @   s>   e Zd ZdddZdd Zdd Zdd	 Zd
d Zdd ZdS )StoreNc                 C   s>   t j| | _t| j| _|| _| jdu rtd| jdS )z Create a store object that acts as an interface to
            perform the basic operations for storing, retrieving
            and erasing credentials using `program`.
        N*{0} not installed or not available in PATH)	r   PROGRAM_PREFIXprogramr   exeenvironmentr   InitializationErrorformat)selfr
   r    r   Q/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/dockerpycreds/store.py__init__   s   
zStore.__init__c                 C   s`   t |tjs|d}| d|}t|d}|d dkr.|d dkr.t	d
| j|S )zt Retrieve credentials for `server`. If no credentials are found,
            a `StoreError` will be raised.
        utf-8getUsername SecretzNo matching credentials in {})
isinstancesixbinary_typeencode_executejsonloadsdecoder   CredentialsNotFoundr   r
   )r   serverdataresultr   r   r   r      s   

z	Store.getc                 C   s$   t |||dd}| d|S )z_ Store credentials for `server`. Raises a `StoreError` if an error
            occurs.
        )	ServerURLr   r   r   store)r   dumpsr   r   )r   r!   usernamesecret
data_inputr   r   r   r%   1   s   zStore.storec                 C   s&   t |tjs|d}| d| dS )z_ Erase credentials for `server`. Raises a `StoreError` if an error
            occurs.
        r   eraseN)r   r   r   r   r   )r   r!   r   r   r   r*   <   s   
zStore.erasec                 C   s   |  dd}t|dS )zB List stored credentials. Requires v0.4.0+ of the helper.
        listNr   )r   r   r   r   )r   r"   r   r   r   r+   D   s   z
Store.listc              
   C   s   d }t | j}z7tjrtj| j|g||d}W |S tj| j|gtjtj|d}|	|\}}|j
dkr<tj|j
d|dW |S  tjyR } zt|| jd }~w tyx } z|jtjjkritd| jtd|j|jd }~ww )N)inputenv)stdinstdoutr-   r   r   )
returncodecmdoutputr   z$Unexpected OS error "{0}", errno={1})r   r   r   PY3
subprocesscheck_outputr   PopenPIPEcommunicater0   CalledProcessErrorr   process_store_errorr
   OSErrorerrnoosENOENT
StoreErrorr   strerror)r   subcmdr)   r2   r-   processerrer   r   r   r   J   sH   

zStore._execute)N)	__name__
__module____qualname__r   r   r%   r*   r+   r   r   r   r   r   r      s    
r   )r   r=   r4   r   r   r   r   utilsr   r   objectr   r   r   r   r   <module>   s    