titech-pubnet-auth 1.3.1 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1105b394137f8c02a980326256be37c1a8d0f30c
4
- data.tar.gz: 9f7883e331fcaddd0ff8b996a4fa3f0bb022ef06
3
+ metadata.gz: 05593e5dec9d131a04ac5be42ca7de6e5a7994c2
4
+ data.tar.gz: bbd03b2b41e239b5d0a246929617396bc0d490c8
5
5
  SHA512:
6
- metadata.gz: 90ed09e86ac16b4d26c280cba335ded1e5f3177927d7a6117418c6fc9a6fc2d51e481c21e7a7ce35355088211fc39cbd297e1d0dbabb88494899db2f82593978
7
- data.tar.gz: b921e1c0a594442b776410a63de369e7503b89924f0b291e32052b40a7cecd988f2be37ac08163c09b062168a67518a51be91b5386158426c1355a289edc3cae
6
+ metadata.gz: 1461fb93108722600e466de33e403d829c02d88d55d93fc7101d8f1cf3f6026bf58f20a8979daed2f49259d9e5b9fa7554474c9fd5fe2b7ce1d5dd8398a0a22a
7
+ data.tar.gz: fed6471199fc471dd692906a2b68bbb86c425fb1e1c2990bedb8d2ee6fa8c762ea330088af3dcc1db20ee83dc73780763302f7a5260752a8faa2d414e2cc89b9
@@ -22,9 +22,9 @@ opt.on('-s','--single','No loop. Use as single command.'){
22
22
  single = true
23
23
  }
24
24
 
25
- configure = !File::exists?(File.expand_path('../config/private.yml', File.dirname(__FILE__)))
25
+ reconfig = false
26
26
  opt.on('-c','--config','Set your username and password.'){
27
- configure = true
27
+ reconfig = true
28
28
  }
29
29
 
30
30
  debug = false
@@ -35,19 +35,14 @@ opt.on('--debug','Debug-mode.'){
35
35
  opt.parse!(ARGV)
36
36
 
37
37
 
38
- if configure
38
+ if !TitechPubnetAuth::Config.get || reconfig
39
+ config = TitechPubnetAuth::Config.new
39
40
  puts 'Please type your username:'
40
- username = gets.strip
41
+ config.username = gets.strip
41
42
  system "stty -echo"
42
43
  puts 'Please type your password (typing will be hidden):'
43
- password = gets.strip
44
- conf = {
45
- 'username' => username,
46
- 'password' => password
47
- }
48
- File::open(File.expand_path('../config/private.yml', File.dirname(__FILE__)),'w'){|f|
49
- f << conf.to_yaml
50
- }
44
+ config.password = gets.strip
45
+ config.save!
51
46
  puts 'configured!'
52
47
  exit!
53
48
  end
@@ -7,7 +7,7 @@ require 'yaml'
7
7
  $:.unshift(File.dirname(__FILE__))
8
8
  require 'titech_pubnet_auth/bin_routines'
9
9
  require 'titech_pubnet_auth/extensions'
10
-
10
+ require 'titech_pubnet_auth/config'
11
11
 
12
12
  class TitechPubnetAuth
13
13
  SAMPLE_URI = URI "http://example.org"
@@ -22,7 +22,8 @@ class TitechPubnetAuth
22
22
  }
23
23
  @agent_with_proxy.set_proxy(HTTP_PROXY[:ip], HTTP_PROXY[:port])
24
24
 
25
- @private = opt[:private] || YAML.load_file(File.dirname(__FILE__) + '/../config/private.yml')
25
+ @config = opt[:config] || TitechPubnetAuth::Config.get
26
+ fail "config not found" unless @config
26
27
  end
27
28
 
28
29
  #
@@ -35,8 +36,8 @@ class TitechPubnetAuth
35
36
  auth_page.form do |form|
36
37
  form.buttonClicked = 4
37
38
  form.redirect_url = sample_uri
38
- form.username = @private['username']
39
- form.password = @private['password']
39
+ form.username = @config.username
40
+ form.password = @config.password
40
41
  end.submit
41
42
 
42
43
  return is_connected?
@@ -0,0 +1,50 @@
1
+ require 'pathname'
2
+ require 'virtus'
3
+
4
+ class TitechPubnetAuth
5
+ class Config
6
+ include Virtus::Model
7
+ attribute :username, String
8
+ attribute :password, String
9
+
10
+ if RbConfig::CONFIG["target_os"].downcase =~ /^darwin/
11
+ require 'keychain'
12
+ SERVICE_NAME = 'titech-pubnet-auth'
13
+
14
+ def self.get
15
+ key = keychain_item
16
+ key && new(username: key.account, password: key.password)
17
+ end
18
+
19
+ def self.keychain_item
20
+ Keychain.generic_passwords.where(service: SERVICE_NAME).first
21
+ end
22
+
23
+ def save!
24
+ key = self.class.keychain_item
25
+ if key
26
+ key.account = username
27
+ key.password = password
28
+ key.save!
29
+ else
30
+ Keychain.generic_passwords.create(service: SERVICE_NAME, account: username, password: password)
31
+ end
32
+ self
33
+ end
34
+ else
35
+ require 'yaml'
36
+ CONFIG_PATH = Pathname(__FILE__) + '../../../config/private.yml'
37
+
38
+ def self.get
39
+ new(YAML.load_file(CONFIG_PATH)) rescue nil
40
+ end
41
+
42
+ def save!
43
+ CONFIG_PATH.open('w') do |f|
44
+ f << attributes.to_yaml
45
+ end
46
+ self
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  class TitechPubnetAuth
2
- VERSION = '1.3.1'
2
+ VERSION = '1.4.0'
3
3
  end
@@ -20,6 +20,8 @@ Gem::Specification.new do |gem|
20
20
  gem.add_dependency 'colorize'
21
21
  gem.add_dependency 'mechanize', '~> 2.7'
22
22
  gem.add_dependency 'terminal-notifier', '~> 1.4'
23
+ gem.add_dependency 'ruby-keychain'
24
+ gem.add_dependency 'virtus', '~> 1.0'
23
25
 
24
26
  gem.add_development_dependency 'rake'
25
27
  gem.add_development_dependency 'rspec'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: titech-pubnet-auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.1
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sohei Takeno
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-15 00:00:00.000000000 Z
11
+ date: 2014-06-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.4'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ruby-keychain
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: virtus
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rake
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -125,6 +153,7 @@ files:
125
153
  - config/private.yml.example
126
154
  - lib/titech_pubnet_auth.rb
127
155
  - lib/titech_pubnet_auth/bin_routines.rb
156
+ - lib/titech_pubnet_auth/config.rb
128
157
  - lib/titech_pubnet_auth/extensions.rb
129
158
  - lib/titech_pubnet_auth/version.rb
130
159
  - titech_pubnet_auth.gemspec