bixby-agent 0.3.1 → 0.3.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 275f6a697efb69ebdbcc9bf56a2d36f983926075
4
- data.tar.gz: 0f3610364c9d921867c3bfed7af414fd5687f286
3
+ metadata.gz: 0269849a53e379766e5cbc9463c1e084af26739b
4
+ data.tar.gz: 67f156df0b65ccbe9e17f24d5b1c4a76719cb17f
5
5
  SHA512:
6
- metadata.gz: c7b8615ad08f8defad163a7990ecd791e61d67b34bd11a3a6bbdb49cde50bfdb4e886faa341366b760a5de409afda48fa7fb1301fe03e01f7871380c87d56ba6
7
- data.tar.gz: 6b85b85a8f310268e94a62e8f15f8d59433b3957c26481ebb5b843a13cdb1a16e1684b57548b0748533db1b4b521a30ac1cb3df25c61738a573c653ef16f63d3
6
+ metadata.gz: b2afe3e7f76744a99b76a87bc96e8f19c5db169ce5b7804b6bfc7128d1ac505eec25c8e2b51c7a55db2248acfb18a1a756c8eb76f7d3283b56cc8e3df953f778
7
+ data.tar.gz: aefb329dced8a26e2bb3e362badeb2c5128a037b53e778facd11e7ec39555e803d15e553d2d930c28fd219402e41cb733a7aaba435fee99dd025229d985140d1
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  before_install:
3
+ - "gem install bundler --no-ri --no-rdoc"
3
4
  - "curl -sL https://s3.bixby.io/wad > ~/wad"
4
5
  - "chmod +x ~/wad"
5
6
  install:
@@ -11,8 +12,9 @@ after_script:
11
12
  - "bundle exec rake coveralls"
12
13
 
13
14
  rvm:
14
- - 2.1.1
15
- - 1.9.3
15
+ - 2.0.0-p598
16
+ - 2.1.5
17
+ - 2.2.0
16
18
 
17
19
  branches:
18
20
  only:
@@ -20,6 +22,7 @@ branches:
20
22
 
21
23
  env:
22
24
  global:
25
+ - MICRON_NO_HTML="1"
23
26
  - S3_REGION="us-east-1"
24
27
  - S3_BUCKET_NAME="io.bixby.gemcache.wad.agent"
25
28
  - secure: bnMJOHx5QrfTgOcxg0glw5x9mDoAJ0kKWILQaFCqwORwiJE4nh/3jYsx/uifVmSqOMXqY/9ozBwYrWeG6krPdcFCPS6mq4dVWsbtgQa31x9IWhjUg5lOt0MCrGXpq1JOD3CFIxnQ2f77hl0TzxutIfAtO023ad598+5/FVviyik=
data/Gemfile CHANGED
@@ -4,7 +4,7 @@ group :self do
4
4
  gem 'bixby-agent', :path => "."
5
5
  end
6
6
 
7
- gem 'bixby-common', "~> 0.5"
7
+ gem 'bixby-common', "~> 0.6"
8
8
  gem 'bixby-client', "~> 0.5"
9
9
  gem 'bixby-auth', "~> 0.1"
10
10
  #gem 'bixby-auth', :path => "../auth"
@@ -16,11 +16,9 @@ gem 'daemons', "~> 1.1"
16
16
  gem 'multi_json', "~> 1.8"
17
17
  gem 'oj', "~> 2.11"
18
18
  gem 'httpi', "~> 2.3"
19
- gem 'curb', "~> 0.8"
20
19
  gem 'facter', '~> 2.0.0'
21
20
  gem 'mixlib-cli', "~> 1.5"
22
- gem 'mixlib-shellout', "~> 1.6"
23
- gem 'highline', "~> 1.6"
21
+ gem 'mixlib-shellout', "~> 2.0"
24
22
  gem 'uuidtools', "~> 2.1"
25
23
  gem 'logging', "~> 1.8"
26
24
 
@@ -39,7 +37,7 @@ group :development do
39
37
  gem "test_guard", :github => "chetan/test_guard"
40
38
 
41
39
  # quality
42
- gem "cane", :platforms => [:mri_19, :mri_20]
40
+ gem "cane", :platforms => [:mri_19, :mri_20, :mri_21, :mri_22]
43
41
  end
44
42
 
45
43
  group :development, :test do
@@ -52,7 +50,7 @@ group :development, :test do
52
50
  gem 'mocha', :require => false
53
51
 
54
52
  # tools
55
- gem "simplecov", :platforms => [:mri_19, :mri_20]
53
+ gem "simplecov", :platforms => [:mri_19, :mri_20, :mri_21, :mri_22]
56
54
  gem "coveralls", :require => false
57
55
  gem "micron", :github => "chetan/micron"
58
56
  gem 'rb-inotify', :require => false
data/Gemfile.lock CHANGED
@@ -1,6 +1,6 @@
1
1
  GIT
