odoo2carddav/README.md

125 lines
3.8 KiB
Markdown

# odoo2carddav
odoo2carddav is a script which can extract contacts from Odoo (using its XMLRPC API), build vcards, and upload them to a carddav server.
It has been tested with Zimbra as carddav server, but should work with others.
You can configure it with a config file
```yaml
---
odoo:
# URL of the Odoo server
url: https://odoo.example.org
# User to connect with
user: odoo2carddav
# Recommended to use an API key
password: <password or API key>
# The name of the database to target on odoo server
database: odoo
# A list of filters to limit contacts returned by odoo
# Note : filters can only be set in a config file (not available as env var or cli arg)
filters:
- ["country_code", "=", "FR"]
- ["name", "ilike", "berteaud"]
dav:
# Url of the dav server
url: https://zimbra.example.org/dav/odoo2carddav%example.org/Odoo
# User and password for the carddav server
user: odoo2carddav
password: <password for the dav server>
# If true, then contacts which exists on the carddav server, but not in odoo will be deleted
delete: true
path:
# Local directory where the script will build vcards. Defaults is to use mkdtemp using /tmp/odoo2carddav.XXXXX as template
workdir: /tmp/odoo2carddav
# If True, vcards won't be deleted from the workdir when the script is finished
keep_vcard: true
```
If odoo.password or dav.password is not defined, it'll be prompted when you run the script.
Then, you can call the script with
```sh
odoo2carddav --config /etc/odoo2carddav.yml
```
You can also configure it with env vars
```
ODOO_URL=https://odoo.example.org \
ODOO_USER=foo \
ODOO_PASSWORD=bar odoo2carddav
```
Or using cli args
```sh
odoo2carddav --config --dav-url=https://webdav.example.org/Contacts/odoo
```
If you combine several sources for the configuration, the precedence will be (from lower to higher priority)
- default values bundled in the script
- environment
- config file
- cli args
The following perl modules are needed to run it
- OpenERP::XMLRPC::Client
- Data::Dumper
- Data::UUID
- Encode
- HTML::Parse
- HTML::FormatText
- URI::Simple
- Term::ReadKey
- HTTP::DAV
- Getopt::Long
- YAML::XS
- File::Basename
- File::Path
- File::Temp
- Hash::Merge::Simple
Or you can use the docker image
```
docker run --rm -e ODOO_URL=https://myodoo.acme.org \
-e ODOO_USER=contacts \
-e ODOO_PASSWORD=XXXXXXXXX \
-e DAV_URL=https://radical.acme.org/contacts/odoo \
-e DAV_USER=contacts \
-e DAV_PASSWORD=SuperS3cr3tP@ssW0rd \
-e DAV_DELETE=1 \
danielberteaud/odoo2carddav
```
If you want to pass a config file, you can use something like
```
docker run --rm -e ODOO_URL=https://myodoo.acme.org \
-e ODOO_USER=contacts \
-e ODOO_PASSWORD=XXXXXXXXX \
-e DAV_URL=https://radical.acme.org/contacts/odoo \
-e DAV_USER=contacts \
-e DAV_PASSWORD=SuperS3cr3tP@ssW0rd \
-e DAV_DELETE=1 \
-v ./odoo2carddav.yml:/conf.yml \
danielberteaud/odoo2carddav odoo2carddav --config /conf.yml
```
If you want not to store password in the config, and prefer being prompted for it when running, you need to add -it to docker command:
```
docker run --rm -e ODOO_URL=https://myodoo.acme.org \
-e ODOO_USER=contacts \
-e ODOO_PASSWORD=XXXXXXXXX \
-e DAV_URL=https://radical.acme.org/contacts/odoo \
-e DAV_USER=contacts \
-e DAV_PASSWORD=SuperS3cr3tP@ssW0rd \
-e DAV_DELETE=1 \
-v ./odoo2carddav.yml:/conf.yml \
-it \
danielberteaud/odoo2carddav odoo2carddav --config /conf.yml
```
If you need to use a proxy to reach the dav server, you can add PERL_LWP_ENV_PROXY=1 env var