lanyard 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 897a19ae78ccd593d98d33b76b2b1741deedde52
4
+ data.tar.gz: 779a462f5f74907f9f228833824a76fabed5b752
5
+ SHA512:
6
+ metadata.gz: ed34172d8470da26754d7c3ce45506992b748313f11534141f281ccd0cdf9e4100a4907bb7f4652184d3625baff7d81ee78795d23b1f05fac9740890f2598d6b
7
+ data.tar.gz: f2ae2c5cbaf5d99b8ea05df761f69d8c97b01e0126cae210f43f1b7a4d8f12c5a7f3a76004f6f3c1532d98d36571915885feb9dd1077140237690900eb655d17
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.2.2
6
+ before_install: gem install bundler -v 1.10.4
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in lanyard.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Manfred Endres
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,52 @@
1
+ # Lanyard
2
+
3
+ [![Gem Version](https://badge.fury.io/rb/lanyard.svg)](http://badge.fury.io/rb/lanyard)
4
+ [![Build Status](https://travis-ci.org/wooga/lanyard.svg?branch=master)](https://travis-ci.org/wooga/lanyard)
5
+ [![Code Climate](https://codeclimate.com/github/wooga/lanyard/badges/gpa.svg)](https://codeclimate.com/github/wooga/lanyard)
6
+ [![Test Coverage](https://codeclimate.com/github/wooga/lanyard/badges/coverage.svg)](https://codeclimate.com/github/wooga/lanyard/coverage)
7
+
8
+ Lanyar is a little gem that helps to work with OSX keychains
9
+ It includes a simple wrapper for `security` and is able to add/remove custom keychains to the keychain lookip list with one command.
10
+
11
+ ## Installation
12
+
13
+ Add this line to your application's Gemfile:
14
+
15
+ ```ruby
16
+ gem 'lanyard'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install lanyard
26
+
27
+ ## Usage
28
+
29
+ ### Commandline tool
30
+ ```
31
+ Usage:
32
+ lanyard use-keychain [(-t=Time | --lock-timeout=Time)] (<keychain> <password>)...
33
+ lanyard unuse-keychain <keychain>...
34
+ lanyard (-h | --help)
35
+ ```
36
+
37
+ ### Rake
38
+ ```
39
+ lanyard = Rake::Lanyard.new
40
+
41
+ # this will add the tasks :unlock and :reset
42
+ ```
43
+
44
+ ## Development
45
+
46
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
47
+
48
+ 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).
49
+
50
+ ## License
51
+
52
+ The gem is available as open source under the terms of the [MIT License](http://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 "lanyard"
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
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env ruby
2
+ require 'docopt'
3
+ require 'lanyard/lanyard_cmd'
4
+
5
+ command_name = File.basename(__FILE__)
6
+
7
+ doc = <<DOCOPT
8
+ #{command_name} - helper script to work with OSX keychain
9
+
10
+ Usage:
11
+ #{command_name} use-keychain [(-t=Time | --lock-timeout=Time)] (<keychain> <password>)...
12
+ #{command_name} unuse-keychain <keychain>...
13
+ #{command_name} (-h | --help)
14
+
15
+ Options:
16
+ -t=Time, --lock-timeout=Time lock timeout [default: 7200].
17
+ -h, --help show this help message and exit
18
+
19
+ Commands:
20
+ use-keychain Add the provided keychains to the lookup list and unlock them with password
21
+ unuse-keychain Lock keychains and remove them from lookup list
22
+
23
+ DOCOPT
24
+
25
+ options = nil
26
+ begin
27
+ options = Docopt::docopt(doc)
28
+ rescue Docopt::Exit => e
29
+ puts e.message
30
+ exit
31
+ end
32
+
33
+ Lanyard.execute options
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lanyard/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lanyard"
8
+ spec.version = Lanyard::VERSION
9
+ spec.authors = ["Manfred Endres"]
10
+ spec.email = ["manfred.endres@tslarusso.de"]
11
+
12
+ spec.summary = %q{Handy little tool to work with the OSX toolchain.}
13
+ spec.homepage = "http://google.de"
14
+ spec.license = "MIT"
15
+
16
+ spec.required_ruby_version = '~> 2.0'
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "docopt", "~> 0.5"
23
+
24
+ spec.add_development_dependency "codeclimate-test-reporter"
25
+ spec.add_development_dependency "bundler", "~> 1.10"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "rspec"
28
+ end
@@ -0,0 +1,69 @@
1
+ require "lanyard/version"
2
+ require "lanyard/security"
3
+
4
+ module Lanyard
5
+ class Lanyard
6
+ attr_reader :security
7
+
8
+ def initialize security=nil
9
+ @security = security
10
+ unless @security
11
+ @security = Security.new
12
+ end
13
+ end
14
+
15
+ public
16
+ def use_keychain keychain, password, **options
17
+ keychain = [keychain] unless keychain.respond_to?('each')
18
+ password = [password] unless password.respond_to?('each')
19
+ abort "count of keychains and password need to be equal" if keychain.count != password.count
20
+
21
+ security.keychains += keychain
22
+
23
+ keychain.zip(password) do |product|
24
+ keychain = product[0]
25
+ password = product[1]
26
+
27
+ if options.fetch(:unlock, true)
28
+ security.unlock_keychain(keychain, password)
29
+ security.set_keychain_settings( keychain:keychain,
30
+ lock_sleep:true,
31
+ lock_after_timeout:true,
32
+ lock_timeout: options.fetch(:lock_timeout, 7200))
33
+ security.print_keychain_info keychain
34
+ end
35
+ end
36
+ end
37
+
38
+ def unuse_keychain keychain, **options
39
+ keychain = [keychain] unless keychain.respond_to?('each')
40
+
41
+ lock_keychain keychain, **options
42
+ security.keychains -= keychain
43
+ end
44
+
45
+ def lock_keychain keychain, **options
46
+ keychain = [keychain] unless keychain.respond_to?('each')
47
+
48
+ keychain.each {|k|
49
+ security.lock_keychain k
50
+ }
51
+ end
52
+ end
53
+
54
+ def self.use_keychain keychain, password, **options
55
+ lanyard = Lanyard.new
56
+ lanyard.use_keychain keychain, password, **options
57
+ end
58
+
59
+ def self.lock_keychain keychain, **options
60
+ lanyard = Lanyard.new
61
+ lanyard.lock_keychain keychain, **options
62
+ end
63
+
64
+ def self.unuse_keychain keychain, **options
65
+ lanyard = Lanyard.new
66
+ lanyard.unuse_keychain keychain, **options
67
+ end
68
+
69
+ end
@@ -0,0 +1,19 @@
1
+ require 'lanyard'
2
+
3
+ module Lanyard
4
+ def self.convert_options options
5
+ Hash[options.select{|key, value|
6
+ key.to_s.start_with? '--'
7
+ }.collect{|key, value|
8
+ [key.to_s.gsub("--","").gsub("-","_").to_sym, value]
9
+ }]
10
+ end
11
+
12
+ def self.execute options
13
+ if options['use-keychain']
14
+ use_keychain options['<keychain>'], options['<password>'], convert_options(options)
15
+ elsif options['unuse-keychain']
16
+ unuse_keychain options['<keychain>'], convert_options(options)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,81 @@
1
+ require 'set'
2
+ require 'open3'
3
+
4
+ module Lanyard
5
+ class Security
6
+
7
+ OPTIONS = {
8
+ account: "-a",
9
+ creator: "-c",
10
+ type: "-C",
11
+ kind: "-D",
12
+ value: "-G",
13
+ comment: "-j",
14
+ label: "-l",
15
+ service: "-s"
16
+ }
17
+
18
+ attr_accessor :keychains
19
+
20
+ def keychains
21
+ keychains = []
22
+ Open3::popen3("security list-keychain -d user") do | stdin, stdout, stderr, wait_thr |
23
+ stdout.each_line { |line|
24
+ keychains << line.gsub(/["\s+]/, "")
25
+ }
26
+ end
27
+
28
+ keychains
29
+ end
30
+
31
+ def keychains= keychains
32
+ abort "can`t append keychain[s]." unless system "security", "list-keychain", "-d", "user", "-s", *keychains.uniq
33
+ end
34
+
35
+ def unlock_keychain keychain, password
36
+ abort "can't unlock keychain #{keychain}" unless system "security", "unlock-keychain", "-p", password, keychain
37
+ end
38
+
39
+ def lock_keychain keychain
40
+ abort "can't lock keychain #{keychain}" unless system "security", "lock-keychain", keychain
41
+ end
42
+
43
+ def set_keychain_settings keychain:nil, verbose:true, lock_sleep:false, lock_after_timeout:false, lock_timeout:7200
44
+ args = ["security"]
45
+ args << "-v" if verbose
46
+ args << "set-keychain-settings"
47
+ args << "-l" if lock_sleep
48
+ args << "-ut #{lock_timeout}" if lock_after_timeout
49
+ args << keychain if keychain
50
+
51
+ abort "can't set keychain settings #{keychain}" unless system(*args)
52
+ end
53
+
54
+ def print_keychain_info keychain
55
+ system "security", "show-keychain-info", keychain
56
+ end
57
+
58
+ def find_generic_password *keychain, **filter_options
59
+ filter = build_filter_options(**filter_options)
60
+
61
+ password = nil
62
+ Open3::popen3("security", "find-generic-password", *filter + keychain) do | stdin, stdout, stderr, wait_thr |
63
+ stdout.each_line { |line|
64
+ if line.start_with? "password: "
65
+ password = line.sub(/password: "(.*)"/, '\1')
66
+ end
67
+ }
68
+ end
69
+ password
70
+ end
71
+
72
+ private
73
+
74
+ def build_filter_options **filter_options
75
+ filter_options.sort_by { |k, v| k }.reduce(["-g"]){|memo, obj|
76
+ memo = memo << Security::OPTIONS[obj[0]] << obj[1] if Security::OPTIONS.has_key? obj[0]
77
+ memo
78
+ }
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,3 @@
1
+ module Lanyard
2
+ VERSION = "0.2.0"
3
+ end
@@ -0,0 +1,79 @@
1
+ require 'rake'
2
+ require 'rake/tasklib'
3
+ require 'rake/clean'
4
+ require 'lanyard'
5
+
6
+ module Rake
7
+ class LanyardTask < Rake::TaskLib
8
+
9
+ attr_accessor :keychain_path
10
+ def keychain_path
11
+ @keychain_path ? @keychain_path : "build.keychain"
12
+ end
13
+
14
+ attr_accessor :original_keychain_path
15
+ def copy_keychain_from file
16
+ @original_keychain_path = file
17
+ end
18
+
19
+ attr_accessor :keychain_password
20
+ def keychain_password
21
+ @keychain_password ? @keychain_password : ""
22
+ end
23
+
24
+ attr_accessor :namespace_name
25
+ def namespace_name
26
+ @namespace_name ? @namespace_name.to_sym : nil
27
+ end
28
+
29
+ def initialize keychain_path = nil, keychain_password = nil
30
+ @keychain_path = keychain_path
31
+ @keychain_password = keychain_password
32
+
33
+ yield self if block_given?
34
+
35
+ unless namespace_name.nil?
36
+ namespace namespace_name do
37
+ define
38
+ end
39
+ else
40
+ define
41
+ end
42
+ self
43
+ end
44
+
45
+ private
46
+
47
+ def define_unlock
48
+ desc "unlock the build keychain"
49
+ task :unlock => [self.keychain_path] do
50
+ Lanyard::use_keychain self.keychain_path, self.keychain_password
51
+ task('keychain:reset').reenable
52
+ end
53
+ end
54
+
55
+ def define_reset
56
+ desc "reset and lock the build keychain"
57
+ task :reset => [self.keychain_path] do
58
+ Lanyard::unuse_keychain self.keychain_path
59
+ task('keychain:unlock').reenable
60
+ end
61
+ end
62
+
63
+ def define_copy_task
64
+ unless self.original_keychain_path.nil?
65
+ CLEAN.include(self.keychain_path)
66
+ desc "copies keychain from #{File.basename self.original_keychain_path}"
67
+ file self.keychain_path do |t|
68
+ cp self.original_keychain_path, t.name
69
+ end
70
+ end
71
+ end
72
+
73
+ def define
74
+ define_unlock
75
+ define_reset
76
+ define_copy_task
77
+ end
78
+ end
79
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lanyard
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Manfred Endres
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: docopt
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: codeclimate-test-reporter
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - manfred.endres@tslarusso.de
86
+ executables:
87
+ - lanyard
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - exe/lanyard
101
+ - lanyard.gemspec
102
+ - lib/lanyard.rb
103
+ - lib/lanyard/lanyard_cmd.rb
104
+ - lib/lanyard/security.rb
105
+ - lib/lanyard/version.rb
106
+ - lib/rake/lanyard_task.rb
107
+ homepage: http://google.de
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '2.0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Handy little tool to work with the OSX toolchain.
131
+ test_files: []