Keeper-Security / Commander

Keeper Commander is a python-based CLI and SDK interface to the Keeper Security platform. Provides administrative controls, reporting, import/export and vault management.
https://www.keepersecurity.com/commander.html
MIT License
186 stars 74 forks source link

recordv3.RecordAddCommand can't add OTP code #1053

Open Luke-Williams9 opened 1 year ago

Luke-Williams9 commented 1 year ago

RecordAddCommand isn't adding an OTP code, is it possible or should I be looking at import functions instead?

here's my function. I've tried using oneTimeCode as a parameter, as well as passing a custom field "TFC:Keeper" to RecordAddCommand, and neither work.

def add_record(rec):
    record_path = ('/' + rootFolder + '/' + rec['client'])
    command = RecordAddCommand()
    record_uid = command.execute(
        connect_params,
        type = rec['type'] if 'type' in rec else None,
        title = rec['title'] if 'title' in rec else None,
        login = rec['login'] if 'login' in rec else None,
        oneTimeCode = rec['otp'] if 'otp' in rec else None,
        password = rec['password'] if 'password' in rec else None,
        url = rec['url'] if 'url' in rec else None,
        notes = rec['notes'] if 'notes' in rec else None,
        folder = record_path,
        custom = rec['custom'] if 'custom' in rec else None,
        generate = False if 'password' in rec else True,
        force = True,
        debug = True
    )
    print(f'Added record {record_uid} to path {record_path}')
sk-keeper commented 1 year ago

oneTimeCode can be passed as an option parameter:

option=['f.oneTimeCode=otpauth://totp/?secret=DFGFDGFDGFDG']

This command is deprecated.

Commander has another command for adding records record-add or record_edit. RecordAddCommand https://docs.keeper.io/secrets-manager/commander-cli/command-reference/record-commands#record-add-and-record-update-commands

Command

record-add --record-type=login --title='Record Title' --notes='a\nb\nc\nd' --folder="Folder Name" login=email@company.io password=$GEN url=https://google.com oneTimeCode=otpauth://totp/?secret=DFGFDGFDGFDG "Custom Field"="Custom Value"

uses the following parser

record_add_parser = argparse.ArgumentParser(prog='record-add', description='Add a record to folder.')
record_add_parser.add_argument('--syntax-help', dest='syntax_help', action='store_true',
                               help='Display help on field parameters.')
record_add_parser.add_argument('-f', '--force', dest='force', action='store_true', help='ignore warnings')
record_add_parser.add_argument('-t', '--title', dest='title', action='store', help='record title')
record_add_parser.add_argument('-rt', '--record-type', dest='record_type', action='store', help='record type')
record_add_parser.add_argument('-n', '--notes', dest='notes', action='store', help='record notes')
record_add_parser.add_argument('--folder', dest='folder', action='store',
                               help='folder name or UID to store record')
record_add_parser.add_argument('fields', nargs='*', type=str,
                               help='load record type data from strings with dot notation')

can be translated to this code

command = record_edit.RecordAddCommand()
record_uid = command.execute(
    connect_params,
    record_type = 'login',
    title = 'Record Title',
    notes = 'a\nb\nc\nd',
   folder='Folder Name',
    fields=['login=email@company.io', 'password=$GEN', 
            'url=https://google.com', 
            'oneTimeCode=otpauth://totp/?secret=DFGFDGFDGFDG',
            '"Custom Field"="Custom Value"'],
    force = True
)