trunk 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d63e9f1885845c0dcfbddc0e2e2b8e9a685e732d19fdb0b6e0b319064b7093c6
4
+ data.tar.gz: ea15f59e0f1864d0d8ad77ea6ad2be038938314481e9d299c00d5aa0a548a413
5
+ SHA512:
6
+ metadata.gz: 4878ac13c5a8508eb4b426bbf3f76d8907c8d2abbd6790fa508e2612f8da6f817309db678e301c67123899b7502f6981ce7c95b89e4abcc038fef05bea351d8e
7
+ data.tar.gz: 42f5ddbc1b13dd8c82846b0363fcfb1edab7cbef80ef7714f73196e705025660ecb374a0db5f19d713601304b06aa3c9f45d0437fe81d2efb126530bfc974e69
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.5.1
5
+ before_install: gem install bundler -v 1.16.1
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in trunk.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 mokha
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,58 @@
1
+ # Trunk
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/trunk`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'trunk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install trunk
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ```bash
28
+ $ trunk add --title=title --username=username --password=password
29
+ $ trunk add <title> <username> - # read password from stdin
30
+ $ trunk add
31
+ $ title:>
32
+ $ username:>
33
+ $ password:>
34
+
35
+
36
+ $ trunk show title
37
+ ```
38
+
39
+ Storage Layout
40
+
41
+ ```yaml
42
+ # ~/.trunk
43
+ development.secret: <encrypted>
44
+ ```
45
+
46
+ ## Development
47
+
48
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
49
+
50
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
51
+
52
+ ## Contributing
53
+
54
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/trunk.
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "trunk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "trunk"
4
+
5
+ Trunk::CLI.start(ARGV)
@@ -0,0 +1,8 @@
1
+ require 'optparse'
2
+
3
+ require "trunk/cli"
4
+ require "trunk/storage"
5
+ require "trunk/version"
6
+
7
+ module Trunk
8
+ end
@@ -0,0 +1,77 @@
1
+ module Trunk
2
+ class AddCommand
3
+ def matches?(command)
4
+ "add" == command
5
+ end
6
+
7
+ def run(arguments)
8
+ OptionParser.new do |parser|
9
+ parser.banner = "Usage: trunk add [options]"
10
+ parser.on_tail("-h", "--help", "print help") do
11
+ puts parser
12
+ end
13
+ end.parse!(arguments)
14
+
15
+ print "title:> "
16
+ title = STDIN.gets
17
+ print "username:> "
18
+ username = STDIN.gets
19
+ print "password:> "
20
+ password = STDIN.gets
21
+
22
+ puts [title, username, password].inspect
23
+ end
24
+ end
25
+
26
+ class DefaultCommand
27
+ def run(arguments)
28
+ parser = OptionParser.new
29
+ parser.banner = "Usage: trunk [options]"
30
+ parser.on("-v", "--[no-]verbose", "run verbosely") do |v|
31
+ end
32
+ parser.on("--version", "show version") do |v|
33
+ puts Trunk::VERSION
34
+ end
35
+ parser.on_tail("-h", "--help", "print help") do
36
+ puts parser
37
+ end
38
+ parser.parse!(arguments)
39
+ end
40
+ end
41
+
42
+ class CLI
43
+ attr_reader :parser, :commands
44
+
45
+ def initialize
46
+ @commands = []
47
+ @commands.push(AddCommand.new)
48
+ end
49
+
50
+ def command_for(arguments)
51
+ if arguments.empty? || arguments[0]&.start_with?("-")
52
+ DefaultCommand.new
53
+ else
54
+ commands.find { |x| x.matches?(arguments[0]) }
55
+ end
56
+ end
57
+
58
+ def run(arguments)
59
+ parser.banner = "Usage: trunk [options]"
60
+ parser.on("-v", "--[no-]verbose", "run verbosely") do |v|
61
+ options[:verbose] = v
62
+ end
63
+ parser.on("--version", "show version") do |v|
64
+ puts Trunk::VERSION
65
+ end
66
+ parser.on_tail("-h", "--help", "print help") do
67
+ puts parser
68
+ end
69
+ parser.parse!(arguments)
70
+ end
71
+
72
+ def self.start(arguments)
73
+ cli = new
74
+ cli.command_for(arguments).run(arguments)
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,80 @@
1
+ module Trunk
2
+ class CompositeSerializer
3
+ def initialize(serializers = [])
4
+ @serializers = serializers
5
+ end
6
+
7
+ def add(serializer)
8
+ @serializers.push(serializer)
9
+ end
10
+
11
+ def serialize(value)
12
+ @serializers.each do |x|
13
+ value = x.serialize(value)
14
+ end
15
+ value
16
+ end
17
+
18
+ def deserialize(value)
19
+ puts "deserialize"
20
+ @serializers.reverse.each do |x|
21
+ puts x.class
22
+ value = x.deserialize(value)
23
+ end
24
+ value
25
+ end
26
+ end
27
+
28
+ class Base64Serializer
29
+ def serialize(value)
30
+ Base64.strict_encode64(value)
31
+ end
32
+
33
+ def deserialize(value)
34
+ Base64.decode64(value)
35
+ end
36
+ end
37
+
38
+ class SymmetricCrypto
39
+ attr_reader :private_key, :algorithm
40
+
41
+ def initialize(private_key, algorithm: 'AES-256-CBC')
42
+ @private_key = private_key
43
+ @algorithm = algorithm
44
+ end
45
+
46
+ def serialize(plain_text)
47
+ cipher = OpenSSL::Cipher.new(algorithm)
48
+ cipher.encrypt
49
+ cipher.key = private_key
50
+ cipher.random_iv + cipher.update(plain_text) + cipher.final
51
+ end
52
+
53
+ def deserialize(cipher_text)
54
+ cipher = OpenSSL::Cipher.new(algorithm)
55
+ cipher.decrypt
56
+ iv = cipher_text[0..cipher.iv_len - 1]
57
+ data = cipher_text[cipher.iv_len..-1]
58
+ cipher.key = private_key
59
+ cipher.iv = iv
60
+ cipher.update(data) + cipher.final
61
+ end
62
+ end
63
+
64
+ class Storage
65
+ def initialize(hash, serializer)
66
+ @hash = hash
67
+ @serializer = serializer
68
+ end
69
+
70
+ def fetch(key)
71
+ value = @hash[key]
72
+ return if value.nil?
73
+ @serializer.deserialize(value)
74
+ end
75
+
76
+ def store(key, value)
77
+ @hash[key] = @serializer.serialize(value)
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module Trunk
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,27 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "trunk/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "trunk"
8
+ spec.version = Trunk::VERSION
9
+ spec.authors = ["mokha"]
10
+ spec.email = ["mokha@cisco.com"]
11
+
12
+ spec.summary = %q{A safe place to put things.}
13
+ spec.description = %q{A safe place to put things.}
14
+ spec.homepage = "https://www.mokhan.ca"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trunk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mokha
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-09 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: A safe place to put things.
56
+ email:
57
+ - mokha@cisco.com
58
+ executables:
59
+ - trunk
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/console
71
+ - bin/setup
72
+ - exe/trunk
73
+ - lib/trunk.rb
74
+ - lib/trunk/cli.rb
75
+ - lib/trunk/storage.rb
76
+ - lib/trunk/version.rb
77
+ - trunk.gemspec
78
+ homepage: https://www.mokhan.ca
79
+ licenses:
80
+ - MIT
81
+ metadata: {}
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ version: '0'
91
+ required_rubygems_version: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ requirements: []
97
+ rubyforge_project:
98
+ rubygems_version: 2.7.6
99
+ signing_key:
100
+ specification_version: 4
101
+ summary: A safe place to put things.
102
+ test_files: []