keystok 1.1.1 → 1.2.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: b171c31a96eb431336e7ddfd324cbedc3721b2ea
4
- data.tar.gz: 035f617aa25a7bf8408c4ed6f048463edfa1f4a3
3
+ metadata.gz: 96769d2e85b97bb6f18cca89c0274b40768df04c
4
+ data.tar.gz: ae029a049d8305e7f18002a951d3097c2b3b5368
5
5
  SHA512:
6
- metadata.gz: e40957f85b6070b234332594758c3052a8a188343c01d7c4257c883fcc5eaee4d5e0f9d14db37cf5ba62b8ffc536cc1e2e37b5e52cd786fbb9349c5fa01ae456
7
- data.tar.gz: bcdf6699966da5ba3f60d32fa08233d7e211a18c77dbddc717946c22abec0055c6a9c5355ae210452cd7975bb1548e66222054c8cef7bd35d39418ff8267696f
6
+ metadata.gz: b6eb31e54a784e0584b8b4849289b03e368233353056eb1638d446fbbaf139792c80c7a91c0906ad75a01aea36c3daea3a9eeca32e698557ca5706ed4a721b7a
7
+ data.tar.gz: 65c1b44253307c9d06a53b9f5e0614f9cc223440bb1fa8aadd9a1e69c4d5b4f4a3e3ac21b361044f5683549c74ea4209a59ab40fa03dced15d7d54f631c7b84c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## master (unreleased)
4
4
 
5
+ ## 1.2.0 (2014-05-07)
6
+
7
+ ### Changes
8
+ * **connection_string** renamed to less confusing **access_token**.
9
+ Please note that **connection_string** is not deprecated in config files
10
+ and it will be still suppoerted except CLI long option name.
11
+ However it will not be mentioned in documentation anymore.
12
+
5
13
  ## 1.1.1 (2014-05-05)
6
14
 
7
15
  ### Bugfixes
data/README.md CHANGED
@@ -12,7 +12,7 @@
12
12
  require 'yaml' # Config is then easier
13
13
  config = YAML.load_file('keystok.yml')
14
14
  # or config can be just hash:
15
- # config = { connection_string: 'das21312312_connection_string',
15
+ # config = { access_token: 'das21312312_access_token',
16
16
  # api_host: 'https://api_custom_domain.keystok.com'
17
17
  # }
18
18
  keystok = Keystok::Client.new(config)
@@ -29,7 +29,7 @@ Add keystok to Gemfile:
29
29
 
30
30
  Keystok have generator that can create config, initializer and .gitignore entry for you
31
31
 
32
- rails g keystok:install connection_string_value
32
+ rails g keystok:install access_token_value
33
33
 
34
34
  In Rails env Keystok will use Rails.logger. Without Rails it will default to logging to STDOUT.
35
35
  If you would like to define your own logger you can do it like:
@@ -42,9 +42,9 @@ If you would like to define your own logger you can do it like:
42
42
 
43
43
  Those values are not needed by default. It can be required if you are using separated Keystok servers
44
44
 
45
- ### connection_string
45
+ ### access_token
46
46
 
47
- This value is visible in app page in Keystok service
47
+ This value is visible in **API Access** app tab in Keystok.com
48
48
 
49
49
  ### eager_fetching
50
50
 
@@ -89,10 +89,10 @@ Get all keys with content in CSV format:
89
89
 
90
90
  $ keystok_rb -a dump
91
91
 
92
- By default **keystok_rb** search for file with connection string in *~/.keystok.yml*. File format is just:
92
+ By default **keystok_rb** search for file with access token in *~/.keystok.yml*. File format is just:
93
93
 
94
94
  ---
95
- :connection_string: connection_string_value
95
+ :access_token: access_token_value
96
96
 
97
97
  It's named keystok_rb to not interfere with other SDK's and you are free to create symlink or RVM wrapper with any name you want.
98
98
 
@@ -104,18 +104,18 @@ Possible values:
104
104
  * dump - get all keys with content and print output
105
105
  * get - print key content or list keys if **-k** is not used (default)
106
106
 
