Ejemplo n.º 1
0
    def do_get(self, arg):
        """
        Get an entry value and metadata from the current directory:
        - `get entry1`: get entry1 value
        """
        entry_name = arg

        if self.path == '':
            path = self.dir_name
        else:
            path = f'{self.path}/{self.dir_name}'

        r = self.caller.get_entry(path, entry_name)
        if r.status_code != 200:
            self.logger.error(r.json()['message'])
            return

        entry = Entry(r.json()['body'])

        if entry.created_with_cli:
            ciphered_nonce = entry.value
            plain_value = Parser.decipher_decode(ciphered_nonce,
                                                 self.p_key_derived)
            Printer.print_entry_encrypted(entry, plain_value)
        else:
            self.logger.warning(
                'this entry has not been created with this CLI, the value is transferred to the '
                'remote server in plain text')
            Printer.print_entry(entry)