Package: data-transfer
Data Transfer Microservice==========================This microservice is a multi-mode file movement wizard. It can transfer files,at a scheduled interval, between two different storage devices, using differenttransfer protocols and storage types.The application is built for Python 3, but also tested against Python 2.7. Itis **not** compatible with Python 2.6.**Note**The application will not work if you have files with spaces in the names and will fail.**Standard FTP is no longer supported in this app**Installing and getting started------------------------------The application should be installed using ``pip3`` (or ``pip`` for Python 2.7).To install from a private PyPI server we suggest using ``~/.pypirc`` to configureyour private PyPI connection details::pip3 install data-transfer --extra-index-url <Repo-URL>After installing and setting the configuration settings, the application can bestarted with the following command::data-transferDeveloping----------Start by cloning the project::git clone git@github.com:UKHomeOffice/data-transfer.gitEnsure that ``python3`` is installed and on your ``path``.Installing for local developmentThese steps will install the application as a local pip installed package,using symlinks so that any updates you make to the files are automaticallypicked up next time you run the application or tests.Using venv""""""""""To install the app using the standard ``python3 venv`` run the followingcommands from the project root folder::python3 -m venv ~/.virtualenvs/data-transfersource ~/.virtualenvs/data-transfer/bin/activatepip3 install -e . -r requirements.txtexport PYTHONPATH=.Using virtualenvwrapper"""""""""""""""""""""""Alternatively, if you are using ``virtualenvwrapper`` then run the following::mkvirtualenv data-transfer -p python3pip3 install -e . -r requirements.txtexport PYTHONPATH=.Dependancies for local testing""""""""""""""""""""""""""""""The project's tests require the following dependencies:* An AWS S3 bucket or a mock* An FTP server* An SFTP serverFor local development and testing, we suggest running Docker images. The followingwill meet the test dependencies and match the default env vars::docker run -d --name s3server -p 8000:8000 scality/s3serverdocker run -d --name ftp_server -p 21:21 -p 30000-30009:30000-30009 onekilo79/ftpd_testdocker run -p 2222:22 -d atmoz/sftp foo:pass:::uploadTest""""Once the application is installed and the dependencies are in place, run thetests::pytest testsBuilding & publishing=====================This project uses ``setuptools`` to build the distributable package.Remember to update the ``version`` in ``setup.py`` before building the package::python setup.py sdistThis will create a ``.tar.gz`` distributable package in ``dist/``. This should beuploaded to an appropriate PyPI registry.Deploying---------The application should be installed using ``pip3`` (or ``pip`` for Python 2.7).If installing from a private PyPI server then we suggest using ``~/.pypirc`` toconfigure your private PyPI connection details::pip3 install data-transfer --extra-index-url <Repo-URL>Configuration-------------The application requires the following environment variables to be set beforerunning.All configuration settings automatically default to suitable values for thetests, based on the local test dependencies running in the Docker imagessuggested in this guide.Application settings""""""""""""""""""""These control various application behaviours, where a variable is not requiredthe default value is used:+---------------------+----------------------+-----------+-----------------------------------+|Environment Variable | Example (Default)    | Required  | Description.                      |+=====================+======================+===========+===================================+|INGEST_SOURCE_PATH   | /upload/files        | Yes       | Source path                       |+---------------------+----------------------+-----------+-----------------------------------+|INGEST_DEST_PATH     | /upload/files/done   | Yes       | Destination path                  |+---------------------+----------------------+-----------+-----------------------------------+|MAX_FILES_BATCH      | 5                    | No        | Number to process each run        |+---------------------+----------------------+-----------+-----------------------------------+|PROCESS_INTERVAL     | 5                    | No        | Runs the task every (x) seconds.  |+---------------------+----------------------+-----------+-----------------------------------+|FOLDER_DATE_OUTPUT   | False                | No        | Moves files to YYYY / MM / DD     |+---------------------+----------------------+-----------+-----------------------------------+|LOG_LEVEL            | INFO                 | No        | Log level                         |+---------------------+----------------------+-----------+-----------------------------------+|LOG_FILE_NAME        | data-transfer.log    | Yes       | Filename for log output           |+---------------------+----------------------+-----------+-----------------------------------+|USE_IAM_CREDS        | False                | Yes       | Indicates to app to use IAM       |+---------------------+----------------------+-----------+-----------------------------------+|READ_STORAGE_TYPE    | See footnote         | Yes       | The type of read storage          |+---------------------+----------------------+-----------+-----------------------------------+|WRITE_STORAGE_TYPE   | See footnote         | Yes       | The type of write storage         |+---------------------+----------------------+-----------+-----------------------------------+Note: the read and write storage types need to be prefixed and options are:* datatransfer.storage.FolderStorage* datatransfer.storage.SftpStorage* datatransfer.storage.S3Storage* Also ensure that the source and destination paths have the correct leading andtrailing slashes, this will depend on the storage type and the OS. See theecosystem.config file for examples.Source / read settings""""""""""""""""""""""Provide the connection settings for either sFTP or S3. You only need toconfigure the settings associated with the source storage type.+----------------------------+------------------------+--------------------------+|Environment Variable        | Example                | Description              |+============================+========================+==========================+|READ_FTP_HOST               | localhost              | Hostname or IP of server |+----------------------------+------------------------+--------------------------+|READ_FTP_PASSWORD           | pass                   | Password                 |+----------------------------+------------------------+--------------------------+|READ_FTP_USER               | user                   | Username                 |+----------------------------+------------------------+--------------------------+|READ_FTP_PORT               | 22                     | Port the server uses     |+----------------------------+------------------------+--------------------------+|READ_AWS_ACCESS_KEY_ID      | accessKey1             | Access key for S3        |+----------------------------+------------------------+--------------------------+|READ_AWS_S3_BUCKET_NAME     | aws-ingest             | Bucket name              |+----------------------------+------------------------+--------------------------+|READ_AWS_S3_HOST            | http://localhost:8000  | URL of S3                |+----------------------------+------------------------+--------------------------+|READ_AWS_S3_REGION          | eu-west-1              | region for s3 bucket     |+----------------------------+------------------------+--------------------------+Target / write settings"""""""""""""""""""""""Provide the connection settings for either sFTP or S3. You only need toconfigure the settings associated with the target storage type.+----------------------------+-----------------------+-------------------------+|Environment Variable        | Example               | Description             |+============================+=======================+=========================+|WRITE_FTP_HOST              | localhost             | Hostname or IP of server|+----------------------------+-----------------------+-------------------------+|WRITE_FTP_USER              | user                  | Username                |+----------------------------+-----------------------+-------------------------+|WRITE_FTP_PASSWORD          | pass                  | Password                |+----------------------------+-----------------------+-------------------------+|WRITE_FTP_PORT              | 22                    | Port for server         |+----------------------------+-----------------------+-------------------------+|WRITE_AWS_ACCESS_KEY_ID     | accesskey1            | Access key for S3       |+----------------------------+-----------------------+-------------------------+|WRITE_AWS_SECRET_ACCESS_KEY | verysecret            | Secrey key              |+----------------------------+-----------------------+-------------------------+|WRITE_AWS_S3_BUCKET_NAME    | aws-ingest            | Bucket name             |+----------------------------+-----------------------+-------------------------+|WRITE_AWS_S3_HOST           | http://localhost:8000 | URL of S3               |+----------------------------+-----------------------+-------------------------+|WRITE_AWS_S3_REGION         | eu-west-1             | region for s3 bucket    |+----------------------------+-----------------------+-------------------------+Running the application-----------------------To run the application from the command line:For pip installed versions::data-transferCalling the application directly::python bin/data-transferFor production use we recommend running the application using PM2, please ensurethat PM2 is installed globally before running this command::pm2 start ecosystem.config.js --only data-transferEnvirnment variables required should be changed in the ecosystem file beforerunning PM2. It is also recommended to run pm2 from within a python virtual env.Running Multi-Instances-----------------------To run more that one instance of the application with different config settings,you will need to change/add additional services into the ecosystem config file.See here for examples:<http://pm2.keymetrics.io/docs/usage/application-declaration/#process-file>Windows-------The application is portable between linux and windows, however when running theapp on windows there are some specifics you may want to take into account:1. If you are running the microservice using a batch file or other mechanismother than PM2, you will need to ensure that the environment variables areset without quotes.2. The file paths for FolderStorage should be Windows paths, for FTP,sFTP andS3 these can be unix format.For sFTP, and Folder storage ensure paths are absolute without a trailing slash/path/to/somethingFor S3 the path is used with the URL so can be relative, but without a trailing slashpath/to/somethingAWS---If you are running the app on a AWS instance that has anIAM policy you can setthe USE_IAM_CREDS var to True and the application will use IAM policies. You musthowever ensure that the bucket name is set correctly.Contributing""""""""""""This project is Open source and we welcome ocntributions to and suggestions toimprove the application. Please raise issues in the usual way on Github and forcontributing code:* Fork the repo github* Clone the project locally* Commit your changes to your own branch* Push your work back to your fork* Submit a Pull Request so that we can review the changesLicensing"""""""""This application is released under the `BSD license`_... _BSD license: LICENSE.txt