2
2
  remote: git://github.com/chetan/jeweler.git
3
- revision: b90381a3958daae7f3ce3d8c4d710fe39e72443b
3
+ revision: 0334ea443c612bcbe3ebb7594b0a391fab233667
4
4
  branch: bixby
5
5
  specs:
6
6
  jeweler (2.0.1)
@@ -14,7 +14,7 @@ GIT
14
14
 
15
15
  GIT
16
16
  remote: git://github.com/chetan/micron.git
17
- revision: 0c1e9c0b9d9e052805f43485fe3454cbd25913c5
17
+ revision: 576f6699e2a7ff1828ce5c333cc5fa433c0be380
18
18
  specs:
19
19
  micron (0.5.1)
20
20
  ansi
@@ -36,19 +36,17 @@ GIT
36
36
  PATH
37
37
  remote: .
38
38
  specs:
39
- bixby-agent (0.3.1)
39
+ bixby-agent (0.3.2)
40
40
  bixby-auth (~> 0.1)
41
41
  bixby-client (~> 0.5)
42
- bixby-common (~> 0.5)
43
- curb (~> 0.8)
42
+ bixby-common (~> 0.6)
44
43
  daemons (~> 1.1)
45
44
  facter (~> 2.0.0)
46
45
  god (~> 0.13)
47
- highline (~> 1.6)
48
46
  httpi (~> 2.3)
49
47
  logging (~> 1.8)
50
48
  mixlib-cli (~> 1.5)
51
- mixlib-shellout (~> 1.6)
49
+ mixlib-shellout (~> 2.0)
52
50
  multi_json (~> 1.8)
53
51
  oj (~> 2.11)
54
52
  uuidtools (~> 2.1)
@@ -57,11 +55,11 @@ GEM
57
55
  remote: https://rubygems.org/
58
56
  specs:
59
57
  CFPropertyList (2.2.8)
60
- addressable (2.3.6)
61
- ansi (1.4.3)
62
- awesome_print (1.2.0)
63
- bixby-auth (0.1.0)
64
- bixby-client (0.5.1)
58
+ addressable (2.3.7)
59
+ ansi (1.5.0)
60
+ awesome_print (1.6.1)
61
+ bixby-auth (0.1.1)
62
+ bixby-client (0.5.2)
65
63
  bixby-common
66
64
  curb
67
65
  fuzzy_file_finder
@@ -69,7 +67,7 @@ GEM
69
67
  mixlib-shellout
70
68
  multi_json
71
69
  oj
72
- bixby-common (0.5.0)
70
+ bixby-common (0.6.3)
73
71
  bixby-auth (~> 0.1)
74
72
  faye-websocket (~> 0.7)
75
73
  httpi (~> 2.1)
@@ -82,13 +80,13 @@ GEM
82
80
  celluloid (0.16.0)
83
81
  timers (~> 4.0.0)
84
82
  coderay (1.1.0)
85
- colorize (0.7.3)
86
- coveralls (0.7.2)
87
- multi_json (~> 1.3)
88
- rest-client (= 1.6.7)
89
- simplecov (>= 0.7)
90
- term-ansicolor (= 1.2.2)
91
- thor (= 0.18.1)
83
+ colorize (0.7.5)
84
+ coveralls (0.7.11)
85
+ multi_json (~> 1.10)
86
+ rest-client (>= 1.6.8, < 2)
87
+ simplecov (~> 0.9.1)
88
+ term-ansicolor (~> 1.3)
89
+ thor (~> 0.19.1)
92
90
  crack (0.4.2)
93
91
  safe_yaml (~> 1.0.0)
94
92
  curb (0.8.6)
@@ -101,18 +99,18 @@ GEM
101
99
  simplecov
102
100
  simplecov-console
103
101
  simplecov-html
104
- eventmachine (1.0.3)
102
+ eventmachine (1.0.7)
105
103
  facter (2.0.2)
106
104
  CFPropertyList (~> 2.2.6)
107
- faraday (0.9.0)
105
+ faraday (0.9.1)
108
106
  multipart-post (>= 1.2, < 3)
109
- faye-websocket (0.8.0)
107
+ faye-websocket (0.9.2)
110
108
  eventmachine (>= 0.12.0)
111
- websocket-driver (>= 0.4.0)
109
+ websocket-driver (>= 0.5.1)
112
110
  ffi (1.9.6)
113
111
  fuzzy_file_finder (1.0.4)
114
- git (1.2.8)
115
- github_api (0.12.2)
112
+ git (1.2.9.1)
113
+ github_api (0.12.3)
116
114
  addressable (~> 2.3)
117
115
  descendants_tracker (~> 0.0.4)
118
116
  faraday (~> 0.8, < 0.10)
@@ -120,16 +118,16 @@ GEM
120
118
  multi_json (>= 1.7.5, < 2.0)
121
119
  nokogiri (~> 1.6.3)
122
120
  oauth2
