keystok 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +36 -29
- data/keystok.gemspec +1 -0
- data/lib/keystok/cli.rb +24 -4
- data/lib/keystok/version.rb +1 -1
- data/spec/functional/cli_spec.rb +87 -0
- data/test_all_rubies.sh +21 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a0cf5afc5c143742229147e90b3e1684e79d508
|
4
|
+
data.tar.gz: b660ce697b8ff1ff45c5350c2dd9414ecb765b61
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d7194ef6cb5b2cdd58fceb899d56e23c5128e60a5cb2587b62051b964e22ecc23523054f5de2f62be571df810102e9cc2521d24e1397aa17fa2c6177b5d3a31
|
7
|
+
data.tar.gz: e24946c959246fb8bf0ecf392870007688660cae2b856e30295cef159dbba492b4d0f72f4c0d22420968617244337b387eba74b30a5d7dc5c614426dcd595628
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,12 @@
|
|
2
2
|
|
3
3
|
## master (unreleased)
|
4
4
|
|
5
|
+
## 1.3.0 (2014-05-12)
|
6
|
+
|
7
|
+
### Changes
|
8
|
+
* **--init-token-file** added to eliminate a need of creating manually ~/.keystok.yml
|
9
|
+
Now it can be created along with executing normal keystok command
|
10
|
+
|
5
11
|
## 1.2.0 (2014-05-07)
|
6
12
|
|
7
13
|
### Changes
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# Keystok
|
2
2
|
|
3
|
+
## Tests status
|
3
4
|
![Build status](https://www.codeship.io/projects/65218fa0-9e09-0131-3f96-16b8a84518ac/status)
|
4
5
|
|
5
6
|
## Installation
|
@@ -10,14 +11,15 @@
|
|
10
11
|
|
11
12
|
require 'keystok'
|
12
13
|
require 'yaml' # Config is then easier
|
13
|
-
|
14
|
-
|
15
|
-
# config
|
16
|
-
#
|
17
|
-
#
|
18
|
-
|
14
|
+
|
15
|
+
keystok = Keystok::Client.new('das21312312_access_token')
|
16
|
+
# or config can be loaded from file:
|
17
|
+
# config = YAML.load_file('keystok.yml')
|
18
|
+
# keystok = Keystok::Client.new(config)
|
19
|
+
|
19
20
|
# get hash with all keys
|
20
21
|
keystok.keys
|
22
|
+
|
21
23
|
# get one key
|
22
24
|
keystok.get(key_id)
|
23
25
|
|
@@ -27,7 +29,7 @@ Add keystok to Gemfile:
|
|
27
29
|
|
28
30
|
gem 'keystok'
|
29
31
|
|
30
|
-
Keystok have generator that can create config
|
32
|
+
Keystok have generator that can create config and initializer for you
|
31
33
|
|
32
34
|
rails g keystok:install access_token_value
|
33
35
|
|
@@ -38,40 +40,40 @@ If you would like to define your own logger you can do it like:
|
|
38
40
|
|
39
41
|
## Config options description
|
40
42
|
|
41
|
-
### api_host
|
43
|
+
### **api_host**, **auth_host**
|
42
44
|
|
43
45
|
Those values are not needed by default. It can be required if you are using separated Keystok servers
|
44
46
|
|
45
|
-
### access_token
|
47
|
+
### **access_token**
|
46
48
|
|
47
49
|
This value is visible in **API Access** app tab in Keystok.com
|
48
50
|
|
49
|
-
### eager_fetching
|
51
|
+
### **eager_fetching**
|
50
52
|
|
51
|
-
When
|
53
|
+
When **true**, client will fetch all keys from API even when one was requested. This will save time
|
52
54
|
when another key will be requested, because client will not have to fetch it from API.
|
53
|
-
However in some cases like huge amount of keys or when
|
54
|
-
this option should be set to
|
55
|
+
However in some cases like huge amount of keys or when **volatile** is set,
|
56
|
+
this option should be set to **false**. Default value is **true**
|
55
57
|
|
56
|
-
### no_cache
|
58
|
+
### **no_cache**
|
57
59
|
|
58
|
-
If you don't want to use cache functionality, you can disable cache writing by setting
|
60
|
+
If you don't want to use cache functionality, you can disable cache writing by setting **no_cache** to **true** in config
|
59
61
|
|
60
|
-
### tmp_dir
|
62
|
+
### **tmp_dir**
|
61
63
|
|
62
64
|
This dir will be used to store encrypted cache which can be used when API can't be contacted
|
63
65
|
|
64
|
-
### volatile
|
66
|
+
### **volatile**
|
65
67
|
|
66
68
|
Normally when asking about key that is in local store, SDK will not perform API request to provide quicker response.
|
67
|
-
Request can be forced on per method call basis by second parameter set to
|
69
|
+
Request can be forced on per method call basis by second parameter set to **true** (default is **false**)
|
68
70
|
|
69
71
|
keystok.get('this_can_change_often', true)
|
70
72
|
|
71
|
-
However if you want SDK to make request on every request without adding
|
72
|
-
you can set
|
73
|
+
However if you want SDK to make request on every request without adding **true** to every **get** or **keys**,
|
74
|
+
you can set **volatile** to **true** in config. This will force SDK to ask API on every request.
|
73
75
|
Please note that this will may decrese performance of you app since it will require API request
|
74
|
-
and cache writing on every
|
76
|
+
and cache writing on every **get** and **keys** call
|
75
77
|
|
76
78
|
## CLI client (since v1.1.0)
|
77
79
|
|
@@ -89,7 +91,7 @@ Get all keys with content in CSV format:
|
|
89
91
|
|
90
92
|
$ keystok_rb -a dump
|
91
93
|
|
92
|
-
By default **keystok_rb** search for file with access token in
|
94
|
+
By default **keystok_rb** search for file with access token in **~/.keystok.yml**. File format is just:
|
93
95
|
|
94
96
|
---
|
95
97
|
:access_token: access_token_value
|
@@ -98,19 +100,19 @@ It's named keystok_rb to not interfere with other SDK's and you are free to crea
|
|
98
100
|
|
99
101
|
### Options
|
100
102
|
|
101
|
-
####
|
103
|
+
#### **-a** **--action**
|
102
104
|
|
103
105
|
Possible values:
|
104
106
|
* dump - get all keys with content and print output
|
105
107
|
* get - print key content or list keys if **-k** is not used (default)
|
106
108
|
|
107
|
-
####
|
109
|
+
#### **-c** **--access-token**
|
108
110
|
|
109
111
|
Specify access token
|
110
112
|
|
111
|
-
####
|
113
|
+
#### **-f** **--access-token-file**
|
112
114
|
|
113
|
-
Specify access token filepath (default is
|
115
|
+
Specify access token filepath (default is **~/.keystok.yml**)
|
114
116
|
Example file format:
|
115
117
|
|
116
118
|
---
|
@@ -118,11 +120,16 @@ Example file format:
|
|
118
120
|
|
119
121
|
NOTE: **-c** have higher precedence than **-f**
|
120
122
|
|
121
|
-
####
|
123
|
+
#### **-i** **--init-token-file**
|
124
|
+
|
125
|
+
When used with **-c** it creates token config file. It's an easy way to create config file while executing first command.
|
126
|
+
Please note that **-f** have effect on this.
|
127
|
+
|
128
|
+
#### **-k** **--key-id**
|
122
129
|
|
123
130
|
Specify which key should be fetched when action is **get**
|
124
131
|
|
125
|
-
####
|
132
|
+
#### **-t** **--dump-format-type**
|
126
133
|
|
127
134
|
Possible values:
|
128
135
|
* csv (default)
|
@@ -131,6 +138,6 @@ Possible values:
|
|
131
138
|
|
132
139
|
Prints all keys with their content in specified format
|
133
140
|
|
134
|
-
####
|
141
|
+
#### **-h** **--help**
|
135
142
|
|
136
143
|
Print help and exit
|
data/keystok.gemspec
CHANGED
@@ -25,6 +25,7 @@ EOS
|
|
25
25
|
spec.add_development_dependency 'bundler'
|
26
26
|
spec.add_development_dependency 'ffaker'
|
27
27
|
spec.add_development_dependency 'fuubar'
|
28
|
+
spec.add_development_dependency 'hashie'
|
28
29
|
spec.add_development_dependency 'pry'
|
29
30
|
spec.add_development_dependency 'rails', '>= 3.0'
|
30
31
|
spec.add_development_dependency 'rake'
|
data/lib/keystok/cli.rb
CHANGED
@@ -11,10 +11,7 @@ module Keystok
|
|
11
11
|
class CLI
|
12
12
|
def run(args = ARGV)
|
13
13
|
options = parse(args)
|
14
|
-
access_token = options
|
15
|
-
if !access_token && options.access_token_filepath
|
16
|
-
access_token = YAML.load_file(options.access_token_filepath)
|
17
|
-
end
|
14
|
+
access_token = choose_access_token(options)
|
18
15
|
if access_token.nil?
|
19
16
|
puts 'You have to use -c or -f option'
|
20
17
|
exit 1
|
@@ -33,10 +30,22 @@ module Keystok
|
|
33
30
|
puts "Unknown command: #{options.command}"
|
34
31
|
exit 1
|
35
32
|
end
|
33
|
+
if options.init_token_file && options.access_token &&
|
34
|
+
options.access_token_filepath
|
35
|
+
init_token_file(access_token, options.access_token_filepath)
|
36
|
+
end
|
36
37
|
end
|
37
38
|
|
38
39
|
private
|
39
40
|
|
41
|
+
def choose_access_token(options)
|
42
|
+
access_token = options.access_token if options.access_token
|
43
|
+
if !access_token && options.access_token_filepath
|
44
|
+
access_token = YAML.load_file(options.access_token_filepath)
|
45
|
+
end
|
46
|
+
access_token
|
47
|
+
end
|
48
|
+
|
40
49
|
def dump_data(keys, format = 'csv')
|
41
50
|
unless %w(csv json yaml).include?(format.to_s)
|
42
51
|
puts "Unknown dump format: #{format}"
|
@@ -66,6 +75,13 @@ module Keystok
|
|
66
75
|
keys.keys.sort.join("\n")
|
67
76
|
end
|
68
77
|
|
78
|
+
def init_token_file(access_token, filepath)
|
79
|
+
config = {}
|
80
|
+
config = YAML.load_file(filepath) || {} if File.exist?(filepath)
|
81
|
+
config[:access_token] = access_token
|
82
|
+
File.open(filepath, 'w') { |file| file.write(config.to_yaml) }
|
83
|
+
end
|
84
|
+
|
69
85
|
# rubocop:disable MethodLength
|
70
86
|
def parse(args = [])
|
71
87
|
options = OpenStruct.new
|
@@ -89,6 +105,10 @@ module Keystok
|
|
89
105
|
' when contacting Keystok API') do |ext|
|
90
106
|
options.access_token_filepath = ext
|
91
107
|
end
|
108
|
+
opts.on('-i', '--init-token-file', 'Create/update access token file',
|
109
|
+
'with value of \'-c\' option') do |_|
|
110
|
+
options.init_token_file = true
|
111
|
+
end
|
92
112
|
opts.on('-k', '--key-id [KEY_ID]', 'When action is GET, fetch value',
|
93
113
|
' for this KEY_ID') do |ext|
|
94
114
|
options.key_id = ext || ''
|
data/lib/keystok/version.rb
CHANGED
data/spec/functional/cli_spec.rb
CHANGED
@@ -4,6 +4,7 @@
|
|
4
4
|
# for details.
|
5
5
|
|
6
6
|
require 'spec_helper'
|
7
|
+
require 'hashie'
|
7
8
|
|
8
9
|
describe Keystok::CLI do
|
9
10
|
let(:cli) { Keystok::CLI.new }
|
@@ -108,6 +109,48 @@ describe Keystok::CLI do
|
|
108
109
|
expect(error.status).to eq(1)
|
109
110
|
}
|
110
111
|
end
|
112
|
+
|
113
|
+
context 'launch init_token_file' do
|
114
|
+
let(:tmp_access_token_filepath) do
|
115
|
+
access_token_file = Tempfile.new('keystok_tests')
|
116
|
+
FileUtils.cp(access_token_filepath, access_token_file.path)
|
117
|
+
access_token_file.path
|
118
|
+
end
|
119
|
+
|
120
|
+
it "when 'init_token_file', 'access_token' is supplied" do
|
121
|
+
expect(cli).to receive(:init_token_file).and_call_original
|
122
|
+
cli.run(["-f#{tmp_access_token_filepath}", "-c#{access_token}", '-i'])
|
123
|
+
end
|
124
|
+
|
125
|
+
it "don't run when 'init_token_file' is not set" do
|
126
|
+
expect(cli).to_not receive(:init_token_file)
|
127
|
+
cli.run(["-f#{tmp_access_token_filepath}", "-c#{access_token}"])
|
128
|
+
end
|
129
|
+
|
130
|
+
it "don't run when 'access_token' is not supplied" do
|
131
|
+
expect(cli).to_not receive(:init_token_file)
|
132
|
+
cli.run(["-f#{tmp_access_token_filepath}", '-i'])
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe 'choose_access_token' do
|
138
|
+
it "return access token passed as 'options.access_token'" do
|
139
|
+
options = Hashie::Mash.new(access_token: 'dummy_token')
|
140
|
+
expect(cli.send(:choose_access_token, options)).to eq('dummy_token')
|
141
|
+
end
|
142
|
+
|
143
|
+
it "return access token passed as 'options.access_token_filepath'" do
|
144
|
+
options = Hashie::Mash.new(access_token_filepath: access_token_filepath)
|
145
|
+
config_hash = YAML.load_file(access_token_filepath)
|
146
|
+
expect(cli.send(:choose_access_token, options)).to eq(config_hash)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "preffer 'options.access_token' over 'options.access_token_filepath'" do
|
150
|
+
options = Hashie::Mash.new(access_token: 'dummy_token',
|
151
|
+
access_token_filepath: access_token_filepath)
|
152
|
+
expect(cli.send(:choose_access_token, options)).to eq('dummy_token')
|
153
|
+
end
|
111
154
|
end
|
112
155
|
|
113
156
|
describe 'dump_data' do
|
@@ -183,6 +226,39 @@ describe Keystok::CLI do
|
|
183
226
|
end
|
184
227
|
end
|
185
228
|
|
229
|
+
describe 'init_token_file' do
|
230
|
+
let(:tmp_filepath) { Tempfile.new('keystok_tests') }
|
231
|
+
|
232
|
+
it 'writes config file' do
|
233
|
+
cli.send(:init_token_file, some_string, "#{tmp_filepath.path}_new")
|
234
|
+
loaded_file = YAML.load_file("#{tmp_filepath.path}_new")
|
235
|
+
expect(loaded_file[:access_token]).to eq(some_string)
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'writes config file even when file is empty' do
|
239
|
+
cli.send(:init_token_file, some_string, tmp_filepath.path)
|
240
|
+
loaded_file = YAML.load_file(tmp_filepath.path)
|
241
|
+
expect(loaded_file[:access_token]).to eq(some_string)
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'updates existing config file' do
|
245
|
+
tmp_filepath.write({ access_token: 'dummy' }.to_yaml)
|
246
|
+
tmp_filepath.rewind
|
247
|
+
cli.send(:init_token_file, some_string, tmp_filepath.path)
|
248
|
+
loaded_file = YAML.load_file(tmp_filepath.path)
|
249
|
+
expect(loaded_file[:access_token]).to eq(some_string)
|
250
|
+
end
|
251
|
+
|
252
|
+
it "don't change other keys in updated config file" do
|
253
|
+
tmp_filepath.write({ my_another_key: 'dummy' }.to_yaml)
|
254
|
+
tmp_filepath.rewind
|
255
|
+
cli.send(:init_token_file, some_string, tmp_filepath.path)
|
256
|
+
loaded_file = YAML.load_file(tmp_filepath.path)
|
257
|
+
expect(loaded_file[:access_token]).to eq(some_string)
|
258
|
+
expect(loaded_file[:my_another_key]).to eq('dummy')
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
186
262
|
describe 'parse' do
|
187
263
|
context 'default values' do
|
188
264
|
[['command', :get],
|
@@ -235,6 +311,17 @@ describe Keystok::CLI do
|
|
235
311
|
end
|
236
312
|
end
|
237
313
|
|
314
|
+
context '--init-token-file' do
|
315
|
+
it "set 'init_token_file'" do
|
316
|
+
expect(cli.send(:parse, %w(--init-token-file)).init_token_file)
|
317
|
+
.to eq(true)
|
318
|
+
end
|
319
|
+
|
320
|
+
it "recognize '-i'" do
|
321
|
+
expect(cli.send(:parse, ['-i']).init_token_file).to eq(true)
|
322
|
+
end
|
323
|
+
end
|
324
|
+
|
238
325
|
context '--dump-format-type' do
|
239
326
|
it "set 'dump_format'" do
|
240
327
|
expect(cli.send(:parse, %w(--dump-format-type yaml)).dump_format)
|
data/test_all_rubies.sh
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/bin/bash -e
|
2
|
+
|
3
|
+
versions=("1.9.3" "2.0.0-p353" "2.0.0-p451" "2.1.0" "2.1.1" "ruby-head")
|
4
|
+
echo "================"
|
5
|
+
echo "Installing dependencies:"
|
6
|
+
echo "================"
|
7
|
+
for version in "${versions[@]}"
|
8
|
+
do
|
9
|
+
echo "================"
|
10
|
+
echo "$version:"
|
11
|
+
rvm $version exec bundle install
|
12
|
+
done
|
13
|
+
echo "================"
|
14
|
+
echo "Running tests:"
|
15
|
+
echo "================"
|
16
|
+
for version in "${versions[@]}"
|
17
|
+
do
|
18
|
+
echo "================"
|
19
|
+
echo "$version:"
|
20
|
+
rvm $version exec bundle exec rspec spec
|
21
|
+
done
|
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.
|
4
|
+
version: 1.3.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-
|
11
|
+
date: 2014-05-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: hashie
|
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
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: pry
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -221,6 +235,7 @@ files:
|
|
221
235
|
- spec/integration/rails_integration_spec.rb
|
222
236
|
- spec/spec_helper.rb
|
223
237
|
- spec/support/webmock_helpers.rb
|
238
|
+
- test_all_rubies.sh
|
224
239
|
homepage: https://keystok.com
|
225
240
|
licenses:
|
226
241
|
- GitDock Oy
|