Copying KVM values from one environment to another

Is there any method to copy the KVM values from environment to another without the use of Key Value Map Operation policy ?

3 14 3,190
14 REPLIES 14

Not applicable

Hi @praveen p - I don't know your complete use case.. but if you want to use key-value-map across environments, you can configure the KVM with "Organization" scope (and avoid copying).

Checkout KVM policy related documents here for more details on scope.

Former Community Member
Not applicable

@praveen p can you describe your use case a little more? As @sudheendra1 explains you can use the Management APIs to move values between KVMs or use Org level KVMs if more appropriate. You can also use node.js to programatically move values between KVMs. You will have to end up using the Management APIs from your node code however.

Slightly unrelated, if you are looking to move entries from one cache to the other without using a PopulateCache policy, you can also use the apigee-access node module to get from one cache & put into another one.

Hope this helps!

@Prithpal Bhogill - To move the KVM from one environement to another through come command like codes or through some plugin feature. (Not through Apigee Edge UI - Using KVM policy)

Not applicable

Hi @praveen p, good question! I know where you're coming from. You want to import KVMs from one environment seamlessly, so down the road you can automate this process. IMO, this is a typical use case for automating the API proxy deployment lifecycle. So, you're in luck! After this weekend, Apigee Deploy Grunt Plugin now supports migration of KVMs leveraging grunt-apigee-kvm plugin task.

So, now you can update KVMs every time you deploy an API Proxy either at organization or environment level. Take a look at this configuration:

grunt.initConfig({
    apigee_kvm: {
        "testmyapi-test" : {
          options: {
            type: "env"
          },
          files: [{src: ['config/kvm/testmyapi/testmyapi-test/*.json']},
          ]
        },
        "testmyapi-prod" : {
          options: {
            type: "env"
          },
          files: [{src: ['config/kvm/testmyapi/testmyapi-prod/*.json']},
          ]
        },
        "testmyapi" : {
          options: {
            type: "org"
          },
          files: [{src: ['config/kvm/testmyapi/*.json']},
          ]
        }
    }
});

Note the plugin is setup to import KVMs for test and prod environment when type is set to "env", and to the organization when type is set as "org". *.json patterns will pick up files containing KVMs entries under these folders.

For a full example, please give it a try to the plugin and let me know your thoughts!

Hope it helps!

Diego

@dzuluaga

Thanks this is really informative. Even my requirement is to move it from one environment to another through some scripts/ plugin feature. I will dig up on this Apigee Grunt plugin.

Agreed @praveen p. The plugin above is half of the answer, as it imports the definition of KVMs sitting in a specified folder. The second half of the answer would be to have an export KVM task, which you could run first to export the entries from an environment and save them to a folder, then run KVM import plugin. This is rather a simple task for Grunt, If you want to take a first stab, you can follow the design patterns from Grunt Apigee KVM Import Task, however this requirement is very compelling, that I'm tempted to look into it this week :-D. Stay tuned.

Not applicable

Hi @praveen p, as I said earlier I'd look into it to implement a Grunt KVM export task. I've just finished this plugin and it's available from NPM. You can also clone the Git repo and try Gruntfile.js and configuration that comes with. Essentially you just need to install the package and specify the configuration in your Gruntfile.js the location in which you want to export KVM entries:

grunt.initConfig({
  apigee_kvm_export: {
    "testmyapi" : { //target specific options go here, in this example first target is testmyapi. This will be replaced with your org in Apigee Edge
      options: {
        type: "org",
        dest: 'config/kvm/testmyapi',
        match: /^(passwords|targets)$/ //  exports all KVMs by default or /(.*?)$/ when match is missing
      }
    },
    "testmyapi-prod" : { //target specific options go here, in this example first target is testmyapi environment and prod org.
      options: {
        type: "env",
        dest: 'config/kvm/testmyapi/testmyapi-prod',
        match: /^(passwords|targets)$/ //  exports all KVMs by default or /(.*?)$/ when match is missing
      }
    }
  }
});

Then, after KVM exports are generated you can leverage Apigee Grunt Import KVM Plugin to import those entries to another organization or environment as specified above.

Hope it helps! Keep me posted if you run into any issues.

Thanks dzuluaga ...I am trying this out...

Will keep you posted on my progress 🙂

~Praveen

Not applicable

Hi Diego,

Thanks for fixing the sdk, I got it working both the import and export codes, I'm currently trying to merge the import and export and noticed that the implementation in the import kvm's is a bit different in export.

What I'm trying to achieve now is to export KVMs from test env then import to prod for now, (but main goal is to transfer those also to another org with specific env). Is it possible to change the env config from test to prod when importing the KVMs?

The challenge I am facing right now is that once the --env is set to test (via console) then gruntfile executes, export will run pointing to test after that I am not able to change the target to 'prod' to import those KVMs in prod env.

Thanks!

denz

Not applicable

I see your point Den z. The initial intend of this plugin was to help developers import/update environments with data from the same environment. However, I think it could be extended to provide more affordances by supporting parameters that point to other environments. I tried a workaround, however it's not pretty. But here it goes:

1) Switch the environment manually by another task before import task executes:

grunt.registerTask('test', ['clean', 'switchOrgEnvTask', 'importKVMs', 'switchOrgEnvBackTask']);

2) Here's the task

  grunt.task.registerTask('switchOrgTask', 'A sample task to switch the org.', function(orgDest) {
    var profiles = grunt.config.get('apigee_profiles');
    profiles[grunt.option('env')].org = 'testmyapi'; // change org to new org
    profiles[grunt.option('env')].env = 'prod'; // same for env
    grunt.config.set('apigee_profiles',profiles);
  });

3) Switch org/env back with switchOrgEnvBackTask similar to step #2

All in all, I think improving the plugin to support multiple orgs and envs shouldn't be hard to implement. I'll have to look at it later on when I get some time. Or if you'd like to take a first stab, it'd be great to collaborate with you on this.

Not applicable

Thanks Diego for your quick response. that is what I'm trying to do last week but since I'm new to grunt I did not make it to work. I'll check on the code you created and see what I can do to improve.

Not applicable

Hi. I was trying to use the grunt plugin to copy KVM from one env to another as mentioned above. But I always get

grunt-apigee-kvm@0.1.0 requires a peer of grunt@~0.4.5 but none was installed error.

I am following the exact steps as mentioned in

https://gruntjs.com/getting-started

Not applicable

Hi @praveen p I am just curious here. I have never used nodeJS to a handle my edge env(proxy, prodcut or KVMs) Where do I start for this. Any infor would be very helpful .