launchdarkly_api_helper 0.4.0 → 0.5.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b32c8619c0d002bd0974ae86f4172b4caa5733633919373d74956df9016a02f8
|
4
|
+
data.tar.gz: aa4328e4904f808b0588c02ecaf04068cc2a6d6a523500dd56a9acda0d872efd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f411f430c4c844dbb4845d678ab77d0fffbc1a0f34cec14246de70e80d1f8ab787e6e3497678abaf85fb1fea61e3f6a296f7f8892f597864724d40ab13190542
|
7
|
+
data.tar.gz: f851657526a6d3efb998159ef78920882dedfab9f71bdd10597c0db0fe49a3885cdfc5b963ac6e244a32a074ddad0112904ad7199e9f6912f4967b917748f234
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# LaunchdarklyApiHelper
|
1
|
+
# LaunchdarklyApiHelper 
|
2
2
|
|
3
3
|
[LaunchDarklyApiHelper](https://rubygems.org/gems/launchdarkly_api_helper) provides you a way to access your [Launch Darkly](https://apidocs.launchdarkly.com/) account using [API token](https://app.launchdarkly.com/settings/authorization/tokens/new) to view, edit or delete them accordingly.
|
4
4
|
|
@@ -27,10 +27,11 @@ To perform any operations such as add, remove, replace, move, copy, test you sho
|
|
27
27
|
```ruby
|
28
28
|
parameters:
|
29
29
|
access_token (*required): this token will be used to send all requests to LaunchDarkly (string)
|
30
|
-
|
30
|
+
project_name: provide project name of your organistaion (NOTE: for most, it should be `default` unless you have made some explicit changes)
|
31
|
+
log_file: all logs will be written to file 'launchdarkly.log' by default if no file name specified (string)
|
31
32
|
|
32
33
|
# set your LD API token and log file to capture logs
|
33
|
-
def ld_access_token(access_token, log_file = 'launchdarkly.log')
|
34
|
+
def ld_access_token(access_token, project_name = 'default', log_file = 'launchdarkly.log')
|
34
35
|
# code ...
|
35
36
|
end
|
36
37
|
```
|
@@ -41,21 +42,21 @@ end
|
|
41
42
|
GET REQUEST
|
42
43
|
https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
43
44
|
|
44
|
-
|
45
|
-
env (*required): name of the environment for which you want to get the details (string)
|
46
|
-
flag (*required): name of the feature flag for which you want to get the details (string)
|
47
|
-
|
48
|
-
Here, 'developer_flag_for_regression' is the feature flag name and default is our Project name - eg. AmitSinghBisht
|
45
|
+
Here, 'developer_flag_for_regression' is the feature flag name and `default` is our Project name - eg. AmitSinghBisht
|
49
46
|
By default, this returns the configurations for all environments
|
50
47
|
You can filter environments with the env query parameter. For example, setting env=staging restricts the returned configurations to just the staging environment
|
51
48
|
https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
|
52
49
|
|
50
|
+
parameters:
|
51
|
+
env (*required): name of the environment for which you want to get the details (string)
|
52
|
+
flag (*required): name of the feature flag for which you want to get the details (string)
|
53
|
+
|
53
54
|
# this method will give you entire details about a flag for that particular environment
|
54
55
|
def ld_fetch_flag_details(env, flag)
|
55
56
|
# code ...
|
56
57
|
end
|
57
58
|
|
58
|
-
@return
|
59
|
+
@return parameter: (response of feature flag details)
|
59
60
|
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" (string)
|
60
61
|
```
|
61
62
|
|
@@ -66,15 +67,12 @@ parameters:
|
|
66
67
|
env (*required): name of the environment for which you want to get the details (string)
|
67
68
|
flag (*required): name of the feature flag for which you want to get the details (string)
|
68
69
|
|
69
|
-
response = https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
|
70
|
-
grab the value of the ['environments'][env]['on'] obtained from the above response
|
71
|
-
|
72
70
|
# this method will return the status of the flag, whether it is on or off viz set to true or false
|
73
71
|
def ld_fetch_flag_toggle_status(env, flag)
|
74
72
|
# code ...
|
75
73
|
end
|
76
74
|
|
77
|
-
@return
|
75
|
+
@return parameter: (response of feature flag toggle status)
|
78
76
|
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
79
77
|
response['environments'][env]['on'] (boolean)
|
80
78
|
```
|
@@ -141,20 +139,20 @@ https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
|
|
141
139
|
PATCH REQUEST
|
142
140
|
https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
143
141
|
|
142
|
+
Here, 'developer_flag_for_regression' is the flag key and `default` is our Project name - eg. AmitSinghBisht
|
143
|
+
You can update any parameter of feature flag using this method
|
144
|
+
|
144
145
|
parameters:
|
145
146
|
env (*required): name of the environment for which you want to get the details (string)
|
146
147
|
flag (*required): name of the feature flag for which you want to get the details (string)
|
147
148
|
flag_value: status of the feature flag that you want to set either on (true) or off (false) (boolean)
|
148
149
|
|
149
|
-
Here, 'developer_flag_for_regression' is the flag key and default is our Project name - eg. AmitSinghBisht
|
150
|
-
You can update any parameter of feature flag using this method
|
151
|
-
|
152
150
|
# this method will be used to toggle status of feature flag either on / off for a particular environment
|
153
151
|
def ld_toggle_specific_environment(env, flag, flag_value = true)
|
154
152
|
# code ...
|
155
153
|
end
|
156
154
|
|
157
|
-
@return
|
155
|
+
@return parameter: (response of feature flag toggle status)
|
158
156
|
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
159
157
|
response['environments'][env]['on'] (boolean)
|
160
158
|
```
|
@@ -162,8 +160,13 @@ response['environments'][env]['on'] (boolean)
|
|
162
160
|
```ruby
|
163
161
|
Get status of feature flag
|
164
162
|
https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
|
165
|
-
|
166
|
-
|
163
|
+
|
164
|
+
parameters:
|
165
|
+
env (*required): name of the environment for which you want to get the details (string)
|
166
|
+
flag (*required): name of the feature flag for which you want to get the details (string)
|
167
|
+
|
168
|
+
# this method will get important parameters from the response
|
169
|
+
def flag_variation_served(env, flag)
|
167
170
|
# code ...
|
168
171
|
end
|
169
172
|
|
@@ -172,38 +175,131 @@ end
|
|
172
175
|
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
173
176
|
fetch_flag_toggle_status_response: response['environments'][env]['on'] (boolean)
|
174
177
|
feature_flag_variation_index_response: response (integer)
|
175
|
-
feature_flag_variation_value_response: response['variations'][feature_flag_variation_index_response]['value'] (
|
178
|
+
feature_flag_variation_value_response: response['variations'][feature_flag_variation_index_response]['value'] (string)
|
176
179
|
feature_flag_variation_name_response: response['variations'][feature_flag_variation_index_response]['name'] (string)
|
177
180
|
```
|
178
181
|
|
179
182
|
```ruby
|
183
|
+
|
184
|
+
"rules": [
|
185
|
+
{ # rules/0
|
186
|
+
"variation": 0,
|
187
|
+
"clauses": [
|
188
|
+
{ # rules/0/clauses/0
|
189
|
+
"attribute": "groups",
|
190
|
+
"op": "in",
|
191
|
+
"values": ["Top Customers"],
|
192
|
+
"negate": false
|
193
|
+
},
|
194
|
+
{ # rules/0/clauses/1
|
195
|
+
"attribute": "email",
|
196
|
+
"op": "endsWith",
|
197
|
+
"values": ["gmail.com"],
|
198
|
+
"negate": false
|
199
|
+
}
|
200
|
+
]
|
201
|
+
},
|
202
|
+
{ # rules/1
|
203
|
+
"variation": 1,
|
204
|
+
"clauses": [
|
205
|
+
{ # rules/1/clauses/0
|
206
|
+
"attribute": "country",
|
207
|
+
"op": "in",
|
208
|
+
"values": [
|
209
|
+
"in", # rules/1/clauses/0/values/0
|
210
|
+
"eu" # rules/1/clauses/0/values/1
|
211
|
+
],
|
212
|
+
"negate": false
|
213
|
+
}
|
214
|
+
]
|
215
|
+
}
|
216
|
+
]
|
217
|
+
|
218
|
+
parameters:
|
219
|
+
env (*required): name of the environment for which you want to get the details (string)
|
220
|
+
flag (*required): name of the feature flag for which you want to get the details (string)
|
221
|
+
clause_name (*required): name of clause that you want to search for in response
|
222
|
+
|
223
|
+
# this method will return the index of rules and clauses by searching for clause_name in response
|
180
224
|
def ld_rules_clauses_index(env, flag, clause_name)
|
181
225
|
# code ...
|
182
226
|
end
|
227
|
+
|
228
|
+
@returns: [rule_at_index, clause_at_index]
|
229
|
+
@return parameter:
|
230
|
+
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" ['environments'][env]['rules']
|
231
|
+
rule_at_index = response[rule_index] (integer) # index at which rule is found
|
232
|
+
clause_at_index = response[rule_index]['clauses'][clause_index] (integer) # index at which clause is found
|
183
233
|
```
|
184
234
|
|
185
235
|
```ruby
|
236
|
+
parameters:
|
237
|
+
env (*required): name of the environment for which you want to get the details (string)
|
238
|
+
flag (*required): name of the feature flag for which you want to get the details (string)
|
239
|
+
clause_name (*required): name of clause that you want to search for in response
|
240
|
+
|
241
|
+
# this method will return values inside a particular clause by searching for clause_name in response
|
186
242
|
def ld_get_values_from_clauses(env, flag, clause_name)
|
187
243
|
# code ...
|
188
244
|
end
|
245
|
+
|
246
|
+
@return parameter: values_for_clause_name
|
247
|
+
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" ['environments'][env]['rules']
|
248
|
+
values_for_clause_name = response[rule_at_index]['clauses'][clause_at_index]['values'] (string)
|
189
249
|
```
|
190
250
|
|
191
251
|
```ruby
|
252
|
+
parameters:
|
253
|
+
env (*required): name of the environment for which you want to get the details (string)
|
254
|
+
flag (*required): name of the feature flag for which you want to get the details (string)
|
255
|
+
clause_name (*required): name of clause that you want to search for in response
|
256
|
+
clause_value (*required): value that you want to add to a particular clause (NOTE: it will be appened at zeroth 0th index)
|
257
|
+
|
258
|
+
# this method will help you to add a value to a particular clause by searching for clause_name in response
|
192
259
|
def ld_add_values_to_clause(env, flag, clause_name, clause_value)
|
193
260
|
# code ...
|
194
261
|
end
|
262
|
+
|
263
|
+
@return parameter: (response of feature flag details)
|
264
|
+
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" (string)
|
195
265
|
```
|
196
266
|
|
197
267
|
```ruby
|
198
|
-
|
268
|
+
parameters:
|
269
|
+
env (*required): name of the environment for which you want to get the details (string)
|
270
|
+
flag (*required): name of the feature flag for which you want to get the details (string)
|
271
|
+
clause_name (*required): name of clause that you want to search for in response
|
272
|
+
clause_value (*required): value that you want to add to a particular clause (NOTE: it will be appened at zeroth 0th index)
|
273
|
+
|
274
|
+
# this method will help you to remove a value to a particular clause by searching for clause_name in response
|
275
|
+
def ld_remove_values_from_clause(env, flag, clause_name, clause_value)
|
199
276
|
# code ...
|
200
277
|
end
|
278
|
+
|
279
|
+
@return parameter: (response of feature flag details)
|
280
|
+
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" (string)
|
201
281
|
```
|
202
282
|
|
203
283
|
```ruby
|
284
|
+
Delete feature flag
|
285
|
+
https://apidocs.launchdarkly.com/tag/Feature-flags#operation/deleteFeatureFlag
|
286
|
+
|
287
|
+
DELETE REQUEST
|
288
|
+
https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
289
|
+
|
290
|
+
Here, 'developer_flag_for_regression' is the flag key and default is our Project name - eg. AmitSinghBisht
|
291
|
+
You can delete any feature flag using this method
|
292
|
+
|
293
|
+
parameters:
|
294
|
+
flag (*required): name of the feature flag for which you want to get the details (string)
|
295
|
+
|
296
|
+
# this method will delete a feature flag in launchdarkly (NOTE: env resided inside flag which means flag is parent, so deleting a feature flag will delete it from all environment)
|
204
297
|
def ld_delete_flag(flag)
|
205
298
|
# code ...
|
206
299
|
end
|
300
|
+
|
301
|
+
@return parameter: (response of feature flag details)
|
302
|
+
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}" (string)
|
207
303
|
```
|
208
304
|
|
209
305
|
## Development
|
@@ -8,8 +8,12 @@ require_relative 'constants'
|
|
8
8
|
|
9
9
|
# All methods related to launch darkly api are defined here
|
10
10
|
class LaunchdarklyApiHelperClass
|
11
|
-
|
11
|
+
|
12
|
+
@launch_darkly_flags = 'https://app.launchdarkly.com/api/v2/flags/project_name'
|
13
|
+
|
14
|
+
def initialize(access_token, project_name, log_file)
|
12
15
|
@access_token = access_token
|
16
|
+
@launch_darkly_flags.gsub! 'project_name', project_name
|
13
17
|
@logger = Logger.new(log_file)
|
14
18
|
end
|
15
19
|
|
@@ -43,7 +47,7 @@ class LaunchdarklyApiHelperClass
|
|
43
47
|
end
|
44
48
|
|
45
49
|
def fetch_flag_details(env, flag)
|
46
|
-
request_url = "#{
|
50
|
+
request_url = "#{@launch_darkly_flags}/#{flag}?env=#{env}"
|
47
51
|
ld_request(:get, request_url)
|
48
52
|
end
|
49
53
|
|
@@ -53,14 +57,14 @@ class LaunchdarklyApiHelperClass
|
|
53
57
|
end
|
54
58
|
|
55
59
|
def create_flag(key, name, description, tags)
|
56
|
-
request_url =
|
60
|
+
request_url = @launch_darkly_flags
|
57
61
|
request_body = {}
|
58
62
|
request_body.merge!(key: key, name: name, description: description, tags: tags)
|
59
63
|
ld_request(:post, request_url, request_body)
|
60
64
|
end
|
61
65
|
|
62
66
|
def toggle_specific_environment(env, flag, flag_value)
|
63
|
-
request_url = "#{
|
67
|
+
request_url = "#{@launch_darkly_flags}/#{flag}"
|
64
68
|
request_body = { 'op' => 'replace', 'path' => "/environments/#{env}/on", 'value' => flag_value }
|
65
69
|
response_body = ld_request(:patch, request_url, [request_body])
|
66
70
|
response_body['environments'][env]['on']
|
@@ -86,7 +90,7 @@ class LaunchdarklyApiHelperClass
|
|
86
90
|
details_response['variations'][index_response]['name']
|
87
91
|
end
|
88
92
|
|
89
|
-
def
|
93
|
+
def flag_variation_served(env, flag)
|
90
94
|
details_response = fetch_flag_details(env, flag)
|
91
95
|
toggle_status_response = fetch_flag_toggle_status(env, flag)
|
92
96
|
variation_index_response = feature_flag_variation_index(toggle_status_response, details_response) # ['environments'][env]['fallthrough']['variation']
|
@@ -130,29 +134,29 @@ class LaunchdarklyApiHelperClass
|
|
130
134
|
end
|
131
135
|
|
132
136
|
def get_values_from_clauses(env, flag, clause_name)
|
133
|
-
rule_at_index, clause_at_index =
|
137
|
+
rule_at_index, clause_at_index = rules_clauses_index(env, flag, clause_name)
|
134
138
|
@feature_flag_rules_list[rule_at_index]['clauses'][clause_at_index]['values']
|
135
139
|
end
|
136
140
|
|
137
141
|
def add_values_to_clause(env, flag, clause_name, clause_value)
|
138
|
-
rule_at_index, clause_at_index =
|
139
|
-
request_url = "#{
|
142
|
+
rule_at_index, clause_at_index = rules_clauses_index(env, flag, clause_name)
|
143
|
+
request_url = "#{@launch_darkly_flags}/#{flag}"
|
140
144
|
request_body = { 'op' => 'add', 'path' => "/environments/#{env}/rules/#{rule_at_index}/clauses/#{clause_at_index}/values/0", 'value' => clause_value }
|
141
145
|
ld_request(:patch, request_url, [request_body])
|
142
146
|
end
|
143
147
|
|
144
148
|
def remove_values_from_clause(env, flag, clause_name, clause_value)
|
145
|
-
rule_at_index, clause_at_index =
|
149
|
+
rule_at_index, clause_at_index = rules_clauses_index(env, flag, clause_name)
|
146
150
|
value_at_index = search_value_index(rule_at_index, clause_at_index, clause_value)
|
147
151
|
puts "value_index: #{value_at_index}"
|
148
|
-
request_url = "#{
|
152
|
+
request_url = "#{@launch_darkly_flags}/#{flag}"
|
149
153
|
request_body = { 'op' => 'test', 'path' => "/environments/#{env}/rules/#{rule_at_index}/clauses/#{clause_at_index}/values/#{value_at_index}", 'value' => clause_value },
|
150
154
|
{ 'op' => 'remove', 'path' => "/environments/#{env}/rules/#{rule_at_index}/clauses/#{clause_at_index}/values/#{value_at_index}" }
|
151
155
|
ld_request(:patch, request_url, request_body)
|
152
156
|
end
|
153
157
|
|
154
158
|
def delete_flag(flag)
|
155
|
-
request_url = "#{
|
159
|
+
request_url = "#{@launch_darkly_flags}/#{flag}"
|
156
160
|
ld_request(:delete, request_url)
|
157
161
|
end
|
158
162
|
end
|
@@ -34,8 +34,8 @@ module LaunchdarklyApiHelper
|
|
34
34
|
# == To perform any operations such as add, remove, replace, move, copy, test you should have a working knowledge of JSON Patch
|
35
35
|
# https://datatracker.ietf.org/doc/html/rfc6902
|
36
36
|
|
37
|
-
def ld_access_token(access_token, log_file = 'launchdarkly.log')
|
38
|
-
@launchdarkly_helper = LaunchdarklyApiHelperClass.new(access_token, log_file)
|
37
|
+
def ld_access_token(access_token, project_name = 'default', log_file = 'launchdarkly.log')
|
38
|
+
@launchdarkly_helper = LaunchdarklyApiHelperClass.new(access_token, project_name, log_file)
|
39
39
|
end
|
40
40
|
|
41
41
|
# == Get feature flag
|
@@ -144,8 +144,8 @@ module LaunchdarklyApiHelper
|
|
144
144
|
#
|
145
145
|
# [fetch_flag_toggle_status_response, feature_flag_variation_index_response, feature_flag_variation_value_response, feature_flag_variation_name_response]
|
146
146
|
|
147
|
-
def
|
148
|
-
@launchdarkly_helper.
|
147
|
+
def ld_flag_variation_served(env, flag)
|
148
|
+
@launchdarkly_helper.flag_variation_served(env, flag)
|
149
149
|
end
|
150
150
|
|
151
151
|
def ld_rules_clauses_index(env, flag, clause_name)
|
@@ -160,7 +160,7 @@ module LaunchdarklyApiHelper
|
|
160
160
|
@launchdarkly_helper.add_values_to_clause(env, flag, clause_name, clause_value)
|
161
161
|
end
|
162
162
|
|
163
|
-
def
|
163
|
+
def ld_remove_values_from_clause(env, flag, clause_name, clause_value)
|
164
164
|
@launchdarkly_helper.remove_values_from_clause(env, flag, clause_name, clause_value)
|
165
165
|
end
|
166
166
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: launchdarkly_api_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- amit-singh-bisht
|
@@ -33,7 +33,7 @@ metadata:
|
|
33
33
|
allowed_push_host: https://rubygems.org
|
34
34
|
homepage_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby
|
35
35
|
source_code_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby
|
36
|
-
changelog_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby/blob/
|
36
|
+
changelog_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby/blob/master/README.md
|
37
37
|
post_install_message:
|
38
38
|
rdoc_options: []
|
39
39
|
require_paths:
|