Skip to content

Commit

Permalink
Parsing / Fetcher / Data Governance redirects / Polling modes
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein committed May 4, 2024
1 parent 68f4919 commit 7606c74
Show file tree
Hide file tree
Showing 25 changed files with 1,826 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @configcat/developers
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
enable-beta-ecosystems: true
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
64 changes: 64 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Rust SDK CI
on:
schedule:
- cron: '0 0 * * *'
push:
branches: [ main ]
paths-ignore:
- '**.md'
pull_request:
branches: [ main ]
paths-ignore:
- '**.md'

workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Run tests
run: cargo test

format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt
- name: Check format
run: cargo fmt --check

clippy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: clippy
- name: Check format
run: cargo clippy -- -D warnings

publish-dry-run:
needs: [test, format, clippy]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Publish dry-run
run: cargo publish --dry-run
16 changes: 16 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Rust SDK Publish
on:
push:
tags: [ '[0-9]+.[0-9]+.[0-9]+' ]

workflow_dispatch:

jobs:
publish:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Publish
run: cargo publish --token ${{ secrets.CRATES_TOKEN }}
12 changes: 12 additions & 0 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Mark stale issues

on:
schedule:
- cron: '0 1 * * *'

workflow_dispatch:

jobs:
stale:
uses: configcat/.github/.github/workflows/stale.yml@master
secrets: inherit
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

.idea

# Added by cargo

/target
40 changes: 40 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Contributing to the ConfigCat Rust SDK

ConfigCat SDK is an open source project. Feedback and contribution are welcome. Contributions are made to this repo via Issues and Pull Requests.

## Submitting bug reports and feature requests

