launchdarkly_api_helper 0.5.0 → 0.7.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: cc0c1b25efd8bceafce66fca401b054433d58bd16057952a5af5454f71c723aa
|
4
|
+
data.tar.gz: 2366bb57ed059ea241df1488c3300fd2ccd2f7803a03a04dd90915c199f7fab4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 31921892456f509b895c2119873daa5b6a9d8d566baacc6721f1e5b307d7413156e7100dd8a890606621433305ea43def942d86d0ab01fe98ef660febd55f51f
|
7
|
+
data.tar.gz: 8ed558e1a93bf0f3e1b42b17ea767f700436b73438aa48eb02de30598f0683c020f98a97172e39249a6c474a0cbcac7c85d806b47a4095c59cf336264b1cd985
|
data/README.md
CHANGED
@@ -1,4 +1,12 @@
|
|
1
|
-
# LaunchdarklyApiHelper
|
1
|
+
# LaunchdarklyApiHelper
|
2
|
+
<div>
|
3
|
+
<a href="https://rubygems.org/gems/launchdarkly_api_helper">
|
4
|
+
<img alt="GEM Version" src="https://img.shields.io/gem/v/launchdarkly_api_helper?color=38C160&logo=ruby&logoColor=FE1616">
|
5
|
+
</a>
|
6
|
+
<a href="https://rubygems.org/gems/launchdarkly_api_helper">
|
7
|
+
<img alt="Gem Downloads" src="https://img.shields.io/gem/dt/launchdarkly_api_helper?color=38C160&logo=ruby&logoColor=FE1616">
|
8
|
+
</a>
|
9
|
+
</div>
|
2
10
|
|
3
11
|
[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
12
|
|
@@ -27,7 +35,7 @@ To perform any operations such as add, remove, replace, move, copy, test you sho
|
|
27
35
|
```ruby
|
28
36
|
parameters:
|
29
37
|
access_token (*required): this token will be used to send all requests to LaunchDarkly (string)
|
30
|
-
project_name: provide project name of your
|
38
|
+
project_name: provide project name of your organization (NOTE: for most, it should be `default` unless you have made some explicit changes)
|
31
39
|
log_file: all logs will be written to file 'launchdarkly.log' by default if no file name specified (string)
|
32
40
|
|
33
41
|
# set your LD API token and log file to capture logs
|
@@ -261,7 +269,8 @@ def ld_add_values_to_clause(env, flag, clause_name, clause_value)
|
|
261
269
|
end
|
262
270
|
|
263
271
|
@return parameter: (response of feature flag details)
|
264
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
272
|
+
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
273
|
+
response[rule_at_index]['clauses'][clause_at_index]['values'] (string)
|
265
274
|
```
|
266
275
|
|
267
276
|
```ruby
|
@@ -277,7 +286,8 @@ def ld_remove_values_from_clause(env, flag, clause_name, clause_value)
|
|
277
286
|
end
|
278
287
|
|
279
288
|
@return parameter: (response of feature flag details)
|
280
|
-
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
289
|
+
response = "https://app.launchdarkly.com/api/v2/flags/default/#{flag}?env=#{env}"
|
290
|
+
response[rule_at_index]['clauses'][clause_at_index]['values'] (string)
|
281
291
|
```
|
282
292
|
|
283
293
|
```ruby
|
@@ -9,11 +9,9 @@ require_relative 'constants'
|
|
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
12
|
def initialize(access_token, project_name, log_file)
|
15
13
|
@access_token = access_token
|
16
|
-
@launch_darkly_flags.gsub
|
14
|
+
@launch_darkly_flags = 'https://app.launchdarkly.com/api/v2/flags/project_name'.gsub 'project_name', project_name
|
17
15
|
@logger = Logger.new(log_file)
|
18
16
|
end
|
19
17
|
|
@@ -142,17 +140,15 @@ class LaunchdarklyApiHelperClass
|
|
142
140
|
rule_at_index, clause_at_index = rules_clauses_index(env, flag, clause_name)
|
143
141
|
request_url = "#{@launch_darkly_flags}/#{flag}"
|
144
142
|
request_body = { 'op' => 'add', 'path' => "/environments/#{env}/rules/#{rule_at_index}/clauses/#{clause_at_index}/values/0", 'value' => clause_value }
|
145
|
-
ld_request(:patch, request_url, [request_body])
|
143
|
+
ld_request(:patch, request_url, [request_body])['environments'][env]['rules'][rule_at_index]['clauses'][clause_at_index]['values']
|
146
144
|
end
|
147
145
|
|
148
146
|
def remove_values_from_clause(env, flag, clause_name, clause_value)
|
149
147
|
rule_at_index, clause_at_index = rules_clauses_index(env, flag, clause_name)
|
150
148
|
value_at_index = search_value_index(rule_at_index, clause_at_index, clause_value)
|
151
|
-
puts "value_index: #{value_at_index}"
|
152
149
|
request_url = "#{@launch_darkly_flags}/#{flag}"
|
153
|
-
request_body = { 'op' => '
|
154
|
-
|
155
|
-
ld_request(:patch, request_url, request_body)
|
150
|
+
request_body = [{ 'op' => 'remove', 'path' => "/environments/#{env}/rules/#{rule_at_index}/clauses/#{clause_at_index}/values/#{value_at_index}" }]
|
151
|
+
ld_request(:patch, request_url, request_body)['environments'][env]['rules'][rule_at_index]['clauses'][clause_at_index]['values']
|
156
152
|
end
|
157
153
|
|
158
154
|
def delete_flag(flag)
|
@@ -25,145 +25,61 @@
|
|
25
25
|
require_relative 'launchdarkly_api_helper/constants'
|
26
26
|
require_relative 'launchdarkly_api_helper/launchdarkly_api_helper_class'
|
27
27
|
|
28
|
-
#
|
28
|
+
# LaunchDarklyApiHelper provides you a way to access your Launch Darkly account using API token to view, edit or delete them accordingly.
|
29
29
|
module LaunchdarklyApiHelper
|
30
30
|
class Error < StandardError; end
|
31
31
|
|
32
|
-
#
|
33
|
-
# https://apidocs.launchdarkly.com/
|
34
|
-
# == To perform any operations such as add, remove, replace, move, copy, test you should have a working knowledge of JSON Patch
|
35
|
-
# https://datatracker.ietf.org/doc/html/rfc6902
|
36
|
-
|
32
|
+
# set your LD API token and log file to capture logs
|
37
33
|
def ld_access_token(access_token, project_name = 'default', log_file = 'launchdarkly.log')
|
38
34
|
@launchdarkly_helper = LaunchdarklyApiHelperClass.new(access_token, project_name, log_file)
|
39
35
|
end
|
40
36
|
|
41
|
-
#
|
42
|
-
# https://apidocs.launchdarkly.com/tag/Feature-flags#operation/getFeatureFlag
|
43
|
-
#
|
44
|
-
# == GET REQUEST
|
45
|
-
# https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
46
|
-
#
|
47
|
-
# == key (*required)
|
48
|
-
# env, flag
|
49
|
-
#
|
50
|
-
# == Here, 'developer_flag_for_regression' is the feature flag name and default is our Project name - eg. AmitSinghBisht
|
51
|
-
# == By default, this returns the configurations for all environments
|
52
|
-
# == You can filter environments with the env query parameter. For example, setting env=staging restricts the returned configurations to just the staging environment
|
53
|
-
# https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
|
54
|
-
|
37
|
+
# this method will give you entire details about a flag for that particular environment
|
55
38
|
def ld_fetch_flag_details(env, flag)
|
56
39
|
@launchdarkly_helper.fetch_flag_details(env, flag)
|
57
40
|
end
|
58
41
|
|
59
|
-
#
|
60
|
-
#
|
61
|
-
# == key (*required)
|
62
|
-
# env, flag
|
63
|
-
#
|
64
|
-
# response = https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression?env=staging
|
65
|
-
# grab the value of the ['environments'][env]['on'] obtained from the above response
|
66
|
-
|
42
|
+
# this method will return the status of the flag, whether it is on or off viz set to true or false
|
67
43
|
def ld_fetch_flag_toggle_status(env, flag)
|
68
44
|
@launchdarkly_helper.fetch_flag_toggle_status(env, flag)
|
69
45
|
end
|
70
46
|
|
71
|
-
#
|
72
|
-
# https://apidocs.launchdarkly.com/tag/Feature-flags/#operation/postFeatureFlag
|
73
|
-
#
|
74
|
-
# == POST REQUEST
|
75
|
-
# https://app.launchdarkly.com/api/v2/flags/default
|
76
|
-
#
|
77
|
-
# Here, default is our Project name - Browserstack
|
78
|
-
#
|
79
|
-
# key (*required): A unique key used to reference the flag in your code (string)
|
80
|
-
#
|
81
|
-
# name (*required): A human-friendly name for the feature flag (string)
|
82
|
-
#
|
83
|
-
# description: Description of the feature flag. Defaults to an empty string (string)
|
84
|
-
#
|
85
|
-
# tags: Tags for the feature flag. Defaults to an empty array (Array of strings)
|
86
|
-
#
|
87
|
-
# variations: An array of possible variations for the flag. The variation values must be unique. If omitted, two boolean variations of true and false will be used (Array of objects)
|
88
|
-
#
|
89
|
-
# defaults
|
90
|
-
# * onVariation (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is on (integer)
|
91
|
-
# * offVariation (*required): The index, from the array of variations for this flag, of the variation to serve by default when targeting is off (integer)
|
92
|
-
#
|
93
|
-
# {
|
94
|
-
# "key": "developer_flag_for_regression",
|
95
|
-
# "name": "developer_flag_for_regression",
|
96
|
-
# "description": "developer_flag_for_regression is created via regression
|
97
|
-
# api on 18_10_2022",
|
98
|
-
# "tags": [
|
99
|
-
# "created_via_regression_api_on_18_10_2022"
|
100
|
-
# ],
|
101
|
-
# "variations": [
|
102
|
-
# {
|
103
|
-
# "age": 10
|
104
|
-
# },
|
105
|
-
# {
|
106
|
-
# "age": 20
|
107
|
-
# }
|
108
|
-
# ],
|
109
|
-
# "defaults": {
|
110
|
-
# "onVariation": 1,
|
111
|
-
# "offVariation": 0
|
112
|
-
# }
|
113
|
-
# }
|
114
|
-
#
|
115
|
-
# Above code will create a key 'developer_flag_for_regression' with name as 'developer_flag_for_regression' and description as 'developer_flag_for_regression is created via regression api on 18_10_2022'
|
116
|
-
#
|
117
|
-
# Variations are provided while creating key, by default variation is a boolean value (true and false). once flag with a specific variation is created, its type cannot be modified later, hence choose your variation type smartly (Boolean, String, Number, JSON) In above example we are creating a flag with JSON type and its two values are 'age': 10 and 'age': 20
|
118
|
-
#
|
119
|
-
# Also, variation has by default two values, and you must also define two variations while creating your own custom feature flag
|
120
|
-
#
|
121
|
-
# Default will specify which variation to serve when flag is on or off. In above example when flag is turned on, '1' variation is served [Note: 0 and 1 are index position], so variations at first index ie variations[1] will be served when flag is turned on ie 'age': 20
|
122
|
-
|
47
|
+
# this method will create a new feature flag, NOTE: feature falg are created at global level and environment resides inside feature flag
|
123
48
|
def ld_create_flag(key, name = key, description = key, tags = ['created_via_regression_api'])
|
124
49
|
@launchdarkly_helper.create_flag(key, name, description, tags)
|
125
50
|
end
|
126
51
|
|
127
|
-
#
|
128
|
-
# https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
|
129
|
-
#
|
130
|
-
# == PATCH REQUEST
|
131
|
-
# https://app.launchdarkly.com/api/v2/flags/default/developer_flag_for_regression
|
132
|
-
#
|
133
|
-
# key (*required)
|
134
|
-
#
|
135
|
-
# == Here, 'developer_flag_for_regression' is the flag key and default is our Project name - Browserstack
|
136
|
-
# == You can update any parameter of feature flag using this method
|
137
|
-
|
52
|
+
# this method will be used to toggle status of feature flag either on / off for a particular environment
|
138
53
|
def ld_toggle_specific_environment(env, flag, flag_value = true)
|
139
54
|
@launchdarkly_helper.toggle_specific_environment(env, flag, flag_value)
|
140
55
|
end
|
141
56
|
|
142
|
-
#
|
143
|
-
# https://apidocs.launchdarkly.com/tag/Feature-flags#operation/patchFeatureFlag
|
144
|
-
#
|
145
|
-
# [fetch_flag_toggle_status_response, feature_flag_variation_index_response, feature_flag_variation_value_response, feature_flag_variation_name_response]
|
146
|
-
|
57
|
+
# this method will get important parameters from the response
|
147
58
|
def ld_flag_variation_served(env, flag)
|
148
59
|
@launchdarkly_helper.flag_variation_served(env, flag)
|
149
60
|
end
|
150
61
|
|
62
|
+
# this method will return the index of rules and clauses by searching for clause_name in response
|
151
63
|
def ld_rules_clauses_index(env, flag, clause_name)
|
152
64
|
@launchdarkly_helper.rules_clauses_index(env, flag, clause_name)
|
153
65
|
end
|
154
66
|
|
67
|
+
# this method will return values inside a particular clause by searching for clause_name in response
|
155
68
|
def ld_get_values_from_clauses(env, flag, clause_name)
|
156
69
|
@launchdarkly_helper.get_values_from_clauses(env, flag, clause_name)
|
157
70
|
end
|
158
71
|
|
72
|
+
# this method will help you to add a value to a particular clause by searching for clause_name in response
|
159
73
|
def ld_add_values_to_clause(env, flag, clause_name, clause_value)
|
160
74
|
@launchdarkly_helper.add_values_to_clause(env, flag, clause_name, clause_value)
|
161
75
|
end
|
162
76
|
|
77
|
+
# this method will help you to remove a value to a particular clause by searching for clause_name in response
|
163
78
|
def ld_remove_values_from_clause(env, flag, clause_name, clause_value)
|
164
79
|
@launchdarkly_helper.remove_values_from_clause(env, flag, clause_name, clause_value)
|
165
80
|
end
|
166
81
|
|
82
|
+
# 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)
|
167
83
|
def ld_delete_flag(flag)
|
168
84
|
@launchdarkly_helper.delete_flag(flag)
|
169
85
|
end
|
metadata
CHANGED
@@ -1,16 +1,17 @@
|
|
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.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- amit-singh-bisht
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2022-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
13
|
+
description: LaunchDarklyApiHelper provides you a way to access your Launch Darkly
|
14
|
+
account using API token to view, edit or delete them accordingly. https://amit-singh-bisht.github.io/launchdarkly_api_helper_ruby/
|
14
15
|
email:
|
15
16
|
- bishtamitsingh98@gmail.com
|
16
17
|
executables: []
|
@@ -34,7 +35,7 @@ metadata:
|
|
34
35
|
homepage_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby
|
35
36
|
source_code_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby
|
36
37
|
changelog_uri: https://github.com/amit-singh-bisht/launchdarkly_api_helper_ruby/blob/master/README.md
|
37
|
-
post_install_message:
|
38
|
+
post_install_message:
|
38
39
|
rdoc_options: []
|
39
40
|
require_paths:
|
40
41
|
- lib
|
@@ -49,9 +50,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
50
|
- !ruby/object:Gem::Version
|
50
51
|
version: '0'
|
51
52
|
requirements: []
|
52
|
-
|
53
|
-
|
54
|
-
signing_key:
|
53
|
+
rubygems_version: 3.2.3
|
54
|
+
signing_key:
|
55
55
|
specification_version: 4
|
56
|
-
summary:
|
56
|
+
summary: LaunchDarklyApiHelper provides you a way to access your Launch Darkly account
|
57
|
+
using API token to view, edit or delete them accordingly. https://amit-singh-bisht.github.io/launchdarkly_api_helper_ruby/
|
57
58
|
test_files: []
|