@@ -150,6 +150,7 @@ def create_flag(
150
150
tags = [],
151
151
migration_stages = 0 ,
152
152
prerequisites = [],
153
+ temporary = False ,
153
154
):
154
155
if self .flag_exists (flag_key ):
155
156
return
@@ -162,6 +163,7 @@ def create_flag(
162
163
"usingEnvironmentId" : True ,
163
164
"usingMobileKey" : True ,
164
165
},
166
+ "temporary" : temporary ,
165
167
}
166
168
167
169
if len (variations ) > 0 :
@@ -201,6 +203,28 @@ def create_flag(
201
203
if "message" in data :
202
204
print ("Error creating flag: " + data ["message" ])
203
205
return response
206
+
207
+ ##################################################
208
+ # Update a flag
209
+ ##################################################
210
+ def update_flag_client_side_availability (self , flag_key ):
211
+
212
+ payload = {
213
+ "instructions" : [
214
+ {
215
+ "kind" : "turnOnClientSideAvailability" , "value" : "usingEnvironmentId"
216
+ }
217
+ ]
218
+ }
219
+
220
+ headers = {
221
+ "Authorization" : self .api_key ,
222
+ "Content-Type" : "application/json; domain-model=launchdarkly.semanticpatch" ,
223
+ }
224
+
225
+ url = "https://app.launchdarkly.com/api/v2/flags/" + self .project_key + "/" + flag_key
226
+ res = self .getrequest ("PATCH" , url , headers = headers , json = payload )
227
+ return res
204
228
205
229
##################################################
206
230
# Copy a flag
@@ -262,7 +286,6 @@ def create_ai_config(self, config_key, config_name, description, tags):
262
286
headers = headers ,
263
287
)
264
288
data = json .loads (response .text )
265
- print (response .text )
266
289
if "message" in data :
267
290
print ("Error creating AI Config: " + data ["message" ])
268
291
return response
@@ -272,13 +295,14 @@ def create_ai_config(self, config_key, config_name, description, tags):
272
295
# Create AI Config Versions
273
296
##################################################
274
297
275
- def create_ai_config_versions (self , ai_config_key , ai_config_version_key , ai_config_version_name , model , messages ):
298
+ def create_ai_config_versions (self , ai_config_key , ai_config_version_key , ai_model_config_key , ai_config_version_name , model , messages ):
276
299
277
300
payload = {
278
301
"key" : ai_config_version_key ,
279
302
"name" : ai_config_version_name ,
280
303
"messages" : messages ,
281
- "model" : model
304
+ "model" : model ,
305
+ "modelConfigKey" : ai_model_config_key
282
306
}
283
307
284
308
headers = {
@@ -614,6 +638,14 @@ def create_experiment(
614
638
print ("Error creating experiment: " + data ["message" ])
615
639
return response
616
640
641
+ ##################################################
642
+ # Create a holdout
643
+ ##################################################
644
+
645
+ ##################################################
646
+ # Create a layer
647
+ ##################################################
648
+
617
649
##################################################
618
650
# Create a release pipeline
619
651
##################################################
@@ -692,18 +724,24 @@ def create_release_pipeline(self, pipeline_key, pipeline_name):
692
724
print ("Error creating release pipeline: " + data ["message" ])
693
725
return response
694
726
695
- def create_shortcut (self ):
727
+ def create_shortcut (self , name , key , icon , tags , env_key , sort_by = "name" ):
696
728
payload = {
697
- "name" : "another" ,
698
- "key" : "another" ,
699
- "icon" : "bolt" ,
729
+ "name" : name ,
730
+ "key" : key ,
731
+ "icon" : icon ,
700
732
"type" : "flags" ,
701
733
"context" : {
702
734
"projectKey" : self .project_key ,
703
- "environmentKeys" : ["production" , "test" ],
704
- "selectedEnvironmentKey" : "production" ,
735
+ "environmentKeys" : ["production" ],
736
+ "selectedEnvironmentKey" : env_key ,
705
737
},
706
- "filters" : {"filter" : {"tags" : ["AI" ]}},
738
+ "filters" : {
739
+ "filter" : {
740
+ "tags" : tags
741
+ },
742
+ "state" : "live" ,
743
+ "sort" : sort_by
744
+ },
707
745
"visibility" : "me" ,
708
746
}
709
747
headers = {
@@ -735,7 +773,7 @@ def create_shortcut(self):
735
773
def get_user_id (self , email ):
736
774
if email is None :
737
775
return None
738
-
776
+
739
777
filter = "email:" + email
740
778
if email == "" :
741
779
filter = "role:owner"
@@ -1029,11 +1067,16 @@ def add_guarded_rollout(
1029
1067
rollback = True ,
1030
1068
weight = 50000 ,
1031
1069
notify = True ,
1070
+ days = 1 ,
1032
1071
):
1033
1072
vars , defaults = self .get_flag_variation_values (flag_key )
1034
1073
1035
1074
control_var = ""
1036
1075
test_var = ""
1076
+ stagesWindow = 17280000
1077
+
1078
+ if days == 7 :
1079
+ stagesWindow = 120960000
1037
1080
1038
1081
for v in vars :
1039
1082
if v ["value" ] == False :
@@ -1051,21 +1094,148 @@ def add_guarded_rollout(
1051
1094
headers = {
1052
1095
"Authorization" : self .api_key ,
1053
1096
"Content-Type" : "application/json; domain-model=launchdarkly.semanticpatch" ,
1054
- "LD-API-Version" : "beta" ,
1055
1097
}
1056
1098
payload = {
1057
1099
"comment" : "" ,
1058
1100
"environmentKey" : env_key ,
1059
1101
"instructions" : [
1060
1102
{
1061
- "kind" : "updateFallthroughWithMeasuredRollout" ,
1103
+ "kind" : "turnFlagOn"
1104
+ },
1105
+ {
1106
+ "kind" : "updateFallthroughWithMeasuredRolloutV2" ,
1062
1107
"testVariationId" : test_var ,
1063
1108
"controlVariationId" : control_var ,
1064
1109
"randomizationUnit" : "user" ,
1065
1110
"onRegression" : {"notify" : notify , "rollback" : rollback },
1066
1111
"onProgression" : {"notify" : notify , "rollForward" : True },
1067
1112
"monitoringWindowMilliseconds" : timeout ,
1068
1113
"rolloutWeight" : weight ,
1114
+ "stages" : [
1115
+ {
1116
+ "rolloutWeight" : 1000 ,
1117
+ "monitoringWindowMilliseconds" : stagesWindow
1118
+ },
1119
+ {
1120
+ "rolloutWeight" : 5000 ,
1121
+ "monitoringWindowMilliseconds" : stagesWindow
1122
+ },
1123
+ {
1124
+ "rolloutWeight" : 10000 ,
1125
+ "monitoringWindowMilliseconds" : stagesWindow
1126
+ },
1127
+ {
1128
+ "rolloutWeight" : 25000 ,
1129
+ "monitoringWindowMilliseconds" : stagesWindow
1130
+ },
1131
+ {
1132
+ "rolloutWeight" : 50000 ,
1133
+ "monitoringWindowMilliseconds" : stagesWindow
1134
+ },
1135
+ ]
1136
+ }
1137
+ ],
1138
+ }
1139
+ res = self .getrequest ("PATCH" , url , headers = headers , json = payload )
1140
+ return res
1141
+
1142
+ ##################################################
1143
+ # Add a guarded rollout to a flag
1144
+ ##################################################
1145
+ def add_progressive_rollout (
1146
+ self ,
1147
+ flag_key ,
1148
+ env_key ,
1149
+ timeout = 604800000 ,
1150
+ rollback = True ,
1151
+ weight = 50000 ,
1152
+ notify = True ,
1153
+ ):
1154
+ vars , defaults = self .get_flag_variation_values (flag_key )
1155
+
1156
+ control_var = ""
1157
+ end_var = ""
1158
+
1159
+ for v in vars :
1160
+ if v ["value" ] == False :
1161
+ control_var = v ["id" ]
1162
+ else :
1163
+ end_var = v ["id" ]
1164
+
1165
+ url = (
1166
+ "https://app.launchdarkly.com/api/v2/flags/"
1167
+ + self .project_key
1168
+ + "/"
1169
+ + flag_key
1170
+ + "?ignoreConflicts=true"
1171
+ )
1172
+ headers = {
1173
+ "Authorization" : self .api_key ,
1174
+ "Content-Type" : "application/json; domain-model=launchdarkly.semanticpatch" ,
1175
+ }
1176
+ payload = {
1177
+ "comment" : "" ,
1178
+ "environmentKey" : env_key ,
1179
+ "instructions" : [
1180
+ {
1181
+ "kind" : "turnFlagOn"
1182
+ },
1183
+ {
1184
+ "kind" : "updateFallthroughVariationOrRollout" ,
1185
+ "rolloutContextKind" : "user" ,
1186
+ "progressiveRolloutConfiguration" : {
1187
+ "controlVariationId" : control_var ,
1188
+ "endVariationId" : end_var ,
1189
+ "stages" : [
1190
+ {
1191
+ "displayUnit" : "day" ,
1192
+ "durationMs" : timeout ,
1193
+ "rollout" : {
1194
+ end_var : 1000 ,
1195
+ control_var : 99000 ,
1196
+ }
1197
+ },
1198
+ {
1199
+ "displayUnit" : "day" ,
1200
+ "durationMs" : timeout ,
1201
+ "rollout" : {
1202
+ end_var : 5000 ,
1203
+ control_var : 95000 ,
1204
+ }
1205
+ },
1206
+ {
1207
+ "displayUnit" : "day" ,
1208
+ "durationMs" : timeout ,
1209
+ "rollout" : {
1210
+ end_var : 10000 ,
1211
+ control_var : 90000 ,
1212
+ }
1213
+ },
1214
+ {
1215
+ "displayUnit" : "day" ,
1216
+ "durationMs" : timeout ,
1217
+ "rollout" : {
1218
+ end_var : 25000 ,
1219
+ control_var : 75000 ,
1220
+ }
1221
+ },
1222
+ {
1223
+ "displayUnit" : "day" ,
1224
+ "durationMs" : timeout ,
1225
+ "rollout" : {
1226
+ end_var : 50000 ,
1227
+ control_var : 50000 ,
1228
+ }
1229
+ },
1230
+ {
1231
+ "displayUnit" : "day" ,
1232
+ "rollout" : {
1233
+ end_var : 100000 ,
1234
+ control_var : 0 ,
1235
+ }
1236
+ }
1237
+ ]
1238
+ }
1069
1239
}
1070
1240
],
1071
1241
}
0 commit comments