mozilla / application-services

Firefox Application Services
https://mozilla.github.io/application-services/
Other
620 stars 227 forks source link

feat: Download collections from remote-settings, sync with local packaged data. #6471

Closed gruberb closed 2 weeks ago

gruberb commented 2 weeks ago

Adding the functionality to be able to read local, packaged data for a collection. This allows us to provide configurations without being able to connect to the internet on a device, or on first start-up, where the sync is not finished yet.

This PR also adds two commands to the cargo remote-settings CLI, so developers can work with and integrate collections more seamlessly.

dump-sync

This command checks the local components/remote_settings/dumps/{bucket}/{collection_name}.json files and updates them with the latest remote copy if they are outdated.

The command scans the components/remote_settings/dumps folder, and goes through each bucket (represented via a folder-name), and each {collection_name}.json. It checks the timestamp of the collection and compares it to the one from the changes endpoint.

> cargo remote-settings dump-sync --dry-run
Finished `dev` profile [unoptimized + debuginfo] target(s) in 1.30s
Running `target/debug/examples-remote-settings-cli dump-sync --dry-run`

Collection main/search-telemetry-v2 is up to date

Dry run summary:
- Would update 0 collections
- 1 collections already up to date
- 0 collections not found on remote

Or without --dry-run:

> cargo remote-settings dump-sync
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s
Running `target/debug/examples-remote-settings-cli dump-sync`

Collection main/search-telemetry-v2 is up to date

Execution summary:
Collections already up to date:
  - main/search-telemetry-v2

dump-get --bucket BUCKETNAME --collection-name COLLECTION.

This will download a copy of a single collection from remote, into the following local folder: components/remote_settings/dumps/{bucket}/{collection_name}.json.

Get a copy of a single collection locally:

> cargo remote-settings dump-get --bucket main --collection-name search-config-v2
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.67s

[00:00:00] ██████████████████████████████ Downloaded search-config-v2

Successfully downloaded collection to ./components/remote_settings/dumps/main/search-config-v2.json