Skip to content

Instantly share code, notes, and snippets.

@guitarrapc guitarrapc/Program.cs
Last active Aug 18, 2019

Embed
What would you like to do?
{
"folders": [
{
"id": "8ab4f62f-84a2-488d-b999-f812c4eb8dae",
"name": "TestGroup"
}
],
"items": []
}
description note Field0 Type0 Value0 Field1 Type1 Value1 Field2 Type2 Value2 Field3 Type3 Value3 Field4 Type4 Value4
Sample URL text https://example.com/ Username text TestUSer Password password TestPass Email text test@example.com GROUP text TestGroup
using System;
using System.IO;
using TeamsidToBitwardenConverter;
using TeamsidToBitwardenConverter.Lib;
using TeamsidToBitwardenConverter.Model.Bitwarden;
using TeamsidToBitwardenConverter.Model.TeamsId;
namespace TeamsId2BitwardeConsole
{
class Program
{
static void Main(string[] args)
{
var outputPath = $@"./data/bitwarden/import/bitwarden_personal_importdata{DateTime.Now.ToString("yyyyMMdd_HHmmss")}.json";
var teamsidPersonalCsv = @"./data/teamsid_export/personal_records.csv";
var bitwardenFolderDefinitionJson = @"./data/bitwarden/definitions/bitwarden_export_folder_definition.json";
Personal(outputPath, teamsidPersonalCsv, bitwardenFolderDefinitionJson);
}
static void Personal(string outputPath, string teamsidPersonalCsv, string bitwardenFolderDefinitionJson)
{
var folderDefinition = DeserializeFolderJson<BitwardenFolderDefinition>(bitwardenFolderDefinitionJson);
// convert teamsid to bitwarden
var teamsIdDatas = new CsvParser(teamsidPersonalCsv).Parse<TeamsIdDefinition4>();
var bitwardenItems = new BitwardenConverter(folderDefinition).Convert(teamsIdDatas, defaultGroup: "TestGroup");
// serialize bitwarden import data
var importData = new BitwardenDefinition
{
folders = folderDefinition.folders,
items = bitwardenItems,
};
importData.WriteJson(outputPath);
}
// deserialize folder definitions
static T DeserializeFolderJson<T>(string path) where T : class
{
using (var stream = File.OpenRead(path))
{
var deserialized = Utf8Json.JsonSerializer.Deserialize<T>(stream);
return deserialized;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.