MuranoCLI 3.1.0 → 3.2.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -32,6 +32,7 @@ require 'MrMurano/commands/show'
32
32
  require 'MrMurano/commands/solution'
33
33
  require 'MrMurano/commands/status'
34
34
  require 'MrMurano/commands/sync'
35
+ require 'MrMurano/commands/token'
35
36
  require 'MrMurano/commands/tsdb'
36
37
  require 'MrMurano/commands/usage'
37
38
 
data/lib/MrMurano/http.rb CHANGED
@@ -13,26 +13,25 @@ require 'uri'
13
13
  # 2017-06-07: [lb] getting "execution expired (Net::OpenTimeout)" on http.start.
14
14
  # Suggestions online say to load the pure-Ruby DNS implementation, resolv.rb.
15
15
  require 'resolv-replace'
16
+
16
17
  require 'MrMurano/progress'
18
+ require 'MrMurano/verbosing'
17
19
 
18
20
  module MrMurano
19
21
  module Http
20
- def token
21
- return @token if defined?(@token) && !@token.to_s.empty?
22
- acc = MrMurano::Account.instance
23
- @token = acc.token
24
- #raise 'Not logged in!' if @token.nil?
25
- ensure_token! @token
26
- # MAYBE: Check that ADC is enabled on the business. If not, tell
27
- # user to run Murano 2.x. See adc_compat_check for comments.
28
- #acc.adc_compat_check
29
- @token
22
+ include Verbose
23
+
24
+ def host
25
+ $cfg['net.host'].to_s
30
26
  end
31
27
 
32
- def ensure_token!(tok)
33
- return unless tok.nil?
34
- error 'Not logged in!'
35
- exit 1
28
+ def user
29
+ $cfg['user.name'].to_s
30
+ end
31
+
32
+ # Default endpoint unless Class overrides it.
33
+ def endpoint(path)
34
+ URI($cfg['net.protocol'] + '://' + host + '/api:1/' + path.to_s)
36
35
  end
37
36
 
38
37
  def json_opts
@@ -78,11 +77,6 @@ module MrMurano
78
77
  end
79
78
  end
80
79
 
81
- # Default endpoint unless Class overrides it.
82
- def endpoint(path)
83
- URI($cfg['net.protocol'] + '://' + $cfg['net.host'] + '/api:1/' + path.to_s)
84
- end
85
-
86
80
  def http
87
81
  uri = URI($cfg['net.protocol'] + '://' + $cfg['net.host'])
88
82
  if !defined?(@http) || @http.nil?
@@ -109,10 +103,6 @@ module MrMurano
109
103
 
110
104
  def add_headers(request)
111
105
  request.content_type = 'application/json'
112
- # 2017-08-14: MrMurano::Account overrides the token method, and
113
- # it doesn't exit if no token, and then we end up here.
114
- ensure_token! token
115
- request['Authorization'] = 'token ' + token unless token.to_s.empty?
116
106
  request['User-Agent'] = "MrMurano/#{MrMurano::VERSION}"
117
107
  request
118
108
  end
@@ -152,7 +142,6 @@ module MrMurano
152
142
  else
153
143
  resp += (jsn || 'nil')
154
144
  end
155
- # assuming verbosing was included.
156
145
  error resp
157
146
  end
158
147
 
@@ -26,7 +26,7 @@ module MrMurano
26
26
  # '3.0.0-beta.2' is changed to '3.0.0.pre.beta.2'
27
27
  # which breaks our build (which expects the version to match herein).
28
28
  # So stick to using the '.pre.X' syntax, which ruby/gems knows.
29
- VERSION = '3.1.0'
29
+ VERSION = '3.2.0.beta.1'
30
30
  EXE_NAME = File.basename($PROGRAM_NAME)
31
31
  SIGN_UP_URL = 'https://exosite.com/signup/'
32
32
  end
data/lib/MrMurano.rb CHANGED
@@ -25,6 +25,7 @@ require 'MrMurano/Account'
25
25
  require 'MrMurano/Business'
26
26
  require 'MrMurano/Exchange'
27
27
  require 'MrMurano/Exchange-Element'
28
+ require 'MrMurano/HttpAuthed'
28
29
  require 'MrMurano/Passwords'
29
30
 
30
31
  require 'MrMurano/Content'
data/spec/Account_spec.rb CHANGED
@@ -26,7 +26,7 @@ RSpec.describe MrMurano::Account, 'token' do
26
26
  $project = MrMurano::ProjectFile.new
27
27
  $project.load
28
28
 
29
- @acc = MrMurano::Account.instance
29
+ @acc = MrMurano::Account.new
30
30
  end
31
31
 
32
32
  after(:example) do
@@ -69,7 +69,7 @@ RSpec.describe MrMurano::Account, 'token' do
69
69
  expect(@acc).to receive(:error).once
70
70
  expect($terminal).to receive(:ask).once.and_return('dog')
71
71
  expect(@pswd).to receive(:set).once.with('bizapi.hosted.exosite.io', 'bob', 'dog')
72
- expect(@pswd).to receive(:set).once.with('bizapi.hosted.exosite.io', 'bob/twofactor', nil)
72
+ expect(@pswd).to receive(:set).once.with('bizapi.hosted.exosite.io', 'bob/token', nil)
73
73
  # 2017-07-31: login_info may exit unless the command okays prompting for the password.
74
74
  # (If we don't set this, login_info exits, which we'd want to
75
75
  # catch with
@@ -112,16 +112,16 @@ RSpec.describe MrMurano::Account, 'token' do
112
112
  end
113
113
 
114
114
  it 'uses existing token' do
115
- @acc.token_reset('quxx')
115
+ @acc.token_reset
116
116
  ret = @acc.token
117
- expect(ret).to eq('quxx')
117
+ expect(ret).to eq('')
118
118
  end
119
119
 
120
120
  it 'uses existing token, even with new instance' do
121
- @acc.token_reset('quxx')
122
- acc = MrMurano::Account.instance
121
+ @acc.token_reset
122
+ acc = MrMurano::Account.new
123
123
  ret = acc.token
124
- expect(ret).to eq('quxx')
124
+ expect(ret).to eq('')
125
125
  end
126
126
  end
127
127
  end
@@ -137,7 +137,7 @@ RSpec.describe MrMurano::Account do
137
137
  $cfg['business.id'] = 'XYZxyz'
138
138
  $cfg['product.id'] = 'XYZ'
139
139
 
140
- @acc = MrMurano::Account.instance
140
+ @acc = MrMurano::Account.new
141
141
  allow(@acc).to receive(:token).and_return('TTTTTTTTTT')
142
142
  end
143
143
  after(:example) do
data/spec/Http_spec.rb CHANGED
@@ -43,7 +43,6 @@ RSpec.describe MrMurano::Http do
43
43
  end
44
44
 
45
45
  it 'gets one' do
46
- #expect(@acc).to receive(:adc_compat_check)
47
46
  expect(@acc).to receive(:token).and_return('ABCDEFG')
48
47
  ret = @tst.token
49
48
  expect(ret).to eq('ABCDEFG')
