bootic_cli 0.1.6 → 0.1.7

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: d1cd34aea083a13ac4498a6ec83efabf0f4f389a
4
- data.tar.gz: 2f5067838d8dccbcbf5eac65176ea9081c76674d
3
+ metadata.gz: c4ace11ad0bee02a140f7a4312f4384d0398cd94
4
+ data.tar.gz: 8dcf28108c63796e137438d04773ce18fc40719f
5
5
  SHA512:
6
- metadata.gz: 0f749cc6438d2d8cb8d5088787bde841a458a48e5485fe9f59e2ec54b42ce028301bee5f5159ba6239ef57904dd9055bef67ae39a3992001493627df588c54ad
7
- data.tar.gz: 8a6fb2e8535280f8db5175d834f1b4a4ca2a1cb1ff64a9c80b0eb38af7efd9b672cb29d38896e0d8c0e7e004844eb1ded66156c5cd776d01f2569dad659b10c9
6
+ metadata.gz: 7acf5cf6b282cd2b60bd2fb563f5d30298f504baff415783f5fea34721cc56518985ed1e8876c1b1c1967a3d9c400f0e62b6731bbfbcd79684715850e4cfcdc5
7
+ data.tar.gz: 48ef1a967baea28dea4f01e8bc0c44439f4be0f7e3a54177bafaf9798ef4376ac21d8874c57603b758ae8929d9e876a283d0b4ee36057f92696e5447587175b1
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ examples
data/bootic_cli.gemspec CHANGED
@@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "bundler", "~> 1.9"
26
26
  spec.add_development_dependency "rake", "~> 10.0"
27
27
  spec.add_development_dependency "rspec"
28
+ spec.add_development_dependency "byebug"
28
29
 
29
30
  spec.post_install_message = <<-END
30
31
  Bootic client installed.
@@ -7,23 +7,32 @@ module BooticCli
7
7
  include Thor::Actions
8
8
  include BooticCli::Connectivity
9
9
 
10
+ DEFAULT_ENV = 'production'.freeze
10
11
  CUSTOM_COMMANDS_DIR = ENV.fetch("BTC_CUSTOM_COMMANDS_PATH") { File.join(ENV["HOME"], "btc") }
11
12
 
13
+ class_option :environment, type: :string, default: DEFAULT_ENV, aliases: :e, banner: '<production>'
14
+
12
15
  desc 'setup', 'Setup OAuth2 application credentials'
13
16
  def setup
17
+ if options[:environment] != DEFAULT_ENV
18
+ auth_host = ask("Enter auth endpoint host (#{BooticClient::AUTH_HOST}):").chomp
19
+ api_root = ask("Enter API root (#{BooticClient::API_ROOT}):").chomp
20
+ auth_host = nil if auth_host == ""
21
+ api_root = nil if api_root == ""
22
+ end
14
23
  client_id = ask("Enter your application's client_id:")
15
24
  client_secret = ask("Enter your application's client_secret:")
16
25
 
17
- session.setup(client_id, client_secret)
26
+ session.setup(client_id, client_secret, auth_host: auth_host, api_root: api_root)
18
27
 
19
- say "Credentials stored. client_id: #{client_id}"
28
+ say "Credentials stored for #{options[:environment]} environment. client_id: #{client_id}"
20
29
  end
21
30
 
22
31
  desc 'login', 'Login to your Bootic account'
23
32
  def login(scope = 'admin')
24
33
  if !session.setup?
25
- say "App not configured. Running setup first. You only need to do this once."
26
- say "Please create an OAuth2 app and get its credentials at https://auth.bootic.net/dev/apps"
34
+ say "App not configured for #{options[:environment]} environment. Running setup first. You only need to do this once."
35
+ say "Please create an OAuth2 app and get its credentials at https://auth.bootic.net/dev/apps or the relevant auth app for your environment"
27
36
  invoke :setup, []
28
37
  end
29
38
 
@@ -8,7 +8,7 @@ module BooticCli
8
8
 
9
9
  def session
10
10
  @session ||= (
11
- store = BooticCli::Store.new(ENV['HOME'])
11
+ store = BooticCli::Store.new(base_dir: ENV['HOME'], namespace: options[:environment])
12
12
  BooticCli::Session.new(store)
13
13
  )
14
14
  end
@@ -22,13 +22,18 @@ module BooticCli
22
22
  end
23
23
 
24
24
  def logged_in_action(&block)
25
+ if session.needs_upgrade?
26
+ say_status "WARNING", "old store data structure, restructuring to support multiple environments"
27
+ session.upgrade!
28
+ end
29
+
25
30
  if !session.setup?
26
- say_status "ERROR", "No app credentials. Run btc setup", :red
31
+ say_status "ERROR", "No app credentials. Run btc setup -e #{options[:environment]}", :red
27
32
  return
28
33
  end
29
34
 
30
35
  if !session.logged_in?