123
- god (0.13.4)
121
+ god (0.13.5)
124
122
  growl (1.0.3)
125
- hashie (3.3.1)
126
- highline (1.6.21)
127
- hirb (0.7.2)
123
+ hashie (3.4.0)
124
+ highline (1.7.1)
125
+ hirb (0.7.3)
128
126
  hitimes (1.2.2)
129
127
  httpi (2.3.0)
130
128
  rack
131
- jwt (1.0.0)
132
- listen (2.8.0)
129
+ jwt (1.4.1)
130
+ listen (2.8.5)
133
131
  celluloid (>= 0.15.2)
134
132
  rb-fsevent (>= 0.9.3)
135
133
  rb-inotify (>= 0.9)
@@ -140,15 +138,16 @@ GEM
140
138
  metaclass (0.0.4)
141
139
  method_source (0.8.2)
142
140
  mime-types (2.4.3)
143
- mini_portile (0.6.1)
141
+ mini_portile (0.6.2)
144
142
  mixlib-cli (1.5.0)
145
- mixlib-shellout (1.6.0)
143
+ mixlib-shellout (2.0.1)
146
144
  mocha (1.1.0)
147
145
  metaclass (~> 0.0.1)
148
- multi_json (1.10.1)
146
+ multi_json (1.11.0)
149
147
  multi_xml (0.5.5)
150
148
  multipart-post (2.0.0)
151
- nokogiri (1.6.4.1)
149
+ netrc (0.10.3)
150
+ nokogiri (1.6.6.2)
152
151
  mini_portile (~> 0.6.0)
153
152
  oauth2 (1.0.0)
154
153
  faraday (>= 0.8, < 0.10)
@@ -156,45 +155,48 @@ GEM
156
155
  multi_json (~> 1.3)
157
156
  multi_xml (~> 0.5)
158
157
  rack (~> 1.2)
159
- oj (2.11.1)
160
- parallel (1.3.3)
158
+ oj (2.12.1)
159
+ parallel (1.4.0)
161
160
  pry (0.10.1)
162
161
  coderay (~> 1.1.0)
163
162
  method_source (~> 0.8.1)
164
163
  slop (~> 3.4)
165
- rack (1.5.2)
166
- rake (10.3.2)
164
+ rack (1.6.0)
165
+ rake (10.4.2)
167
166
  rb-fchange (0.0.6)
168
167
  ffi
169
168
  rb-fsevent (0.9.4)
170
169
  rb-inotify (0.9.5)
171
170
  ffi (>= 0.5.0)
172
- rest-client (1.6.7)
173
- mime-types (>= 1.16)
171
+ rest-client (1.7.3)
172
+ mime-types (>= 1.16, < 3.0)
173
+ netrc (~> 0.7)
174
174
  safe_yaml (1.0.4)
175
- semver2 (3.4.0)
176
- simplecov (0.9.1)
175
+ semver2 (3.4.1)
176
+ simplecov (0.9.2)
177
177
  docile (~> 1.1.0)
178
178
  multi_json (~> 1.0)
179
- simplecov-html (~> 0.8.0)
179
+ simplecov-html (~> 0.9.0)
180
180
  simplecov-console (0.2.0)
181
181
  colorize
182
182
  hirb
183
183
  simplecov
184
- simplecov-html (0.8.0)
184
+ simplecov-html (0.9.0)
185
185
  slop (3.6.0)
186
- term-ansicolor (1.2.2)
187
- tins (~> 0.8)
188
- thor (0.18.1)
189
- thread_safe (0.3.4)
186
+ term-ansicolor (1.3.0)
187
+ tins (~> 1.0)
188
+ thor (0.19.1)
189
+ thread_safe (0.3.5)
190
190
  timers (4.0.1)
191
191
  hitimes
192
- tins (0.13.2)
192
+ tins (1.3.4)
193
193
  uuidtools (2.1.5)
194
194
  webmock (1.20.4)
195
195
  addressable (>= 2.3.6)
196
196
  crack (>= 0.3.2)
197
- websocket-driver (0.4.0)
197
+ websocket-driver (0.5.3)
198
+ websocket-extensions (>= 0.1.0)
199
+ websocket-extensions (0.1.2)
198
200
  yard (0.8.7.6)
199
201
 
200
202
  PLATFORMS
@@ -205,23 +207,21 @@ DEPENDENCIES
205
207
  bixby-agent!
206
208
  bixby-auth (~> 0.1)
207
209
  bixby-client (~> 0.5)
208
- bixby-common (~> 0.5)
210
+ bixby-common (~> 0.6)
209
211
  cane
210
212
  colorize
211
213
  coveralls
212
- curb (~> 0.8)
213
214
  daemons (~> 1.1)
214
215
  facter (~> 2.0.0)
215
216
  god (~> 0.13)
216
217
  growl
217
- highline (~> 1.6)
218
218
  hirb
219
219
  httpi (~> 2.3)
220
220
  jeweler!