107
- #### -c --connection-string
107
+ #### -c --access-token
108
108
 
109
- Specify connection string
109
+ Specify access token
110
110
 
111
- #### -f --connection-string-file
111
+ #### -f --access-token-file
112
112
 
113
- Specify connection string filepath (default is *~/.keystok.yml*)
113
+ Specify access token filepath (default is *~/.keystok.yml*)
114
114
  Example file format:
115
115
 
116
116
  ---
117
- :connection_string: connection_string_value
118
-
117
+ :access_token: access_token_value
118
+
119
119
  NOTE: **-c** have higher precedence than **-f**
120
120
 
121
121
  #### -k --key-id
@@ -8,9 +8,9 @@ module Keystok
8
8
  # Generator that creates config file and initializer
9
9
  # It also add config file to .gitignore
10
10
  class InstallGenerator < Rails::Generators::Base
11
- argument :connection_string,
11
+ argument :access_token,
12
12
  type: :string,
13
- banner: 'connection_string'
13
+ banner: 'access_string'
14
14
 
15
15
  source_root File.expand_path('../templates', __FILE__)
16
16
 
@@ -1,10 +1,10 @@
1
1
  ---
2
2
  :production:
3
- :connection_string: <%= connection_string %>
3
+ :access_token: <%= access_token %>
4
4
  :tmp_dir: 'tmp'
5
5
  :development:
6
- :connection_string: <%= connection_string %>
6
+ :access_token: <%= access_token %>
7
7
  :tmp_dir: 'tmp'
8
8
  :test:
9
- :connection_string: <%= connection_string %>
9
+ :access_token: <%= access_token %>
10
10
  :tmp_dir: 'tmp'
data/lib/keystok/cli.rb CHANGED
@@ -11,18 +11,15 @@ module Keystok
11
11
  class CLI
12
12
  def run(args = ARGV)
13
13
  options = parse(args)
14
- if options.connection_string
15
- connection_string = options.connection_string
14
+ access_token = options.access_token if options.access_token
15
+ if !access_token && options.access_token_filepath
16
+ access_token = YAML.load_file(options.access_token_filepath)
16
17
  end
17
- if !connection_string && options.connection_string_filepath
18
- connection_string = YAML.load_file(
19
- options.connection_string_filepath)['connection_string']
20
- end
21
- if connection_string.nil?
18
+ if access_token.nil?
22
19
  puts 'You have to use -c or -f option'
23
20
  exit 1
24
21
  end
25
- client = Keystok::Client.new(connection_string)
22
+ client = Keystok::Client.new(access_token)
26
23
  case options.command
27
24
  when :dump
28
25
  puts dump_data(client.keys, options.dump_format)
@@ -73,7 +70,7 @@ module Keystok
73
70
  def parse(args = [])
74
71
  options = OpenStruct.new
75
72
  options.command = :get
76
- options.connection_string_filepath = File.expand_path('~/.keystok.yml')
73
+ options.access_token_filepath = File.expand_path('~/.keystok.yml')
77
74
  options.dump_format = :csv
78
75
  opts_parser = OptionParser.new do |opts|
79
76
  opts.banner = 'Usage: keystok_rb [options] COMMAND'
@@ -83,14 +80,14 @@ module Keystok
83
80
  'Action to perform (dump, get, keys)') do |ext|
84
81
  options.command = ext
85
82
  end
86
- opts.on('-c', '--connection-string [CONNECTION_STRING]',
87
- 'Use CONNECTION_STRING when contacting Keystok API') do |ext|
88
- options.connection_string = ext
83
+ opts.on('-c', '--access-token [access_token]',
84
+ 'Use access_token when contacting Keystok API') do |ext|
85
+ options.access_token = ext
89
86
  end
90
- opts.on('-f', '--connection-string-file [FILE_PATH]',
91
- 'Use content of file at FILE_PATH as connection string',
87
+ opts.on('-f', '--access-token-file [FILE_PATH]',
88
+ 'Use content of file at FILE_PATH as access token',
92
89
  ' when contacting Keystok API') do |ext|
93
- options.connection_string_filepath = ext
90
+ options.access_token_filepath = ext
94
91
  end
95
92
  opts.on('-k', '--key-id [KEY_ID]', 'When action is GET, fetch value',
96
93
  ' for this KEY_ID') do |ext|
@@ -22,7 +22,7 @@ module Keystok
22
22
  REQUEST_TRY_COUNT = 3
23
23
 
24
24
  def initialize(config = {})
25
- @config = DEFAULT_CONFIG.merge(keys_to_symbols(decode_config(config)))
25
+ @config = DEFAULT_CONFIG.merge(decode_config(config))
26
26
  @keys_store = {}
27
27
  end
28
28
 
@@ -82,44 +82,42 @@ module Keystok
82
82
  ssl: { verify: true })
83
83
  end
84
84
 
85
- def decode_config(connection_string)
86
- config_hash = connection_string
85
+ def decode_config(access_token)
86
+ config_hash = access_token
87
87
  case
88
- when connection_string.kind_of?(Hash)
89
- when connection_string.kind_of?(String)
90
- config_hash = decode_string_config(connection_string)
88
+ when access_token.kind_of?(Hash)
89
+ when access_token.kind_of?(String)
90
+ config_hash = decode_string_config(access_token)
91
91
  else
92
92
  fail Error::ConfigError, 'Unknown config format'
93
93
  end
94
- if config_hash[:connection_string]
95
- decoded_hash = decode_string_config(config_hash[:connection_string])
96
- config_hash.delete(:connection_string)
97
- config_hash = decoded_hash.merge(config_hash)
98
- end
94
+ config_hash = keys_to_symbols(config_hash)
95
+ config_hash = merge_access_token(config_hash, :connection_string)
96
+ config_hash = merge_access_token(config_hash)
99
97
  config_hash
100
98
  end
101
99
 
102
- def decode_json_string_config(connection_string)
100
+ def decode_json_string_config(access_token)
103
101
  parsed_config = nil
104
102
  begin
105
- parsed_config = JSON.parse(connection_string)
103
+ parsed_config = JSON.parse(access_token)
106
104
  # rubocop:disable HandleExceptions
107
105
  rescue JSON::ParserError
108
106
  # rubocop:enable HandleExceptions
109
107
  # Whatever may fail, we don't want to raise it.
110
108
  end
111
- parsed_config
109
+ parsed_config ? keys_to_symbols(parsed_config) : parsed_config
112
110
  end
113
111
 
114
- def decode_string_config(connection_string)
115
- return {} if connection_string == ''
116
- parsed_config = decode_json_string_config(connection_string)
112
+ def decode_string_config(access_token)
113
+ return {} if access_token == ''
114
+ parsed_config = decode_json_string_config(access_token)
117
115
  unless parsed_config
118
- decoded_string = Base64.decode64(connection_string)
116
+ decoded_string = Base64.decode64(access_token)
119
117
  parsed_config = decode_json_string_config(decoded_string)
120
118
  end
121
119
  fail Error::ConfigError, 'Unknown config format' unless parsed_config
122
- parsed_config
120
+ keys_to_symbols(parsed_config)
123
121
  end
124
122
 
125
123
  def fetch_data(key = nil)
@@ -189,6 +187,15 @@ module Keystok
189
187
  @keys_store
190
188
  end
191
189
 
190
+ def merge_access_token(config_hash, field = :access_token)
191
+ if config_hash[field]
192
+ decoded_hash = decode_string_config(config_hash[field])
193
+ config_hash.delete(field)
194
+ config_hash = decoded_hash.merge(config_hash)
195
+ end
196
+ config_hash
197
+ end
198
+
192
199
  def oauth_client
193
200
  @oauth_client ||= begin
194
201
  OAuth2::Client.new(nil, nil, site: @config[:auth_host] || AUTH_HOST)
@@ -5,5 +5,5 @@
5
5
 
6
6
  #:nodoc:
7
7
  module Keystok
8
- VERSION = '1.1.1'
8
+ VERSION = '1.2.0'
9
9
  end
@@ -0,0 +1,2 @@
1
+ ---
2
+ access_token: eyJkayI6Ijk2NTM5MWYyYmJhMzdiNDU4NjQzMWI4NjkwZDcwNDRkNWNkYzczYWRmN2RkYTUzOWY4ZGQzYTYwY2IzZTliMTIiLCJydCI6IjJjYjQ1ODNjZDhhMzk5ZjUxZGIxNWRhNTdkMDY3OTcwNmFlOTc1ZDJhYTlkM2M3MWY1ZmRkMDI1NWRkNmEwMjgiLCJpZCI6MX0=
@@ -0,0 +1,2 @@
1
+ ---
2
+ access_token: eyJkayI6Ijk2NTM5MWYyYmJhMzdiNDU4NjQzMWI4NjkwZDcwNDRkNWNkYzczYWRmN2RkYTUzOWY4ZGQzYTYwY2IzZTliMTIiLCJydCI6IjJjYjQ1ODNjZDhhMzk5ZjUxZGIxNWRhNTdkMDY3OTcwNmFlOTc1ZDJhYTlkM2M3MWY1ZmRkMDI1NWRkNmEwMjgiLCJpZCI6Mn0=
@@ -10,12 +10,12 @@ describe Keystok::CLI do
10
10
  let(:config) { { id: 1 } }
11
11
  let(:some_string) { Faker::Lorem.characters(20) }
12
12
 
13
- def connection_string(id = '00')
14
- YAML.load_file(connection_string_filepath(id))['connection_string']
13
+ def access_token(id = '00')
14
+ YAML.load_file(access_token_filepath(id))['access_token']
15
15
  end
16
16
 
17
- def connection_string_filepath(id = '00')
18
- File.expand_path("../../fixtures/connection_string_#{id}.data", __FILE__)
17
+ def access_token_filepath(id = '00')
18
+ File.expand_path("../../fixtures/access_token_#{id}.data", __FILE__)
19
19
  end
20
20
 
21
21
  def suppress_puts
@@ -48,23 +48,29 @@ describe Keystok::CLI do
48
48
  end
49
49
  end
50
50
 
51
- it 'loads connection string from file when filepath is provided' do
52
- expect_any_instance_of(Keystok::Client).to receive(:decode_config)
53
- .with(connection_string).and_call_original
54
- cli.run(["-f#{connection_string_filepath}"])
51
+ it 'loads access token from file when filepath is provided' do
52
+ expect_any_instance_of(Keystok::Client).to receive(:decode_string_config)
53
+ .with(access_token).and_call_original
54
+ cli.run(["-f#{access_token_filepath}"])
55
55
  end
56
56
 
57
- it 'sets connection string if provided' do
58
- expect_any_instance_of(Keystok::Client).to receive(:decode_config)
59
- .with(connection_string).and_call_original
60
- cli.run(["-c#{connection_string}"])
57
+ it "loads access token from legacy file with 'connection_string'" do
58
+ expect_any_instance_of(Keystok::Client).to receive(:decode_string_config)
59
+ .with(access_token).and_call_original
60
+ cli.run(["-f#{access_token_filepath('02')}"])
61
61
  end
62
62
 
63
- it 'use connection string if both with filepath are provided' do
64
- expect_any_instance_of(Keystok::Client).to receive(:decode_config)
65
- .with(connection_string).and_call_original
66
- cli.run(["-f#{connection_string_filepath('01')}",
67
- "-c#{connection_string}"])
63
+ it 'sets access token if provided' do
64
+ expect_any_instance_of(Keystok::Client).to receive(:decode_string_config)
65
+ .with(access_token).and_call_original
66
+ cli.run(["-c#{access_token}"])
67
+ end
68
+
69
+ it 'use access token if both with filepath are provided' do
70
+ expect_any_instance_of(Keystok::Client).to receive(:decode_string_config)
71
+ .with(access_token).and_call_original
72
+ cli.run(["-f#{access_token_filepath('01')}",
73
+ "-c#{access_token}"])
68
74
  end
69
75
 
70
76
  it 'reports error when no -f or -c options are used' do
@@ -77,26 +83,26 @@ describe Keystok::CLI do
77
83
 
78
84
  it "execute 'dump_data' when command is 'dump'" do
79
85
  expect(cli).to receive(:dump_data).and_call_original
80
- cli.run(["-c#{connection_string}", '-adump'])
86
+ cli.run(["-c#{access_token}", '-adump'])
81
87
  end
82
88
 
83
89
  it "execute 'get' on client when command is 'get' with '-k'" do
84
90
  expect_any_instance_of(Keystok::Client).to receive(:get)
85
91
  .and_call_original
86
- cli.run(["-c#{connection_string}", '-aget', '-kmy_key'])
92
+ cli.run(["-c#{access_token}", '-aget', '-kmy_key'])
87
93
  end
88
94
 
89
95
  it "execute 'format_keys' when command is 'get' without key_id" do
90
96
  expect_any_instance_of(Keystok::Client).to receive(:keys)
91
97
  .and_call_original
92
98
  expect(cli).to receive(:format_keys_list)
93
- cli.run(["-c#{connection_string}", '-aget'])
99
+ cli.run(["-c#{access_token}", '-aget'])
94
100
  end
95
101
 
96
102
  it "execute 'format_keys_list' when command is unknown" do
97
103
  expect($stdout).to receive(:puts).with('Unknown command: ')
98
104
  expect do
99
- cli.run(["-c#{connection_string}", '-asomething_else'])
105
+ cli.run(["-c#{access_token}", '-asomething_else'])
100
106
  end.to raise_error { |error|
101
107
  expect(error).to be_a(SystemExit)
102
108
  expect(error.status).to eq(1)
@@ -181,7 +187,7 @@ describe Keystok::CLI do
181
187
  context 'default values' do
182
188
  [['command', :get],
183
189
  ['dump_format', :csv],
184
- ['connection_string_filepath', File.expand_path('~/.keystok.yml')]
190
+ ['access_token_filepath', File.expand_path('~/.keystok.yml')]
185
191
  ].each do |property, value|
186
192
  it "for '#{property}' is '#{value.inspect}'" do
187
193
  expect(cli.send(:parse, []).send(property)).to eq(value)
@@ -213,8 +219,8 @@ describe Keystok::CLI do
213
219
  end
214
220
  end
215
221
 
216
- [%w(connection-string c connection_string),
217
- %w(connection-string-file f connection_string_filepath),
222
+ [%w(access-token c access_token),
223
+ %w(access-token-file f access_token_filepath),
218
224
  %w(key-id k key_id)].each do |full_name, short_name, property|
219
225
  context "--#{full_name}" do
220
226
  it "set '#{property}'" do
@@ -36,7 +36,7 @@ describe Keystok::Client do
36
36
  it 'allow initialization with empty config' do
37
37
  Keystok::Client.new
38
38
  Keystok::Client.new('')
39
- Keystok::Client.new(connection_string: '', tmp_dir: 'tmp')
39
+ Keystok::Client.new(access_token: '', tmp_dir: 'tmp')
40
40
  end
41
41
 
42
42
  describe 'default for' do
@@ -247,26 +247,34 @@ describe Keystok::Client do
247
247
  end
248
248
 
249
249
  context 'config parsing' do
250
- let(:config_hash) { { 'api_host' => 'http://dum.my', 'some_data' => 2 } }
250
+ let(:config_hash) { { api_host: 'http://dum.my', some_data: 2 } }
251
251
  describe 'decode_config' do
252
252
  it "returns input if it's a hash" do
253
253
  expect(client.send(:decode_config, config_hash)).to eq(config_hash)
254
254
  end
255
255
 
256
- it 'decodes connection string and merges it to the config hash' do
257
- config_with_connection_string = {
258
- connection_string: Base64.urlsafe_encode64(config_hash.to_json)
256
+ it 'decodes access token and merges it to the config hash' do
257
+ config_with_access_token = {
258
+ access_token: Base64.urlsafe_encode64(config_hash.to_json)
259
259
  }
260
260
  expect(client.send(:decode_config,
261
- config_with_connection_string)).to eq(config_hash)
261
+ config_with_access_token)).to eq(config_hash)
262
262
  end
263
263
 
264
- it "raise ConfigError when connection string can't be decoded" do
265
- config_with_connection_string = {
264
+ it "decodes access token when legacy 'connection_string' is used" do
265
+ config_with_access_token = {
266
266
  connection_string: Base64.urlsafe_encode64(config_hash.to_json)
267
267
  }
268
268
  expect(client.send(:decode_config,
269
- config_with_connection_string)).to eq(config_hash)
269
+ config_with_access_token)).to eq(config_hash)
270
+ end
271
+
272
+ it "raise ConfigError when access token can't be decoded" do
273
+ config_with_access_token = {
274
+ access_token: Base64.urlsafe_encode64(config_hash.to_json)
275
+ }
276
+ expect(client.send(:decode_config,
277
+ config_with_access_token)).to eq(config_hash)
270
278
  end