31
- say_status "ERROR", "No access token. Run btc login", :red
36
+ say_status "ERROR", "No access token. Run btc login -e #{options[:environment]}", :red
32
37
  return
33
38
  end
34
39
 
@@ -8,6 +8,14 @@ module BooticCli
8
8
  @store = store
9
9
  end
10
10
 
11
+ def needs_upgrade?
12
+ store.needs_upgrade?
13
+ end
14
+
15
+ def upgrade!
16
+ store.upgrade!
17
+ end
18
+
11
19
  def setup?
12
20
  store.transaction do
13
21
  store['client_id'] && store['client_secret']
@@ -22,10 +30,14 @@ module BooticCli
22
30
  setup? && logged_in?
23
31
  end
24
32
 
25
- def setup(client_id, client_secret)
33
+ def setup(client_id, client_secret, auth_host: nil, api_root: nil)
34
+ upgrade!
35
+
26
36
  store.transaction do
27
37
  store['client_id'] = client_id
28
38
  store['client_secret'] = client_secret
39
+ store['auth_host'] = auth_host if auth_host
40
+ store['api_root'] = api_root if api_root
29
41
  end
30
42
  end
31
43
 
@@ -49,11 +61,14 @@ module BooticCli
49
61
 
50
62
  def config
51
63
  @config ||= store.transaction do
52
- {
64
+ h = {
53
65
  client_id: store['client_id'],
54
66
  client_secret: store['client_secret'],
55
67
  access_token: store['access_token']
56
68
  }
69
+ h[:auth_host] = store['auth_host'] if store['auth_host']
70
+ h[:api_root] = store['api_root'] if store['api_root']
71
+ h
57
72
  end
58
73
  end
59
74
 
@@ -77,6 +92,8 @@ module BooticCli
77
92
  @client ||= begin
78
93
  raise "First setup credentials and log in" unless ready?
79
94
  BooticClient.configure do |c|
95
+ c.auth_host = config[:auth_host] if config[:auth_host]
96
+ c.api_root = config[:api_root] if config[:api_root]
80
97
  c.client_id = config[:client_id]
81
98
  c.client_secret = config[:client_secret]
82
99
  c.logger = Logger.new(STDOUT)
@@ -98,7 +115,7 @@ module BooticCli
98
115
  @oauth_client ||= OAuth2::Client.new(
99
116
  config[:client_id],
100
117
  config[:client_secret],
101
- site: BooticClient.auth_host
118
+ site: (config[:auth_host] || BooticClient.auth_host)
102
119
  )
103
120
  end
104
121
 
@@ -4,21 +4,26 @@ require 'pstore'
4
4
  module BooticCli
5
5
 
6
6
  class Store
7
-
7
+ VERSION = 1
8
+ DEFAULT_NAMESPACE = 'production'.freeze
8
9
  DIRNAME = '.btc'.freeze
9
10
  FILE_NAME = 'store.pstore'.freeze
10
11
 
11
- def initialize(base_dir = ENV['HOME'], dir = DIRNAME)
12
+ def initialize(base_dir: ENV['HOME'], dir: DIRNAME, namespace: DEFAULT_NAMESPACE)
12
13
  @base_dir = File.join(base_dir, dir)
14
+ @namespace = namespace
13
15
  FileUtils.mkdir_p @base_dir
14
16
  end
15
17
 
16
18
  def []=(k, v)
17
- store[k] = v
19
+ hash = store[namespace] || {}
20
+ hash[k] = v
21
+ store[namespace] = hash
18
22
  end
19
23
 
20
24
  def [](k)
21
- store[k]
25
+ hash = store[namespace] || {}
26
+ hash[k]
22
27
  end
23
28
 
24
29
  def transaction(&block)
@@ -29,9 +34,34 @@ module BooticCli
29
34
  FileUtils.rm_rf base_dir
30
35
  end
31
36
 
37
+ def needs_upgrade?
38
+ transaction do
39
+ store['version'].to_i < VERSION && store[DEFAULT_NAMESPACE].nil?
40
+ end
41
+ end
42
+
43
+ def upgrade!
44
+ return unless needs_upgrade?
45
+
46
+ transaction do
47
+ current_values = {}
48
+ store.roots.each do |r|
49
+ v = store[r]
50
+ store.delete(r)
51
+ current_values[r] = v
52
+ end
53
+
54
+ current_values.each do |k, v|
55
+ self[k] = v
56
+ end
57
+
58
+ self['version'] = VERSION
59
+ end
60
+ end
61
+
32
62
  private
33
63
 
34
- attr_reader :base_dir
64
+ attr_reader :base_dir, :namespace
35
65
 
36
66
  def store
37
67
  @store ||= PStore.new(File.join(base_dir, FILE_NAME))
@@ -1,3 +1,3 @@
1
1
  module BooticCli
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootic_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Celis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-12 00:00:00.000000000 Z
11
+ date: 2017-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Bootic command line.
84
98
  email:
85
99
  - ismaelct@gmail.com