checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
---
2
2
SHA256:
3
- metadata.gz: 55aaa860486faaaed1fb9b1dcb1d44b351b4cf694cab1db0498d043168d99b9b
4
- data.tar.gz: e4d08727a9e1505bae464aab89f16432793e1275dbf5789a1620afe831eb0200
3
+ metadata.gz: de9001a9e249f065997001450d453c225bf127ddd03faa337a9ec01054349299
4
+ data.tar.gz: 841fc4c60204d05fa101d904dacd5ade476d862258ce5d6c16206b67d8999456
5
5
SHA512:
6
- metadata.gz: a06ba03570bdd98945ea4a7be7ad694368245a80c349ac600dbc117b02012b0d70d689243cde228741a0a8395636e1d398ffaaf53540844940c9057913ee5a73
7
- data.tar.gz: 1ce92c22a7cffe6d62b198f215939ca107a3db33fb4dbf0a5d268231fdb3e4e8b7d02773acccd4dbbc02112394daaef9b19d541ce7709abf9a012b225275a395
6
+ metadata.gz: b9dff72f5b2a6436cefc6ca8706e7bf6e2956fb8a2d62f3f59444950f800549022f0a2ad7243a52570d1abe516c28d9500ff87ac90f3a2cb5274a9348bc2578e
7
+ data.tar.gz: 15da4523a462a3b16a67921a0f29ae78fb1812f7802260980c03a25d84f052dab45ab788cf19654e4cd6fd225fb12f7ed3bfcac9418a066d90cc3ab51e0ffaf3
data/.github/CODEOWNERS ADDED
@@ -0,0 +1 @@
1
+ * @RadekMolenda @cfabianski
data/.rubocop.yml CHANGED
@@ -18,7 +18,10 @@ Metrics/LineLength:
18
18
Exclude:
19
19
- 'config/**/*'
20
20
- 'spec/**/*'
21
- Max: 120
21
+ Max: 160
22
+
23
+ Metrics/ClassLength:
24
+ Max: 200
22
25
23
26
Metrics/BlockLength:
24
27
Exclude:
@@ -38,3 +41,6 @@ Layout/AlignParameters:
38
41
39
42
Bundler/OrderedGems:
40
43
Enabled: false
44
+
45
+ Metrics/ParameterLists:
46
+ Enabled: false
data/Gemfile.lock CHANGED
@@ -1,52 +1,54 @@
1
1
PATH
2
2
remote: .
3
3
specs:
4
- bearer (1.0.1)
4
+ bearer (1.1.0)
5
5
6
6
GEM
7
7
remote: https://rubygems.org/
8
8
specs:
9
- addressable (2.6.0)
10
- public_suffix (>= 2.0.2, < 4.0)
9
+ addressable (2.7.0)
10
+ public_suffix (>= 2.0.2, < 5.0)
11
11
ast (2.4.0)
12
- childprocess (0.9.0)
13
- ffi (~> 1.0, >= 1.0.11)
12
+ byebug (11.0.1)
13
+ childprocess (3.0.0)
14
14
coderay (1.1.2)
15
15
crack (0.4.3)
16
16
safe_yaml (~> 1.0.0)
17
17
diff-lcs (1.3)
18
- ffi (1.10.0)
18
+ hashdiff (1.0.0)
19
- hashdiff (0.3.8)
20
19
iniparse (1.4.4)
21
- jaro_winkler (1.5.2)
20
+ jaro_winkler (1.5.3)
22
21
method_source (0.9.2)
23
- overcommit (0.46.0)
24
- childprocess (~> 0.6, >= 0.6.3)
22
+ overcommit (0.50.0)
23
+ childprocess (>= 0.6.3, < 4)
25
24
iniparse (~> 1.4)
26
- parallel (1.14.0)
27
- parser (2.6.0.0)
25
+ parallel (1.17.0)
26
+ parser (2.6.4.1)
28
27
ast (~> 2.4.0)
29
28
powerpack (0.1.2)
30
29
pry (0.12.2)
31
30
coderay (~> 1.1.0)
32
31
method_source (~> 0.9.0)
32
+ pry-byebug (3.7.0)
33
+ byebug (~> 11.0)
34
+ pry (~> 0.10)
33
35
psych (3.1.0)
34
- public_suffix (3.0.3)
36
+ public_suffix (4.0.1)
35
37
rainbow (3.0.0)
36
38
rake (10.5.0)
37
39
rspec (3.8.0)
38
40
rspec-core (~> 3.8.0)
39
41
rspec-expectations (~> 3.8.0)
40
42
rspec-mocks (~> 3.8.0)
41
- rspec-core (3.8.0)
43
+ rspec-core (3.8.2)
42
44
rspec-support (~> 3.8.0)
43
- rspec-expectations (3.8.2)
45
+ rspec-expectations (3.8.4)
44
46
diff-lcs (>= 1.2.0, < 2.0)
45
47
rspec-support (~> 3.8.0)
46
- rspec-mocks (3.8.0)
48
+ rspec-mocks (3.8.1)
47
49
diff-lcs (>= 1.2.0, < 2.0)
48
50
rspec-support (~> 3.8.0)
49
- rspec-support (3.8.0)
51
+ rspec-support (3.8.2)
50
52
rubocop (0.65.0)
51
53
jaro_winkler (~> 1.5.1)
52
54
parallel (~> 1.10)
@@ -56,26 +58,27 @@ GEM
56
58
rainbow (>= 2.2.2, < 4.0)
57
59
ruby-progressbar (~> 1.7)
58
60
unicode-display_width (~> 1.4.0)
59
- ruby-progressbar (1.10.0)
61
+ ruby-progressbar (1.10.1)
60
62
safe_yaml (1.0.5)
61
63
unicode-display_width (1.4.1)
62
- webmock (3.5.1)
64
+ webmock (3.7.6)
63
65
addressable (>= 2.3.6)
64
66
crack (>= 0.3.2)
65
- hashdiff
67
+ hashdiff (>= 0.4.0, < 2.0.0)
66
68
67
69
PLATFORMS
68
70
ruby
69
71
70
72
DEPENDENCIES
71
73
bearer!
72
- bundler (~> 1.16)
74
+ bundler (~> 2.0)
73
75
overcommit
74
76
pry
77
+ pry-byebug
75
78
rake (~> 10.0)
76
79
rspec (~> 3.0)
77
80
rubocop (~> 0.65.0)
78
81
webmock
79
82
80
83
BUNDLED WITH
81
- 1.17.2
84
+ 2.0.2
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
# Bearer
2
2
3
- This gem is a Ruby client to interact with APIs via [Bearer](https://www.bearer.sh).
3
+ This gem is a Ruby client to universally call any API using [Bearer.sh](https://www.bearer.sh).
4
4
5
5
_NB: If you are using Rails, also have a look at the [Rails](https://github.com/bearer/bearer-rails) gem_
6
6
@@ -25,7 +25,7 @@ $ gem install bearer
25
25
26
26
## Usage
27
27
28
- Grab your Bearer [API Key](https://app.bearer.sh/keys) and integration id from
28
+ Grab your Bearer [Secret Key](https://app.bearer.sh/keys) and integration id from
29
29
the [Dashboard](https://app.bearer.sh) and then you can use the client as follows:
30
30
31
31
### Calling any APIs
@@ -33,7 +33,7 @@ the [Dashboard](https://app.bearer.sh) and then you can use the client as follow
33
33
```ruby
34
34
require "bearer"
35
35
36
- bearer = Bearer.new("your api key") # find it on https://app.bearer.sh/keys
36
+ bearer = Bearer.new("BEARER_SECRET_KEY") # find it on https://app.bearer.sh/keys
37
37
github = (
38
38
bearer
39
39
.integration("your integration id") # you'll find it on the Bearer dashboard https://app.bearer.sh
@@ -62,7 +62,7 @@ puts JSON.parse(github.post("/user/repos", body: { name: "Just setting up my Bea
62
62
```ruby
63
63
require "bearer"
64
64
65
- bearer = Bearer.new("your api key")
65
+ bearer = Bearer.new("BEARER_SECRET_KEY")
66
66
github = bearer.integration("your integration id")
67
67
68
68
puts github.invoke("your function name")
@@ -72,15 +72,15 @@ puts github.invoke("your function name")
72
72
73
73
### Global configuration
74
74
75
- You can configure the client globally with your [API Key](https://app.bearer.sh/keys):
75
+ You can configure the client globally with your [Secret Key](https://app.bearer.sh/keys):
76
76
77
77
```ruby
78
78
Bearer::Configuration.setup do |config|
79
- config.api_key = "your api key" # copy and paste the `API key`
79
+ config.secret_key = "BEARER_SECRET_KEY" # copy and paste your Bearer `Secret Key`
80
80
end
81
81
```
82
82
83
- You can now use the client without needing to pass the API Key each time:
83
+ You can now use the client without having to pass the Secret Key each time:
84
84
85
85
```ruby
86
86
github = Bearer.integration("your integration id").auth("your auth id")
data/bearer.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
spec.email = ["engineering@bearer.sh"]
10
10
11
11
spec.summary = %q{Bearer Ruby}
12
- spec.description = %q{Bearer Ruby description}
12
+ spec.description = %q{Ruby client to universally call any API using Bearer.sh}
13
13
spec.homepage = "https://www.bearer.sh"
14
14
spec.licenses = ['MIT']
15
15
if spec.respond_to?(:metadata)
@@ -26,10 +26,11 @@ Gem::Specification.new do |spec|
26
26
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
spec.require_paths = ["lib"]
28
28
29
- spec.add_development_dependency "bundler", "~> 1.16"
29
+ spec.add_development_dependency "bundler", "~> 2.0"
30
30
spec.add_development_dependency "rake", "~> 10.0"
31
31
spec.add_development_dependency "rspec", "~> 3.0"
32
32
spec.add_development_dependency "rubocop", "~> 0.65.0"
33
33
spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "pry-byebug"
34
35
spec.add_development_dependency "overcommit"
35
36
end
data/lib/bearer.rb CHANGED
@@ -4,21 +4,19 @@ require_relative "./bearer/configuration"
4
4
require_relative "./bearer/integration"
5
5
6
6
class Bearer
7
- PRODUCTION_INTEGRATION_HOST = "https://int.bearer.sh"
8
-
9
7
# Public: Create an instance of the Bearer client
10
8
#
11
9
# api_key - developer API Key from the Dashboard. Defaults to the value from the `Bearer::Configuration` object
12
- def initialize(api_key = Bearer::Configuration.api_key, integration_host: nil)
13
- @api_key = api_key
14
- @integration_host = integration_host || Bearer::Configuration.integration_host || PRODUCTION_INTEGRATION_HOST
10
+ def initialize(secret_key = Bearer::Configuration.secret_key, integration_host: nil)
11
+ @secret_key = secret_key
12
+ @integration_host = integration_host || Bearer::Configuration.integration_host
15
13
end
16
14
17
15
# Public: Return an integration client
18
16
#
19
17
# integration_id - the integration's unique identifier from the Dashboard
20
18
def integration(integration_id)
21
- Integration.new(integration_id: integration_id, integration_host: @integration_host, api_key: @api_key)
19
+ Integration.new(integration_id: integration_id, integration_host: @integration_host, secret_key: @secret_key)
22
20
end
23
21
24
22
class << self
data/lib/bearer/configuration.rb CHANGED
@@ -8,25 +8,88 @@ class Bearer
8
8
class Configuration
9
9
include Singleton
10
10
11
- FIELDS = %i[api_key client_id secret integration_host].freeze
11
+ PRODUCTION_INTEGRATION_HOST = "https://int.bearer.sh"
12
- OPTIONAL_FIELDS = %i[integration_host].freeze
13
12
14
- attr_writer(*FIELDS)
13
+ FIELDS = %i[
14
+ secret_key
15
+ publishable_key
16
+ encryption_key
17
+ integration_host
18
+ http_client_params
19
+ ].freeze
15
20
16
- FIELDS.each do |field|
17
- is_optional = OPTIONAL_FIELDS.include?(field)
21
+ DEPRECATED_FIELDS = %i[
22
+ api_key
23
+ client_id
24
+ secret
25
+ ].freeze
18
26
19
- define_method field do
20
- value = instance_variable_get(:"@#{field}")
27
+ DEFAULT_READ_TIMEOUT = 5
28
+ DEFAULT_OPEN_TIMEOUT = 5
21
29
22
- raise ::Bearer::Errors::Configuration, "Bearer #{field} is missing!" unless value || is_optional
30
+ # @return [Hash]
31
+ def integration_host
32
+ @integration_host ||= PRODUCTION_INTEGRATION_HOST
33
+ end
23
34
24
- value
25
- end
35
+ # @return [Hash]
36
+ def http_client_params
37
+ default_http_client_params.merge(@http_client_params || {})
38
+ end
39
+
40
+ # @return [String]
41
+ def secret_key
42
+ raise_if_missing(:secret_key)
43
+ end
44
+
45
+ # @return [String]
46
+ def publishable_key
47
+ raise_if_missing(:publishable_key)
48
+ end
49
+
50
+ # @return [String]
51
+ def encryption_key
52
+ raise_if_missing(:encryption_key)
53
+ end
54
+
55
+ # @return [String]
56
+ def api_key
57
+ deprecate("api_key", "secret_key")
58
+ secret_key
59
+ end
60
+
61
+ # @return [String]
62
+ def client_id
63
+ deprecate("client_id", "publishable_key")
64
+ publishable_key
65
+ end
66
+
67
+ # @return [String]
68
+ def secret
69
+ deprecate("secret", "encryption_key")
70
+ encryption_key
71
+ end
72
+
73
+ attr_writer(*FIELDS)
74
+
75
+ def api_key=(value)
76
+ deprecate("api_key=", "secret_key=")
77
+ @secret_key = value
78
+ end
79
+
80
+ def client_id=(value)
81
+ deprecate("client_id=", "publishable_key=")
82
+ @publishable_key = value
83
+ end
84
+
85
+ def secret=(value)
86
+ deprecate("secret=", "encryption_key=")
87
+ @encryption_key = value
26
88
end
27
89
28
90
class << self
29
- EXISTING_METHODS = FIELDS.flat_map { |field| [field, "#{field}=".to_sym] }
91
+ ALL_METHODS = [*FIELDS, *DEPRECATED_FIELDS].freeze
92
+ EXISTING_METHODS = ALL_METHODS.flat_map { |field| [field, "#{field}=".to_sym] }
30
93
31
94
def method_missing(name, *args, &block)
32
95
super unless EXISTING_METHODS.include? name
@@ -36,16 +99,50 @@ class Bearer
36
99
def respond_to_missing?(name, include_private = false)
37
100
EXISTING_METHODS.include?(name) || super
38
101
end
39
- end
40
102
41
- def self.reset
42
- FIELDS.each do |field|
43
- instance.public_send("#{field}=", nil)
103
+ def reset
104
+ FIELDS.each do |field|
105
+ instance.public_send("#{field}=", nil)
106
+ end
44
107
end
108
+
109
+ def setup
110
+ yield(instance)
111
+ end
112
+ end
113
+
114
+ private
115
+
116
+ def raise_if_missing(field)
117
+ value = instance_variable_get(:"@#{field}")
118
+
119
+ raise ::Bearer::Errors::Configuration, "Bearer #{field} is missing!" unless value
120
+
121
+ value
122
+ end
123
+
124
+ def deprecate(old_field, new_field)
125
+ puts "Bearer Deprecation Warning: #{old_field} is deprecated, use #{new_field} instead"
126
+ end
127
+
128
+ # defaults to 5 seconds
129
+ # @return [Integer]
130
+ def open_timeout
131
+ @open_timeout || DEFAULT_READ_TIMEOUT
132
+ end
133
+
134
+ # defaults to 5 seconds
135
+ # @return [Integer]
136
+ def read_timeout
137
+ @read_timeout || DEFAULT_READ_TIMEOUT
45
138
end
46
139
47
- def self.setup
48
- yield(instance)
140
+ # @return [Hash]
141
+ def default_http_client_params
142
+ {
143
+ read_timeout: read_timeout,
144
+ open_timeout: open_timeout
145
+ }
49
146
end
50
147
end
51
148
end
data/lib/bearer/integration.rb CHANGED
@@ -2,6 +2,7 @@
2
2
3
3
require "net/http"
4
4
require "json"
5
+ require "forwardable"
5
6
6
7
require_relative "./errors"
7
8
require_relative "./version"
@@ -10,19 +11,22 @@ class Bearer
10
11
class Integration
11
12
FUNCTIONS_PATH = "api/v4/functions/backend"
12
13
PROXY_FUNCTION_NAME = "bearer-proxy"
14
+ extend Forwardable
13
15
14
16
def initialize(
15
17
integration_id:,
16
18
integration_host:,
17
- api_key:,
19
+ secret_key:,
20
+ read_timeout: nil,
18
21
setup_id: nil,
19
22
auth_id: nil
20
23
)
21
24
@integration_id = integration_id
22
25
@integration_host = integration_host
23
- @api_key = api_key
26
+ @secret_key = secret_key
24
27
@setup_id = setup_id
25
28
@auth_id = auth_id
29
+ @read_timeout = read_timeout
26
30
end
27
31
28
32
# Public: Invoke an integration function
@@ -36,8 +40,8 @@ class Bearer
36
40
url = "#{@integration_host}/#{FUNCTIONS_PATH}/#{@integration_id}/#{function_name}"
37
41
headers = {
38
42
"Content-Type" => "application/json",
39
- "Authorization": @api_key,
40
- "User-Agent" => "Bearer (#{Bearer::VERSION})"
43
+ "Authorization": @secret_key,
44
+ "User-Agent" => "Bearer-Ruby (#{Bearer::VERSION})"
41
45
}
42
46
43
47
response = make_request(method: "POST", url: url, query: query, body: body, headers: headers)
@@ -54,7 +58,7 @@ class Bearer
54
58
self.class.new(
55
59
integration_id: @integration_id,
56
60
integration_host: @integration_host,
57
- api_key: @api_key,
61
+ secret_key: @secret_key,
58
62
setup_id: setup_id,
59
63
auth_id: @auth_id
60
64
)
@@ -67,7 +71,7 @@ class Bearer
67
71
self.class.new(
68
72
integration_id: @integration_id,
69
73
integration_host: @integration_host,
70
- api_key: @api_key,
74
+ secret_key: @secret_key,
71
75
setup_id: @setup_id,
72
76
auth_id: auth_id
73
77
)
@@ -129,8 +133,8 @@ class Bearer
129
133
# query - parameters to add to the URL's query string
130
134
def request(method, endpoint, headers: nil, body: nil, query: nil)
131
135
pre_headers = {
132
- "Authorization": @api_key,
133
- "User-Agent": "Bearer.sh",
136
+ "Authorization": @secret_key,
137
+ "User-Agent": "Bearer-Ruby (#{Bearer::VERSION})",
134
138
"Bearer-Auth-Id": @auth_id,
135
139
"Bearer-Setup-Id": @setup_id,
136
140
# TODO: Remove this when integration service content type support is fixed
@@ -150,11 +154,21 @@ class Bearer
150
154
151
155
private
152
156
157
+ # @return [Hash]
158
+ def http_client_params
159
+ Bearer::Configuration.http_client_params
160
+ end
161
+
153
162
def make_request(method:, url:, query:, body:, headers:)
154
163
parsed_url = URI(url)
155
164
parsed_url.query = URI.encode_www_form(query) if query
156
165
157
- Net::HTTP.start(parsed_url.hostname, parsed_url.port, use_ssl: parsed_url.scheme == "https") do |http|
166
+ Net::HTTP.start(
167
+ parsed_url.hostname,
168
+ parsed_url.port,
169
+ use_ssl: parsed_url.scheme == "https",
170
+ **http_client_params
171
+ ) do |http|
158
172
http.send_request(method, parsed_url, body ? body.to_json : nil, headers)
159
173
end
160
174
end
data/lib/bearer/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
# frozen_string_literal: true
2
2
3
3
class Bearer
4
- VERSION = "1.0.1"
4
+ VERSION = "1.1.0"
5
5
end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
--- !ruby/object:Gem::Specification
2
2
name: bearer
3
3
version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
platform: ruby
6
6
authors:
7
7
- Bearer Team<engineering@bearer.sh>
8
8
autorequire:
9
9
bindir: exe
10
10
cert_chain: []
11
- date: 2019-07-21 00:00:00.000000000 Z
11
+ date: 2019-10-02 00:00:00.000000000 Z
12
12
dependencies:
13
13
- !ruby/object:Gem::Dependency
14
14
name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
requirements:
17
17
- - "~>"
18
18
- !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: '2.0'
20
20
type: :development
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: '1.16'
26
+ version: '2.0'
27
27
- !ruby/object:Gem::Dependency
28
28
name: rake
29
29
requirement: !ruby/object:Gem::Requirement
@@ -81,6 +81,20 @@ dependencies:
81
81
- !ruby/object:Gem::Version
82
82
version: '0'
83
83
- !ruby/object:Gem::Dependency
84
+ name: pry-byebug
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'
97
+ - !ruby/object:Gem::Dependency
84
98
name: overcommit
85
99
requirement: !ruby/object:Gem::Requirement
86
100
requirements:
@@ -94,13 +108,14 @@ dependencies:
94
108
- - ">="
95
109
- !ruby/object:Gem::Version
96
110
version: '0'
97
- description: Bearer Ruby description
111
+ description: Ruby client to universally call any API using Bearer.sh
98
112
email:
99
113
- engineering@bearer.sh
100
114
executables: []
101
115
extensions: []
102
116
extra_rdoc_files: []
103
117
files:
118
+ - ".github/CODEOWNERS"
104
119
- ".github/PULL_REQUEST_TEMPLATE.md"
105
120
- ".github/main.workflow"
106
121
- ".gitignore"