whiplash-app 0.7.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +41 -0
- data/lib/whiplash/app/connections.rb +28 -12
- data/lib/whiplash/app/version.rb +1 -1
- data/lib/whiplash/app.rb +5 -22
- data/whiplash-app.gemspec +2 -3
- metadata +12 -27
- data/lib/whiplash/app/caching.rb +0 -22
- data/lib/whiplash/app/moneta/namespace.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38965dd5a29730aa36f70c5b685aa575aef968b6b6fb8f81efd4e4defb6c8b56
|
4
|
+
data.tar.gz: 0d42efa6c4d541f49d8fcc0b67d09e06ab25dc585fe4abf9c0ac8058c1ddf24c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2a65da32cf144d8e5c22f6c4efce8f9b3109cb484398bdb65ad4a17fb3a3b4ae85b9a29d28919055e0a597d16fd907dea9847ff8054e5bb5c353c9877f1433a
|
7
|
+
data.tar.gz: 3b7c40b3da5a6bb4dd3e7bf4e4fd9e1c29587f870853c3c8df3f706d2aa35e030151de3759abc1c6170deb7af92e443a4377e4761f9a4851f7b607259c64fbbd
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: "Whiplash App CI Workflow"
|
2
|
+
on:
|
3
|
+
pull_request_target:
|
4
|
+
types: [opened, synchronize, reopened]
|
5
|
+
workflow_dispatch:
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
build:
|
9
|
+
runs-on: ubuntu-latest
|
10
|
+
|
11
|
+
steps:
|
12
|
+
- name: Checkout code
|
13
|
+
uses: actions/checkout@v3
|
14
|
+
with:
|
15
|
+
ref: ${{ github.event.pull_request.head.sha }}
|
16
|
+
|
17
|
+
- name: Install ruby and gems
|
18
|
+
uses: ruby/setup-ruby@v1
|
19
|
+
with:
|
20
|
+
ruby-version: '2.6.7'
|
21
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
22
|
+
|
23
|
+
- run: gem install bundler -v 2.2.25
|
24
|
+
|
25
|
+
- run: bundle exec rake
|
26
|
+
|
27
|
+
- name: Slack Notification
|
28
|
+
uses: 8398a7/action-slack@v3
|
29
|
+
with:
|
30
|
+
status: ${{ job.status }}
|
31
|
+
fields: repo,message,pullRequest,author
|
32
|
+
custom_payload: |
|
33
|
+
{
|
34
|
+
attachments: [{
|
35
|
+
color: '${{ job.status }}' === 'success' ? 'good' : '${{ job.status }}' === 'failure' ? 'danger' : 'warning',
|
36
|
+
text: `${process.env.AS_WORKFLOW}\n${process.env.AS_JOB} for (${process.env.AS_COMMIT}) of ${process.env.AS_REPO}@${process.env.AS_REF} by ${process.env.AS_AUTHOR} ${{ job.status }} in ${process.env.AS_TOOK}`,
|
37
|
+
}]
|
38
|
+
}
|
39
|
+
env:
|
40
|
+
SLACK_WEBHOOK_URL: ${{secrets.SLACK_WEBHOOK_URL}}
|
41
|
+
if: always() #Pick up events even if the job fails or is canceled.
|
@@ -45,16 +45,16 @@ module Whiplash
|
|
45
45
|
case e.message
|
46
46
|
when 'end of file reached'
|
47
47
|
store_whiplash_error!(:eof, options)
|
48
|
-
Rails.logger.error "[Whiplash][EOF] Failed to connect
|
49
|
-
raise
|
48
|
+
Rails.logger.error "[Whiplash][EOF] Failed to connect with options: #{options.inspect}"
|
49
|
+
raise WhiplashApiError::InternalServerError, e.message
|
50
50
|
when 'Net::OpenTimeout'
|
51
51
|
store_whiplash_error!(:timeout, options)
|
52
|
-
Rails.logger.error "[Whiplash][Timeout] Request
|
53
|
-
raise
|
52
|
+
Rails.logger.error "[Whiplash][Timeout] Request with options: #{options.inspect} timed out"
|
53
|
+
raise WhiplashApiError::Timeout, e.message
|
54
54
|
else
|
55
55
|
store_whiplash_error!(:connection, options)
|
56
|
-
Rails.logger.error "[Whiplash] Request
|
57
|
-
raise
|
56
|
+
Rails.logger.error "[Whiplash] Request with options: #{options.inspect} failed"
|
57
|
+
raise WhiplashApiError::InternalServerError, e.message
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
@@ -63,6 +63,7 @@ module Whiplash
|
|
63
63
|
results = []
|
64
64
|
page = 1
|
65
65
|
params[:per_page] = PER_PAGE_REQUEST_LIMIT
|
66
|
+
response = nil
|
66
67
|
|
67
68
|
loop do
|
68
69
|
partial_results_request = app_request!(
|
@@ -70,19 +71,33 @@ module Whiplash
|
|
70
71
|
endpoint: endpoint,
|
71
72
|
params: params,
|
72
73
|
headers: headers
|
73
|
-
)
|
74
|
+
)
|
75
|
+
|
76
|
+
if !partial_results_request.success?
|
77
|
+
response = Faraday::Response.new(
|
78
|
+
body: partial_results_request.body,
|
79
|
+
status: partial_results_request.status,
|
80
|
+
method: :get
|
81
|
+
)
|
82
|
+
break
|
83
|
+
end
|
74
84
|
|
75
|
-
results << partial_results_request
|
85
|
+
results << partial_results_request.body
|
76
86
|
results.flatten!
|
77
87
|
|
78
88
|
page += 1
|
79
89
|
params[:page] = page
|
80
90
|
|
81
|
-
break if partial_results_request.size == 0
|
82
|
-
break if partial_results_request.size < PER_PAGE_REQUEST_LIMIT
|
91
|
+
break if partial_results_request.body.size == 0
|
92
|
+
break if partial_results_request.body.size < PER_PAGE_REQUEST_LIMIT
|
83
93
|
end
|
84
94
|
|
85
|
-
|
95
|
+
response ||= Faraday::Response.new(
|
96
|
+
body: results,
|
97
|
+
status: 200,
|
98
|
+
method: :get
|
99
|
+
)
|
100
|
+
|
86
101
|
end
|
87
102
|
|
88
103
|
def delete(endpoint, params = {}, headers = nil)
|
@@ -146,7 +161,8 @@ module Whiplash
|
|
146
161
|
if !response.success?
|
147
162
|
case response.status
|
148
163
|
when 500
|
149
|
-
|
164
|
+
# Do we want to replace this with anything?
|
165
|
+
# Appsignal.send_error(WhiplashApiError::InternalServerError.new(response.body), {raised: false})
|
150
166
|
else
|
151
167
|
end
|
152
168
|
|
data/lib/whiplash/app/version.rb
CHANGED
data/lib/whiplash/app.rb
CHANGED
@@ -1,37 +1,28 @@
|
|
1
1
|
require "whiplash/app/api_config"
|
2
|
-
require "whiplash/app/caching"
|
3
2
|
require "whiplash/app/connections"
|
4
3
|
require "whiplash/app/finder_methods"
|
5
4
|
require "whiplash/app/signing"
|
6
5
|
require "whiplash/app/version"
|
7
6
|
require "errors/whiplash_api_error"
|
8
7
|
require "oauth2"
|
9
|
-
require "
|
8
|
+
require "faraday"
|
10
9
|
|
11
10
|
module Whiplash
|
12
11
|
class App
|
13
12
|
include Whiplash::App::ApiConfig
|
14
|
-
include Whiplash::App::Caching
|
15
13
|
include Whiplash::App::Connections
|
16
14
|
include Whiplash::App::FinderMethods
|
17
15
|
extend Whiplash::App::Signing
|
18
16
|
|
19
17
|
attr_accessor :customer_id, :shop_id, :token
|
20
18
|
|
21
|
-
def initialize(token
|
22
|
-
token
|
23
|
-
@token = format_token(token) unless token.nil?
|
19
|
+
def initialize(token, options={})
|
20
|
+
@token = format_token(token)
|
24
21
|
@customer_id = options[:customer_id]
|
25
22
|
@shop_id = options[:shop_id]
|
26
23
|
@api_version = options[:api_version] || 2 # can be 2_1
|
27
24
|
end
|
28
25
|
|
29
|
-
def self.whiplash_api_token
|
30
|
-
store = Moneta.new(:Redis, host: ENV["REDIS_HOST"], port: ENV["REDIS_PORT"], password: ENV["REDIS_PASSWORD"], expires: 7200)
|
31
|
-
cache_store = Moneta::Namespace.new store, Whiplash::App::Caching.namespace_value
|
32
|
-
cache_store["whiplash_api_token"]
|
33
|
-
end
|
34
|
-
|
35
26
|
def client
|
36
27
|
OAuth2::Client.new(ENV["WHIPLASH_CLIENT_ID"], ENV["WHIPLASH_CLIENT_SECRET"], site: api_url)
|
37
28
|
end
|
@@ -41,14 +32,11 @@ module Whiplash
|
|
41
32
|
end
|
42
33
|
|
43
34
|
def connection
|
44
|
-
|
45
|
-
conn.request :
|
35
|
+
Faraday.new [api_url, versioned_api_url].join("/") do |conn|
|
36
|
+
conn.request :authorization, 'Bearer', token.token
|
46
37
|
conn.request :json
|
47
38
|
conn.response :json, :content_type => /\bjson$/
|
48
|
-
conn.use :instrumentation
|
49
|
-
conn.adapter Faraday.default_adapter
|
50
39
|
end
|
51
|
-
return out
|
52
40
|
end
|
53
41
|
|
54
42
|
def token=(oauth_token)
|
@@ -60,8 +48,6 @@ module Whiplash
|
|
60
48
|
when /app_(manage|read)/
|
61
49
|
begin
|
62
50
|
access_token = client.client_credentials.get_token(scope: ENV["WHIPLASH_CLIENT_SCOPE"])
|
63
|
-
new_token = access_token.to_hash
|
64
|
-
cache_store["whiplash_api_token"] = new_token
|
65
51
|
rescue URI::InvalidURIError => e
|
66
52
|
raise StandardError, "The provide URL (#{ENV["WHIPLASH_API_URL"]}) is not valid"
|
67
53
|
end
|
@@ -75,9 +61,6 @@ module Whiplash
|
|
75
61
|
|
76
62
|
def token_expired?
|
77
63
|
return token.expired? unless token.nil?
|
78
|
-
return true unless cache_store.key?("whiplash_api_token")
|
79
|
-
return true if cache_store["whiplash_api_token"].nil?
|
80
|
-
return true if cache_store["whiplash_api_token"].empty?
|
81
64
|
false
|
82
65
|
end
|
83
66
|
|
data/whiplash-app.gemspec
CHANGED
@@ -18,9 +18,8 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "oauth2", "~>
|
22
|
-
spec.add_dependency "
|
23
|
-
spec.add_dependency "moneta", "~> 0.8.0"
|
21
|
+
spec.add_dependency "oauth2", "~> 2.0.4"
|
22
|
+
spec.add_dependency "faraday", "~> 2.7"
|
24
23
|
|
25
24
|
spec.add_development_dependency "bundler", ">= 2.2"
|
26
25
|
spec.add_development_dependency "rake", ">= 12.3.3"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whiplash-app
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Don Sullivan, Mark Dickson
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-12-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oauth2
|
@@ -16,42 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.0.4
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.0.4
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: faraday
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: '2.7'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: moneta
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.8.0
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.8.0
|
40
|
+
version: '2.7'
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: bundler
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -116,6 +102,7 @@ executables: []
|
|
116
102
|
extensions: []
|
117
103
|
extra_rdoc_files: []
|
118
104
|
files:
|
105
|
+
- ".github/workflows/ci.yml"
|
119
106
|
- ".gitignore"
|
120
107
|
- ".idea/.gitignore"
|
121
108
|
- ".rspec"
|
@@ -128,17 +115,15 @@ files:
|
|
128
115
|
- lib/errors/whiplash_api_error.rb
|
129
116
|
- lib/whiplash/app.rb
|
130
117
|
- lib/whiplash/app/api_config.rb
|
131
|
-
- lib/whiplash/app/caching.rb
|
132
118
|
- lib/whiplash/app/connections.rb
|
133
119
|
- lib/whiplash/app/finder_methods.rb
|
134
|
-
- lib/whiplash/app/moneta/namespace.rb
|
135
120
|
- lib/whiplash/app/signing.rb
|
136
121
|
- lib/whiplash/app/version.rb
|
137
122
|
- whiplash-app.gemspec
|
138
123
|
homepage: https://github.com/whiplashmerch/whiplash-app
|
139
124
|
licenses: []
|
140
125
|
metadata: {}
|
141
|
-
post_install_message:
|
126
|
+
post_install_message:
|
142
127
|
rdoc_options: []
|
143
128
|
require_paths:
|
144
129
|
- lib
|
@@ -153,8 +138,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
138
|
- !ruby/object:Gem::Version
|
154
139
|
version: '0'
|
155
140
|
requirements: []
|
156
|
-
rubygems_version: 3.
|
157
|
-
signing_key:
|
141
|
+
rubygems_version: 3.4.10
|
142
|
+
signing_key:
|
158
143
|
specification_version: 4
|
159
144
|
summary: this gem provides connectivity to the Whiplash API for authentication and
|
160
145
|
REST requests.
|
data/lib/whiplash/app/caching.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "moneta"
|
2
|
-
require "whiplash/app/moneta/namespace"
|
3
|
-
module Whiplash
|
4
|
-
class App
|
5
|
-
module Caching
|
6
|
-
|
7
|
-
def cache_store
|
8
|
-
if ENV["REDIS_HOST"]
|
9
|
-
store = Moneta.new(:Redis, host: ENV["REDIS_HOST"], port: ENV["REDIS_PORT"], password: ENV["REDIS_PASSWORD"], expires: 7200)
|
10
|
-
Moneta::Namespace.new store, Whiplash::App::Caching.namespace_value
|
11
|
-
else
|
12
|
-
Moneta.new(:File, dir: "tmp", expires: 7200)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.namespace_value
|
17
|
-
ENV["REDIS_NAMESPACE"] || ENV["WHIPLASH_CLIENT_ID"]
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,45 +0,0 @@
|
|
1
|
-
module Moneta
|
2
|
-
class Namespace
|
3
|
-
attr_reader :moneta_store
|
4
|
-
|
5
|
-
def initialize store, ns
|
6
|
-
@moneta_store, @ns = store, ns
|
7
|
-
end
|
8
|
-
|
9
|
-
def [] key
|
10
|
-
@moneta_store["#{@ns}:#{key}"]
|
11
|
-
end
|
12
|
-
|
13
|
-
def []= key, value
|
14
|
-
@moneta_store["#{@ns}:#{key}"] = value
|
15
|
-
end
|
16
|
-
|
17
|
-
def delete key
|
18
|
-
@moneta_store.delete "#{@ns}:#{key}"
|
19
|
-
end
|
20
|
-
|
21
|
-
def key? key
|
22
|
-
@moneta_store.key? "#{@ns}:#{key}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def has_key? key
|
26
|
-
@moneta_store.has_key? "#{@ns}:#{key}"
|
27
|
-
end
|
28
|
-
|
29
|
-
def store key, value, options
|
30
|
-
@moneta_store.store "#{@ns}:#{key}", value, options
|
31
|
-
end
|
32
|
-
|
33
|
-
def update_key key, options
|
34
|
-
@moneta_store.update_key "#{@ns}:#{key}", options
|
35
|
-
end
|
36
|
-
|
37
|
-
def clear
|
38
|
-
@moneta_store.clear
|
39
|
-
end
|
40
|
-
|
41
|
-
def method_missing method, args
|
42
|
-
@moneta_store.call method, *args
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|