ff-ruby-server-sdk 0.0.2 → 1.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/.run/build.sh.run.xml +17 -0
- data/.run/install.sh.run.xml +17 -0
- data/.run/openapi.sh.run.xml +17 -0
- data/.run/publish.sh.run.xml +17 -0
- data/.run/sdk_test.rb.run.xml +3 -3
- data/.run/unpublish.sh.run.xml +17 -0
- data/CHANGELOG.md +1 -1
- data/Gemfile +20 -3
- data/README.md +155 -7
- data/api.yaml +736 -0
- data/example/example.rb +99 -3
- data/lib/ff/ruby/server/sdk/api/auth_service.rb +91 -0
- data/lib/ff/ruby/server/sdk/api/cf_client.rb +93 -0
- data/lib/ff/ruby/server/sdk/api/client_callback.rb +45 -0
- data/lib/ff/ruby/server/sdk/api/config.rb +140 -0
- data/lib/ff/ruby/server/sdk/api/config_builder.rb +116 -0
- data/lib/ff/ruby/server/sdk/api/default_cache.rb +112 -0
- data/lib/ff/ruby/server/sdk/api/evaluation.rb +29 -0
- data/lib/ff/ruby/server/sdk/api/evaluator.rb +526 -0
- data/lib/ff/ruby/server/sdk/api/file_map_store.rb +60 -0
- data/lib/ff/ruby/server/sdk/api/flag_evaluate_callback.rb +13 -0
- data/lib/ff/ruby/server/sdk/api/inner_client.rb +311 -0
- data/lib/ff/ruby/server/sdk/api/inner_client_flag_evaluate_callback.rb +30 -0
- data/lib/ff/ruby/server/sdk/api/inner_client_metrics_callback.rb +33 -0
- data/lib/ff/ruby/server/sdk/api/inner_client_repository_callback.rb +44 -0
- data/lib/ff/ruby/server/sdk/api/inner_client_updater.rb +63 -0
- data/lib/ff/ruby/server/sdk/api/metrics_callback.rb +19 -0
- data/lib/ff/ruby/server/sdk/api/metrics_event.rb +16 -0
- data/lib/ff/ruby/server/sdk/api/metrics_processor.rb +297 -0
- data/lib/ff/ruby/server/sdk/api/operators.rb +20 -0
- data/lib/ff/ruby/server/sdk/api/polling_processor.rb +164 -0
- data/lib/ff/ruby/server/sdk/api/repository_callback.rb +28 -0
- data/lib/ff/ruby/server/sdk/api/storage_repository.rb +263 -0
- data/lib/ff/ruby/server/sdk/api/summary_metrics.rb +16 -0
- data/lib/ff/ruby/server/sdk/api/update_processor.rb +149 -0
- data/lib/ff/ruby/server/sdk/common/cache.rb +27 -0
- data/lib/ff/ruby/server/sdk/common/closeable.rb +7 -0
- data/lib/ff/ruby/server/sdk/common/destroyable.rb +12 -0
- data/lib/ff/ruby/server/sdk/common/repository.rb +45 -0
- data/lib/ff/ruby/server/sdk/common/storage.rb +29 -0
- data/lib/ff/ruby/server/sdk/connector/connector.rb +44 -0
- data/lib/ff/ruby/server/sdk/connector/events.rb +118 -0
- data/lib/ff/ruby/server/sdk/connector/harness_connector.rb +236 -0
- data/lib/ff/ruby/server/sdk/connector/service.rb +19 -0
- data/lib/ff/ruby/server/sdk/connector/updater.rb +32 -0
- data/lib/ff/ruby/server/sdk/dto/message.rb +13 -0
- data/lib/ff/ruby/server/sdk/dto/target.rb +24 -0
- data/lib/ff/ruby/server/sdk/version.rb +2 -1
- data/lib/ff/ruby/server/sdk.rb +39 -3
- data/openapitools.json +7 -0
- data/scripts/openapi.sh +35 -0
- data/scripts/sdk_specs.sh +1 -1
- metadata +46 -3
- data/lib/ff/ruby/server/sdk/cf_client.rb +0 -6
@@ -0,0 +1,236 @@
|
|
1
|
+
require "jwt"
|
2
|
+
|
3
|
+
require_relative "events"
|
4
|
+
require_relative "connector"
|
5
|
+
|
6
|
+
require_relative "../version"
|
7
|
+
|
8
|
+
class HarnessConnector < Connector
|
9
|
+
|
10
|
+
def initialize(api_key, config, on_unauthorized)
|
11
|
+
|
12
|
+
@api_key = api_key
|
13
|
+
@config = config
|
14
|
+
@on_unauthorized = on_unauthorized
|
15
|
+
@user_agent = "RubySDK " + Ff::Ruby::Server::Sdk::VERSION
|
16
|
+
|
17
|
+
@api = OpenapiClient::ClientApi.new(make_api_client)
|
18
|
+
@metrics_api = OpenapiClient::MetricsApi.new(make_metrics_api_client)
|
19
|
+
|
20
|
+
@config.logger.debug "Api: " + @api.to_s
|
21
|
+
@config.logger.debug "Metrics api: " + @metrics_api.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
def authenticate
|
25
|
+
|
26
|
+
begin
|
27
|
+
|
28
|
+
options = {
|
29
|
+
:'authentication_request' => {
|
30
|
+
:'apiKey' => @api_key
|
31
|
+
}
|
32
|
+
}
|
33
|
+
|
34
|
+
response = @api.authenticate(opts = options)
|
35
|
+
@token = response.auth_token
|
36
|
+
|
37
|
+
@config.logger.info "Token has been obtained"
|
38
|
+
process_token
|
39
|
+
return true
|
40
|
+
|
41
|
+
rescue OpenapiClient::ApiError => e
|
42
|
+
|
43
|
+
log_error(e)
|
44
|
+
end
|
45
|
+
|
46
|
+
false
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_flags
|
50
|
+
|
51
|
+
begin
|
52
|
+
|
53
|
+
return @api.get_feature_config(
|
54
|
+
|
55
|
+
environment_uuid = @environment,
|
56
|
+
opts = get_query_params
|
57
|
+
)
|
58
|
+
|
59
|
+
rescue OpenapiClient::ApiError => e
|
60
|
+
|
61
|
+
log_error(e)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def get_segments
|
66
|
+
|
67
|
+
begin
|
68
|
+
|
69
|
+
return @api.get_all_segments(
|
70
|
+
|
71
|
+
environment_uuid = @environment,
|
72
|
+
opts = get_query_params
|
73
|
+
)
|
74
|
+
|
75
|
+
rescue OpenapiClient::ApiError => e
|
76
|
+
|
77
|
+
log_error(e)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def get_flag(identifier)
|
82
|
+
|
83
|
+
@api.get_feature_config_by_identifier(
|
84
|
+
|
85
|
+
identifier = identifier,
|
86
|
+
environment_uuid = @environment,
|
87
|
+
opts = get_query_params
|
88
|
+
)
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_segment(identifier)
|
92
|
+
|
93
|
+
@api.get_segment_by_identifier(
|
94
|
+
|
95
|
+
identifier = identifier,
|
96
|
+
environment_uuid = @environment,
|
97
|
+
opts = get_query_params
|
98
|
+
)
|
99
|
+
end
|
100
|
+
|
101
|
+
def post_metrics(metrics)
|
102
|
+
|
103
|
+
begin
|
104
|
+
|
105
|
+
options = {
|
106
|
+
|
107
|
+
:'metrics' => metrics,
|
108
|
+
:'query_params' => {
|
109
|
+
|
110
|
+
:'cluster' => @cluster
|
111
|
+
}
|
112
|
+
}
|
113
|
+
|
114
|
+
@metrics_api.post_metrics(
|
115
|
+
|
116
|
+
environment = @environment,
|
117
|
+
opts = options
|
118
|
+
)
|
119
|
+
|
120
|
+
@config.logger.info "Successfully sent analytics data to the server"
|
121
|
+
|
122
|
+
rescue OpenapiClient::ApiError => e
|
123
|
+
|
124
|
+
log_error(e)
|
125
|
+
@config.logger.error "Exception while posting metrics to the event server"
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def stream(updater)
|
130
|
+
|
131
|
+
if @event_source != nil
|
132
|
+
|
133
|
+
@event_source.close
|
134
|
+
@event_source = nil
|
135
|
+
end
|
136
|
+
|
137
|
+
url = @config.config_url + "/stream?cluster=" + @cluster.to_s
|
138
|
+
|
139
|
+
headers = {
|
140
|
+
|
141
|
+
"Authorization" => "Bearer " + @token,
|
142
|
+
"API-Key" => @api_key
|
143
|
+
}
|
144
|
+
|
145
|
+
@event_source = Events.new(
|
146
|
+
|
147
|
+
url,
|
148
|
+
headers,
|
149
|
+
updater,
|
150
|
+
@config.logger
|
151
|
+
)
|
152
|
+
|
153
|
+
@event_source
|
154
|
+
end
|
155
|
+
|
156
|
+
def close
|
157
|
+
|
158
|
+
if @event_source != nil
|
159
|
+
|
160
|
+
@event_source.close
|
161
|
+
@event_source = nil
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
protected
|
166
|
+
|
167
|
+
def make_api_client
|
168
|
+
|
169
|
+
api_client = OpenapiClient::ApiClient.new
|
170
|
+
|
171
|
+
api_client.config = @config
|
172
|
+
api_client.user_agent = @user_agent
|
173
|
+
|
174
|
+
api_client
|
175
|
+
end
|
176
|
+
|
177
|
+
def make_metrics_api_client
|
178
|
+
|
179
|
+
max_timeout = 30 * 60 * 1000
|
180
|
+
|
181
|
+
api_client = OpenapiClient::ApiClient.new
|
182
|
+
|
183
|
+
config = @config.clone
|
184
|
+
|
185
|
+
config.read_timeout = max_timeout
|
186
|
+
config.write_timeout = max_timeout
|
187
|
+
config.connection_timeout = max_timeout
|
188
|
+
config.config_url = config.event_url
|
189
|
+
|
190
|
+
api_client.config = config
|
191
|
+
api_client.user_agent = @user_agent
|
192
|
+
|
193
|
+
api_client
|
194
|
+
end
|
195
|
+
|
196
|
+
def process_token
|
197
|
+
|
198
|
+
headers = {
|
199
|
+
|
200
|
+
"Authorization" => "Bearer " + @token
|
201
|
+
}
|
202
|
+
|
203
|
+
@api.api_client.default_headers = @api.api_client.default_headers.merge(headers)
|
204
|
+
@metrics_api.api_client.default_headers = @metrics_api.api_client.default_headers.merge(headers)
|
205
|
+
|
206
|
+
decoded_token = JWT.decode @token, nil, false
|
207
|
+
|
208
|
+
if decoded_token != nil && !decoded_token.empty?
|
209
|
+
|
210
|
+
@environment = decoded_token[0]["environment"]
|
211
|
+
@cluster = decoded_token[0]["clusterIdentifier"]
|
212
|
+
|
213
|
+
@config.logger.debug "Token has been processed: environment='" + @environment.to_s + "', cluster='" + @cluster.to_s + "'"
|
214
|
+
else
|
215
|
+
|
216
|
+
@config.logger.error "ERROR: Could not obtain the environment and cluster data from the token"
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
private
|
221
|
+
|
222
|
+
def get_query_params
|
223
|
+
|
224
|
+
{
|
225
|
+
:'query_params' => {
|
226
|
+
|
227
|
+
:'cluster' => @cluster
|
228
|
+
}
|
229
|
+
}
|
230
|
+
end
|
231
|
+
|
232
|
+
def log_error(e)
|
233
|
+
|
234
|
+
@config.logger.error "ERROR - Start\n\n" + e.to_s + "\nERROR - End"
|
235
|
+
end
|
236
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class Updater
|
2
|
+
|
3
|
+
def initialize
|
4
|
+
|
5
|
+
@tbi = "To be implemented"
|
6
|
+
end
|
7
|
+
|
8
|
+
def on_connected
|
9
|
+
|
10
|
+
raise @tbi
|
11
|
+
end
|
12
|
+
|
13
|
+
def on_disconnected
|
14
|
+
|
15
|
+
raise @tbi
|
16
|
+
end
|
17
|
+
|
18
|
+
def on_ready
|
19
|
+
|
20
|
+
raise @tbi
|
21
|
+
end
|
22
|
+
|
23
|
+
def on_error
|
24
|
+
|
25
|
+
raise @tbi
|
26
|
+
end
|
27
|
+
|
28
|
+
def update(message)
|
29
|
+
|
30
|
+
raise @tbi
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class Target
|
2
|
+
|
3
|
+
attr_accessor :name, :identifier, :attributes, :is_private, :private_attributes
|
4
|
+
|
5
|
+
def initialize(
|
6
|
+
|
7
|
+
name,
|
8
|
+
identifier = name,
|
9
|
+
attributes = [],
|
10
|
+
is_private = false
|
11
|
+
)
|
12
|
+
|
13
|
+
@name = name
|
14
|
+
@identifier = identifier
|
15
|
+
@attributes = attributes
|
16
|
+
@is_private = is_private
|
17
|
+
@private_attributes = Set[]
|
18
|
+
end
|
19
|
+
|
20
|
+
def is_valid
|
21
|
+
|
22
|
+
@identifier != nil && !@identifier.strip.empty?
|
23
|
+
end
|
24
|
+
end
|
data/lib/ff/ruby/server/sdk.rb
CHANGED
@@ -1,14 +1,50 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative "sdk/version"
|
4
|
-
|
4
|
+
|
5
|
+
require_relative "sdk/common/cache"
|
6
|
+
require_relative "sdk/common/storage"
|
7
|
+
require_relative "sdk/common/closeable"
|
8
|
+
require_relative "sdk/common/repository"
|
9
|
+
require_relative "sdk/common/destroyable"
|
10
|
+
|
11
|
+
require_relative "sdk/dto/target"
|
12
|
+
require_relative "sdk/dto/message"
|
13
|
+
|
14
|
+
require_relative "sdk/api/config"
|
15
|
+
require_relative "sdk/api/operators"
|
16
|
+
require_relative "sdk/api/cf_client"
|
17
|
+
require_relative "sdk/api/evaluation"
|
18
|
+
require_relative "sdk/api/inner_client"
|
19
|
+
require_relative "sdk/api/auth_service"
|
20
|
+
require_relative "sdk/api/metrics_event"
|
21
|
+
require_relative "sdk/api/default_cache"
|
22
|
+
require_relative "sdk/api/config_builder"
|
23
|
+
require_relative "sdk/api/file_map_store"
|
24
|
+
require_relative "sdk/api/summary_metrics"
|
25
|
+
require_relative "sdk/api/client_callback"
|
26
|
+
require_relative "sdk/api/update_processor"
|
27
|
+
require_relative "sdk/api/metrics_callback"
|
28
|
+
require_relative "sdk/api/metrics_processor"
|
29
|
+
require_relative "sdk/api/polling_processor"
|
30
|
+
require_relative "sdk/api/storage_repository"
|
31
|
+
require_relative "sdk/api/repository_callback"
|
32
|
+
require_relative "sdk/api/inner_client_updater"
|
33
|
+
require_relative "sdk/api/flag_evaluate_callback"
|
34
|
+
require_relative "sdk/api/inner_client_repository_callback"
|
35
|
+
require_relative "sdk/api/inner_client_flag_evaluate_callback"
|
36
|
+
|
37
|
+
require_relative "sdk/connector/updater"
|
38
|
+
require_relative "sdk/connector/service"
|
39
|
+
require_relative "sdk/connector/connector"
|
40
|
+
require_relative "sdk/connector/events"
|
41
|
+
require_relative "sdk/connector/harness_connector"
|
5
42
|
|
6
43
|
module Ff
|
7
44
|
module Ruby
|
8
45
|
module Server
|
9
46
|
module Sdk
|
10
|
-
|
11
|
-
# Your code goes here...
|
47
|
+
|
12
48
|
end
|
13
49
|
end
|
14
50
|
end
|
data/openapitools.json
ADDED
data/scripts/openapi.sh
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
full_path=$(realpath "$0")
|
4
|
+
dir_path=$(dirname "$full_path")
|
5
|
+
|
6
|
+
. "$dir_path/sdk_specs.sh"
|
7
|
+
|
8
|
+
if which openapi-generator; then
|
9
|
+
|
10
|
+
generated_path="$dir_path/../generated"
|
11
|
+
|
12
|
+
if test -e "$generated_path"; then
|
13
|
+
|
14
|
+
if rm -rf "$generated_path"; then
|
15
|
+
|
16
|
+
echo "'$generated_path' was removed with success 🙂"
|
17
|
+
else
|
18
|
+
|
19
|
+
echo "ERROR: '$$generated_path' was not removed before the generation process 😬"
|
20
|
+
exit 1
|
21
|
+
fi
|
22
|
+
fi
|
23
|
+
|
24
|
+
cd "$dir_path/.." &&
|
25
|
+
openapi-generator generate -i api.yaml -g ruby -o generated &&
|
26
|
+
cd "$generated_path" && gem build openapi_client.gemspec && cd .. &&
|
27
|
+
echo "Please enter your 'sudo' password if asked" &&
|
28
|
+
sudo gem install "$generated_path/openapi_client-1.0.0.gem" &&
|
29
|
+
echo "Generated API has been installed with success 🤟"
|
30
|
+
|
31
|
+
else
|
32
|
+
|
33
|
+
echo "ERROR: 'openapi-generator' is not installed 😬"
|
34
|
+
exit 1
|
35
|
+
fi
|
data/scripts/sdk_specs.sh
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ff-ruby-server-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Milos Vasic
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Harness is a feature management platform that helps teams to build better
|
14
14
|
software and to test features quicker.
|
@@ -19,22 +19,65 @@ extensions: []
|
|
19
19
|
extra_rdoc_files: []
|
20
20
|
files:
|
21
21
|
- ".idea/.gitignore"
|
22
|
+
- ".run/build.sh.run.xml"
|
22
23
|
- ".run/example.run.xml"
|
24
|
+
- ".run/install.sh.run.xml"
|
25
|
+
- ".run/openapi.sh.run.xml"
|
26
|
+
- ".run/publish.sh.run.xml"
|
23
27
|
- ".run/sdk_test.rb.run.xml"
|
28
|
+
- ".run/unpublish.sh.run.xml"
|
24
29
|
- ".standard.yml"
|
25
30
|
- CHANGELOG.md
|
26
31
|
- Gemfile
|
27
32
|
- LICENSE
|
28
33
|
- README.md
|
29
34
|
- Rakefile
|
35
|
+
- api.yaml
|
30
36
|
- bin/console
|
31
37
|
- bin/setup
|
32
38
|
- example/example.rb
|
33
39
|
- lib/ff/ruby/server/sdk.rb
|
34
|
-
- lib/ff/ruby/server/sdk/
|
40
|
+
- lib/ff/ruby/server/sdk/api/auth_service.rb
|
41
|
+
- lib/ff/ruby/server/sdk/api/cf_client.rb
|
42
|
+
- lib/ff/ruby/server/sdk/api/client_callback.rb
|
43
|
+
- lib/ff/ruby/server/sdk/api/config.rb
|
44
|
+
- lib/ff/ruby/server/sdk/api/config_builder.rb
|
45
|
+
- lib/ff/ruby/server/sdk/api/default_cache.rb
|
46
|
+
- lib/ff/ruby/server/sdk/api/evaluation.rb
|
47
|
+
- lib/ff/ruby/server/sdk/api/evaluator.rb
|
48
|
+
- lib/ff/ruby/server/sdk/api/file_map_store.rb
|
49
|
+
- lib/ff/ruby/server/sdk/api/flag_evaluate_callback.rb
|
50
|
+
- lib/ff/ruby/server/sdk/api/inner_client.rb
|
51
|
+
- lib/ff/ruby/server/sdk/api/inner_client_flag_evaluate_callback.rb
|
52
|
+
- lib/ff/ruby/server/sdk/api/inner_client_metrics_callback.rb
|
53
|
+
- lib/ff/ruby/server/sdk/api/inner_client_repository_callback.rb
|
54
|
+
- lib/ff/ruby/server/sdk/api/inner_client_updater.rb
|
55
|
+
- lib/ff/ruby/server/sdk/api/metrics_callback.rb
|
56
|
+
- lib/ff/ruby/server/sdk/api/metrics_event.rb
|
57
|
+
- lib/ff/ruby/server/sdk/api/metrics_processor.rb
|
58
|
+
- lib/ff/ruby/server/sdk/api/operators.rb
|
59
|
+
- lib/ff/ruby/server/sdk/api/polling_processor.rb
|
60
|
+
- lib/ff/ruby/server/sdk/api/repository_callback.rb
|
61
|
+
- lib/ff/ruby/server/sdk/api/storage_repository.rb
|
62
|
+
- lib/ff/ruby/server/sdk/api/summary_metrics.rb
|
63
|
+
- lib/ff/ruby/server/sdk/api/update_processor.rb
|
64
|
+
- lib/ff/ruby/server/sdk/common/cache.rb
|
65
|
+
- lib/ff/ruby/server/sdk/common/closeable.rb
|
66
|
+
- lib/ff/ruby/server/sdk/common/destroyable.rb
|
67
|
+
- lib/ff/ruby/server/sdk/common/repository.rb
|
68
|
+
- lib/ff/ruby/server/sdk/common/storage.rb
|
69
|
+
- lib/ff/ruby/server/sdk/connector/connector.rb
|
70
|
+
- lib/ff/ruby/server/sdk/connector/events.rb
|
71
|
+
- lib/ff/ruby/server/sdk/connector/harness_connector.rb
|
72
|
+
- lib/ff/ruby/server/sdk/connector/service.rb
|
73
|
+
- lib/ff/ruby/server/sdk/connector/updater.rb
|
74
|
+
- lib/ff/ruby/server/sdk/dto/message.rb
|
75
|
+
- lib/ff/ruby/server/sdk/dto/target.rb
|
35
76
|
- lib/ff/ruby/server/sdk/version.rb
|
77
|
+
- openapitools.json
|
36
78
|
- scripts/build.sh
|
37
79
|
- scripts/install.sh
|
80
|
+
- scripts/openapi.sh
|
38
81
|
- scripts/publish.sh
|
39
82
|
- scripts/sdk_specs.sh
|
40
83
|
- scripts/unpublish.sh
|