@@ -0,0 +1,56 @@
1
+ # Copyright © 2016-2017 Exosite LLC. All Rights Reserved
2
+ # License: PROPRIETARY. See LICENSE.txt.
3
+ # frozen_string_literal: true
4
+
5
+ # vim:tw=0:ts=2:sw=2:et:ai
6
+ # Unauthorized copying of this file is strictly prohibited.
7
+
8
+ require 'fileutils'
9
+ require 'open3'
10
+
11
+ require 'cmd_common'
12
+ require 'MrMurano/Config'
13
+ require 'MrMurano/commands/token'
14
+
15
+ RSpec.describe 'murano token', :cmd, :needs_password, :nondeterministic do
16
+ include_context 'CI_CMD'
17
+
18
+ context 'without project' do
19
+ it 'help' do
20
+ cmd_verify_help('token')
21
+ end
22
+ end
23
+
24
+ context 'with project' do
25
+ #before(:example) { project_up }
26
+ #after(:example) { project_down }
27
+
28
+ def expect_token_host_user_table(stdout, stderr, num_cols: nil)
29
+ expect(stderr).to eq('')
30
+ lines = stdout.lines
31
+ # FIXME/2017-08-29: Is this too much detail??
32
+ # What about running test once, dumping output to file,
33
+ # and expecting same output next time?
34
+ # Outline of table. n columns. '+-----+-----+---...----+\n'
35
+ expect(lines[0]).to match(/^(\+-+){#{num_cols}}\+$/)
36
+ # Header.
37
+ expect(lines[1]).to match(/^\| Host/)
38
+ # Separator.
39
+ expect(lines[2]).to match(/^(\+-+){#{num_cols}}\+$/)
40
+ # Content. Starts with elementId.
41
+ (3..(lines.length - 2)).to_a.each do |line|
42
+ expect(lines[line]).to match(/^\| [0-9a-f]+ \| /)
43
+ end
44
+ expect(lines[-1]).to match(/^(\+-+){#{num_cols}}\+$/)
45
+ end
46
+
47
+ context 'list' do
48
+ it 'as table' do
49
+ stdout, stderr = murano_command_run('token list')
50
+ # 2 columns: elementId, name, status, description.
51
+ expect_token_host_user_table(stdout, stderr, num_cols: 2)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
@@ -57,8 +57,8 @@ need to disable the token mechanism.
57
57
 
58
58
  Add this to ``lib/MrMurano/Account.rb``::
59
59
 
60
- def token_fetch
61
- @token = 'XXX'
60
+ def token_fetch_biz
61
+ @token_biz = 'XXX'
62
62
  return
63
63
 
64
64
  =========================
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MuranoCLI
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0.beta.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Conrad Tadpol Tilstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-25 00:00:00.000000000 Z
11
+ date: 2018-03-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: certified
@@ -478,6 +478,7 @@ files:
478
478
  - docs/develop.rst
479
479
  - lib/MrMurano.rb
480
480
  - lib/MrMurano/Account.rb
481
+ - lib/MrMurano/AccountBase.rb
481
482
  - lib/MrMurano/Business.rb
482
483
  - lib/MrMurano/Commander-Entry.rb
483
484
  - lib/MrMurano/Config-Migrate.rb
@@ -486,6 +487,7 @@ files:
486
487
  - lib/MrMurano/Exchange-Element.rb
487
488
  - lib/MrMurano/Exchange.rb
488
489
  - lib/MrMurano/Gateway.rb
490
+ - lib/MrMurano/HttpAuthed.rb
489
491
  - lib/MrMurano/Keystore.rb
490
492
  - lib/MrMurano/Logs.rb
491
493
  - lib/MrMurano/Mock.rb
@@ -537,6 +539,7 @@ files:
537
539
  - lib/MrMurano/commands/status.rb
538
540
  - lib/MrMurano/commands/sync.rb
539
541
  - lib/MrMurano/commands/timeseries.rb
542
+ - lib/MrMurano/commands/token.rb
540
543
  - lib/MrMurano/commands/tsdb.rb
541
544
  - lib/MrMurano/commands/usage.rb
542
545
  - lib/MrMurano/hash.rb
@@ -602,6 +605,7 @@ files:
602
605
  - spec/cmd_syncdown_application_spec.rb
603
606
  - spec/cmd_syncdown_both_spec.rb
604
607
  - spec/cmd_syncup_spec.rb
608
+ - spec/cmd_token_spec.rb
605
609
  - spec/cmd_usage_spec.rb
606
610
  - spec/fixtures/.mrmuranorc
607
611
  - spec/fixtures/ProjectFiles/invalid.yaml
@@ -661,9 +665,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
661
665
  version: '2.0'
662
666
  required_rubygems_version: !ruby/object:Gem::Requirement
663
667
  requirements:
664
- - - ">="
668
+ - - ">"
665
669
  - !ruby/object:Gem::Version
666
- version: '0'
670
+ version: 1.3.1
667
671
  requirements: []
668
672
  rubyforge_project:
669
673
  rubygems_version: 2.7.4