apache / openwhisk-client-js

JavaScript client library for the Apache OpenWhisk platform
https://openwhisk.apache.org/
Apache License 2.0
83 stars 53 forks source link

Updating package parameters doesn't seem to take affect #143

Closed macdonst closed 5 years ago

macdonst commented 5 years ago

I'm attempting to update my package parameters while executing an action. Unfortunately, no matter what I try the parameters don't seem to be updated.

Here is some sample action code that illustrates the problem:

const openwhisk = require('openwhisk');

function extractPackageName(action) {
  return action.split('/')[2];
}

function main(params) {
  const ow = openwhisk();
  const packageName = extractPackageName(process.env['__OW_ACTION_NAME']);

  return ow.packages
    .get(packageName)
    .then(pack => {
        // a and b not in package
        console.log(pack);
        pack.parameters.push({key: 'a', value: 'a'});
        pack.parameters.push({key: 'b', value: 'b'});
        // alternatively tried
        // pack.parameters.a = 'a';
        // pack.parameters.b = 'b';
        // a and b included in the package
        console.log(pack);
        return ow.packages
          .update(pack)
          .then(updatedPackage => {
            // a and b not in package
            console.log(updatedPackage);
            return {
              ...params
            };
          })
          .catch(err => {
            return err;
          });
    })
    .catch(function(err) {
      return err;
    });
}

As well subsequent calls to this action do not show the updated a and b parameters I've attempted to add.

starpit commented 5 years ago

hi, i think the issue is that the parameters field is an array i.e. [{key, value}, ...] of key-value pairs, not a map from key to value?

macdonst commented 5 years ago

@starpit Yeah, I updated the code above as that was a copy and paste from my trashing trying to figure out what I was doing wrong. I have the same issue if I push new object into the parameters array.

As well, if I run the example code directly from here: https://github.com/apache/incubator-openwhisk-client-js#update-package-parameters I still get the same issue.

starpit commented 5 years ago

you have tried ow.packages.update({ name, package})? your example has ow.packages.update(pack) which i think won't work.

macdonst commented 5 years ago

Yeah, using ow.packages.update({ name, package}) has resolved the issue but I'm not sure why that would be different than ow.packages.update(pack) where pack is an object that has a name and parameters properties.

starpit commented 5 years ago

yes, i agree that this API could be refined; it is not a reflexive API.

macdonst commented 5 years ago

Okay, well I'm going to close this a user error :)