221
221
  logging (~> 1.8)
222
222
  micron!
223
223
  mixlib-cli (~> 1.5)
224
- mixlib-shellout (~> 1.6)
224
+ mixlib-shellout (~> 2.0)
225
225
  mocha
226
226
  multi_json (~> 1.8)
227
227
  oj (~> 2.11)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.1
1
+ 0.3.2
data/bixby-agent.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: bixby-agent 0.3.1 ruby lib
5
+ # stub: bixby-agent 0.3.2 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "bixby-agent"
9
- s.version = "0.3.1"
9
+ s.version = "0.3.2"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Chetan Sarva"]
14
- s.date = "2014-11-21"
14
+ s.date = "2015-03-19"
15
15
  s.description = "Bixby Agent"
16
16
  s.email = "chetan@pixelcop.net"
17
17
  s.executables = ["bixby-agent"]
@@ -72,14 +72,14 @@ Gem::Specification.new do |s|
72
72
  ]
73
73
  s.homepage = "http://github.com/chetan/bixby-agent"
74
74
  s.licenses = ["MIT"]
75
- s.rubygems_version = "2.4.2"
75
+ s.rubygems_version = "2.4.6"
76
76
  s.summary = "Bixby Agent"
77
77
 
78
78
  if s.respond_to? :specification_version then
79
79
  s.specification_version = 4
80
80
 
81
81
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
82
- s.add_runtime_dependency(%q<bixby-common>, ["~> 0.5"])
82
+ s.add_runtime_dependency(%q<bixby-common>, ["~> 0.6"])
83
83
  s.add_runtime_dependency(%q<bixby-client>, ["~> 0.5"])
84
84
  s.add_runtime_dependency(%q<bixby-auth>, ["~> 0.1"])
85
85
  s.add_runtime_dependency(%q<god>, ["~> 0.13"])
@@ -87,11 +87,9 @@ Gem::Specification.new do |s|
87
87
  s.add_runtime_dependency(%q<multi_json>, ["~> 1.8"])
88
88
  s.add_runtime_dependency(%q<oj>, ["~> 2.11"])
89
89
  s.add_runtime_dependency(%q<httpi>, ["~> 2.3"])
90
- s.add_runtime_dependency(%q<curb>, ["~> 0.8"])
91
90
  s.add_runtime_dependency(%q<facter>, ["~> 2.0.0"])
92
91
  s.add_runtime_dependency(%q<mixlib-cli>, ["~> 1.5"])
93
- s.add_runtime_dependency(%q<mixlib-shellout>, ["~> 1.6"])
94
- s.add_runtime_dependency(%q<highline>, ["~> 1.6"])
92
+ s.add_runtime_dependency(%q<mixlib-shellout>, ["~> 2.0"])
95
93
  s.add_runtime_dependency(%q<uuidtools>, ["~> 2.1"])
96
94
  s.add_runtime_dependency(%q<logging>, ["~> 1.8"])
97
95
  s.add_development_dependency(%q<yard>, ["~> 0.7"])
@@ -113,7 +111,7 @@ Gem::Specification.new do |s|
113
111
  s.add_development_dependency(%q<rb-fsevent>, [">= 0"])
114
112
  s.add_development_dependency(%q<rb-fchange>, [">= 0"])
115
113
  else
116
- s.add_dependency(%q<bixby-common>, ["~> 0.5"])
114
+ s.add_dependency(%q<bixby-common>, ["~> 0.6"])
117
115
  s.add_dependency(%q<bixby-client>, ["~> 0.5"])
118
116
  s.add_dependency(%q<bixby-auth>, ["~> 0.1"])
119
117
  s.add_dependency(%q<god>, ["~> 0.13"])
@@ -121,11 +119,9 @@ Gem::Specification.new do |s|
121
119
  s.add_dependency(%q<multi_json>, ["~> 1.8"])
122
120
  s.add_dependency(%q<oj>, ["~> 2.11"])
123
121
  s.add_dependency(%q<httpi>, ["~> 2.3"])
124
- s.add_dependency(%q<curb>, ["~> 0.8"])
125
122
  s.add_dependency(%q<facter>, ["~> 2.0.0"])
126
123
  s.add_dependency(%q<mixlib-cli>, ["~> 1.5"])
127
- s.add_dependency(%q<mixlib-shellout>, ["~> 1.6"])
128
- s.add_dependency(%q<highline>, ["~> 1.6"])
124
+ s.add_dependency(%q<mixlib-shellout>, ["~> 2.0"])
129
125
  s.add_dependency(%q<uuidtools>, ["~> 2.1"])
130
126
  s.add_dependency(%q<logging>, ["~> 1.8"])
131
127
  s.add_dependency(%q<yard>, ["~> 0.7"])
@@ -148,7 +144,7 @@ Gem::Specification.new do |s|
148
144
  s.add_dependency(%q<rb-fchange>, [">= 0"])
149
145
  end
