launchdarkly_api_helper 0.2.0 → 0.3.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: ce783cd020dfb08afa37d2c2def2a34e637ac5206372cde1e33692fce4fc7e9c
|
|
4
|
+
data.tar.gz: 001f9d326e6361449587ac36107296af04e02cacc1d238c903a7622cb9af718f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 97992fe3501448666a630a59f779e35228fe75afa9e2b57d55396d56e2a8917caac50f232041bb5c59e6d9f356093628c4730db192dca2225bbd384323f57e0f
|
|
7
|
+
data.tar.gz: ebb0edb818fb938053a390ee8680d6fe6e309a6433c634ad2cd0e9de93220577584db74aa5157ea643b6f0a19f8ba70591e780493cce4fb0e6d776546cd7b628
|
data/.rubocop.yml
CHANGED
|
@@ -9,12 +9,21 @@ Style/StringLiteralsInInterpolation:
|
|
|
9
9
|
Enabled: true
|
|
10
10
|
EnforcedStyle: double_quotes
|
|
11
11
|
|
|
12
|
+
Style/OptionalBooleanParameter:
|
|
13
|
+
Enabled: false
|
|
14
|
+
|
|
12
15
|
Layout/LineLength:
|
|
13
16
|
Max: 120
|
|
14
17
|
|
|
15
18
|
Metrics/MethodLength:
|
|
16
19
|
Max: 100
|
|
17
20
|
|
|
21
|
+
Metrics/MethodName:
|
|
22
|
+
Max: 100
|
|
23
|
+
|
|
24
|
+
Metrics/ClassLength:
|
|
25
|
+
Max: 150
|
|
26
|
+
|
|
18
27
|
Metrics/AbcSize:
|
|
19
28
|
Enabled: false
|
|
20
29
|
|
|
@@ -59,18 +59,18 @@ class LaunchdarklyApiHelperClass
|
|
|
59
59
|
ld_request(:post, request_url, request_body)
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
def
|
|
62
|
+
def toggle_specific_environment(env, flag, flag_value)
|
|
63
63
|
request_url = "#{LAUNCH_DARKLY_FLAGS}/#{flag}"
|
|
64
64
|
request_body = { 'op' => 'replace', 'path' => "/environments/#{env}/on", 'value' => flag_value }
|
|
65
65
|
response_body = ld_request(:patch, request_url, [request_body])
|
|
66
66
|
response_body['environments'][env]['on']
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
def feature_flag_variation_index(
|
|
70
|
-
variations =
|
|
69
|
+
def feature_flag_variation_index(status_response, details_response)
|
|
70
|
+
variations = details_response['variations']
|
|
71
71
|
value_at_index = -1
|
|
72
72
|
variations.length.times do |index|
|
|
73
|
-
next unless variations[index]['value'].eql?
|
|
73
|
+
next unless variations[index]['value'].eql? status_response
|
|
74
74
|
|
|
75
75
|
value_at_index = index
|
|
76
76
|
break
|
|
@@ -78,60 +78,81 @@ class LaunchdarklyApiHelperClass
|
|
|
78
78
|
value_at_index
|
|
79
79
|
end
|
|
80
80
|
|
|
81
|
-
def feature_flag_variation_value(
|
|
82
|
-
|
|
81
|
+
def feature_flag_variation_value(details_response, index_response)
|
|
82
|
+
details_response['variations'][index_response]['value']
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
def feature_flag_variation_name(
|
|
86
|
-
|
|
85
|
+
def feature_flag_variation_name(details_response, index_response)
|
|
86
|
+
details_response['variations'][index_response]['name']
|
|
87
87
|
end
|
|
88
88
|
|
|
89
|
-
def
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
[
|
|
89
|
+
def ld_toggle_variation_served(env, flag)
|
|
90
|
+
details_response = fetch_flag_details(env, flag)
|
|
91
|
+
toggle_status_response = fetch_flag_toggle_status(env, flag)
|
|
92
|
+
variation_index_response = feature_flag_variation_index(toggle_status_response, details_response) # ['environments'][env]['fallthrough']['variation']
|
|
93
|
+
variation_value_response = feature_flag_variation_value(details_response, variation_index_response) # ['variations'][variation_index_response]['value']
|
|
94
|
+
variation_name_response = feature_flag_variation_name(details_response, variation_index_response)
|
|
95
|
+
[toggle_status_response, variation_index_response, variation_value_response, variation_name_response]
|
|
96
96
|
end
|
|
97
97
|
|
|
98
|
-
def
|
|
98
|
+
def search_rule_index_clause_index(clause_name)
|
|
99
|
+
rule_at_index = -1
|
|
100
|
+
clause_at_index = -1
|
|
101
|
+
@feature_flag_rules_list.length.times do |rule_index|
|
|
102
|
+
@feature_flag_clauses_list = @feature_flag_rules_list[rule_index]['clauses']
|
|
103
|
+
@feature_flag_clauses_list.length.times do |clause_index|
|
|
104
|
+
next unless @feature_flag_clauses_list[clause_index]['attribute'].eql? clause_name
|
|
105
|
+
|
|
106
|
+
rule_at_index = rule_index
|
|
107
|
+
clause_at_index = clause_index
|
|
108
|
+
break
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
[rule_at_index, clause_at_index]
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def search_value_index(rule_at_index, clause_at_index, clause_value)
|
|
99
115
|
value_at_index = -1
|
|
100
|
-
|
|
101
|
-
|
|
116
|
+
@feature_flag_values_list = @feature_flag_rules_list[rule_at_index]['clauses'][clause_at_index]['values']
|
|
117
|
+
@feature_flag_values_list.length.times do |value_index|
|
|
118
|
+
next unless @feature_flag_values_list[value_index].eql? clause_value
|
|
102
119
|
|
|
103
|
-
value_at_index =
|
|
120
|
+
value_at_index = value_index
|
|
104
121
|
break
|
|
105
122
|
end
|
|
106
123
|
value_at_index
|
|
107
124
|
end
|
|
108
125
|
|
|
109
|
-
def
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
rule_index = search_value_in_hash(@feature_flag_env_rules, attribute)
|
|
114
|
-
@feature_flag_env_rules_clauses = @feature_flag_env_rules[rule_index]['clauses']
|
|
115
|
-
clause_index = search_value_in_hash(@feature_flag_env_rules_clauses, attribute)
|
|
116
|
-
[rule_index, clause_index]
|
|
126
|
+
def rules_clauses_index(env, flag, clause_name)
|
|
127
|
+
feature_flag_response = fetch_flag_details(env, flag)
|
|
128
|
+
@feature_flag_rules_list = feature_flag_response['environments'][env]['rules']
|
|
129
|
+
search_rule_index_clause_index(clause_name)
|
|
117
130
|
end
|
|
118
131
|
|
|
119
|
-
def
|
|
120
|
-
|
|
121
|
-
@
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
def get_values_from_clauses(env, flag, clause_name)
|
|
133
|
+
rule_at_index, clause_at_index = feature_flag_rules_clauses_index(env, flag, clause_name)
|
|
134
|
+
@feature_flag_rules_list[rule_at_index]['clauses'][clause_at_index]['values']
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def add_values_to_clause(env, flag, clause_name, clause_value)
|
|
138
|
+
rule_at_index, clause_at_index = feature_flag_rules_clauses_index(env, flag, clause_name)
|
|
124
139
|
request_url = "#{LAUNCH_DARKLY_FLAGS}/#{flag}"
|
|
125
|
-
request_body = { 'op' => 'add', 'path' => "/environments/#{env}/rules/#{
|
|
140
|
+
request_body = { 'op' => 'add', 'path' => "/environments/#{env}/rules/#{rule_at_index}/clauses/#{clause_at_index}/values/0", 'value' => clause_value }
|
|
126
141
|
ld_request(:patch, request_url, [request_body])
|
|
127
142
|
end
|
|
128
143
|
|
|
129
|
-
def
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
value_index
|
|
144
|
+
def remove_values_from_clause(env, flag, clause_name, clause_value)
|
|
145
|
+
rule_at_index, clause_at_index = feature_flag_rules_clauses_index(env, flag, clause_name)
|
|
146
|
+
value_at_index = search_value_index(rule_at_index, clause_at_index, clause_value)
|
|
147
|
+
puts "value_index: #{value_at_index}"
|
|
133
148
|
request_url = "#{LAUNCH_DARKLY_FLAGS}/#{flag}"
|
|
134
|
-
request_body = { 'op'
|
|
149
|
+
request_body = { 'op' => 'test', 'path' => "/environments/#{env}/rules/#{rule_at_index}/clauses/#{clause_at_index}/values/#{value_at_index}", 'value' => clause_value },
|
|
150
|
+
{ 'op' => 'remove', 'path' => "/environments/#{env}/rules/#{rule_at_index}/clauses/#{clause_at_index}/values/#{value_at_index}" }
|
|
135
151
|
ld_request(:patch, request_url, request_body)
|
|
136
152
|
end
|
|
153
|
+
|
|
154
|
+
def delete_flag(flag)
|
|
155
|
+
request_url = "#{LAUNCH_DARKLY_FLAGS}/#{flag}"
|
|
156
|
+
ld_request(:delete, request_url)
|
|
157
|
+
end
|
|
137
158
|
end
|
|
@@ -135,8 +135,8 @@ module LaunchdarklyApiHelper
|
|
|
135
135
|
# == Here, 'developer_flag_for_regression' is the flag key and default is our Project name - Browserstack
|
|
136
136
|
# == You can update any parameter of feature flag using this method
|
|
137
137
|
|
|
138
|
-
def
|
|
139
|
-
@launchdarkly_helper.
|
|
138
|
+
def ld_toggle_specific_environment(env, flag, flag_value = true)
|
|
139
|
+
@launchdarkly_helper.toggle_specific_environment(env, flag, flag_value)
|
|
140
140
|
end
|
|
141
141
|
|
|
142
142
|
# == Get status of feature flag
|
|
@@ -144,12 +144,27 @@ 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_toggle_variation_served(env, flag)
|
|
148
|
+
@launchdarkly_helper.ld_toggle_variation_served(env, flag)
|
|
149
149
|
end
|
|
150
150
|
|
|
151
|
-
def
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
def ld_rules_clauses_index(env, flag, clause_name)
|
|
152
|
+
@launchdarkly_helper.rules_clauses_index(env, flag, clause_name)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def ld_get_values_from_clauses(env, flag, clause_name)
|
|
156
|
+
@launchdarkly_helper.get_values_from_clauses(env, flag, clause_name)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def ld_add_values_to_clause(env, flag, clause_name, clause_value)
|
|
160
|
+
@launchdarkly_helper.add_values_to_clause(env, flag, clause_name, clause_value)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def ld__remove_values_from_clause(env, flag, clause_name, clause_value)
|
|
164
|
+
@launchdarkly_helper.remove_values_from_clause(env, flag, clause_name, clause_value)
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
def ld_delete_flag(flag)
|
|
168
|
+
@launchdarkly_helper.delete_flag(flag)
|
|
154
169
|
end
|
|
155
170
|
end
|