Skip to content

Using programmatic cli with multiple namespaces does not work #155

@rabbah

Description

@rabbah

Here is a sample program to illustrate the problem. You'll need to test this with a couple of namespaces (and need to generate a couple of login tokens to run this code).

const { runNimCommand} = require('nimbella-cli');

async function getResourceFromToken(token) {
  await runNimCommand('auth/login', [token]);
  const namespace = (await runNimCommand('auth/current')).captured[0]
  const actions = (await runNimCommand('action/list')).table
  console.log(namespace)
  console.log(actions[0].namespace)
}

async function main() {
 await getResourceFromToken(process.env.TOKEN1)
 await getResourceFromToken(process.env.TOKEN2)    
}

main().catch(console.log)

To run this you'll need to use nim auth export for two different namespaces and create two env vars TOKEN1 and TOKEN2, and ensure you have at least one action in each namespace.

expected result

namespace1
namespace1
namespace2
namespace2

actual result

namespace1
namespace1
namespace2
namespace1

If you run this with DEBUG=* you'll see that the second handoff to AIO is wrong and preserved the "whisk identity" from the first login. Look for output like this:

nim:base aio capture intercepts installed
  aio-cli-config reading config: ...
  aio-cli-config reading env variables: runtime.namespace, runtime.apihost, runtime.auth
  aio-cli-plugin-runtime {
  aio-cli-plugin-runtime   apiversion: 'v1',
  aio-cli-plugin-runtime   apihost: 'https://...',
  aio-cli-plugin-runtime   api_key: 'namespace1-only-will-appear-here'
  aio-cli-plugin-runtime }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions