Module: Mellon::Utils Private
- Defined in:
- lib/mellon/utils.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Class Method Summary collapse
-
.build_info(key, options = {}) ⇒ Hash
private
Build an entry info hash.
-
.parse_contents(password_string) ⇒ String
private
Parse entry contents.
- .parse_dump(keychain_dump) ⇒ Array<[keychain_path, info]> private
-
.parse_info(info) ⇒ Hash
private
Parse entry information.
- .security(*command, &block) ⇒ Object private
- .sh(*command) ⇒ Object private
Class Method Details
.build_info(key, options = {}) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Build an entry info hash.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/mellon/utils.rb', line 14 def build_info(key, = {}) = DEFAULT_OPTIONS.merge() note_type = TYPES.fetch(.fetch(:type, :note).to_s) account_name = .fetch(:account_name, "") service_name = .fetch(:service_name, key) label = .fetch(:label, service_name) { account_name: account_name, service_name: service_name, label: label, kind: note_type.fetch(:kind), type: note_type.fetch(:type), } end |
.parse_contents(password_string) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse entry contents.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/mellon/utils.rb', line 77 def parse_contents(password_string) unpacked = password_string[/password: 0x([a-f0-9]+)/i, 1] password = if unpacked [unpacked].pack("H*") else password_string[/password: "(.+)"/m, 1] end password ||= "" parsed = Plist.parse_xml(password.force_encoding("".encoding)) if parsed and parsed["NOTE"] parsed["NOTE"] else password end end |
.parse_dump(keychain_dump) ⇒ Array<[keychain_path, info]>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/mellon/utils.rb', line 33 def parse_dump(keychain_dump) attributes_start = /attributes:/ keychain_start = /keychain: #{KEYCHAIN_REGEXP}/ keychain_path = nil state = :ignoring info_chunks = keychain_dump.each_line.chunk do |line| if line =~ attributes_start state = :attributes nil elsif line =~ keychain_start state = :ignoring keychain_path = $1 nil elsif state == :attributes keychain_path end end info_chunks.each_with_object([]) do |(keychain_path, chunk), keys| info = parse_info(chunk.join) keys << [keychain_path, info] if TYPES.has_key?(info[:type]) end end |
.parse_info(info) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Parse entry information.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/mellon/utils.rb', line 62 def parse_info(info) extract = lambda { |key| info[/#{key}.+=(?:<NULL>|[^"]*"(.+)")/, 1].to_s } { account_name: extract["acct"], kind: extract["desc"], type: extract["type"], label: extract["0x00000007"], service_name: extract["svce"], } end |
.security(*command, &block) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
97 98 99 |
# File 'lib/mellon/utils.rb', line 97 def security(*command, &block) sh("security", *command, &block) end |
.sh(*command, &block) ⇒ Object .sh(*command) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 |
# File 'lib/mellon/utils.rb', line 108 def sh(*command) $stderr.puts "$ " + command.join(" ") if $VERBOSE stdout, stderr, status = Open3.capture3(*command) stdout.chomp! stderr.chomp! if $DEBUG $stderr.puts stdout.gsub(/(?<=\n|\A)/, "--> ") unless stdout.empty? $stderr.puts stderr.gsub(/(?<=\n|\A)/, "--! ") unless stderr.empty? end unless status.success? error_string = Shellwords.join(command) error_string << "\n" stderr = "<no output>" if stderr.empty? error_string << " " << stderr.chomp raise CommandError, "[ERROR] #{error_string}" end if block_given? yield [stdout, stderr] else stdout end end |