Skip to content

Commit

Permalink
Also enable environment used
Browse files Browse the repository at this point in the history
  • Loading branch information
chriswk committed Jun 29, 2023
1 parent 76dc805 commit 6c335a3
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 32 deletions.
109 changes: 85 additions & 24 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
name = "datagenerator"
version = "0.1.0"
edition = "2021"
description = "Generates features and strategies for https://github.com/Unleash/unleash"
authors = ["Christopher Kolstad <chriswk@getunleash.io>"]
license = "MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
clap = { version = "4.3.5", features = ["env", "derive"] }
clap = { version = "4.3.8", features = ["env", "derive"] }
rand = "0.8.5"
regex = "1.8.4"
reqwest = { version = "0.11.18", features = ["json"] }
serde = { version = "1.0.164", features = ["derive"] }
serde_json = "1.0.97"
tokio = { version = "1.28.2", features = ["rt", "macros", "rt-multi-thread"] }
serde_json = "1.0.99"
tokio = { version = "1.29.0", features = ["rt", "macros", "rt-multi-thread"] }
ulid = "1.0.0"
7 changes: 7 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2023 Christopher Kolstad

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 changes: 25 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,18 @@ fn strategies_url(features_url: &Url, feature_name: &str, env: &str) -> Url {
update_url
}

fn environment_enable_url(features_url: &Url, feature_name: &str, env: &str) -> Url {
let mut enable_url = features_url.clone();
enable_url
.path_segments_mut()
.expect("Could not modify environment-enable URL")
.push(feature_name)
.push("environments")
.push(env)
.push("on");
enable_url
}

async fn post_data_to(
url: String,
api_key: String,
Expand All @@ -174,22 +186,30 @@ async fn post_data_to(
.send()
.await
.expect("Failed to send feature");
}
for (feature_name, strategies) in feature_strategies {
let update_url = strategies_url(&feature_url, &feature_name, &environment);
let strategies_url = strategies_url(&feature_url, &feature.name, &environment);
let strategies = feature_strategies
.get(&feature.name)
.expect("Somehow lost a feature");
println!(
"Posting {} strategies to {}",
strategies.len(),
update_url.clone()
strategies_url.clone()
);
for strategy in strategies {
client
.post(update_url.clone())
.post(strategies_url.clone())
.json(&strategy)
.send()
.await
.expect("Failed to send strategy");
}
let enable_url = environment_enable_url(&feature_url, &feature.name, &environment);
println!("Enabling {} environment for {}", environment, feature.name);
client
.post(enable_url)
.send()
.await
.expect("Failed to enable environment");
}
}

Expand Down

0 comments on commit 6c335a3

Please sign in to comment.