150
146
  else
151
- s.add_dependency(%q<bixby-common>, ["~> 0.5"])
147
+ s.add_dependency(%q<bixby-common>, ["~> 0.6"])
152
148
  s.add_dependency(%q<bixby-client>, ["~> 0.5"])
153
149
  s.add_dependency(%q<bixby-auth>, ["~> 0.1"])
154
150
  s.add_dependency(%q<god>, ["~> 0.13"])
@@ -156,11 +152,9 @@ Gem::Specification.new do |s|
156
152
  s.add_dependency(%q<multi_json>, ["~> 1.8"])
157
153
  s.add_dependency(%q<oj>, ["~> 2.11"])
158
154
  s.add_dependency(%q<httpi>, ["~> 2.3"])
159
- s.add_dependency(%q<curb>, ["~> 0.8"])
160
155
  s.add_dependency(%q<facter>, ["~> 2.0.0"])
161
156
  s.add_dependency(%q<mixlib-cli>, ["~> 1.5"])
162
- s.add_dependency(%q<mixlib-shellout>, ["~> 1.6"])
163
- s.add_dependency(%q<highline>, ["~> 1.6"])
157
+ s.add_dependency(%q<mixlib-shellout>, ["~> 2.0"])
164
158
  s.add_dependency(%q<uuidtools>, ["~> 2.1"])
165
159
  s.add_dependency(%q<logging>, ["~> 1.8"])
166
160
  s.add_dependency(%q<yard>, ["~> 0.7"])
@@ -43,7 +43,6 @@ class Agent
43
43
  end
44
44
 
45
45
  def initialize()
46
- #uri, tenant = nil, password = nil, root_dir = nil
47
46
  Bixby::Log.setup_logger()
48
47
  @new = true
49
48
 
@@ -14,19 +14,17 @@ module Handshake
14
14
  # Register the agent with the server
15
15
  #
16
16
  # @param [String] url Bixby manager URL
17
- # @param [String] tenant Tenant name
18
- # @param [String] password Tenant registration password
17
+ # @param [String] token Client registration token
19
18
  # @param [String] tags Comma-separated list of tags (e.g., "foo,bar")
20
19
  #
21
20
  # @return [JsonResponse] response from server
22
- def register_agent(url, tenant, password, tags=nil)
21
+ def register_agent(url, token, tags=nil)
23
22
  Bixby.manager_uri = @manager_uri = url
24
23
  ret = Bixby::Inventory.register_agent({
25
24
  :uuid => @uuid,
26
25
  :public_key => self.public_key.to_s,
27
26
  :hostname => get_hostname(),
28
- :tenant => tenant,
29
- :password => password,
27
+ :token => token,
30
28
  :tags => tags,
31
29
  :version => Bixby::Agent::VERSION
32
30
  })
@@ -38,10 +38,12 @@ module ShellExec
38
38
  old_env[r] = ENV.delete(r) if ENV.include?(r) }
39
39
 
40
40
  logger.debug("exec: #{cmd}")
41
+ uid = lookup_id(:uid, spec.user)
42
+ gid = lookup_id(:gid, spec.group)
41
43
  shell = Mixlib::ShellOut.new(cmd, :input => spec.stdin,
42
- :env => spec.env,
43
- :user => uid(spec.user),
44
- :group => gid(spec.group))
44
+ :env => reset_env(spec.env, uid),
45
+ :user => uid,
46
+ :group => gid)
45
47
 
46
48
  shell.run_command
47
49
 
@@ -55,51 +57,44 @@ module ShellExec
55
57
 
56
58
  private
57
59
 
58
- # Return uid of 'bixby' user, if it exists
59
- #
60
- # @param [String] user username to run as [Optional, default=bixby]
61
- # @return [Fixnum]
62
- def uid(user)
63
- if Process.uid != 0 then
64
- logger.warn("Can't change effective uid unless running as root")
65
- return nil
60
+ # Merge in the correct ENV settings for the target user
61
+ def reset_env(env, uid)
62
+ if uid.nil? || uid == Process.uid then
63
+ # no need to change
64
+ return env
66
65
  end
67
66
 
68
- if user then
69
- begin
70
- return Etc.getpwnam(user).uid
71
- rescue ArgumentError => ex
72
- logger.warn("Username '#{user}' was invalid: #{ex.message}")
73
- end
74
- end
75
-
76
- begin
77
- return Etc.getpwnam("bixby").uid
78
- rescue ArgumentError
79
- end
80
- return nil
67
+ env ||= {}
68
+ user = Etc.getpwuid(uid)
69
+ env.merge({"HOME" => user.dir, "USER" => user.name})
81
70
  end
82
71
 
83
- # Return uid of 'bixby' group, if it exists
72
+ # Lookup the id of the given user or group
73
+ #
74
+ # @param [Symbol] type :uid or :gid
75
+ # @param [String] str user or group name [Optional, default=bixby]
84
76
  #
