Skip to content

Commit

Permalink
fix(api commands): cmdb-password-data-migrate (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
pycook authored Nov 2, 2023
1 parent fe26061 commit 46fd684
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion cmdb-api/api/commands/click_cmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ def valid_address(address):
}
KeyManage.print_response(response)
return False

return True


Expand Down Expand Up @@ -444,6 +443,7 @@ def cmdb_password_data_migrate():

value_table = CIIndexValueText if attr.is_index else CIValueText

failed = False
for i in value_table.get_by(attr_id=attr.id, to_dict=False):
if current_app.config.get("SECRETS_ENGINE", 'inner') == 'inner':
_, status = InnerCrypt().decrypt(i.value)
Expand All @@ -454,6 +454,7 @@ def cmdb_password_data_migrate():
if status:
CIValueText.create(ci_id=i.ci_id, attr_id=attr.id, value=encrypt_value)
else:
failed = True
continue
elif current_app.config.get("SECRETS_ENGINE") == 'vault':
if i.value == '******':
Expand All @@ -464,8 +465,12 @@ def cmdb_password_data_migrate():
vault.update("/{}/{}".format(i.ci_id, i.attr_id), dict(v=i.value))
except Exception as e:
print('save password to vault failed: {}'.format(e))
failed = True
continue
else:
continue

i.delete()

if not failed and attr.is_index:
attr.update(is_index=False)
3 changes: 2 additions & 1 deletion cmdb-api/api/lib/secrets/inner.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ def __init__(self, trigger=None, backend=None):
self.backend = Backend(backend)

def init_app(self, app, backend=None):
if sys.argv[0].endswith("gunicorn") or (len(sys.argv) > 1 and sys.argv[1] == "run"):
if (sys.argv[0].endswith("gunicorn") or
(len(sys.argv) > 1 and sys.argv[1] in ("run", "cmdb-password-data-migrate"))):
self.trigger = app.config.get("INNER_TRIGGER_TOKEN")
if not self.trigger:
return
Expand Down

0 comments on commit 46fd684

Please sign in to comment.