lpgrid 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5d36cbd25c87299a26d2207c76ebdf64fb11a7bb0ec788934c7e79b872c7dcf3
4
+ data.tar.gz: 42f7159ec594d4e900bcce3eba468442c1cc7e145c8698da41cb6186ac63ab54
5
+ SHA512:
6
+ metadata.gz: 582e907a539eff5f15c790bf9a084c753cfdbc88994303e8a110a80b0515e6f3ca51ee9ef32f071231e6de1288690f0b6fce310459e85a57e1e929e2b4dcf4ce
7
+ data.tar.gz: 8b158213fb19b80b47345531cfd97bdba9eec92ca0a51ed454d5768a94ad7ca8b457f7c04437a12d526f6cf4969ff3e77585c80adbeb3fc626b9d80350b53149
data/.gitignore ADDED
@@ -0,0 +1,21 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .ruby-version
6
+ .ruby-gemset
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ grid
21
+ /config.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.1.1
6
+ - rbx
7
+ - ruby-head
8
+ - jruby-head
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lpgrid.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Tomas Valent
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Lpgrid
2
+
3
+ Last Pass Grid reader
4
+
5
+ [![Build Status](https://api.travis-ci.org/equivalent/lpgrid.png?branch=master)](http://travis-ci.org/equivalent/lpgrid)
6
+ [![Code Climate](https://codeclimate.com/github/equivalent/lpgrid.png)](https://codeclimate.com/github/equivalent/lpgrid)
7
+
8
+ Last pass introduced another layer of protection with Grid card.
9
+ This small Ruby program is here to help you read you grid card
10
+ information more easily.
11
+
12
+ ## Requirements
13
+
14
+ ruby 2.0 or greater
15
+
16
+ ## Installation
17
+
18
+ git clone git@github.com:equivalent/lpgrid.git
19
+
20
+ ## Usage
21
+
22
+ cd lpgrid
23
+ bin/lpgrid
24
+
25
+ ## Tests
26
+
27
+ To run tests trigger
28
+
29
+ rake
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes with TESTS (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/lpgrid ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
5
+ Pathname.new(__FILE__).realpath)
6
+
7
+ require 'rubygems'
8
+ require 'bundler/setup'
9
+ require 'lpgrid'
10
+
11
+ puts "Welcome to Lpgrid - Last Pass Grid reader !"
12
+
13
+ loop do
14
+ puts "Enter grid fields separated by space or \"exit\" to quit"
15
+ begin
16
+ input = gets.chomp
17
+ case input
18
+ when 'exit', 'quit'
19
+ exit 0
20
+ else
21
+ puts "=> #{Lpgrid::InputReader.translate input}"
22
+ end
23
+ rescue Lpgrid::InputReader::IncorectInputFormat
24
+ puts "ERROR: Incorrect format. Input must look like: a0 b3 d9 x2"
25
+ end
26
+ puts "\n"
27
+ end
@@ -0,0 +1 @@
1
+ csv_path: '/home/myuser/path/to/my/grid.csv'
@@ -0,0 +1,28 @@
1
+ module Lpgrid
2
+ class Configuration
3
+
4
+ def file_path
5
+ Lpgrid.root.join('config.yml')
6
+ end
7
+
8
+ def csv
9
+ return options['csv_path'] if options['csv_path']
10
+
11
+ home_dot_grid = "#{ENV['HOME']}/.grid.csv"
12
+ return home_dot_grid if File.exist?(home_dot_grid)
13
+
14
+ home_grid = "#{ENV['HOME']}/grid.csv"
15
+ return home_grid if File.exist?(home_grid)
16
+
17
+ raise "You need to define grid path in project 'config.yml' or just move your grid to '~/.grid.csv'"
18
+ end
19
+
20
+ private
21
+
22
+ def options
23
+ @options ||= YAML.load_file(file_path)
24
+ rescue Errno::ENOENT
25
+ {}
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,24 @@
1
+ module Lpgrid
2
+ class Grid
3
+ attr_reader :position
4
+
5
+ def self.grid
6
+ @grid ||= CSV.table(Lpgrid.config.csv)
7
+ end
8
+
9
+ def initialize(position)
10
+ @position = position
11
+ end
12
+
13
+ def fetch
14
+ parse_position
15
+ self.class.grid[@row.to_i].field(@col.downcase.to_sym)
16
+ end
17
+
18
+ private
19
+
20
+ def parse_position
21
+ @col, @row = position.split(//)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ module Lpgrid
2
+ class InputReader
3
+ IncorectInputFormat = Class.new(StandardError)
4
+
5
+ attr_reader :string
6
+
7
+ def self.translate(string)
8
+ instance = new(string)
9
+ instance.check_format
10
+ instance.translate
11
+ end
12
+
13
+ def initialize(string)
14
+ @string = string
15
+ end
16
+
17
+ def check_format
18
+ if splitter.collect(&:length).select { |leng| leng !=2 } .any?
19
+ raise IncorectInputFormat
20
+ end
21
+ end
22
+
23
+ def translate
24
+ splitter.collect do |element|
25
+ Grid.new(element).fetch
26
+ end.join(' ')
27
+ end
28
+
29
+ def splitter
30
+ string.split(' ')
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Lpgrid
2
+ VERSION = "0.1.0"
3
+ end
data/lib/lpgrid.rb ADDED
@@ -0,0 +1,18 @@
1
+ require 'csv'
2
+ require 'yaml'
3
+ require 'lpgrid/version'
4
+ require 'lpgrid/configuration'
5
+ require 'lpgrid/grid'
6
+ require 'lpgrid/input_reader'
7
+
8
+ module Lpgrid
9
+ attr_reader :config
10
+
11
+ def self.config
12
+ @config ||= Configuration.new
13
+ end
14
+
15
+ def self.root
16
+ Pathname.new(File.expand_path '../..', __FILE__)
17
+ end
18
+ end
data/lpgrid.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lpgrid/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lpgrid"
8
+ spec.version = Lpgrid::VERSION
9
+ spec.authors = ["Tomas Valent"]
10
+ spec.email = ["equivalent@eq8.eu"]
11
+ spec.description = %q{Last Pass Grid reader}
12
+ spec.summary = %q{Reads last pass grid.csv. Just save it to your LastPass generated MFA grid to ~/.grid.csv and run lpass}
13
+ spec.homepage = "https://github.com/equivalent/lpgrid"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ end
data/spec/config.yml ADDED
@@ -0,0 +1 @@
1
+ csv_path: './spec/fixtures/pure_grid.csv'
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe Lpgrid::Configuration do
4
+ let(:configuration) { described_class.new }
5
+
6
+ describe '#file_path' do
7
+ before { Lpgrid::Configuration.any_instance.unstub(:file_path) }
8
+ it do
9
+ configuration.file_path.to_s.should eq File.
10
+ expand_path '../../config.yml', __FILE__
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,12 @@
1
+ ,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
2
+ 0,a,b,1,a,z,a,b,c,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,0
3
+ 1,b,c,2,b,a,b,c,d,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,1
4
+ 2,c,d,3,c,b,c,d,e,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,2
5
+ 3,d,e,4,d,c,d,e,f,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,3
6
+ 4,e,f,5,e,d,e,f,g,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,4
7
+ 5,f,g,6,f,e,f,g,h,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,5
8
+ 6,g,h,7,g,f,g,h,i,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,6
9
+ 7,h,i,8,h,g,h,i,j,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,h,7
10
+ 8,i,j,9,i,h,i,j,k,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,x,8
11
+ 9,j,k,0,j,i,j,k,l,0,1,2,3,4,5,6,7,8,9,a,b,c,d,e,f,g,u,9
12
+ ,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z
data/spec/grid_spec.rb ADDED
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+ describe Lpgrid::Grid do
3
+ let(:grid) { described_class.new(position) }
4
+
5
+ describe '#fetch' do
6
+ subject { grid.fetch }
7
+
8
+ context "when A0" do
9
+ let(:position) { 'a0' }
10
+ it { should eq 'a' }
11
+ end
12
+
13
+ context "when Z9" do
14
+ let(:position) { 'z9' }
15
+ it { should eq 'u' }
16
+ end
17
+
18
+ context "when E3" do
19
+ let(:position) { 'E3' }
20
+ it { should eq 'c' }
21
+ end
22
+ end
23
+
24
+
25
+ end
26
+ #p Lpgrid::Grid
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+ describe Lpgrid::InputReader do
3
+ let(:instance) { described_class.new }
4
+
5
+ describe '.translate' do
6
+ subject { described_class.translate(string) }
7
+
8
+ context "when correct syntax of 1 element" do
9
+ let(:string) { 'c3' }
10
+
11
+ it 'should use Grid for calculating' do
12
+ grid_instance = double :grid_instance
13
+ Lpgrid::Grid.should_receive(:new).with('c3').once.and_return(grid_instance)
14
+ grid_instance.should_receive(:fetch)
15
+ subject
16
+ end
17
+
18
+ it 'should fetch correct values' do
19
+ should eq '4'
20
+ end
21
+ end
22
+
23
+ context "when correct syntax of 4 elements" do
24
+ let(:string) { 'a1 B9 z9 d6' }
25
+
26
+ it 'should use Grid for calculating' do
27
+ Lpgrid::Grid.should_receive(:new).exactly(4).times.and_call_original
28
+ subject
29
+ end
30
+
31
+ it 'should fetch correct values' do
32
+ should eq 'b k u g'
33
+ end
34
+ end
35
+
36
+ context 'when joint together' do
37
+ let(:string) { 'a1b9z9d6' }
38
+ it 'should fetch correct values' do
39
+ expect { subject } .to raise_error Lpgrid::InputReader::IncorectInputFormat
40
+ end
41
+ end
42
+
43
+ context 'when rows out of scope' do
44
+ let(:string) { 'b2 a10 c3' }
45
+ it 'should fetch correct values' do
46
+ expect { subject } .to raise_error Lpgrid::InputReader::IncorectInputFormat
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,13 @@
1
+ require 'lpgrid'
2
+
3
+ RSpec.configure do |config|
4
+ config.treat_symbols_as_metadata_keys_with_true_values = true
5
+ config.run_all_when_everything_filtered = true
6
+ config.filter_run :focus
7
+ config.order = 'random'
8
+
9
+ config.before :each do
10
+ Lpgrid::Configuration.any_instance.stub(:file_path).
11
+ and_return(Lpgrid.root.join('spec', 'config.yml'))
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lpgrid
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tomas Valent
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-03-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Last Pass Grid reader
56
+ email:
57
+ - equivalent@eq8.eu
58
+ executables:
59
+ - lpgrid
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - LICENSE.txt
68
+ - README.md
69
+ - Rakefile
70
+ - bin/lpgrid
71
+ - config.yml.example
72
+ - lib/lpgrid.rb
73
+ - lib/lpgrid/configuration.rb
74
+ - lib/lpgrid/grid.rb
75
+ - lib/lpgrid/input_reader.rb
76
+ - lib/lpgrid/version.rb
77
+ - lpgrid.gemspec
78
+ - spec/config.yml
79
+ - spec/configuration_spec.rb
80
+ - spec/fixtures/pure_grid.csv
81
+ - spec/grid_spec.rb
82
+ - spec/input_reader_spec.rb
83
+ - spec/spec_helper.rb
84
+ homepage: https://github.com/equivalent/lpgrid
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.7.7
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Reads last pass grid.csv. Just save it to your LastPass generated MFA grid
108
+ to ~/.grid.csv and run lpass
109
+ test_files:
110
+ - spec/config.yml
111
+ - spec/configuration_spec.rb
112
+ - spec/fixtures/pure_grid.csv
113
+ - spec/grid_spec.rb
114
+ - spec/input_reader_spec.rb
115
+ - spec/spec_helper.rb