Skip to content

Commit 49b438d

Browse files
authored
Issue #162 Impl check_access (#165)
* update toolchain to nightly and fix `cargo clippy` installation error * fix clippy errors * update to `.await` and fix cargo errors/warnings * clean up some files * Clean up some files and some not needed dependencies * update .travis.yml to use latest nightly * follower - merge fix for `.await` * fix cargo fmt * add rust-toolchain for sentry only, until `.await` is merged * clean up `sentry` * make sentry build again * cargo-make 0.22.2 fixes the installation of clippy so remove the custom task override * update `futures-preview` to `alpha.19` * sentry - add the `adapter` along side `futures-preview`, `hyper`, `regex` and `tokio` * sentry - add the cli options, load config and make a 404 Not found response. * sentry - add `serde` & `serde_urlencoded` * sentry - routes - channel - list channel WIP * sentry - move `fn not_found` & `fn bad_request` to lib * sentry - Cargo.toml - add `unstable-stream` feature for `hyper` * sentry - more to channels list and channel create endpoints * sentry - fix some issues and clean up code * sentry - Cargo.toml - add `chrono` * primitives - remove channel::ChannelListParams * sentry - ChannelListQuery * sentry - better error response handling & move channel list & create code to own modules * sentry - Fix changes required because of the merge & `clippy` warnings * sentry - remove `rust-toolchain` * fix `rustfmt` * improve `Adapter`, `EthereumAdapter` & `DummyAdapter` * sentry - Application struct * Fix `EthereumAdapter` and fix `clippy` warnings * fix import * primitives - big_num - fix `clippy` warnings about `to_owned()` * primitives - add `slog` and impl own PrefixCompactFormat * primitives - re-export `slog_async::Async` & `slog_term::TermDecorator` * sentry - working logging for the `Application`: - use the re-exported from `primitives` `slog` structs & traits - Cargo.toml - remove `slog-term` & `slog-async` since we use the re-exported once * sentry - use `error!` for server error & suppress `clustered` warning for not using it now * Use patch instead of `git` url & branch in the `primitives` `Cargo.toml` * sentry - add listening to port on `Application::run` * sentry - add missing `info` import * Fix some merge problems and re-add the `Send` trait bound for the `Adapter` * sentry - Cargo.toml - add `redis` * sentry - register `db` module and add `REDIS_URL` to it * sentry - function for creating `redis` async connection * [WIP] sentry - access - check_access - rules that are applicable * primitives - config - use `RateLimit` from `event_submission` module * primitives - use `std::time::Duration` for `RateLimit.time_frame` - primitives - Cargo.toml - add `serde_millis` - primitives - `RateLimit.time_frame` to `Duration` * primitives - Cargo.toml - reorder dependencies * sentry - access - finish up `check_access` * Clean up README files * sentry - db - fix wrong merge & change to SharedConnection * sentry - db - `expect()` instead of `unwrap()` * sentry - access - take reference to `RateLimit` * sentry - Cargo.toml - `redis` to version `0.13.1-alpha` - Cargo.toml - `redis` patch for WIP branch of `async_await_api` * [+test] sentry - access - check_access - return Result, fix `redis` error * [test] sentry - access - check_access - finish the last test for an IP RateLimit * Travis-ci - add `redis` service
1 parent 0ae4619 commit 49b438d

File tree

13 files changed

+399
-141
lines changed

13 files changed

+399
-141
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ env:
66
global:
77
- CARGO_MAKE_RUN_CHECK_FORMAT="true"
88
- CARGO_MAKE_RUN_CLIPPY="true"
9+
services:
10+
- redis-server
911
matrix:
1012
fast_finish: true
1113
script:

Cargo.lock

Lines changed: 70 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,6 @@ members = [
77
"sentry",
88
"adview-manager",
99
]
10+
11+
[patch.crates-io]
12+
redis = {version = "0.13.1-alpha.0", git = "https://github.com/Marwes/redis-rs", branch = "async_await_api"}

README.md

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,12 @@ Reference implementation of the [AdEx validator stack](https://github.com/adexne
66

77
Components:
88

9-
* Domain crate
10-
* Sentry - check the list of [opened issues](https://github.com/AdExNetwork/adex-validator-stack-rust/issues?q=is:open+is:issue+project:AdExNetwork/adex-validator-stack-rust/1)
11-
* Validator worker - The validator worker(`Leader` or `Follower`) that validates/proposes new states.
12-
* memory-repository - Generic helper crate for creating InMemory repositories for testing.
13-
* adapter - Adapter trait for `sign`, `verify` and `validate_channel` with Dummy implementation for testing.
9+
* Sentry
10+
* Validator worker
11+
* Adapter
12+
* AdView manager
1413

15-
**Note:** Please refer to the README.md of the component for a more detailed overview of it.
16-
17-
## Domain
18-
Contains all the Domain `Aggregates`, `Entities`, `Value Objects`, interfaces (traits) and `Domain Error`.
19-
The interfaces(traits) include The `RepositoryFuture` and the `Aggregates`/`Entities` traits for the repositories.
20-
21-
All the structs have defined (de)serialization. The also have incorporated domain rules, e.g.
22-
`TargetingTag.score` (the `Score` struct) should be with a value between `0` and `100`.
23-
This means that once we have a `Score` object, we are guaranteed to have a valid object everywhere.
24-
25-
The `Repository` traits are meant to help you create the correct abstractions in the underlying application,
26-
as every application has different requirements for the way and things it will fetch.
27-
28-
## Sentry & Validator worker
29-
30-
Split into 3 layer - Domain, Infrastructure & Application.
31-
- Domain - the domain objects/structs that are defining the business rules and constraints.
32-
- Infrastructure - specific implementations of e.g. Repositories, Logging and etc.
33-
like `Memory__Repository`, `Api__Repository` and so on.
34-
- Application - all the application specific logic, which means services, structs and etc. that use the Domain and it's
35-
traits to achieve the task at hand. For example: In sentry we have the `resource`s, there we define the
36-
`channel_create`. Which handles the request, validates it and uses the `ChannelRepository` trait to
37-
`add` the new Channel and returns the appropriate Response. It is not however limited to Request -> Response.
38-
39-
## Testing setup
40-
41-
### Rust setup
42-
43-
- Requires `nightly 2019-05-08`, because of the new syntax for `await` and our `tower-web` dependency fails to build.
44-
We've setup `rust-toolchain` but you can manually override it as well with `rustup override set nightly-2019-05-08`.
14+
## Local & Testing setup
4515

4616
#### Linux
4717
- The crate `openssl-sys` requires `libssl-dev` and `pkg-config` for Ubuntu.
@@ -53,32 +23,30 @@ We've setup `rust-toolchain` but you can manually override it as well with `rust
5323
- `$HOME/docker/volumes/postgres` - your local storage for postgres (persist the data when we remove the container)
5424
- `POSTGRES_PASSWORD=docker` - the password of `postgres` user
5525

56-
### Run Sentry Rest API
26+
### Run Redis:
5727

58-
`DATABASE_URL=postgresql://postgres:docker@localhost:5432/sentry cargo run --bin sentry`
28+
`docker run --name some-redis -d redis`
5929

60-
### Run Validator Worker
30+
### Run automated tests
6131

62-
`cargo run --bin validator`
32+
Since we have integration tests that require Redis & Postgres,
33+
you need to be running those in order to run the automated tests:
6334

64-
For the available options:
35+
`cargo make test`
6536

66-
`cargo run --bin validator -- --help`
37+
### Run Sentry Rest API
6738

68-
#### Environment variables:
39+
* With the DummyAdapter(replace the `DummyIdentity`):
6940

70-
**NOTE: Currently we use `.env` file to define values for those environment variables.
71-
We need to see if we want configuration files per binary instead.**
41+
`export PORT=8006; cargo run -p sentry -- -a dummy -i DummyIdentity`
7242

73-
##### Sentry:
74-
- `DATABASE_URL` - The url of the Postgres database used for production.
75-
- `SENTRY_CHANNEL_LIST_LIMIT` - the limit per page for listing channels from the `/channel/list` request.
43+
* With the EthereumAdapter:
7644

77-
##### Validator:
78-
- `VALIDATOR_TICKS_WAIT_TIME` - The time for a whole cycle(tick) of the validator worker to get & loop channels,
79-
validate and send statuses and etc.
80-
- `VALIDATOR_SENTRY_URL` - The url of the Sentry API that should be used
81-
- `VALIDATOR_VALIDATION_TICK_TIMEOUT` - The maximum time for validation of a single channel as a `Leader` or `Follower`
45+
TODO
46+
47+
### Run Validator Worker
48+
49+
TODO
8250

8351
## Development environment
8452

@@ -89,5 +57,7 @@ as well as on CI. For a complete list of out-of-the-box commands you can check
8957
Locally it's enough to ensure that `cargo make` command (it will execute the default dev. command) is passing.
9058
It will run `rustfmt` for you, it will fail on `clippy` warnings and it will run all the tests.
9159

60+
*Note:* You need to have setup Redis and Postgres as well.
61+
9262
You can related to the [Makefile.stable.toml](https://github.com/sagiegurari/cargo-make/blob/master/src/lib/Makefile.stable.toml)
9363
for more commands and cargo-make as a whole.

adapter/README.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

primitives/Cargo.toml

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ futures-preview = { version = "=0.3.0-alpha.19", features = ["compat"]}
1111
serde = { version = "^1.0", features = ['derive'] }
1212
serde_json = "1.0"
1313
serde-hex = "0.1.0"
14+
serde_millis = "0.1.1"
15+
# Configuration
1416
toml = "0.5"
1517
# Logging
1618
slog = { version = "^2.5.2" , features = ["max_level_trace"] }
@@ -20,6 +22,9 @@ slog-async = "^2.3.0"
2022
chrono = { version = "0.4", features = ["serde"] }
2123
time = "0.1.42"
2224
hex = "0.3.2"
25+
merkletree = "0.10.0"
26+
tiny-keccak = "1.5"
27+
eth_checksum = "0.1.1"
2328
# Numbers - BigNum, Numbers, Traits and Derives
2429
num-bigint = { version = "0.2", features = ["serde"] }
2530
num = "0.2.0"
@@ -28,9 +33,5 @@ num-derive = "0.2"
2833
# Fixtures
2934
fake = { version = "^1.3", features = ["chrono"] }
3035
rand = { version = "^0.6" }
36+
# Other
3137
lazy_static = "1.4.0"
32-
merkletree = "0.10.0"
33-
tiny-keccak = "1.5"
34-
eth_checksum = "0.1.1"
35-
36-

0 commit comments

Comments
 (0)