MCPcopy Create free account
hub / github.com/Flagsmith/flagsmith / _import_rules

Function _import_rules

api/integrations/launch_darkly/services.py:608–656  ·  view source on GitHub ↗

Import each rule in the given Launch Darkly's feature flag as a feature-specific segment in Flagsmith. :param ld_flag_config: the feature flag config from Launch Darkly. :param feature: the feature to import the rules to. :param segments_by_ld_key: a mapping from Launch Darkly segm

(
    import_request: LaunchDarklyImportRequest,
    ld_flag_config: ld_types.FeatureFlagConfig,
    feature: Feature,
    environment: Environment,
    segments_by_ld_key: dict[str, Segment],
    mv_feature_options_by_variation: dict[str, MultivariateFeatureOption],
)

Source from the content-addressed store, hash-verified

606
607
608def _import_rules(
609 import_request: LaunchDarklyImportRequest,
610 ld_flag_config: ld_types.FeatureFlagConfig,
611 feature: Feature,
612 environment: Environment,
613 segments_by_ld_key: dict[str, Segment],
614 mv_feature_options_by_variation: dict[str, MultivariateFeatureOption],
615) -> None:
616 """
617 Import each rule in the given Launch Darkly's feature flag as a feature-specific segment in Flagsmith.
618
619 :param ld_flag_config: the feature flag config from Launch Darkly.
620 :param feature: the feature to import the rules to.
621 :param segments_by_ld_key: a mapping from Launch Darkly segment key to Segment. Used for "segmentMatch" op.
622 :param mv_feature_options_by_variation: a mapping from variation index to MultivariateFeatureOption if the
623 flag is multivariate. Used for setting multivariate flag weights.
624 """
625
626 if "prerequisites" in ld_flag_config and len(ld_flag_config["prerequisites"]) > 0:
627 _log_error(
628 import_request=import_request,
629 error_message=f"Prerequisites are not supported, skipping prerequisites for feature"
630 f" {feature.name} in environment {environment.name}",
631 )
632
633 # For each rule in LD's flag,
634 if "rules" in ld_flag_config:
635 for rule in ld_flag_config["rules"]:
636 # Generate a unique and descriptive name for the rule. This name is re-used on consecutive imports
637 # to prevent duplicate rules.
638 rule_name = rule.get("description", "imported-" + rule["_id"])
639 # Create the feature segment for the given rule and get the feature state objects from those
640 # newly created feature-specific segments.
641 feature_states = _create_feature_segment_from_clauses(
642 import_request=import_request,
643 clauses=rule["clauses"],
644 project=feature.project,
645 feature=feature,
646 environment=environment,
647 segments_by_ld_key=segments_by_ld_key,
648 rule_name=rule_name,
649 )
650
651 _set_imported_mv_feature_state_values(
652 variation_idx=rule.get("variation", None), # type: ignore[arg-type]
653 rollout=rule.get("rollout", None),
654 feature_states=feature_states,
655 mv_feature_options_by_variation=mv_feature_options_by_variation,
656 )
657
658
659def _create_boolean_feature_states_with_segments_identities(

Calls 4

_log_errorFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…