Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions keepercommander/importer/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ def execute(self, params, **kwargs):
class LoadRecordTypeCommand(EnterpriseCommand):
def get_parser(self):
return load_record_type_parser



def execute(self, params, **kwargs):
file_name = kwargs.get('name') or 'record_types.json'
Expand Down Expand Up @@ -652,9 +654,9 @@ def execute(self, params, **kwargs):
record_type_name = r_type.get('record_type_name')
if not record_type_name:
continue
record_type_name = record_type_name[:30]
record_type_name = record_type_name[:32]
if record_type_name.lower() in loaded_record_types:
logging.warning('Custom record type "%s" already exists. Skipping.', record_type_name)
logging.warning(_c('yellow',f'Custom record type "{record_type_name}" already exists. Skipping'))
continue
fields = r_type.get('fields')
if not isinstance(fields, list):
Expand All @@ -664,7 +666,7 @@ def execute(self, params, **kwargs):
for field in fields:
field_type = field.get('$type')
if field_type not in record_types.RecordFields:
logging.warning('Custom record type "%s": Invalid field \"%s\". Skipping.', record_type_name, field_type)
logging.warning(_c('red',f'Custom record type "{record_type_name}": Invalid field "{field_type}". Skipping'))
is_valid = False
break
if not is_valid:
Expand All @@ -688,14 +690,25 @@ def execute(self, params, **kwargs):
rq = record_pb2.RecordType()
rq.content = json.dumps(content)
rq.scope = record_pb2.RT_ENTERPRISE
rs = api.communicate_rest(params, rq, 'vault/record_type_add')

counter += 1
try:
rs = api.communicate_rest(params, rq, 'vault/record_type_add')
logging.info(_c('green',f'Successfully imported record type "{record_type_name}"'))
counter += 1
except Exception as e:
logging.warning(_c('red',f'Failed to add record type "{record_type_name}" with error:\n {e}'))

if counter > 0:
logging.info('Added %d custom record types', counter)
api.sync_down(params, record_types=True)

def _c(color,text):
if color == 'green':
return f'\033[92m{text}\033[0m'
if color == 'yellow':
return f'\033[1;93m{text}\033[0m'
if color == 'red':
return f'\033[1;91m{text}\033[0m'
return text

def importer_for_format(input_format):
full_name = 'keepercommander.importer.' + input_format
Expand Down