3

The manual at http://couchapp.org/page/couchapp-config says that you can store passwords in ~/.couchapp.conf. However, the db url is acutally the url to the specific database. If there are two applications in different databases, say /db1 and /db2, then we'd have to have this:

{
  "env" : {
    "default" : {
      "db" : "http://admin:pass@localhost:5984/db1"
    }
  }
}

and:

{
  "env" : {
    "default" : {
      "db" : "http://admin:pass@localhost:5984/db2"
    }
  }
}

but I don't see how this can be merged into one (unless instead of default a hack is used to add one "environment" per DB, e.g. default-db1 and default-db2 and such).

How can I combine this into one, so e.g. I specify db1 and db2 within .couchapprc files in respective applications or something similar?

icyrock.com
  • 27,952
  • 4
  • 66
  • 85

2 Answers2

2

I can't test it right now, but I think you should simply merge the two environments giving them different names (e.g. "env1", and "env2"):

{
  "env" : {
    "env1" : {
      "db" : "http://admin:pass@localhost:5984/db1"
    },
    "env2" : {
      "db" : "http://admin:pass@localhost:5984/db2"
    }
  }
}

Then pass the environment as the last command line argument: couchapp push env1.

However I think the easiest solution is to put the info in .couchapprc in the root of the project, then add it to .gitignore, .htignore, or whatever you use for version control.

Marcello Nuccio
  • 3,901
  • 2
  • 28
  • 28
  • The issue is that I want to have this separate. I don't want to define all the environments in the global file, I don't want to spread passwords all around (e.g. if I change the pass, I'd have to change everywhere) and, when shared, it's important to have others use their settings instead of mine. – icyrock.com Aug 19 '11 at 02:47
1

Looking in dist-packages/couchapp/config.py, method Config.load does this in the middle:

new_conf = util.read_json(p, use_environment=True,
    raise_on_error=True)

Note use_environment=True. This is not a perfect thing, as it does not take into account the variables within global ~/.couchapp.conf file, but it gives at least a workaround - just define the necessary environment variables, say COUCHAPP_USER and COUCHAPP_PASS, and use them in the .couchapprc file:

"db" : "http://$COUCHAPP_USER:$COUCHAPP_PASS@localhost:5984/db1"

Now you can run couchapp push:

$ export COUCHAPP_USER=testadmin 
$ export COUCHAPP_PASS=pass 
$ couchapp push

and it will work as expected.

icyrock.com
  • 27,952
  • 4
  • 66
  • 85