85
- # @param [String] group group to run as [Optional, default=bixby]
86
77
  # @return [Fixnum]
87
- def gid(group)
78
+ def lookup_id(type, str=nil)
88
79
  if Process.uid != 0 then
89
80
  logger.warn("Can't change effective gid unless running as root")
90
81
  return nil
91
82
  end
92
83
 
93
- if group then
84
+ method = type == :uid ? :getpwnam : :getgrnam
85
+
86
+ if !(str.nil? or str.empty?) then
94
87
  begin
95
- return Etc.getgrnam(group).gid
88
+ logger.debug "Running as #{type} '#{str}'"
89
+ return Etc.send(method, str).send(type)
96
90
  rescue ArgumentError => ex
97
- logger.warn("Group '#{group}' was invalid: #{ex.message}")
91
+ logger.warn("#{type} lookup for '#{str}' failed: #{ex.message}")
98
92
  end
99
93
  end
100
94
 
101
95
  begin
102
- return Etc.getgrnam("bixby").gid
96
+ logger.debug "Running as #{type} 'bixby' (default)"
97
+ return Etc.send(method, "bixby").send(type)
103
98
  rescue ArgumentError
104
99
  end
105
100
  return nil
@@ -4,7 +4,6 @@ module Bixby
4
4
  class AgentHandler < Bixby::RpcHandler
5
5
 
6
6
  include Bixby::Log
7
- # include Bixby::CryptoUti
8
7
 
9
8
  def initialize(request)
10
9
  @request = request
@@ -5,7 +5,6 @@ require 'bixby-agent/app/cli'
5
5
  require 'bixby-agent/help/system_time'
6
6
 
7
7
  require 'daemons'
8
- require 'highline/import'
9
8
 
10
9
  module Bixby
11
10
  class App
@@ -62,12 +61,9 @@ class App
62
61
  raise ConfigException, "Bad manager URI: '#{uri}'"
63
62
  end
64
63
 
65
- tenant = @config[:tenant] || HighLine.new.ask("Tenant: ")
66
- password = @config[:password] || HighLine.new.ask("Enter agent registration password: ") { |q| q.echo = "*" }
67
-
68
64
  # register
69
65
  $stdout.puts "Going to register with manager: #{uri}"
70
- if (ret = agent.register_agent(uri, tenant, password, @config[:tags])).fail? then
66
+ if (ret = agent.register_agent(uri, @config[:token], @config[:tags])).fail? then
71
67
  $stderr.puts "error: failed to register with manager!"
72
68
  $stderr.puts "reason:"
73
69
  if ret.message =~ /900 seconds old/ then
@@ -125,21 +121,26 @@ class App
125
121
  def start_websocket_client
126
122
  # make sure log level is still set correctly here
127
123
  Bixby::Log.setup_logger(:level => Logging.appenders["file"].level)
128
- logger.info "Started Bixby Agent"
124
+ logger.info "Started Bixby Agent #{Bixby::Agent::VERSION}"
129
125
  @client = Bixby::WebSocket::Client.new(Bixby.agent.manager_ws_uri, AgentHandler)
130
126
  trap_signals()
131
127
  @client.start
132
128
  end
133
129
 
134
130
  def trap_signals
135
- %w{INT QUIT TERM}.each do |sig|
136
- Kernel.trap(sig) do
137
- @client.stop()
131
+
132
+ Bixby::Signal.trap(%w{INT QUIT TERM}) do |sig|
133
+ @client.stop()
134
+ if sig == "INT" then
138
135
  puts # to get a blank line after the ^C in the term
139
- reason = sig + (sig == "INT" ? " (^C)" : "")
140
- logger.warn "caught #{reason} signal; exiting"
136
+ reason = " (^C)"
137
+ else
138
+ reason = ""
141
139
  end
140
+ logger.warn "caught #{sig}#{reason} signal; exiting"
142
141
  end
142
+
143
+ Bixby::ThreadDump.trap!
143
144
  end
144
145
 
145
146
  # If running as root, fix ownership of var and etc dirs
@@ -192,8 +193,7 @@ class App
192
193
  end
193
194
 
194
195
  # Copied from daemons gem. We hit a bug where closing FDs failed,
195
- # probably related to prompting for a password. So close them
196
- # all cleanly before daemonizing.
196
+ # so close them all cleanly before daemonizing.
197
197
  def close_fds
198
198
  # don't close stdin/out/err (0/1/2)
199
199
  3.upto(8192).each do |i|
@@ -1,6 +1,5 @@
1
1
 
2
2
  require 'mixlib/cli'
3
- require 'highline/import'
4
3
 
5
4
  module Bixby
6
5
  class App
@@ -30,7 +29,7 @@ Where <command> is one of:
30
29
 
31
30
  To register with the manager:
32
31
 
33
- #{$0} --register [URL] -t TENANT -P [PASSWORD] [--tags TAG1,TAG2]
32
+ #{$0} --register [URL] --token TOKEN [--tags TAG1,TAG2]
34
33
 
35
34
  Options:
36
35
 
@@ -44,24 +43,11 @@ EOF
44
43
  :description => "Register with the management server (optional URL, default: https://bixby.io)",
45
44
  :proc => Proc.new { |url| url || "https://bixby.io" } # default URL
46
45
 
47
- option :tenant,
46
+ option :token,
48
47
  :on => :head,
49
- :short => "-t TENANT",
50
- :long => "--tenant TENANT",
51
- :description => "Tenant name"
52
-
53
- option :password,
54
- :on => :head,
55
- :short => "-P [PASSWORD]",
56
- :long => "--password [PASSWORD]",
57
- :description => "Agent registration password (prompt if not supplied)",
58
- :proc => Proc.new { |c|
59
- if c then
60
- c
61
- else
62
- HighLine.new.ask("Enter agent registration password: ") { |q| q.echo = "*" }
63
- end
64
- }
48
+ :short => "-t TOKEN",
49
+ :long => "--token TOKEN",
50
+ :description => "Client registration token"
65
51
 
66
52
  option :tags,
67
53
  :on => :head,
@@ -2,7 +2,7 @@
2
2
  module Bixby
3
3
  class Agent
4
4
 
5
- VERSION = File.new(File.expand_path(File.join(File.dirname(__FILE__), "../../VERSION"))).read.strip
5
+ VERSION = File.new(File.expand_path("../../../VERSION", __FILE__)).read.strip
6
6
 
7
7
  end
8
8
  end
@@ -20,6 +20,7 @@ module Bixby
20
20
  @handler = handler
21
21
  @tries = 0
22
22
  @exiting = false
23
+ @thread_pool = Bixby::ThreadPool.new(:min_size => 1, :max_size => 4)
23
24
  end
24
25
 
25
26
  # Start the Client thread
@@ -53,11 +54,19 @@ module Bixby
53
54
  # the connection open forever, reconnecting as needed.
54
55
  def connect
55
56
 
57
+ # cleanup any previously opened connections
58
+ if !@ws.nil? && ws.ready_state != Faye::WebSocket::API::CLOSED then
59
+ begin
60
+ @ws.close
61
+ rescue Exception => ex
62
+ end
63
+ end
64
+
56
65
  # Ping is set to 55 sec to workaround issues with certain gateway devices which have a hard
57
66
  # 60 sec timeout, like the AWS ELB:
58
67
  # http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/ts-elb-healthcheck.html
59
68
  @ws = Faye::WebSocket::Client.new(@url, nil, :ping => 55)
60
- @api = Bixby::WebSocket::APIChannel.new(@ws, @handler)
69
+ @api = Bixby::WebSocket::APIChannel.new(@ws, @handler, @thread_pool)
61
70
 
62
71
  ws.on :open do |e|
63
72
  begin
@@ -82,7 +91,7 @@ module Bixby
82
91
  api.close(e)
83
92
  return if @exiting or not EM.reactor_running?
84
93
  if was_connected then
85
- logger.info "lost connection to manager"
94
+ logger.info "lost connection to manager (code=#{e.code}; reason=\"#{e.reason}\")"
86
95
  else
87
96
  logger.debug "failed to connect"
88
97
  end
@@ -120,6 +129,9 @@ module Bixby
120
129
  end
121
130
 
122
131
  # Start a thread to watch for auth timeout
132
+ #
133
+ # Because the CONNECT request is fully-async, we need to make sure a reply is received
134
+ # within a certain time limit. If not, reconnect
123
135
  Thread.new do
124
136
  begin
125
137
  sec = 60
@@ -155,13 +167,13 @@ module Bixby
155
167
 
156
168
  if @exiting or not EM.reactor_running? then
157
169
  # shutting down, don't try to reconnect
158
- logger.debug "not retrying since we are shutting down"
170
+ logger.info "not reconnecting since we are shutting down"
159
171
  return false
160
172
  end
161
173
 
162
174
  @tries += 1
163
175
  if @tries == 1 then
164
- logger.debug "retrying immediately"
176
+ logger.info "retrying immediately"
165
177
 
166
178
  # :nocov:
167
179
  elsif @tries == 2 then
data/test/base.rb CHANGED
@@ -18,8 +18,7 @@ module Bixby
18
18
  @support_path = File.join(@git_path, "test", "support")
19
19
 
20
20
  @manager_uri = "http://localhost:3000"
21
- @tenant = "pixelcop"
22
- @password = "foobar"
21
+ @token = "ABCDEF012345"
23
22
  @root_dir = Dir.mktmpdir("bixby-agent-test-")
24
23
  @port = 9999
25
24
 
data/test/helper.rb CHANGED
@@ -10,8 +10,6 @@ end
10
10
 
11
11
  require 'micron/minitest'
12
12
 
13
- # load curb first so webmock can stub it out as necessary
14
- require 'curb'
15
13
  require 'webmock'