271
279
 
272
280
  it "returns hash if it's a JSON string" do
@@ -41,7 +41,7 @@ describe 'Rails integration' do
41
41
  end
42
42
 
43
43
  it 'creates initializer' do
44
- Keystok::Generators::InstallGenerator.start(['connection_string'],
44
+ Keystok::Generators::InstallGenerator.start(['access_token'],
45
45
  destination_root:
46
46
  destination_dir)
47
47
  expect(File.size(File.join(destination_dir,
@@ -56,7 +56,7 @@ describe 'Rails integration' do
56
56
  end
57
57
 
58
58
  before do
59
- Keystok::Generators::InstallGenerator.start(['connection_string'],
59
+ Keystok::Generators::InstallGenerator.start(['access_token'],
60
60
  destination_root:
61
61
  destination_dir)
62
62
  end
@@ -68,9 +68,9 @@ describe 'Rails integration' do
68
68
  end
69
69
 
70
70
  %w(production development test).map(&:to_sym).each do |env|
71
- it "config file have :connection_string set in #{env} environment" do
72
- expect(loaded_config[env][:connection_string])
73
- .to eq('connection_string')
71
+ it "config file have :access_token set in #{env} environment" do
72
+ expect(loaded_config[env][:access_token])
73
+ .to eq('access_token')
74
74
  end
75
75
 
76
76
  it "config file have :tmp_dir set in #{env} environment" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystok
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Sokolowski
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-05 00:00:00.000000000 Z
11
+ date: 2014-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -208,8 +208,9 @@ files:
208
208
  - lib/keystok/errors.rb
209
209
  - lib/keystok/railtie.rb
210
210
  - lib/keystok/version.rb
211
- - spec/fixtures/connection_string_00.data
212
- - spec/fixtures/connection_string_01.data
211
+ - spec/fixtures/access_token_00.data
212
+ - spec/fixtures/access_token_01.data
213
+ - spec/fixtures/access_token_02.data
213
214
  - spec/fixtures/encrypted_data_00.data
214
215
  - spec/fixtures/response_data_00.data
215
216
  - spec/functional/aes_crypto_spec.rb
@@ -245,8 +246,9 @@ signing_key:
245
246
  specification_version: 4
246
247
  summary: Keystok API client
247
248
  test_files:
248
- - spec/fixtures/connection_string_00.data
249
- - spec/fixtures/connection_string_01.data
249
+ - spec/fixtures/access_token_00.data
250
+ - spec/fixtures/access_token_01.data
251
+ - spec/fixtures/access_token_02.data
250
252
  - spec/fixtures/encrypted_data_00.data
251
253
  - spec/fixtures/response_data_00.data
252
254
  - spec/functional/aes_crypto_spec.rb
@@ -1,2 +0,0 @@
1
- ---
2
- connection_string: eyJkayI6Ijk2NTM5MWYyYmJhMzdiNDU4NjQzMWI4NjkwZDcwNDRkNWNkYzczYWRmN2RkYTUzOWY4ZGQzYTYwY2IzZTliMTIiLCJydCI6IjJjYjQ1ODNjZDhhMzk5ZjUxZGIxNWRhNTdkMDY3OTcwNmFlOTc1ZDJhYTlkM2M3MWY1ZmRkMDI1NWRkNmEwMjgiLCJpZCI6Mn0=