Last active
February 1, 2017 13:45
-
-
Save Rio517/aac03b13e5df488d084cc9b98dc0a1e0 to your computer and use it in GitHub Desktop.
First pseudo code of how I might do this. Obviously, this is only 5 minutes of work, so my parser class is not well thought out or might not be neccessary.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# psudeo code for how I might build a 1password => lastpass converter | |
# this is done becuase lastpasse's importer seems to ingore many fields. | |
# Usage: | |
# OnePasswordCsv.new( | |
# input_csv_path: 'exported_admin_folder_from_1password.csv', | |
# output_csv_path: 'lastpass_admin_import.csv' | |
# ) | |
class OnePasswordCsv | |
attr_accessor :input_csv_path, :output_csv_path, :csv_rows | |
LAST_PASS_HEADERS = [:name, :password, :url, :notes] | |
def initialize(input_csv_path:,output_csv_path:) | |
self.csv_path = csv_path | |
end | |
def parse_rows | |
self.csv_rows = [] | |
CSV.foreach(csv_path) do |row| | |
csv_rows << OnePasswordObject.new(row_data: row).parse! | |
end | |
end | |
def export_lastpass_csv | |
CSV.generate(headers: true) do |csv| | |
csv << attributes | |
csv_rows.each do |csv_row| | |
csv << csv_row.csv_row_output | |
end | |
end | |
end | |
class OnePasswordObject | |
attr_accessor :row_data, :object_class, :parser | |
ONE_PASSWORD_CATEGORY_MAPPING = { | |
'001' => WebPasswordParser, | |
'002' => ServerPasswordParser, | |
'003' => WifiPasswordParser, | |
'004' => WebPasswordParser, #might convert one category to many | |
'005' => WebPasswordParser, | |
'006' => SomeOtherOtherFormat, | |
} | |
def initialize(row_data:) | |
self.row_data = row_data | |
end | |
def parse! | |
identify_object_class | |
self.parser = identify_object_class.new(row_data) | |
parser.process | |
#parse into the right fields | |
end | |
def identify_object_class | |
one_password_category = row_data[categroy] | |
self.object_class = ONE_PASSWORD_CATEGORY_MAPPING[one_password_category] | |
end | |
def csv_row_output | |
parser.output | |
end | |
end | |
class WebPasswordParser | |
attr_accessor :row_data | |
def initialize(row_data) | |
self.row_data = row_data | |
end | |
def process | |
#map the right fields to the right place | |
end | |
def output | |
#whatever would be the csv row | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment