keystok 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +8 -2
- data/CHANGELOG.md +8 -0
- data/README.md +62 -0
- data/Rakefile +1 -1
- data/bin/keystok_rb +8 -0
- data/keystok.gemspec +1 -0
- data/lib/keystok/cache.rb +2 -2
- data/lib/keystok/cli.rb +113 -0
- data/lib/keystok/client.rb +4 -4
- data/lib/keystok/version.rb +1 -1
- data/lib/keystok.rb +2 -0
- data/spec/fixtures/connection_string_00.data +2 -0
- data/spec/fixtures/connection_string_01.data +2 -0
- data/spec/functional/cache_spec.rb +3 -3
- data/spec/functional/cli_spec.rb +260 -0
- data/spec/functional/client_spec.rb +1 -46
- data/spec/integration/rails_integration_spec.rb +2 -2
- data/spec/spec_helper.rb +6 -0
- data/spec/support/webmock_helpers.rb +48 -0
- metadata +29 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58c17d257cc3c0d2ad96cdc648f5029629b1d161
|
4
|
+
data.tar.gz: 62df792c7e1a369208e0dc8532b68d87db6e71db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 75472301c3926d79b02a49c76b7200cc1b5338aa51b2a8efad14b32e57da79f12b028b9a03b2afe10c2e5f11e94efff289a6cc5def3cf36fe895b0c7a8192bd5
|
7
|
+
data.tar.gz: eee34c8e02e55a9bec0fecc45cef379da430bc82be8d4d69e5749ea73af7ae38756814bd40730fe232a82c2f13fd6a6ec46e1d2ce0cb8e63f5fdef540f77964c
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -72,3 +72,65 @@ However if you want SDK to make request on every request without adding *true* t
|
|
72
72
|
you can set *volatile* to *true* in config. This will force SDK to ask API on every request.
|
73
73
|
Please note that this will may decrese performance of you app since it will require API request
|
74
74
|
and cache writing on every *get* and *keys* call
|
75
|
+
|
76
|
+
## CLI client (since v1.1.0)
|
77
|
+
|
78
|
+
CLI client purpose is to be able to easily use Keystok in for example shell scripts when you already have Keystok Ruby SDK installed.
|
79
|
+
### Example usage
|
80
|
+
Get key content:
|
81
|
+
|
82
|
+
$ keystok_rb -k my_key
|
83
|
+
|
84
|
+
Get keys list:
|
85
|
+
|
86
|
+
$ keystok_rb
|
87
|
+
|
88
|
+
Get all keys with content in CSV format:
|
89
|
+
|
90
|
+
$ keystok_rb -a dump
|
91
|
+
|
92
|
+
By default **keystok_rb** search for file with connection string in *~/.keystok.yml*. File format is just:
|
93
|
+
|
94
|
+
---
|
95
|
+
:connection_string: connection_string_value
|
96
|
+
|
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
|
+
|
99
|
+
### Options
|
100
|
+
|
101
|
+
#### -a --action
|
102
|
+
|
103
|
+
Possible values:
|
104
|
+
* dump - get all keys with content and print output
|
105
|
+
* get - print key content or list keys if **-k** is not used (default)
|
106
|
+
|
107
|
+
#### -c --connection-string
|
108
|
+
|
109
|
+
Specify connection string
|
110
|
+
|
111
|
+
#### -f --connection-string-file
|
112
|
+
|
113
|
+
Specify connection string filepath (default is *~/.keystok.yml*)
|
114
|
+
Example file format:
|
115
|
+
|
116
|
+
---
|
117
|
+
:connection_string: connection_string_value
|
118
|
+
|
119
|
+
NOTE: **-c** have higher precedence than **-f**
|
120
|
+
|
121
|
+
#### -k --key-id
|
122
|
+
|
123
|
+
Specify which key should be fetched when action is **get**
|
124
|
+
|
125
|
+
#### -t --dump-format-type
|
126
|
+
|
127
|
+
Possible values:
|
128
|
+
* csv (default)
|
129
|
+
* json
|
130
|
+
* yaml
|
131
|
+
|
132
|
+
Prints all keys with their content in specified format
|
133
|
+
|
134
|
+
#### -h --help
|
135
|
+
|
136
|
+
Print help and exit
|
data/Rakefile
CHANGED
data/bin/keystok_rb
ADDED
data/keystok.gemspec
CHANGED
@@ -23,6 +23,7 @@ EOS
|
|
23
23
|
spec.add_dependency 'oauth2'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler'
|
26
|
+
spec.add_development_dependency 'ffaker'
|
26
27
|
spec.add_development_dependency 'fuubar'
|
27
28
|
spec.add_development_dependency 'pry'
|
28
29
|
spec.add_development_dependency 'rails', '>= 3.0'
|
data/lib/keystok/cache.rb
CHANGED
data/lib/keystok/cli.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under GitDock Oy license terms.
|
3
|
+
# See https://bitbucket.org/keystok/keystok-client-ruby/raw/master/LICENSE.txt
|
4
|
+
# for details.
|
5
|
+
|
6
|
+
require 'optparse'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
module Keystok
|
10
|
+
# Parses command line arguments and execute requested actions
|
11
|
+
class CLI
|
12
|
+
def run(args = ARGV)
|
13
|
+
options = parse(args)
|
14
|
+
if options.connection_string
|
15
|
+
connection_string = options.connection_string
|
16
|
+
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?
|
22
|
+
puts 'You have to use -c or -f option'
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
client = Keystok::Client.new(connection_string)
|
26
|
+
case options.command
|
27
|
+
when :dump
|
28
|
+
puts dump_data(client.keys, options.dump_format)
|
29
|
+
when :get
|
30
|
+
if options.key_id
|
31
|
+
puts client.get(options.key_id)
|
32
|
+
else
|
33
|
+
puts format_keys_list(client.keys)
|
34
|
+
end
|
35
|
+
else
|
36
|
+
puts "Unknown command: #{options.command}"
|
37
|
+
exit 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def dump_data(keys, format = 'csv')
|
44
|
+
unless %w(csv json yaml).include?(format.to_s)
|
45
|
+
puts "Unknown dump format: #{format}"
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
send("dump_data_#{format}", keys)
|
49
|
+
end
|
50
|
+
|
51
|
+
def dump_data_csv(keys)
|
52
|
+
CSV.generate do |csv|
|
53
|
+
csv << %w(key_id content)
|
54
|
+
keys.each do |key_id, content|
|
55
|
+
csv << [key_id, content]
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def dump_data_json(keys)
|
61
|
+
keys.to_json
|
62
|
+
end
|
63
|
+
|
64
|
+
def dump_data_yaml(keys)
|
65
|
+
keys.to_yaml
|
66
|
+
end
|
67
|
+
|
68
|
+
def format_keys_list(keys)
|
69
|
+
keys.keys.sort.join("\n")
|
70
|
+
end
|
71
|
+
|
72
|
+
# rubocop:disable MethodLength
|
73
|
+
def parse(args = [])
|
74
|
+
options = OpenStruct.new
|
75
|
+
options.command = :get
|
76
|
+
options.connection_string_filepath = File.expand_path('~/.keystok.yml')
|
77
|
+
options.dump_format = :csv
|
78
|
+
opts_parser = OptionParser.new do |opts|
|
79
|
+
opts.banner = 'Usage: keystok_rb [options] COMMAND'
|
80
|
+
opts.separator ''
|
81
|
+
opts.separator 'Options:'
|
82
|
+
opts.on('-a', '--action [ACTION]', [:dump, :get, :keys],
|
83
|
+
'Action to perform (dump, get, keys)') do |ext|
|
84
|
+
options.command = ext
|
85
|
+
end
|
86
|
+
opts.on('-c', '--connection-string [CONNECTION_STRING]',
|
87
|
+
'Use CONNECTION_STRING when contacting Keystok API') do |ext|
|
88
|
+
options.connection_string = ext
|
89
|
+
end
|
90
|
+
opts.on('-f', '--connection-string-file [FILE_PATH]',
|
91
|
+
'Use content of file at FILE_PATH as connection string',
|
92
|
+
' when contacting Keystok API') do |ext|
|
93
|
+
options.connection_string_filepath = ext
|
94
|
+
end
|
95
|
+
opts.on('-k', '--key-id [KEY_ID]', 'When action is GET, fetch value',
|
96
|
+
' for this KEY_ID') do |ext|
|
97
|
+
options.key_id = ext || ''
|
98
|
+
end
|
99
|
+
opts.on('-t', '--dump-format-type [TYPE]', [:csv, :json, :yaml],
|
100
|
+
'Format of data dump file (csv, json, yaml)') do |ext|
|
101
|
+
options.dump_format = ext
|
102
|
+
end
|
103
|
+
opts.on_tail('-h', '--help', 'Show this message') do
|
104
|
+
puts opts
|
105
|
+
exit
|
106
|
+
end
|
107
|
+
end
|
108
|
+
opts_parser.parse!(args)
|
109
|
+
options
|
110
|
+
end
|
111
|
+
# rubocop:enable MethodLength
|
112
|
+
end
|
113
|
+
end
|
data/lib/keystok/client.rb
CHANGED
@@ -165,19 +165,19 @@ module Keystok
|
|
165
165
|
response = fetch_data(key)
|
166
166
|
if response.status == 200
|
167
167
|
response_data = response.body
|
168
|
-
elsif
|
168
|
+
elsif cache_file_exist?
|
169
169
|
response_data = load_cache
|
170
170
|
else
|
171
171
|
fail Keystok::Error::ConnectionError,
|
172
|
-
"No cache data and response code:\n"
|
172
|
+
"No cache data and response code:\n" \
|
173
173
|
"#{response.status} with body: #{response.body}"
|
174
174
|
end
|
175
175
|
rescue Faraday::Error::ClientError => exception
|
176
|
-
if
|
176
|
+
if cache_file_exist?
|
177
177
|
response_data = load_cache
|
178
178
|
else
|
179
179
|
raise Keystok::Error::ConnectionError,
|
180
|
-
"No cache data and connection error:\n"
|
180
|
+
"No cache data and connection error:\n" \
|
181
181
|
"#{exception.class} with message: #{exception.message}"
|
182
182
|
end
|
183
183
|
end
|
data/lib/keystok/version.rb
CHANGED
data/lib/keystok.rb
CHANGED
@@ -3,6 +3,7 @@
|
|
3
3
|
# See https://bitbucket.org/keystok/keystok-client-ruby/raw/master/LICENSE.txt
|
4
4
|
# for details.
|
5
5
|
|
6
|
+
require 'csv'
|
6
7
|
require 'faraday'
|
7
8
|
require 'json'
|
8
9
|
require 'logger'
|
@@ -10,6 +11,7 @@ require 'yaml'
|
|
10
11
|
|
11
12
|
require 'keystok/version'
|
12
13
|
require 'keystok/errors'
|
14
|
+
require 'keystok/cli'
|
13
15
|
require 'keystok/client'
|
14
16
|
|
15
17
|
#:nodoc:
|
@@ -43,19 +43,19 @@ describe Keystok::Cache do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
describe '
|
46
|
+
describe 'cache_file_exist?' do
|
47
47
|
before do
|
48
48
|
dummy.config = { tmp_dir: tmp_dir }
|
49
49
|
end
|
50
50
|
|
51
51
|
it 'returns true if file exists' do
|
52
52
|
FileUtils.touch(tmp_filepath)
|
53
|
-
expect(dummy.
|
53
|
+
expect(dummy.cache_file_exist?).to eq(true)
|
54
54
|
end
|
55
55
|
|
56
56
|
it 'returns false if file not exists' do
|
57
57
|
FileUtils.rm_f(tmp_filepath)
|
58
|
-
expect(dummy.
|
58
|
+
expect(dummy.cache_file_exist?).to eq(false)
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -0,0 +1,260 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# This file is distributed under GitDock Oy license terms.
|
3
|
+
# See https://bitbucket.org/keystok/keystok-client-ruby/raw/master/LICENSE.txt
|
4
|
+
# for details.
|
5
|
+
|
6
|
+
require 'spec_helper'
|
7
|
+
|
8
|
+
describe Keystok::CLI do
|
9
|
+
let(:cli) { Keystok::CLI.new }
|
10
|
+
let(:config) { { id: 1 } }
|
11
|
+
let(:some_string) { Faker::Lorem.characters(20) }
|
12
|
+
|
13
|
+
def connection_string(id = '00')
|
14
|
+
YAML.load_file(connection_string_filepath(id))['connection_string']
|
15
|
+
end
|
16
|
+
|
17
|
+
def connection_string_filepath(id = '00')
|
18
|
+
File.expand_path("../../fixtures/connection_string_#{id}.data", __FILE__)
|
19
|
+
end
|
20
|
+
|
21
|
+
def suppress_puts
|
22
|
+
allow($stdout).to receive(:puts)
|
23
|
+
end
|
24
|
+
|
25
|
+
before do
|
26
|
+
suppress_puts
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'run' do
|
30
|
+
before do
|
31
|
+
stub_deployment_req(API_HOST, request_path)
|
32
|
+
stub_request(:post, KEYSTOK_OAUTH_REFRESH_URL)
|
33
|
+
.to_return(status: 200, body: refresh_response,
|
34
|
+
headers: { 'Content-Type' => 'application/json' })
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'use ARGV by default' do
|
38
|
+
begin
|
39
|
+
original_argv = ARGV
|
40
|
+
ARGV.clear
|
41
|
+
ARGV << '-czzaaqq'
|
42
|
+
expect { cli.run }.to raise_error(Keystok::Error::ConfigError)
|
43
|
+
ensure
|
44
|
+
ARGV.clear
|
45
|
+
original_argv.each do |arg|
|
46
|
+
ARGV << arg
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
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}"])
|
55
|
+
end
|
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}"])
|
61
|
+
end
|
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}"])
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'reports error when no -f or -c options are used' do
|
71
|
+
expect($stdout).to receive(:puts).with('You have to use -c or -f option')
|
72
|
+
expect { cli.run(['-f']) }.to raise_error { |error|
|
73
|
+
expect(error).to be_a(SystemExit)
|
74
|
+
expect(error.status).to eq(1)
|
75
|
+
}
|
76
|
+
end
|
77
|
+
|
78
|
+
it "execute 'dump_data' when command is 'dump'" do
|
79
|
+
expect(cli).to receive(:dump_data).and_call_original
|
80
|
+
cli.run(["-c#{connection_string}", '-adump'])
|
81
|
+
end
|
82
|
+
|
83
|
+
it "execute 'get' on client when command is 'get' with '-k'" do
|
84
|
+
expect_any_instance_of(Keystok::Client).to receive(:get)
|
85
|
+
.and_call_original
|
86
|
+
cli.run(["-c#{connection_string}", '-aget', '-kmy_key'])
|
87
|
+
end
|
88
|
+
|
89
|
+
it "execute 'format_keys' when command is 'get' without key_id" do
|
90
|
+
expect_any_instance_of(Keystok::Client).to receive(:keys)
|
91
|
+
.and_call_original
|
92
|
+
expect(cli).to receive(:format_keys_list)
|
93
|
+
cli.run(["-c#{connection_string}", '-aget'])
|
94
|
+
end
|
95
|
+
|
96
|
+
it "execute 'format_keys_list' when command is unknown" do
|
97
|
+
expect($stdout).to receive(:puts).with('Unknown command: ')
|
98
|
+
expect do
|
99
|
+
cli.run(["-c#{connection_string}", '-asomething_else'])
|
100
|
+
end.to raise_error { |error|
|
101
|
+
expect(error).to be_a(SystemExit)
|
102
|
+
expect(error.status).to eq(1)
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'dump_data' do
|
108
|
+
it 'defaults to :csv' do
|
109
|
+
expect(cli).to receive(:dump_data_csv).with({})
|
110
|
+
cli.send(:dump_data, {})
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'exits 1 on unknown format' do
|
114
|
+
expect($stdout).to receive(:puts).with('Unknown dump format: yaml2')
|
115
|
+
expect { cli.send(:dump_data, {}, :yaml2) }.to raise_error { |error|
|
116
|
+
expect(error).to be_a(SystemExit)
|
117
|
+
expect(error.status).to eq(1)
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
%w(csv json yaml).each do |format|
|
122
|
+
it "execute 'dump_data_#{format}' on '#{format}' format" do
|
123
|
+
expect(cli).to receive("dump_data_#{format}")
|
124
|
+
cli.send(:dump_data, {}, format)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context do
|
130
|
+
let(:keys) do
|
131
|
+
hash = {}
|
132
|
+
4.times do
|
133
|
+
hash[Faker::Lorem.characters(rand(8) + 8)] = Faker::Lorem.sentence
|
134
|
+
end
|
135
|
+
hash
|
136
|
+
end
|
137
|
+
|
138
|
+
describe 'dump_data_csv' do
|
139
|
+
it 'produces valid csv output' do
|
140
|
+
output = cli.send(:dump_data_csv, keys)
|
141
|
+
hash = {}
|
142
|
+
CSV.parse(output, headers: true) do |row|
|
143
|
+
hash[row['key_id']] = row['content']
|
144
|
+
end
|
145
|
+
expect(hash).to eq(keys)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'dump_data_json' do
|
150
|
+
it 'produces valid json output' do
|
151
|
+
output = cli.send(:dump_data_json, keys)
|
152
|
+
hash = JSON.parse(output)
|
153
|
+
expect(hash).to eq(keys)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'dump_data_yaml' do
|
158
|
+
it 'produces valid yaml output' do
|
159
|
+
output = cli.send(:dump_data_yaml, keys)
|
160
|
+
hash = YAML.load(output)
|
161
|
+
expect(hash).to eq(keys)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'format_keys_list' do
|
167
|
+
it 'return key names in separate lines' do
|
168
|
+
keys = { a_key: 10, b_key: 20 }
|
169
|
+
output = cli.send(:format_keys_list, keys)
|
170
|
+
expect(output).to eq(keys.keys.join("\n"))
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'return key names in alphabetical order' do
|
174
|
+
keys = { b_key: 20, a_key: 10 }
|
175
|
+
output = cli.send(:format_keys_list, keys)
|
176
|
+
expect(output).to eq(keys.keys.sort.join("\n"))
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe 'parse' do
|
181
|
+
context 'default values' do
|
182
|
+
[['command', :get],
|
183
|
+
['dump_format', :csv],
|
184
|
+
['connection_string_filepath', File.expand_path('~/.keystok.yml')]
|
185
|
+
].each do |property, value|
|
186
|
+
it "for '#{property}' is '#{value.inspect}'" do
|
187
|
+
expect(cli.send(:parse, []).send(property)).to eq(value)
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'works without argument' do
|
193
|
+
expect { cli.send(:parse) }.to_not raise_error
|
194
|
+
end
|
195
|
+
|
196
|
+
context '--action' do
|
197
|
+
it "set 'command'" do
|
198
|
+
expect(cli.send(:parse, %w(--action get)).command).to eq(:get)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "recognize '-a'" do
|
202
|
+
expect(cli.send(:parse, ['-aget']).command).to eq(:get)
|
203
|
+
end
|
204
|
+
|
205
|
+
%w(dump get keys).map(&:to_sym).each do |action|
|
206
|
+
it "accept '#{action}' command" do
|
207
|
+
expect(cli.send(:parse, ["-a#{action}"]).command).to eq(action)
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
it "don't allow custom actions" do
|
212
|
+
expect(cli.send(:parse, ['-aget2']).command).to be_nil
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
[%w(connection-string c connection_string),
|
217
|
+
%w(connection-string-file f connection_string_filepath),
|
218
|
+
%w(key-id k key_id)].each do |full_name, short_name, property|
|
219
|
+
context "--#{full_name}" do
|
220
|
+
it "set '#{property}'" do
|
221
|
+
expect(cli.send(:parse, ["--#{full_name}", some_string])
|
222
|
+
.send(property)).to eq(some_string)
|
223
|
+
end
|
224
|
+
|
225
|
+
it "recognize '-#{short_name}'" do
|
226
|
+
expect(cli.send(:parse, ["-#{short_name}#{some_string}"])
|
227
|
+
.send(property)).to eq(some_string)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context '--dump-format-type' do
|
233
|
+
it "set 'dump_format'" do
|
234
|
+
expect(cli.send(:parse, %w(--dump-format-type yaml)).dump_format)
|
235
|
+
.to eq(:yaml)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "recognize '-t'" do
|
239
|
+
expect(cli.send(:parse, ['-tyaml']).dump_format).to eq(:yaml)
|
240
|
+
end
|
241
|
+
|
242
|
+
%w(csv json yaml).map(&:to_sym).each do |format|
|
243
|
+
it "accept '#{format}' format" do
|
244
|
+
expect(cli.send(:parse, ["-t#{format}"]).dump_format).to eq(format)
|
245
|
+
end
|
246
|
+
|
247
|
+
end
|
248
|
+
it "don't allow custom formats" do
|
249
|
+
expect(cli.send(:parse, ['-tyaml2']).dump_format).to be_nil
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
it "exit clean on '-h'" do
|
254
|
+
expect { cli.send(:parse, ['-h']) }.to raise_error { |error|
|
255
|
+
expect(error).to be_a(SystemExit)
|
256
|
+
expect(error.status).to eq(0)
|
257
|
+
}
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
@@ -7,36 +7,6 @@ require 'spec_helper'
|
|
7
7
|
require 'fileutils'
|
8
8
|
|
9
9
|
describe Keystok::Client do
|
10
|
-
DECRYPTION_KEY =
|
11
|
-
'965391f2bba37b4586431b8690d7044d5cdc73adf7dda539f8dd3a60cb3e9b12'
|
12
|
-
API_HOST = 'https://api.keystok.com'
|
13
|
-
|
14
|
-
def request_url(host = nil, path = nil)
|
15
|
-
host ||= config[:api_host]
|
16
|
-
path ||= request_path
|
17
|
-
"#{host}/#{path}"
|
18
|
-
end
|
19
|
-
|
20
|
-
def override_config_key(key, value = nil)
|
21
|
-
config_tmp = client.instance_variable_get('@config')
|
22
|
-
config_tmp[key] = value
|
23
|
-
client.instance_variable_set('@config', config_tmp)
|
24
|
-
end
|
25
|
-
|
26
|
-
def request_path(key = nil)
|
27
|
-
if key
|
28
|
-
key_path = "/#{key}"
|
29
|
-
else
|
30
|
-
key_path = ''
|
31
|
-
end
|
32
|
-
"apps/#{config[:id]}/deploy#{key_path}?access_token=#{refreshed_token}"
|
33
|
-
end
|
34
|
-
|
35
|
-
def stub_deployment_req(host = nil, path = nil)
|
36
|
-
stub_request(:get, request_url(host, path))
|
37
|
-
.to_return(status: 200, body: example_response, headers: {})
|
38
|
-
end
|
39
|
-
|
40
10
|
let(:config) do
|
41
11
|
{ api_host: 'https://api.keystok-host.com',
|
42
12
|
auth_host: 'https://keystok-host.com',
|
@@ -46,21 +16,6 @@ describe Keystok::Client do
|
|
46
16
|
tmp_dir: tmp_dir }
|
47
17
|
end
|
48
18
|
let(:client) { Keystok::Client.new(config) }
|
49
|
-
let(:example_response) do
|
50
|
-
File.open(File.expand_path('../../fixtures/response_data_00.data',
|
51
|
-
__FILE__)).read
|
52
|
-
end
|
53
|
-
let(:keystok_oauth_refresh_url) { 'https://keystok.com/oauth/token' }
|
54
|
-
let(:oauth_refresh_url) { "#{config[:auth_host]}/oauth/token" }
|
55
|
-
let(:refresh_response) do
|
56
|
-
{
|
57
|
-
'access_token' => refreshed_token,
|
58
|
-
'token_type' => 'bearer', 'expires_in' => 124
|
59
|
-
}.to_json
|
60
|
-
end
|
61
|
-
let(:refreshed_token) do
|
62
|
-
'2cb4583cd8a399f51db15da57d0679706ae975d2aa9d3c71f5fdd0255dd6a028'
|
63
|
-
end
|
64
19
|
let(:tmp_dir) { File.expand_path('../../../tmp', __FILE__) }
|
65
20
|
let(:tmp_filepath) { File.join(tmp_dir, 'keystok_cache.data') }
|
66
21
|
|
@@ -73,7 +28,7 @@ describe Keystok::Client do
|
|
73
28
|
headers: { 'Content-Type' => 'application/json' })
|
74
29
|
# Keystok URL's
|
75
30
|
stub_deployment_req(API_HOST, request_path)
|
76
|
-
stub_request(:post,
|
31
|
+
stub_request(:post, KEYSTOK_OAUTH_REFRESH_URL)
|
77
32
|
.to_return(status: 200, body: refresh_response,
|
78
33
|
headers: { 'Content-Type' => 'application/json' })
|
79
34
|
end
|
@@ -18,8 +18,8 @@ describe 'Rails integration' do
|
|
18
18
|
|
19
19
|
describe 'logger' do
|
20
20
|
it 'is using Rails.logger when Rails is defined' do
|
21
|
-
initializer = Keystok::Railtie.initializers.find do |
|
22
|
-
|
21
|
+
initializer = Keystok::Railtie.initializers.find do |initializer_tmp|
|
22
|
+
initializer_tmp.name == 'keystok.configure_rails_initialization'
|
23
23
|
end
|
24
24
|
initializer.run
|
25
25
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
SimpleCov.profiles.define 'keystok-client-ruby' do
|
3
|
+
add_filter 'bin/keystok_rb'
|
3
4
|
add_filter 'lib/keystok.rb'
|
4
5
|
add_filter 'spec'
|
5
6
|
end
|
6
7
|
SimpleCov.start 'keystok-client-ruby'
|
7
8
|
|
8
9
|
require 'webmock/rspec'
|
10
|
+
require 'ffaker'
|
9
11
|
require 'keystok'
|
10
12
|
|
13
|
+
Dir[File.expand_path('../support/**/*.rb', __FILE__)].each do |filepath|
|
14
|
+
require filepath
|
15
|
+
end
|
16
|
+
|
11
17
|
RSpec.configure do |config|
|
12
18
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
19
|
config.run_all_when_everything_filtered = true
|
@@ -0,0 +1,48 @@
|
|
1
|
+
API_HOST = 'https://api.keystok.com'
|
2
|
+
DECRYPTION_KEY =
|
3
|
+
'965391f2bba37b4586431b8690d7044d5cdc73adf7dda539f8dd3a60cb3e9b12'
|
4
|
+
KEYSTOK_OAUTH_REFRESH_URL = 'https://keystok.com/oauth/token'
|
5
|
+
REFRESHED_TOKEN =
|
6
|
+
'2cb4583cd8a399f51db15da57d0679706ae975d2aa9d3c71f5fdd0255dd6a028'
|
7
|
+
|
8
|
+
def example_response
|
9
|
+
File.open(File.expand_path('../../fixtures/response_data_00.data',
|
10
|
+
__FILE__)).read
|
11
|
+
end
|
12
|
+
|
13
|
+
def oauth_refresh_url
|
14
|
+
"#{config[:auth_host]}/oauth/token"
|
15
|
+
end
|
16
|
+
|
17
|
+
def override_config_key(key, value = nil)
|
18
|
+
config_tmp = client.instance_variable_get('@config')
|
19
|
+
config_tmp[key] = value
|
20
|
+
client.instance_variable_set('@config', config_tmp)
|
21
|
+
end
|
22
|
+
|
23
|
+
def refresh_response
|
24
|
+
{
|
25
|
+
'access_token' => REFRESHED_TOKEN,
|
26
|
+
'token_type' => 'bearer', 'expires_in' => 124
|
27
|
+
}.to_json
|
28
|
+
end
|
29
|
+
|
30
|
+
def request_path(key = nil)
|
31
|
+
if key
|
32
|
+
key_path = "/#{key}"
|
33
|
+
else
|
34
|
+
key_path = ''
|
35
|
+
end
|
36
|
+
"apps/#{config[:id]}/deploy#{key_path}?access_token=#{REFRESHED_TOKEN}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def request_url(host = nil, path = nil)
|
40
|
+
host ||= config[:api_host]
|
41
|
+
path ||= request_path
|
42
|
+
"#{host}/#{path}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def stub_deployment_req(host = nil, path = nil)
|
46
|
+
stub_request(:get, request_url(host, path))
|
47
|
+
.to_return(status: 200, body: example_response, headers: {})
|
48
|
+
end
|
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.1.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-04-
|
11
|
+
date: 2014-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: ffaker
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: fuubar
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -168,17 +182,20 @@ description: |
|
|
168
182
|
Ruby client for Keystok service. https://keystok.com
|
169
183
|
email:
|
170
184
|
- piotr@keystok.com
|
171
|
-
executables:
|
185
|
+
executables:
|
186
|
+
- keystok_rb
|
172
187
|
extensions: []
|
173
188
|
extra_rdoc_files: []
|
174
189
|
files:
|
175
190
|
- ".gitignore"
|
176
191
|
- ".rspec"
|
177
192
|
- ".rubocop.yml"
|
193
|
+
- CHANGELOG.md
|
178
194
|
- Gemfile
|
179
195
|
- LICENSE.txt
|
180
196
|
- README.md
|
181
197
|
- Rakefile
|
198
|
+
- bin/keystok_rb
|
182
199
|
- keystok.gemspec
|
183
200
|
- lib/generators/keystok/install_generator.rb
|
184
201
|
- lib/generators/keystok/templates/keystok.rb
|
@@ -186,18 +203,23 @@ files:
|
|
186
203
|
- lib/keystok.rb
|
187
204
|
- lib/keystok/aes_crypto.rb
|
188
205
|
- lib/keystok/cache.rb
|
206
|
+
- lib/keystok/cli.rb
|
189
207
|
- lib/keystok/client.rb
|
190
208
|
- lib/keystok/errors.rb
|
191
209
|
- lib/keystok/railtie.rb
|
192
210
|
- lib/keystok/version.rb
|
211
|
+
- spec/fixtures/connection_string_00.data
|
212
|
+
- spec/fixtures/connection_string_01.data
|
193
213
|
- spec/fixtures/encrypted_data_00.data
|
194
214
|
- spec/fixtures/response_data_00.data
|
195
215
|
- spec/functional/aes_crypto_spec.rb
|
196
216
|
- spec/functional/cache_spec.rb
|
217
|
+
- spec/functional/cli_spec.rb
|
197
218
|
- spec/functional/client_spec.rb
|
198
219
|
- spec/functional/keystok_spec.rb
|
199
220
|
- spec/integration/rails_integration_spec.rb
|
200
221
|
- spec/spec_helper.rb
|
222
|
+
- spec/support/webmock_helpers.rb
|
201
223
|
homepage: https://keystok.com
|
202
224
|
licenses:
|
203
225
|
- GitDock Oy
|
@@ -223,11 +245,15 @@ signing_key:
|
|
223
245
|
specification_version: 4
|
224
246
|
summary: Keystok API client
|
225
247
|
test_files:
|
248
|
+
- spec/fixtures/connection_string_00.data
|
249
|
+
- spec/fixtures/connection_string_01.data
|
226
250
|
- spec/fixtures/encrypted_data_00.data
|
227
251
|
- spec/fixtures/response_data_00.data
|
228
252
|
- spec/functional/aes_crypto_spec.rb
|
229
253
|
- spec/functional/cache_spec.rb
|
254
|
+
- spec/functional/cli_spec.rb
|
230
255
|
- spec/functional/client_spec.rb
|
231
256
|
- spec/functional/keystok_spec.rb
|
232
257
|
- spec/integration/rails_integration_spec.rb
|
233
258
|
- spec/spec_helper.rb
|
259
|
+
- spec/support/webmock_helpers.rb
|