How to export all firebase remote config keys and values?
Asked Answered
F

5

6

I want to migrate from existing firebase project to a new firebase project Issue is that I have a lot of remote config keys and values in my existing project Now I want to export all remote config keys and values then import to the new firebase project rather than writing everything over again in new project.

Is there any easy way to do it?.

Flamsteed answered 13/10, 2017 at 6:53 Comment(0)
H
6

You cannot do it from the Firebase console, but you can write a simple script which uses the Remote Config REST API - https://firebase.google.com/docs/remote-config/use-config-rest

So essentially you can download remote config from one project and then upload that into the new project - programmatically.

Cheers!

Hurd answered 20/4, 2018 at 20:36 Comment(2)
Thanks, Mayank when I asked this question that time this API wasn't there, now they added itFlamsteed
Is there a way to use that endpoint without having to setup GoogleAuthentication services? I don't have a java, ruby or python environment setup, doing so and integrating a third party library in to it just so I can run a curl command from bash isn't all that simple.Wessling
P
2
mFirebaseRemoteConfig.fetch(cacheExpiration)
            .addOnCompleteListener(this, task -> {
                if (task.isSuccessful()) {
                    mFirebaseRemoteConfig.activateFetched();
                    Map<String, String> map =  getFirebaseRemoteMap(context,R.xml.defultValues);
                    //map contains all remote values   
                }
            });

make sure you have defined all keys in the defaultValue file, After activateFetched success, you will able to dump all remote values

    public Map<String, String> getFirebaseRemoteMap(Context context, @XmlRes int xmlRes) {
    Map<String, String> stringStringMap = new HashMap<>();
    XmlResourceParser xmlResourceParser = context.getResources().getXml(xmlRes);
    try {
        boolean isInKeyTag = false;
        while (xmlResourceParser.getEventType() != XmlResourceParser.END_DOCUMENT) {
            if (xmlResourceParser.getEventType() == XmlResourceParser.START_TAG) {
                String tagName = xmlResourceParser.getName();
                if (tagName.equals("key")) {
                    isInKeyTag = true;
                }
            }
            if (xmlResourceParser.getEventType() == XmlResourceParser.END_TAG) {
                String tagName = xmlResourceParser.getName();
                if (tagName.equals("key")) {
                    isInKeyTag = false;
                }
            }
            if (xmlResourceParser.getEventType() == XmlResourceParser.TEXT) {
                if (isInKeyTag) {
                    String key = xmlResourceParser.getText();
                    FirebaseRemoteConfigValue val = FirebaseRemoteConfig.getInstance().getValue(key);
                    String s = val.asString();
                    stringStringMap.put(key, s);
                }
            }
            xmlResourceParser.next();
        }

        return stringStringMap;
    } catch (Exception e) {
        return null;
    }
}
Plainsong answered 21/1, 2019 at 12:46 Comment(1)
activateFetched is now deprecatedMorrie
X
2

You can get the remote config keys and values as follows (Swift 4.2):

let remoteConfig = RemoteConfig.remoteConfig()
let ns = NamespaceGoogleMobilePlatform // Oddly evaluates to: "configns:firebase" including spelling mistake

let remoteKeys = remoteConfig.allKeys(from: .remote, namespace: ns)
let remoteDict = Dictionary(uniqueKeysWithValues: remoteKeys.map { ($0, remoteConfig[$0].stringValue) })

let defaultKeys = remoteConfig.allKeys(from: .default, namespace: ns)
let defaultDict = Dictionary(uniqueKeysWithValues: defaultKeys.map { ($0, remoteConfig[$0].stringValue) })

let staticKeys = remoteConfig.allKeys(from: .static, namespace: ns)
let staticDict = Dictionary(uniqueKeysWithValues: staticKeys.map { ($0, remoteConfig[$0].stringValue) })

In my brief searching, I couldn't get the flattened remoteConfig keys and values (i.e. what gets returned when using the subscript: remoteConfig[key]). I'm guessing you'd just need to overlay the remote values over the default values?

Xerophthalmia answered 23/4, 2019 at 16:52 Comment(0)
M
1

I know this has been answered but I just ran into this. Found an easy way

remoteConfigInstance?.let {
    it.fetchAndActivate().addOnCompleteListener { task ->
        if (task.isSuccessful) {
            val result = task.result
            Timber.d("RemoteConfig - updated=$result")
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                it.all.forEach { (t, _) ->
                    Timber.i( "All remoteConfig values = $t - ${it.getBoolean(t)}")
                }
            }
        } else {
            Timber.e("RemoteConfig - ERROR fetching ..")
        }
    }
}
Morrie answered 7/4, 2020 at 3:29 Comment(1)
Why you add checking android version ? Is only for using all ?Libb
A
0

I found a solution but did not try it.

https://github.com/epool/firebase-cloning-tool

Altman answered 13/10, 2017 at 7:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.