copy_tuner_client 2.5.1 → 3.0.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 +1 -2
- data/README.md +2 -0
- data/UPGRADING.md +44 -0
- data/lib/copy_tuner_client/client.rb +17 -3
- data/lib/copy_tuner_client/configuration.rb +12 -1
- data/lib/copy_tuner_client/errors.rb +10 -3
- data/lib/copy_tuner_client/poller.rb +4 -2
- data/lib/copy_tuner_client/version.rb +1 -1
- data/lib/copy_tuner_client.rb +1 -0
- data/mise.toml +1 -0
- data/spec/copy_tuner_client/client_spec.rb +39 -4
- data/spec/copy_tuner_client/configuration_spec.rb +30 -0
- data/spec/copy_tuner_client/poller_spec.rb +15 -0
- data/spec/support/client_spec_helpers.rb +1 -0
- data/spec/support/fake_copy_tuner_app.rb +33 -17
- metadata +2 -3
- data/.ruby-version +0 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc7ea8326b6b40250965bd4e76dc2d8e598047ba7d91ff4827ba46cd6e71a530
|
|
4
|
+
data.tar.gz: 6f609f48108914b7d66fc14b27b1c0c88d211d2496a2f4d95605ff9d42873c15
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: d20c645325447d51131bce8cd08f99ebb1456958d65e79d1da7e6236902439c182c529c017d67cedd47cbb67c459105ad3d56dcc21d3d84934867b1edabdd5fb
|
|
7
|
+
data.tar.gz: 6abdb7682094ce5d247039b68bc1b64a81f27c554f4f3dfe31cbae4d158fb4c75900fe5bac33570dfbc9e9bf55e37c5b528607e9e27816a37e96d07f12f43973
|
data/.rubocop.yml
CHANGED
|
@@ -7,8 +7,7 @@ plugins:
|
|
|
7
7
|
- rubocop-rake
|
|
8
8
|
- rubocop-rspec
|
|
9
9
|
|
|
10
|
-
#
|
|
11
|
-
# サポート最低バージョンを明示する
|
|
10
|
+
# ローカルの Ruby(mise で latest)ではなく、gemspec のサポート最低バージョンを基準に解析する
|
|
12
11
|
# rubocop-rails は Rails プロジェクトではないため意図的に読み込まない
|
|
13
12
|
AllCops:
|
|
14
13
|
TargetRubyVersion: 3.3
|
data/README.md
CHANGED
|
@@ -17,6 +17,8 @@ Create config/initializers/copy_tuner.rb
|
|
|
17
17
|
CopyTunerClient.configure do |config|
|
|
18
18
|
config.api_key = 'YOUR-API-KEY'
|
|
19
19
|
config.project_id = 77
|
|
20
|
+
# 必須。プロジェクト設定画面の「S3パストークン」の値(翻訳の download にのみ使われる)
|
|
21
|
+
config.s3_path_token = 'YOUR-S3-PATH-TOKEN'
|
|
20
22
|
config.host = 'COPY-TUNER-HOST-NAME'
|
|
21
23
|
|
|
22
24
|
# I18n keys and messages will be sent to server if the locale matches
|
data/UPGRADING.md
CHANGED
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
# v2 から v3 へのアップグレードガイド
|
|
2
|
+
|
|
3
|
+
CopyTuner Ruby クライアント gem を **v2.x 系から v3.0.0** へ上げる際の移行手順です。
|
|
4
|
+
|
|
5
|
+
## 変更点早見表
|
|
6
|
+
|
|
7
|
+
| 区分 | 設定 / API | 対応 | 影響箇所 |
|
|
8
|
+
| --- | --- | --- | --- |
|
|
9
|
+
| 破壊的変更 | `config.s3_path_token` | **必須化**。未設定(nil / 空文字)だと起動時に `ArgumentError`。`api_key` へのフォールバックはなし | initializer |
|
|
10
|
+
| 破壊的変更 | download 失敗時の例外 | S3 からの download で 403 / 404 になると `InvalidS3PathToken` が発生。`InvalidCredential` で rescue 推奨 | 例外を rescue しているコード(あれば) |
|
|
11
|
+
|
|
12
|
+
## 1. `config.s3_path_token` が必須になりました
|
|
13
|
+
|
|
14
|
+
翻訳の download(S3)のパスにだけ `s3_path_token` を使います。upload / deploy は従来どおり `api_key` を使います。
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
CopyTunerClient.configure do |config|
|
|
18
|
+
config.api_key = 'YOUR-API-KEY'
|
|
19
|
+
config.s3_path_token = 'YOUR-S3-PATH-TOKEN' # プロジェクト設定画面の「S3パストークン」
|
|
20
|
+
config.project_id = 77
|
|
21
|
+
end
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
未設定のまま起動すると次の例外で失敗します。
|
|
25
|
+
|
|
26
|
+
```
|
|
27
|
+
ArgumentError: s3_path_token is required
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## 2. 例外クラスの変更
|
|
31
|
+
|
|
32
|
+
```
|
|
33
|
+
StandardError
|
|
34
|
+
└─ InvalidCredential ← Poller はこれを rescue してポーリングを中止
|
|
35
|
+
├─ InvalidApiKey upload / deploy の 404
|
|
36
|
+
└─ InvalidS3PathToken download の 403 / 404
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
- 本番の S3 / CloudFront は存在しないパスに 403 を返すため、download の 403 / 404 はどちらも `InvalidS3PathToken` になります(従来の download は `ConnectionError` や `InvalidApiKey` になっていました)。
|
|
40
|
+
- `InvalidS3PathToken` のメッセージにトークン値は含まれません(例: `Invalid s3_path_token (403)`)。
|
|
41
|
+
- `InvalidApiKey` を rescue しているコードは、download の失敗も拾うなら `InvalidCredential` に変更してください。
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
1
45
|
# v1 から v2 へのアップグレードガイド
|
|
2
46
|
|
|
3
47
|
CopyTuner Ruby クライアント gem を **v1.5.0 系から v2.0.0** へ上げる際の移行手順です。
|
|
@@ -26,7 +26,8 @@ module CopyTunerClient
|
|
|
26
26
|
|
|
27
27
|
# Usually instantiated from {Configuration#apply}. Copies options.
|
|
28
28
|
# @param options [Hash]
|
|
29
|
-
# @option options [String] :api_key API key of the project to connect to
|
|
29
|
+
# @option options [String] :api_key API key of the project to connect to (upload / deploy)
|
|
30
|
+
# @option options [String] :s3_path_token token used in the S3 path (download)
|
|
30
31
|
# @option options [Fixnum] :port the port to connect to
|
|
31
32
|
# @option options [Boolean] :public whether to download draft or published content
|
|
32
33
|
# @option options [Fixnum] :http_read_timeout how long to wait before timing out when reading data from the socket
|
|
@@ -39,7 +40,7 @@ module CopyTunerClient
|
|
|
39
40
|
@downloaded_blurbs = {}
|
|
40
41
|
|
|
41
42
|
%i[
|
|
42
|
-
api_key host port public http_read_timeout
|
|
43
|
+
api_key s3_path_token host port public http_read_timeout
|
|
43
44
|
http_open_timeout secure logger ca_file s3_host download_cache_dir
|
|
44
45
|
].each do |option|
|
|
45
46
|
instance_variable_set("@#{option}", options[option])
|
|
@@ -61,12 +62,13 @@ module CopyTunerClient
|
|
|
61
62
|
# @raise [ConnectionError] if the connection fails
|
|
62
63
|
def download(cache_fallback: false)
|
|
63
64
|
connect(s3_host) do |http|
|
|
64
|
-
request = Net::HTTP::Get.new(
|
|
65
|
+
request = Net::HTTP::Get.new(download_uri)
|
|
65
66
|
request['If-None-Match'] = @etag
|
|
66
67
|
log('Start downloading translations')
|
|
67
68
|
t = Time.now
|
|
68
69
|
response = http.request(request)
|
|
69
70
|
t_ms = ((Time.now - t) * 1000).to_i
|
|
71
|
+
check_s3_path_token(response)
|
|
70
72
|
downloaded = check(response)
|
|
71
73
|
if downloaded
|
|
72
74
|
# NOTE: Net::HTTPではgzipが透過的に扱われるため正確なファイルサイズや速度をログに出すのは難しい
|
|
@@ -109,6 +111,7 @@ module CopyTunerClient
|
|
|
109
111
|
attr_reader :host,
|
|
110
112
|
:port,
|
|
111
113
|
:api_key,
|
|
114
|
+
:s3_path_token,
|
|
112
115
|
:http_read_timeout,
|
|
113
116
|
:http_open_timeout,
|
|
114
117
|
:secure,
|
|
@@ -124,6 +127,10 @@ module CopyTunerClient
|
|
|
124
127
|
"/api/v2/projects/#{api_key}/#{resource}"
|
|
125
128
|
end
|
|
126
129
|
|
|
130
|
+
def download_uri
|
|
131
|
+
"/api/v2/projects/#{s3_path_token}/#{download_resource}"
|
|
132
|
+
end
|
|
133
|
+
|
|
127
134
|
def download_resource
|
|
128
135
|
if public?
|
|
129
136
|
'published_blurbs.json'
|
|
@@ -162,6 +169,13 @@ module CopyTunerClient
|
|
|
162
169
|
end
|
|
163
170
|
end
|
|
164
171
|
|
|
172
|
+
# S3/CloudFront は存在しないパスに 403 を返すため 404 と同様に扱う。メッセージにトークン値は含めない
|
|
173
|
+
def check_s3_path_token(response)
|
|
174
|
+
return unless response.is_a?(Net::HTTPNotFound) || response.is_a?(Net::HTTPForbidden)
|
|
175
|
+
|
|
176
|
+
raise InvalidS3PathToken, "Invalid s3_path_token (#{response.code})"
|
|
177
|
+
end
|
|
178
|
+
|
|
165
179
|
def check(response)
|
|
166
180
|
case response
|
|
167
181
|
when Net::HTTPNotFound
|
|
@@ -13,7 +13,7 @@ module CopyTunerClient
|
|
|
13
13
|
class Configuration # rubocop:disable Metrics/ClassLength
|
|
14
14
|
# These options will be present in the Hash returned by {#to_hash}.
|
|
15
15
|
OPTIONS = %i[
|
|
16
|
-
api_key development_environments environment_name host
|
|
16
|
+
api_key s3_path_token development_environments environment_name host
|
|
17
17
|
http_open_timeout http_read_timeout client_name client_url
|
|
18
18
|
client_version port protocol proxy_host proxy_pass
|
|
19
19
|
proxy_port proxy_user secure polling_delay sync_interval
|
|
@@ -156,6 +156,9 @@ module CopyTunerClient
|
|
|
156
156
|
# @return [Integer] The project id
|
|
157
157
|
attr_accessor :project_id
|
|
158
158
|
|
|
159
|
+
# @return [String] The token used in the S3 path when downloading translations (required)
|
|
160
|
+
attr_accessor :s3_path_token
|
|
161
|
+
|
|
159
162
|
# @return [Pathname] The directory to cache downloaded files
|
|
160
163
|
attr_accessor :download_cache_dir
|
|
161
164
|
|
|
@@ -183,6 +186,7 @@ module CopyTunerClient
|
|
|
183
186
|
self.ignored_key_handler = ->(e) { raise e }
|
|
184
187
|
self.local_first_key_regexp = nil
|
|
185
188
|
self.project_id = nil
|
|
189
|
+
self.s3_path_token = nil
|
|
186
190
|
self.download_cache_dir = Pathname.new(Dir.pwd).join('tmp', 'cache', 'copy_tuner_client')
|
|
187
191
|
self.middleware_position = default_middleware_position
|
|
188
192
|
|
|
@@ -258,6 +262,7 @@ module CopyTunerClient
|
|
|
258
262
|
def apply # rubocop:disable Metrics/AbcSize
|
|
259
263
|
# NOTE: project_id は必須。未設定なら apply 時点で明示的に失敗させる
|
|
260
264
|
validate_project_id!
|
|
265
|
+
validate_s3_path_token!
|
|
261
266
|
|
|
262
267
|
self.locales ||= default_locales
|
|
263
268
|
|
|
@@ -422,6 +427,12 @@ module CopyTunerClient
|
|
|
422
427
|
raise ArgumentError, 'project_id is required' if project_id.nil?
|
|
423
428
|
end
|
|
424
429
|
|
|
430
|
+
# s3_path_token は必須。api_key へのフォールバックはしない
|
|
431
|
+
# (設定漏れを gem 更新時に起動で検知し、api_key のローテーションと独立に扱えるようにするため)。
|
|
432
|
+
def validate_s3_path_token!
|
|
433
|
+
raise ArgumentError, 's3_path_token is required' if s3_path_token.nil? || s3_path_token.empty?
|
|
434
|
+
end
|
|
435
|
+
|
|
425
436
|
def default_port
|
|
426
437
|
if secure?
|
|
427
438
|
443
|
|
@@ -5,9 +5,16 @@ module CopyTunerClient
|
|
|
5
5
|
class ConnectionError < StandardError
|
|
6
6
|
end
|
|
7
7
|
|
|
8
|
-
#
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
# 設定された認証情報(api_key / s3_path_token)が拒否されたことを表す例外の基底クラス
|
|
9
|
+
class InvalidCredential < StandardError
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# upload / deploy で api_key が CopyTuner サーバに認識されなかったときの例外
|
|
13
|
+
class InvalidApiKey < InvalidCredential
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# download で s3_path_token のパスに S3 の JSON が見つからなかったときの例外
|
|
17
|
+
class InvalidS3PathToken < InvalidCredential
|
|
11
18
|
end
|
|
12
19
|
|
|
13
20
|
class IgnoredKey < StandardError
|
|
@@ -85,8 +85,10 @@ module CopyTunerClient
|
|
|
85
85
|
timeout = polling_delay
|
|
86
86
|
end
|
|
87
87
|
logger.info 'stop poller thread'
|
|
88
|
-
rescue
|
|
89
|
-
#
|
|
88
|
+
rescue InvalidCredential => e
|
|
89
|
+
# キーが不正なら張り直しても同じ結果になるので、以後の再開を止める。
|
|
90
|
+
# S3 の 403/404(InvalidS3PathToken)も同様に扱う: サーバはプロジェクト作成直後に JSON を書き出し、
|
|
91
|
+
# 削除するのはアーカイブ時だけなので、正しいトークンで再試行して回復するケースは実運用上ない
|
|
90
92
|
@aborted = true
|
|
91
93
|
logger.error(e.message)
|
|
92
94
|
rescue StandardError => e
|
data/lib/copy_tuner_client.rb
CHANGED
|
@@ -48,6 +48,7 @@ module CopyTunerClient
|
|
|
48
48
|
# @example
|
|
49
49
|
# CopyTunerClient.configure do |config|
|
|
50
50
|
# config.api_key = '1234567890abcdef'
|
|
51
|
+
# config.s3_path_token = 'abcdef1234567890' # required
|
|
51
52
|
# config.host = 'your-copy-tuner-server.herokuapp.com'
|
|
52
53
|
# config.secure = true
|
|
53
54
|
# end
|
data/mise.toml
CHANGED
|
@@ -10,6 +10,8 @@ describe 'CopyTunerClient' do
|
|
|
10
10
|
def build_client(config = {})
|
|
11
11
|
config[:logger] ||= FakeLogger.new
|
|
12
12
|
config[:download_cache_dir] = download_cache_dir
|
|
13
|
+
# FakeCopyTunerApp.add_project は既定で api_key と同値の s3_path_token で登録するので、明示指定がなければ揃える
|
|
14
|
+
config[:s3_path_token] ||= config[:api_key]
|
|
13
15
|
default_config = CopyTunerClient::Configuration.new.to_hash
|
|
14
16
|
default_config[:s3_host] = 'copy-tuner.com'
|
|
15
17
|
CopyTunerClient::Client.new(default_config.update(config))
|
|
@@ -99,15 +101,21 @@ describe 'CopyTunerClient' do
|
|
|
99
101
|
expect { client.upload({}) }.to raise_error(CopyTunerClient::ConnectionError)
|
|
100
102
|
end
|
|
101
103
|
|
|
102
|
-
it '
|
|
103
|
-
client = build_client(api_key: 'bogus')
|
|
104
|
+
it 'ダウンロード時に存在しないパスで403エラーが発生した場合はトークン値を含まないInvalidS3PathTokenになること' do
|
|
105
|
+
client = build_client(api_key: 'xyz123', s3_path_token: 'bogus')
|
|
106
|
+
expect { client.download {} }
|
|
107
|
+
.to raise_error(CopyTunerClient::InvalidS3PathToken, 'Invalid s3_path_token (403)')
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it 'ダウンロード時に404エラーが発生した場合もInvalidS3PathTokenになること' do
|
|
111
|
+
client = build_client(api_key: 'xyz123', s3_path_token: 'not_found')
|
|
104
112
|
expect { client.download {} }
|
|
105
|
-
.to raise_error(CopyTunerClient::
|
|
113
|
+
.to raise_error(CopyTunerClient::InvalidS3PathToken, 'Invalid s3_path_token (404)')
|
|
106
114
|
end
|
|
107
115
|
|
|
108
116
|
it 'アップロード時に404エラーが発生した場合はInvalidApiKeyになること' do
|
|
109
117
|
client = build_client(api_key: 'bogus')
|
|
110
|
-
expect { client.upload({}) }.to raise_error(CopyTunerClient::InvalidApiKey)
|
|
118
|
+
expect { client.upload({}) }.to raise_error(CopyTunerClient::InvalidApiKey, 'Invalid API key: bogus')
|
|
111
119
|
end
|
|
112
120
|
end
|
|
113
121
|
|
|
@@ -240,6 +248,33 @@ describe 'CopyTunerClient' do
|
|
|
240
248
|
expect(logger).to have_entry(:info, 'Deployed')
|
|
241
249
|
end
|
|
242
250
|
|
|
251
|
+
describe 'api_key と s3_path_token が別値のプロジェクト' do
|
|
252
|
+
let!(:project) do
|
|
253
|
+
FakeCopyTunerApp.add_project('api-key-1', s3_path_token: 's3-token-1').tap do |p|
|
|
254
|
+
p.update('draft' => { 'key.one' => 'draft one' }, 'published' => { 'key.one' => 'published one' })
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
it 'ダウンロードは s3_path_token のパスから取得すること' do
|
|
259
|
+
client = build_client(api_key: 'api-key-1', s3_path_token: 's3-token-1')
|
|
260
|
+
downloaded = nil
|
|
261
|
+
client.download { |blurbs| downloaded = blurbs }
|
|
262
|
+
expect(downloaded).to eq('key.one' => 'published one')
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
it 'アップロードは s3_path_token を設定していても api_key のパスを使うこと' do
|
|
266
|
+
client = build_client(api_key: 'api-key-1', s3_path_token: 's3-token-1')
|
|
267
|
+
client.upload('key.two' => 'uploaded')
|
|
268
|
+
expect(project.reload.draft).to include('key.two' => 'uploaded')
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
it 'deploy は s3_path_token を設定していても api_key のパスを使うこと' do
|
|
272
|
+
client = build_client(api_key: 'api-key-1', s3_path_token: 's3-token-1')
|
|
273
|
+
client.deploy
|
|
274
|
+
expect(project.reload.published).to eq('key.one' => 'draft one')
|
|
275
|
+
end
|
|
276
|
+
end
|
|
277
|
+
|
|
243
278
|
it 'deploy時にエラーが発生した場合は例外が発生すること' do
|
|
244
279
|
expect { build_client.deploy }.to raise_error(CopyTunerClient::InvalidApiKey)
|
|
245
280
|
end
|
|
@@ -19,6 +19,7 @@ shared_context 'stubbed configuration' do
|
|
|
19
19
|
# NOTE: apply は project_id 必須になったため、未設定だと raise する。applied 系テストは
|
|
20
20
|
# project_id 自体を検証しないので適当な値を補っておく
|
|
21
21
|
configuration.project_id ||= 1
|
|
22
|
+
configuration.s3_path_token ||= 'token'
|
|
22
23
|
apply
|
|
23
24
|
end
|
|
24
25
|
end
|
|
@@ -93,6 +94,7 @@ describe CopyTunerClient::Configuration do
|
|
|
93
94
|
it { is_expected.to have_config_option(:port).overridable }
|
|
94
95
|
it { is_expected.to have_config_option(:development_environments).overridable }
|
|
95
96
|
it { is_expected.to have_config_option(:api_key).overridable }
|
|
97
|
+
it { is_expected.to have_config_option(:s3_path_token).overridable.default(nil) }
|
|
96
98
|
it { is_expected.to have_config_option(:polling_delay).overridable.default(300) }
|
|
97
99
|
it { is_expected.to have_config_option(:framework).overridable }
|
|
98
100
|
it { is_expected.to have_config_option(:middleware).overridable }
|
|
@@ -330,6 +332,34 @@ describe CopyTunerClient::Configuration do
|
|
|
330
332
|
end
|
|
331
333
|
end
|
|
332
334
|
|
|
335
|
+
describe 's3_path_token の必須化' do
|
|
336
|
+
let(:config) do
|
|
337
|
+
config = described_class.new
|
|
338
|
+
config.api_key = 'abc123'
|
|
339
|
+
config.project_id = 1
|
|
340
|
+
config
|
|
341
|
+
end
|
|
342
|
+
|
|
343
|
+
it 's3_path_token が nil のとき apply が ArgumentError を出すこと' do
|
|
344
|
+
config.s3_path_token = nil
|
|
345
|
+
expect { config.apply }.to raise_error(ArgumentError, 's3_path_token is required')
|
|
346
|
+
end
|
|
347
|
+
|
|
348
|
+
it 's3_path_token が空文字のとき apply が ArgumentError を出すこと' do
|
|
349
|
+
config.s3_path_token = ''
|
|
350
|
+
expect { config.apply }.to raise_error(ArgumentError, 's3_path_token is required')
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
it 'api_key が設定されていても s3_path_token へフォールバックしないこと' do
|
|
354
|
+
expect(config.s3_path_token).to be_nil
|
|
355
|
+
end
|
|
356
|
+
|
|
357
|
+
it 's3_path_token が to_hash に含まれること' do
|
|
358
|
+
config.s3_path_token = 'token'
|
|
359
|
+
expect(config.to_hash[:s3_path_token]).to eq('token')
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
|
|
333
363
|
context 'applied when testing' do
|
|
334
364
|
it_behaves_like 'applied configuration' do
|
|
335
365
|
it 'does not start the process guard' do
|
|
@@ -57,6 +57,21 @@ describe CopyTunerClient::Poller do
|
|
|
57
57
|
expect(cache['test.key']).to be_nil
|
|
58
58
|
end
|
|
59
59
|
|
|
60
|
+
it 's3_path_token が不正な場合はポーリングを停止すること' do
|
|
61
|
+
failure = 'Invalid s3_path_token (403)'
|
|
62
|
+
logger = FakeLogger.new
|
|
63
|
+
|
|
64
|
+
allow(cache).to receive(:download).and_raise(CopyTunerClient::InvalidS3PathToken.new(failure))
|
|
65
|
+
poller = build_poller(logger:)
|
|
66
|
+
|
|
67
|
+
cache['upload.key'] = 'upload'
|
|
68
|
+
poller.start
|
|
69
|
+
wait_for_next_sync
|
|
70
|
+
|
|
71
|
+
expect(logger).to have_entry(:error, failure)
|
|
72
|
+
expect(poller.stop).to be false
|
|
73
|
+
end
|
|
74
|
+
|
|
60
75
|
it 'stops polling with an invalid api key' do
|
|
61
76
|
failure = 'server is napping'
|
|
62
77
|
logger = FakeLogger.new
|
|
@@ -21,8 +21,8 @@ class FakeCopyTunerApp < Sinatra::Base
|
|
|
21
21
|
ENV.fetch('COPY_TUNER_PORT', 3002).to_i
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
def self.add_project(api_key)
|
|
25
|
-
Project.create api_key
|
|
24
|
+
def self.add_project(api_key, s3_path_token: api_key)
|
|
25
|
+
Project.create api_key, s3_path_token:
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
def self.reset
|
|
@@ -33,25 +33,31 @@ class FakeCopyTunerApp < Sinatra::Base
|
|
|
33
33
|
Project.find api_key
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
def with_project(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
yield project
|
|
41
|
-
else
|
|
42
|
-
halt 404, { error: 'No such project' }.to_json
|
|
36
|
+
def with_project(key, finder: :find, missing_status: 404)
|
|
37
|
+
case key
|
|
38
|
+
when 'raise_error' then halt 500, { error: 'Blah ha' }.to_json
|
|
39
|
+
when 'not_found' then halt 404, { error: 'No such project' }.to_json
|
|
43
40
|
end
|
|
41
|
+
|
|
42
|
+
project = Project.public_send(finder, key)
|
|
43
|
+
halt missing_status, { error: 'No such project' }.to_json unless project
|
|
44
|
+
yield project
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
# 本番の S3/CloudFront は存在しないパスに 404 ではなく 403 を返すので合わせる
|
|
48
|
+
def with_project_by_s3_path_token(s3_path_token, &)
|
|
49
|
+
with_project(s3_path_token, finder: :find_by_s3_path_token, missing_status: 403, &)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
get '/api/v2/projects/:s3_path_token/published_blurbs.json' do |s3_path_token|
|
|
53
|
+
with_project_by_s3_path_token(s3_path_token) do |project|
|
|
48
54
|
etag project.etag
|
|
49
55
|
project.published.to_json
|
|
50
56
|
end
|
|
51
57
|
end
|
|
52
58
|
|
|
53
|
-
get '/api/v2/projects/:
|
|
54
|
-
|
|
59
|
+
get '/api/v2/projects/:s3_path_token/draft_blurbs.json' do |s3_path_token|
|
|
60
|
+
with_project_by_s3_path_token(s3_path_token) do |project|
|
|
55
61
|
etag project.etag
|
|
56
62
|
project.draft.to_json
|
|
57
63
|
end
|
|
@@ -82,19 +88,27 @@ class FakeCopyTunerApp < Sinatra::Base
|
|
|
82
88
|
end
|
|
83
89
|
|
|
84
90
|
class Project
|
|
85
|
-
attr_reader :draft, :published, :api_key
|
|
91
|
+
attr_reader :draft, :published, :api_key, :s3_path_token
|
|
86
92
|
|
|
87
93
|
MUTEX = Mutex.new
|
|
88
94
|
|
|
89
|
-
def self.create(api_key)
|
|
90
|
-
project = Project.new('api_key' => api_key)
|
|
95
|
+
def self.create(api_key, s3_path_token: api_key)
|
|
96
|
+
project = Project.new('api_key' => api_key, 's3_path_token' => s3_path_token)
|
|
91
97
|
save project
|
|
92
98
|
project
|
|
93
99
|
end
|
|
94
100
|
|
|
95
101
|
def self.find(api_key)
|
|
102
|
+
find_by { |data| data[api_key] }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def self.find_by_s3_path_token(s3_path_token)
|
|
106
|
+
find_by { |data| data.values.find { |h| h['s3_path_token'] == s3_path_token } }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def self.find_by
|
|
96
110
|
open_project_data do |data|
|
|
97
|
-
if (project_hash = data
|
|
111
|
+
if (project_hash = yield(data))
|
|
98
112
|
Project.new project_hash.dup
|
|
99
113
|
end
|
|
100
114
|
end
|
|
@@ -132,6 +146,7 @@ class FakeCopyTunerApp < Sinatra::Base
|
|
|
132
146
|
|
|
133
147
|
def initialize(attrs)
|
|
134
148
|
@api_key = attrs['api_key']
|
|
149
|
+
@s3_path_token = attrs['s3_path_token']
|
|
135
150
|
@draft = attrs.fetch('draft', {})
|
|
136
151
|
@etag = attrs.fetch('etag', 1)
|
|
137
152
|
@published = attrs.fetch('published', {})
|
|
@@ -140,6 +155,7 @@ class FakeCopyTunerApp < Sinatra::Base
|
|
|
140
155
|
def to_hash
|
|
141
156
|
{
|
|
142
157
|
'api_key' => @api_key,
|
|
158
|
+
's3_path_token' => @s3_path_token,
|
|
143
159
|
'etag' => @etag,
|
|
144
160
|
'draft' => @draft,
|
|
145
161
|
'published' => @published,
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: copy_tuner_client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SonicGarden
|
|
@@ -188,7 +188,6 @@ files:
|
|
|
188
188
|
- ".gitignore"
|
|
189
189
|
- ".rspec"
|
|
190
190
|
- ".rubocop.yml"
|
|
191
|
-
- ".ruby-version"
|
|
192
191
|
- ".vscode/settings.json"
|
|
193
192
|
- CHANGELOG.md
|
|
194
193
|
- CLAUDE.md
|
|
@@ -307,7 +306,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
307
306
|
- !ruby/object:Gem::Version
|
|
308
307
|
version: '0'
|
|
309
308
|
requirements: []
|
|
310
|
-
rubygems_version: 4.0.
|
|
309
|
+
rubygems_version: 4.0.20
|
|
311
310
|
specification_version: 4
|
|
312
311
|
summary: Client for the CopyTuner copy management service
|
|
313
312
|
test_files: []
|
data/.ruby-version
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
4.0.5
|