Description
Passing comma separated API product values while invoking Creat App key, below error is returned from associateKeySecret function.
Error:
Associate KeySecret result: {"code":"cps.kms.ApiProductDoesNotExist","message":"API Product [{apiproduct1},{apiproduct2}] does not exist for tenant [32e6baf6] and id [null]","contexts":[]}
Solution:
Below particular line of code (createappkey.js line number 106) is incorrect. Incoming api product string is assigned as is within square brackets without splitting which results in single string with comma separated api product value i.e.
['Bronze,Gold'] which ideally should be ['Bronze','Gold'] after splitting up.
var prods = opts.apiProducts;
if (typeof prods === 'string') {
prods = [prods];
}
Reference:
createApp.js line number 68 has same functionality where api products are split and stored into array. Need to apply same logic in createAppKey.js instead of directly assigning apiproduct string with in square brackets.
if(opts.apiProducts){
var split = opts.apiProducts.split(',')
split.forEach(function(s){
if(s && s.trim()!= '') {
app.apiProducts.push(s.trim())
}
})
}