openrewrite / rewrite-feature-flags

OpenRewrite recipes for LaunchDarkly.
Apache License 2.0
3 stars 3 forks source link

Find feature flag by key #1

Closed shanman190 closed 12 months ago

shanman190 commented 1 year ago

Parameters:

SDK v5.x

Before:

import com.launchdarkly.sdk.LDUser;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDUser user = new LDUser.Builder("user-key")
                .name("user")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", user, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

After:

import com.launchdarkly.sdk.LDUser;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDUser user = new LDUser.Builder("user-key")
                .name("user")
                .build();
        /*~~>*/boolean flagValue = client.boolVariation("flag-key-123abc", user, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

SDK v6.x

Before:

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDContext context = LDContext.builder("context-key")
                .name("user")
                .build();
        boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

After:

import com.launchdarkly.sdk.LDContext;
import com.launchdarkly.sdk.server.LDClient;

class Test {
    public void a() {
        LDClient client = new LDClient("sdk-key");
        LDContext context = LDContext.builder("context-key")
                .name("user")
                .build();
        /*~~>*/boolean flagValue = client.boolVariation("flag-key-123abc", context, false);
        if (flagValue) {
            // Application code to show the feature
        } else {
            // The code to run if the feature is off
        }
    }
}

Should handle

shanman190 commented 1 year ago

Not sure if we should do this as part of this or another issue, but also handling when the flag key is in a local constant. For the non-local constant, that would require the recipe pipelines feature.