The ConfigCat SDK team monitors the [issue tracker](https://github.com/configcat/rust-sdk/issues) in the SDK repository. Bug reports and feature requests specific to this SDK should be filed in this issue tracker. The team will respond to all newly filed issues.

## Submitting pull requests

We encourage pull requests and other contributions from the community.
- Before submitting pull requests, ensure that all temporary or unintended code is removed.
- Be accompanied by a complete Pull Request template (loaded automatically when a PR is created).
- Add unit or integration tests for fixed or changed functionality.

When you submit a pull request or otherwise seek to include your change in the repository, you waive all your intellectual property rights, including your copyright and patent claims for the submission. For more details please read the [contribution agreement](https://github.com/configcat/legal/blob/main/contribution-agreement.md).

In general, we follow the ["fork-and-pull" Git workflow](https://github.com/susam/gitpr)

1. Fork the repository to your own Github account
2. Clone the project to your machine
3. Create a branch locally with a succinct but descriptive name
4. Commit changes to the branch
5. Following any formatting and testing guidelines specific to this repo
6. Push changes to your fork
7. Open a PR in our repository and follow the PR template so that we can efficiently review the changes.

## Build instructions

This ConfigCat SDK builds with `cargo`.

```bash
cargo build
```

## Running tests

```bash
cargo test
```
34 changes: 34 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[package]
name = "configcat"
description = "ConfigCat Rust SDK"
authors = ["ConfigCat"]
homepage = "https://configcat.com"
repository = "https://github.com/configcat/rust-sdk"
documentation = "https://configcat.com/docs/sdk-reference/rust"
keywords = ["configcat", "feature-flag", "feature-toggle"]
license = "MIT"
version = "0.1.0"
edition = "2021"
build = "build.rs"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_repr = "0.1"
log = { version = "0.4", features = ["kv"] }
chrono = "0.4.38"
thiserror = "1.0"
reqwest = "0.12.4"
futures = "0.3.12"
tokio = { version = "1.17.0", features = ["rt", "sync", "macros"] }
tokio-util = "0.7"
lazy_static = "1.4"
sha1 = "0.10"
base16ct = { version = "0.2", features = ["alloc"] }

[build-dependencies]
built = "0.7"

[dev-dependencies]
mockito = "1.2.0"
tokio = { version = "1.17.0", features = ["macros"] }
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
# rust-sdk
# ConfigCat SDK for Rust

ConfigCat SDK for Rust provides easy integration for your application to [ConfigCat](https://configcat.com).

## Polling Modes
The ConfigCat SDK supports 3 different polling mechanisms to acquire the setting values from ConfigCat. After latest setting values are downloaded, they are stored in the internal cache then all requests are served from there. Read more about Polling Modes and how to use them at [ConfigCat Docs](https://configcat.com/docs/sdk-reference/rust).

## Need help?
https://configcat.com/support

## Contributing
Contributions are welcome. For more info please read the [Contribution Guideline](CONTRIBUTING.md).

## About ConfigCat
ConfigCat is a feature flag and configuration management service that lets you separate releases from deployments. You can turn your features ON/OFF using <a href="https://app.configcat.com" target="_blank">ConfigCat Dashboard</a> even after they are deployed. ConfigCat lets you target specific groups of users based on region, email or any other custom user attribute.

ConfigCat is a <a href="https://configcat.com" target="_blank">hosted feature flag service</a>. Manage feature toggles across frontend, backend, mobile, desktop apps. <a href="https://configcat.com" target="_blank">Alternative to LaunchDarkly</a>. Management app + feature flag SDKs.

- [Official ConfigCat SDKs for other platforms](https://github.com/configcat)
- [Documentation](https://configcat.com/docs)
- [Blog](https://configcat.com/blog)
3 changes: 3 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
fn main() {
built::write_built_file().expect("Failed to acquire build-time information");
}
23 changes: 23 additions & 0 deletions src/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// A cache API used to make custom cache implementations.
pub trait ConfigCache: Sync + Send {
/// Gets the actual value from the cache identified by the given `key`.
fn read(&self, key: &str) -> Option<String>;

/// Writes the given `value` to the cache by the given `key`.
fn write(&self, key: &str, value: &str);
}

pub struct EmptyConfigCache {}

impl EmptyConfigCache {
pub fn new() -> Self {

Check failure on line 13 in src/cache.rs

View workflow job for this annotation

GitHub Actions / test

associated function `new` is never used

Check failure on line 13 in src/cache.rs

View workflow job for this annotation

GitHub Actions / clippy

associated function `new` is never used
Self {}
}
}

impl ConfigCache for EmptyConfigCache {
fn read(&self, _: &str) -> Option<String> {
None
}
fn write(&self, _: &str, _: &str) {}
}
22 changes: 22 additions & 0 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use crate::options::{Options, OptionsBuilder, OptionsError};
use std::sync::Arc;

pub struct Client {

Check failure on line 4 in src/client.rs

View workflow job for this annotation

GitHub Actions / test

struct `Client` is never constructed

Check failure on line 4 in src/client.rs

View workflow job for this annotation

GitHub Actions / clippy

struct `Client` is never constructed
options: Arc<Options>,
}

impl Client {
pub fn from_builder(builder: OptionsBuilder) -> Result<Self, OptionsError> {

Check failure on line 9 in src/client.rs

View workflow job for this annotation

GitHub Actions / test

associated functions `from_builder` and `new` are never used

Check failure on line 9 in src/client.rs

View workflow job for this annotation

GitHub Actions / clippy

associated functions `from_builder` and `new` are never used
let result = builder.build();
match result {
Ok(opts) => Ok(Client::new(opts)),
Err(err) => Err(err),
}
}

pub fn new(options: Options) -> Self {
Self {
options: Arc::new(options),
}
}
}
15 changes: 15 additions & 0 deletions src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include!(concat!(env!("OUT_DIR"), "/built.rs"));

pub const SDK_KEY_PROXY_PREFIX: &str = "configcat-proxy/";

Check failure on line 3 in src/constants.rs

View workflow job for this annotation

GitHub Actions / test

constant `SDK_KEY_PROXY_PREFIX` is never used

Check failure on line 3 in src/constants.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `SDK_KEY_PROXY_PREFIX` is never used
pub const SDK_KEY_PREFIX: &str = "configcat-sdk-1";

Check failure on line 4 in src/constants.rs

View workflow job for this annotation

GitHub Actions / test

constant `SDK_KEY_PREFIX` is never used

Check failure on line 4 in src/constants.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `SDK_KEY_PREFIX` is never used
pub const CONFIG_FILE_NAME: &str = "config_v6.json";

Check failure on line 5 in src/constants.rs

View workflow job for this annotation

GitHub Actions / test

constant `CONFIG_FILE_NAME` is never used

Check failure on line 5 in src/constants.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `CONFIG_FILE_NAME` is never used
pub const SERIALIZATION_FORMAT_VERSION: &str = "v2";

Check failure on line 6 in src/constants.rs

View workflow job for this annotation

GitHub Actions / test

constant `SERIALIZATION_FORMAT_VERSION` is never used

Check failure on line 6 in src/constants.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `SERIALIZATION_FORMAT_VERSION` is never used
pub const SDK_KEY_SECTION_LENGTH: i64 = 22;

Check failure on line 7 in src/constants.rs

View workflow job for this annotation

GitHub Actions / test

constant `SDK_KEY_SECTION_LENGTH` is never used

Check failure on line 7 in src/constants.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `SDK_KEY_SECTION_LENGTH` is never used
pub const GLOBAL_CDN_URL: &str = "https://cdn-global.configcat.com";

Check failure on line 8 in src/constants.rs

View workflow job for this annotation

GitHub Actions / test

constant `GLOBAL_CDN_URL` is never used

Check failure on line 8 in src/constants.rs

View workflow job for this annotation

GitHub Actions / clippy

constant `GLOBAL_CDN_URL` is never used
pub const EU_CDN_URL: &str = "https://cdn-eu.configcat.com";

#[cfg(test)]
pub mod test_constants {
pub const MOCK_PATH: &str = "/configuration-files/key/config_v6.json";
pub const MOCK_KEY: &str = "key";
}
1 change: 1 addition & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 7606c74

Please sign in to comment.