|
1 | | -# GOBI Processor |
| 1 | +# SFTP Handler |
2 | 2 |
|
3 | | -A command-line tool for retrieving GOBI order marc files (.ord) via sftp. |
| 3 | +A command-line tool for SFTP-ing files from different providers. Currently supports LBNL patron files and Gobi E-Order files. |
4 | 4 |
|
5 | | -## Running it locally |
| 5 | +## Getting started |
6 | 6 |
|
7 | | -To run the application for real, you'll need to configure a local `.env` file with the GOBI password, which you can obtain from LastPass (search for "gobi"). Don't worry: this file is git-ignored. |
8 | | - |
9 | | -```ini |
10 | | -# ./.env (in the directory you cloned this from GitLab) |
11 | | -GOBI_PASS=password-from-lastpass |
12 | | -``` |
13 | | - |
14 | | ---- |
15 | | - |
16 | | -> **Additional Configuration:** The app accepts a few other configuration options, which you can see in `config/connections.yml`. The default values should work fine, however, so you probably don't need to change them. Also note that everything is mocked in the rspec tests, where you're not actually hitting the GOBI server. |
17 | | -
|
18 | | ---- |
19 | | - |
20 | | -With that configured, you can run the application like so: |
21 | | - |
22 | | -```sh |
23 | | -docker compose build # as always, you need to build it first |
24 | | -docker compose run --rm app ebook0413.ord |
25 | | -``` |
26 | | - |
27 | | -Today's GOBI order file will be at `/gobiord/eboo{mmdd}.ord` on their server. By default, the app copies it into the `/opt/app/data` directory within the container (mapped to `./data` in development), but this can be overwritten by the `--local_dir` flag: |
| 7 | +The application is dockerized, so for starters, just build it: |
28 | 8 |
|
29 | 9 | ```sh |
30 | | -docker compose run --rm app --local_dir /path/in/container |
| 10 | +docker compose build |
31 | 11 | ``` |
32 | 12 |
|
33 | | -Look for a specific file by passing its name as an argument: |
34 | | - |
35 | | -```sh |
36 | | -docker-compose run --rm app ebook0413.ord |
37 | | -``` |
| 13 | +Besides that, it's a fairly standard Ruby library: |
| 14 | +- [Thor](https://github.com/rails/thor) for the CLI |
| 15 | +- RSpec for testing (along with a few RSpec plugins) |
38 | 16 |
|
39 | | -You can also pass additional arguments when looking for a specific file: |
| 17 | +The `bin/berkeley_library-sftp_handler.rb` script is the container's entrypoint, so you can run it ad-hoc like so: |
40 | 18 |
|
41 | 19 | ```sh |
42 | | -docker-compose run --rm app ebook0413.ord \ |
43 | | - --remote_dir gobiord-staging \ |
44 | | - --local_dir path_to_local_dir |
| 20 | +# view help docs |
| 21 | +docker compose run --rm app help |
| 22 | +docker compose run --rm app help gobi |
| 23 | +docker compose run --rm app help lbnl |
| 24 | + |
| 25 | +# run the gobi loader |
| 26 | +docker compose run --rm app gobi |
| 27 | +docker compose run --rm app gobi --filename specific-file.ord |
| 28 | + |
| 29 | +# run the lbnl loader |
| 30 | +docker compose run --rm app lbnl |
| 31 | +docker compose run --rm app lbnl --filename specific-file.zip |
45 | 32 | ``` |
46 | 33 |
|
47 | | -## Testing |
| 34 | +By default, files are downloaded to `./data`. You can override this with the `--local-dir` option. See the specific help output or the [CLI class](lib/berkeley_library/sftp_handler/cli.rb) for details. |
48 | 35 |
|
49 | | -The app includes a number of RSpec tests integrated into its Jenkins pipeline. You can run the tests locally via: |
| 36 | +Open a shell (e.g. to run tests) by overriding the entrypoint: |
50 | 37 |
|
51 | 38 | ```sh |
52 | | -docker compose run --rm --entrypoint=rspec app |
| 39 | +docker compose run --rm --entrypoint bash app |
53 | 40 | ``` |
54 | 41 |
|
55 | | -Or by shelling into the container and running RSpec from there: |
| 42 | +### Secrets and .env |
56 | 43 |
|
57 | | -```sh |
58 | | -docker compose run --rm --entrypoint=sh app |
59 | | -rspec |
60 | | -``` |
| 44 | +SSH passwords and key data should be stored in the .env file. This file is git-ignored, so don't worry about it being committed. The contents of different secrets will be shared with you via LastPass; just ask for it in Slack. |
61 | 45 |
|
62 | | ---- |
| 46 | +```ini |
| 47 | +LIT_GOBI_PASSWORD="the-password" |
| 48 | +LIT_LBNL_KEY_DATA="-----BEGIN RSA PRIVATE KEY----- |
| 49 | +... |
| 50 | +-----END RSA PRIVATE KEY-----" |
| 51 | +``` |
63 | 52 |
|
64 | | -> **Insecure KEX:** As of 04/28/22, Gobi's server only supports outdated Diffie-Hellman key exchange algorithms, which you local sftp client will probably (and correctly) refuse. If you want to test manually, then for now you must explicitly allow the old algorithm by passing the following option to your sftp client: `-oKexAlgorithms=+diffie-hellman-group1-sha1`. |
| 53 | +## Adding new downloaders |
65 | 54 |
|
66 | | ---- |
| 55 | +To add a new downloader, create a class under BerkeleyLibrary::SftpHandler::Downloader, inherit from Downloader::Base, and implement the `download!` method. Then, integrate it into the CLI by adding a new method to BerkeleyLibrary::SftpHandler::Cli. See the existing examples for Lbnl and Gobi for more guidance. |
67 | 56 |
|
68 | 57 | ## Production configuration |
69 | 58 |
|
|
0 commit comments