Esempio n. 1
0
def migrate_from_workspaces(apps, schema_editor):

    if not workspace_exists():
        return

    cursor = connection.cursor()
    cursor.execute("ALTER TABLE public.vaultier_member ALTER COLUMN workspace_id DROP NOT NULL;")
    cursor.execute("SELECT * FROM vaultier_workspace")
    nodes = []
    for w in _dictfetchall(cursor):
        node = Node(
            name=w['name'],
            meta=json.dumps({'description': w['description']}),
            created_by_id=w['created_by_id'],
            type=1


        )
        node.save()
        node.acl.initialize_node()
        node._workspace = w['id']
        nodes.append(node)
        _migrate_members(node)
        _migrate_vaults(node)
        _migrate_acl('workspace', w['id'], node)
Esempio n. 2
0
    def handle(self, *args, **options):
        known_nodes = set(Node.objects.values_list('id', flat=True))

        res = requests.get(URL)
        res.raise_for_status()

        reader = csv.DictReader(codecs.iterdecode(res.iter_lines(), 'utf-8'))
        for row in reader:
            if row['node_id'] not in known_nodes:
                self.stdout.write(f'Adding node {row["node_id"]}')

                vsn = row['vsn']
                location = row['location']
                description = row['description']

                if '(T)' in description or 'Returned' in location or 'RET' in vsn:
                    state = 'decommissioned'
                elif 'Surya Burn-In' in location:
                    state = 'burn in'
                elif '!' in vsn:
                    state = 'testing'
                elif vsn is not None:
                    state = 'deployed'
                else:
                    state = 'build out'

                Node(id=row['node_id'],
                     name=vsn,
                     ssh_port=row['reverse_ssh_port'],
                     address=location,
                     description=description,
                     state=state).save()
Esempio n. 3
0
def _migrate_secret(card_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_secret WHERE card_id = %s",
                   [card_node._card])

    for c in _dictfetchall(cursor):
        node = Node(
            name=c['name'],
            created_by_id=c['created_by_id'],
            parent=card_node,
            type=2
        )
        node.save(force_insert=True)
Esempio n. 4
0
def _migrate_vaults(workspace_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_vault WHERE workspace_id = %s",
                   [workspace_node._workspace])
    for v in _dictfetchall(cursor):
        node = Node(
            name=v['name'],
            meta=json.dumps({'description': v['description']}),
            created_by_id=v['created_by_id'],
            color=v['color'],
            parent=workspace_node,
            type=1
        )
        node.save(force_insert=True)
        node._vault = v['id']
        _migrate_cards(node)
        _migrate_acl('vault', v['id'], node)
Esempio n. 5
0
def _migrate_cards(vault_node):
    cursor = connection.cursor()
    cursor.execute("SELECT * FROM vaultier_card WHERE vault_id = %s",
                   [vault_node._vault])

    for c in _dictfetchall(cursor):
        node = Node(
            name=c['name'],
            meta=json.dumps({'description': c['description']}),
            created_by_id=c['created_by_id'],
            parent=vault_node,
            type=1
        )
        node._card = c['id']
        node.save(force_insert=True)
        _migrate_secret(node)
        _migrate_acl('card', c['id'], node)