16
14
  include WebMock::API
17
15
  require 'mocha/setup'
@@ -8,6 +8,7 @@ module EventMachine
8
8
  alias_method :_orig_stop_event_loop, :stop_event_loop
9
9
 
10
10
  def run_immediately(&block)
11
+ @reactor_pid = Process.pid
11
12
  @reactor_running = true
12
13
  block.call() if block
13
14
  end
data/test/test_agent.rb CHANGED
@@ -74,11 +74,11 @@ class TestAgent < TestCase
74
74
 
75
75
  # stub out http request
76
76
  stub_request(:post, "#{@manager_uri}/api").with { |req|
77
- req.body =~ /inventory:register_agent/ and req.body =~ /"tenant":"pixelcop"/
77
+ req.body =~ /inventory:register_agent/ and req.body =~ /"token":"#{@token}"/
78
78
 
79
79
  }.to_return(:body => response_str, :status => 200)
80
80
 
81
- response = @agent.register_agent(@manager_uri, @tenant, @password)
81
+ response = @agent.register_agent(@manager_uri, @token)
82
82
  assert response.status == "success"
83
83
 
84
84
  key_file = Bixby.path("etc", "server.pub")
data/test/test_app.rb CHANGED
@@ -15,8 +15,7 @@ class TestApp < TestCase
15
15
  ARGV.clear
16
16
  ARGV << "--register" << @manager_uri
17
17
  ARGV << "-d" << @root_dir
18
- ARGV << "--tenant" << "mytenant"
19
- ARGV << "--password" << "mypass"
18
+ ARGV << "--token" << "mytoken"
20
19
 
21
20
  response_str = MultiJson.dump({
22
21
  :data => {:server_key => "-----BEGIN RSA PUBLIC KEY-----",
@@ -63,8 +62,7 @@ class TestApp < TestCase
63
62
  ARGV << "--register" # uri should default to bixby.io
64
63
  ARGV << "--debug"
65
64
  ARGV << "--directory" << @root_dir
66
- ARGV << "--tenant" << "mytenant"
67
- ARGV << "--password" << "mypass"
65
+ ARGV << "--token" << "mytoken"
68
66
 
69
67
  Bixby::WebSocket::Client.any_instance.expects(:start).once()
70
68
 
@@ -116,8 +114,7 @@ class TestApp < TestCase
116
114
  ARGV << "--register" # uri should default to bixby.io
117
115
  ARGV << "--debug"
118
116
  ARGV << "--directory" << @root_dir
119
- ARGV << "--tenant" << "mytenant"
120
- ARGV << "--password" << "mypass"
117
+ ARGV << "--token" << "mytoken"
121
118
 
122
119
  stub_request(:get, "http://google.com/").to_return(:status => 200, :body => "", :headers => {"Date" => (Time.new+1).utc.to_s})
123
120
 
@@ -19,7 +19,10 @@ module WebSocket
19
19
  class TestClient < TestCase
20
20
 
21
21
  class FakeClient
22
- attr_reader :types
22
+ class Event
23
+ attr_reader :code, :reason
24
+ end
25
+ attr_reader :types, :ready_state
23
26
  def initialize
24
27
  @types = {}
25
28
  end
@@ -27,6 +30,7 @@ class TestClient < TestCase
27
30
  @types[type] = block
28
31
  end
29
32
  def trigger(type, event)
33
+ event ||= Event.new
30
34
  @types[type].call(event)
31
35
  end
32
36
  def close
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bixby-agent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chetan Sarva
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2015-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bixby-common
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.6'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bixby-client
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - "~>"
123
123
  - !ruby/object:Gem::Version
124
124
  version: '2.3'
125
- - !ruby/object:Gem::Dependency
126
- name: curb
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '0.8'
132
- type: :runtime
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '0.8'
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: facter
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -170,28 +156,14 @@ dependencies:
170
156
  requirements:
171
157
  - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: '1.6'
174
- type: :runtime
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '1.6'
181
- - !ruby/object:Gem::Dependency
182
- name: highline
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - "~>"
186
- - !ruby/object:Gem::Version
187
- version: '1.6'
159
+ version: '2.0'
188
160
  type: :runtime
189
161
  prerelease: false
190
162
  version_requirements: !ruby/object:Gem::Requirement
191
163
  requirements:
192
164
  - - "~>"
193
165
  - !ruby/object:Gem::Version
194
- version: '1.6'
166
+ version: '2.0'
195
167
  - !ruby/object:Gem::Dependency
196
168
  name: uuidtools
197
169
  requirement: !ruby/object:Gem::Requirement
@@ -550,7 +522,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
550
522
  version: '0'
551
523
  requirements: []
552
524
  rubyforge_project:
553
- rubygems_version: 2.4.2
525
+ rubygems_version: 2.4.6
554
526
  signing_key:
555
527
  specification_version: 4
556
528
  summary: Bixby Agent