bwcli 1.0.0 → 2.0.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: 74d73712b88433fc3573ed6361018686b95e8e18
4
- data.tar.gz: 3705e7faae6ff8da83a0e92e85cc3dadfcc7293b
3
+ metadata.gz: ef8e740832b3c56470d00e388264cefe5c4cfed0
4
+ data.tar.gz: 694d79bd4663a392de3e750479ea5ea8041aa10c
5
5
  SHA512:
6
- metadata.gz: ba7a0d48b232ff53b3631fb9228b6a5ce5baf975459888ca21e44e1a1290f2b088a54fca2d8069a004eb84abfece61b783b1c3a4bf0104c6bc315f9bb91cc5ae
7
- data.tar.gz: caefe5b3737721cb1819932fe56c213dd852c3290d77a026f20353dca64da1e135e077d1564e35beb0313b9c204ec09c70ebc58f847f7ed0a84e00e255b48699
6
+ metadata.gz: 7c69167c5cdfa29a040411883155782e9fcaf7573646ef602a778b2ba1cfb56c7963b90a7bbda4800338d57c91dd96ff6e5aca3cedd7449b4f0fe55202b24779
7
+ data.tar.gz: c7f23b04f08e6daba85fa965080b5db1bb24385625cbc7f97870d019fb5ebadd72188030cc601bff2d149e4c6e42dffdcb460599adc788461c88c1952c30e928
data/README.md CHANGED
@@ -1,3 +1,7 @@
1
+ [![Gem Version](https://badge.fury.io/rb/bwcli.png)](http://badge.fury.io/rb/bwcli)
2
+ [![Dependency Status](https://gemnasium.com/jonathanchrisp/bwcli.png)](https://gemnasium.com/jonathanchrisp/bwcli)
3
+ [![Code Climate](https://codeclimate.com/github/jonathanchrisp/bwcli.png)](https://codeclimate.com/github/jonathanchrisp/bwcli)
4
+
1
5
  # bwcli
2
6
 
3
7
  __PLEASE NOTE THAT THIS PROJECT IS NOT OFFICIALLY SUPPORTED BY BRANDWATCH__
data/bwcli.gemspec CHANGED
@@ -1,6 +1,8 @@
1
+ require File.dirname(__FILE__) + "/lib/bwcli/version"
2
+
1
3
  Gem::Specification.new do |s|
2
4
  s.name = 'bwcli'
3
- s.version = '1.0.0'
5
+ s.version = BWCLI::VERSION
4
6
  s.date = '2013-08-15'
5
7
  s.summary = 'Brandwatch CLI'
6
8
  s.description = 'A CLI interface to interact with the Brandwatch v2 API'
data/lib/bwcli/config.rb CHANGED
@@ -41,10 +41,10 @@ module BWCLI
41
41
  conf.set_current_user options[:e], options[:u] if yes? "Would you like set this user as the current user?"
42
42
  end
43
43
 
44
- desc "switch", "Switch to user"
44
+ desc "set", "Set the current user"
45
45
  method_option :u, :banner => 'Username', :required => true
46
46
  method_option :e, :banner => 'Environment', :required => true
47
- def switch
47
+ def set
48
48
  conf.set_current_user options[:e], options[:u]
49
49
  end
50
50
 
@@ -1,4 +1,6 @@
1
1
  require 'yaml'
2
+ require "openssl"
3
+ require "digest"
2
4
 
3
5
  module BWCLI
4
6
 
@@ -10,7 +12,9 @@ module BWCLI
10
12
  @config_file = File.join(File.expand_path("~"), ".bwcli")
11
13
  @config = Hashie::Mash.new(YAML.load_file @config_file)
12
14
  rescue Errno::ENOENT
13
- abort "You dont have a .bwcli file!".red.underline
15
+ File.new(@config_file, "w")
16
+ puts "\nAs you didn't have a .bwcli file, I created one for you!\n".green
17
+ retry
14
18
  end
15
19
 
16
20
  # Add user to the config hash
@@ -21,7 +25,7 @@ module BWCLI
21
25
  def add_user env, username, pwd
22
26
  config[env] = {} unless env_exists? env
23
27
  abort "The #{username} already exists!".yellow if user_exists? env, username
24
- config[env][username] = { 'access_token' => '', 'password' => pwd }
28
+ config[env][username] = { 'access_token' => '', 'password' => encrypt_password(username, pwd) }
25
29
  write_config
26
30
  end
27
31
 
@@ -47,7 +51,7 @@ module BWCLI
47
51
  abort "There is no access token set for the current user".yellow if config.current_user.access_token.nil?
48
52
  abort "There is no environment set for the current user".yellow if config.current_user.environment.nil?
49
53
 
50
- return @bwapi ||= BWAPI::Client.new(:username => current_user.username, :password => current_user.password, :api_endpoint => api_endpoint)
54
+ return @bwapi ||= BWAPI::Client.new(:username => current_user.username, :password => decrypt_password(current_user.username, current_user.password), :api_endpoint => api_endpoint)
51
55
  end
52
56
 
53
57
  # Returns the config
@@ -85,10 +89,10 @@ module BWCLI
85
89
  # List all users within the config hash
86
90
  def list_users
87
91
  abort "You have no users within your config file!".yellow if config.empty?
88
- puts "\nUser Configuration".yellow
92
+ puts "\nUser Configuration"
89
93
  config.each do |k, v|
90
94
  next if k == 'current_user'
91
- puts "\nEnvironment: #{k}".yellow
95
+ puts "\nEnvironment: #{k}"
92
96
  print_hash_values v
93
97
  end
94
98
 
@@ -98,9 +102,13 @@ module BWCLI
98
102
  # List the current user within the config hash
99
103
  def list_current_user
100
104
  abort "You have no current user set!".yellow unless current_user_exists?
101
- puts "\nCurrent User:".yellow
105
+ puts "\nCurrent User"
102
106
  config.current_user.each do |k,v|
103
- puts "#{k.yellow}: #{v}\n" unless v.nil?
107
+ if k == 'password'
108
+ puts "#{k.yellow}: ** HIDDEN **".yellow
109
+ else
110
+ puts "#{k.yellow}: #{v}".yellow unless v.nil?
111
+ end
104
112
  end
105
113
  end
106
114
 
@@ -117,19 +125,6 @@ module BWCLI
117
125
  return bwapi
118
126
  end
119
127
 
120
- # Print out hash values
121
- def print_hash_values hash
122
- puts hash.yellow unless hash.is_a? Hash
123
- hash.each do |k, v|
124
- if v.is_a? Hash
125
- puts "User: #{k}:".yellow
126
- print_hash_values v
127
- else
128
- puts " - #{k}: #{v}"
129
- end
130
- end
131
- end
132
-
133
128
  # Resets the config to an empty hash
134
129
  def reset
135
130
  @config = {}
@@ -182,5 +177,40 @@ module BWCLI
182
177
  File.open(@config_file, "w"){|f| YAML.dump(config, f)}
183
178
  end
184
179
 
180
+ private
181
+
182
+ def encrypt_password key, pwd
183
+ key = Digest::SHA256.digest(key) if(key.kind_of?(String) && 32 != key.bytesize)
184
+ aes = OpenSSL::Cipher.new('AES-256-CBC')
185
+ aes.encrypt
186
+ aes.key = key
187
+ return aes.update(pwd) + aes.final
188
+ end
189
+
190
+ def decrypt_password key, pwd
191
+ key = Digest::SHA256.digest(key) if(key.kind_of?(String) && 32 != key.bytesize)
192
+ aes = OpenSSL::Cipher.new('AES-256-CBC')
193
+ aes.decrypt
194
+ aes.key = key
195
+ return aes.update(pwd) + aes.final
196
+ end
197
+
198
+ # Print out hash values
199
+ def print_hash_values hash
200
+ puts hash unless hash.is_a? Hash
201
+ hash.each do |k, v|
202
+ if v.is_a? Hash
203
+ puts "User:".yellow + " #{k}"
204
+ print_hash_values v
205
+ else
206
+ if k == 'password'
207
+ puts "#{k.yellow}: ** HIDDEN **"
208
+ else
209
+ puts "#{k.yellow}: #{v}\n" unless v.nil?
210
+ end
211
+ end
212
+ end
213
+ end
214
+
185
215
  end
186
216
  end
data/lib/bwcli/me.rb CHANGED
@@ -9,11 +9,12 @@ module BWCLI
9
9
  def configuration
10
10
  @configuration ||= BWCLI::Configuration.new
11
11
  end
12
+ alias :conf :configuration
12
13
  end
13
14
 
14
15
  desc "me", "Users credentials"
15
16
  def me
16
- ap configuration.oauth.me
17
+ ap conf.oauth.me
17
18
  end
18
19
  default_task :me
19
20
 
@@ -9,15 +9,16 @@ module BWCLI
9
9
  def configuration
10
10
  @configuration ||= BWCLI::Configuration.new
11
11
  end
12
+ alias :conf :configuration
12
13
  end
13
14
 
14
15
  desc "projects", "Users projects"
15
- method_option :i, :banner => 'project id', :required => false
16
+ method_option :i, :banner => 'project id', :required => false, :type => :numeric
16
17
  def projects
17
18
  if options[:i].nil?
18
- ap configuration.oauth.projects
19
+ ap conf.oauth.projects
19
20
  else
20
- configuration.oauth.project options[:i]
21
+ ap conf.oauth.project options[:i]
21
22
  end
22
23
  end
23
24
  default_task :projects
@@ -0,0 +1,3 @@
1
+ module BWCLI
2
+ VERSION = "2.0.0"
3
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bwcli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Chrisp
@@ -113,6 +113,7 @@ files:
113
113
  - lib/bwcli/configuration.rb
114
114
  - lib/bwcli/me.rb
115
115
  - lib/bwcli/projects.rb
116
+ - lib/bwcli/version.rb
116
117
  homepage: https://github.com/jonathanchrisp/bwcli
117
118
  licenses:
118
119
  - MIT