Skip to content

Commit

Permalink
feat: make _filter tags_ optional in the API routes.
Browse files Browse the repository at this point in the history
demeringo committed Jan 12, 2024
1 parent f757acd commit 36bfbcb
Showing 2 changed files with 12 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -13,6 +13,8 @@ _This paragraph may describe WIP/unreleased features. They are merged to main br

### Changed

- Make _filter tags_ optional in the API routes.

## [2.0.0]-2024-01-10

### Added
20 changes: 10 additions & 10 deletions cloud-scanner-cli/src/standalone_server.rs
Original file line number Diff line number Diff line change
@@ -38,17 +38,17 @@ fn index(config: &State<Config>) -> String {

/// # Returns Prometheus metrics.
///
/// Region is mandatory, filter_tags can be an empty string ("").
/// Region is mandatory. Filter_tags (if any) should be written as string containing tag_name=tag_value
///
/// Results are estimated for one hour of use by default.
/// Results are estimated for one hour of use by default.
///
/// Example query: http://localhost:8000/metrics?aws_region=eu-west-3&filter_tag=Name=boatest&filter_tag=OtherTag=other-value&use_duration_hours=1.0&include_storage=true
#[openapi(tag = "metrics")]
#[get("/metrics?<aws_region>&<filter_tags>&<use_duration_hours>&<include_block_storage>")]
async fn metrics(
config: &State<Config>,
aws_region: &str,
filter_tags: Vec<String>,
filter_tags: Option<Vec<String>>,
use_duration_hours: Option<f32>,
include_block_storage: Option<bool>,
) -> String {
@@ -57,7 +57,7 @@ async fn metrics(
warn!("Filtering on tags {:?}", filter_tags);
let metrics = crate::get_default_impacts_as_metrics(
&hours_use_time,
&filter_tags,
&filter_tags.unwrap_or_default(),
aws_region,
&config.boavizta_url,
include_block_storage.unwrap_or(false),
@@ -68,22 +68,22 @@ async fn metrics(

/// # Returns the inventory as json.
///
/// Region is mandatory, filter_tags can be an empty string ("").
/// Region is mandatory. Filter_tags (if any) should be written as string containing tag_name=tag_value
///
/// Example query: http://localhost:8000/inventorynew?aws_region=eu-west-3&filter_tag=Name=boatest&filter_tag=OtherTag=other-value
#[openapi(tag = "inventory")]
#[get("/inventory?<aws_region>&<filter_tags>&<include_block_storage>")]
async fn inventory(
_config: &State<Config>,
aws_region: &str,
filter_tags: Vec<String>,
filter_tags: Option<Vec<String>>,
include_block_storage: Option<bool>,
) -> Json<Inventory> {
warn!("Getting something on /inventory");
warn!("Filtering on tags {:?}", filter_tags);
Json(
crate::get_inventory(
&filter_tags,
&filter_tags.unwrap_or_default(),
aws_region,
include_block_storage.unwrap_or(false),
)
@@ -94,7 +94,7 @@ async fn inventory(

/// # Returns the impacts (use and embedded) as json.
///
/// Region is mandatory, filter_tags can be an empty string ("").
/// Region is mandatory. Filter_tags (if any) should be written as string containing tag_name=tag_value
///
/// Example query: http://localhost:8000/impacts?aws_region=eu-west-3&filter_tag=Name=boatest&filter_tag=OtherTag=other-value&use_duration_hours=1.0
#[openapi(tag = "impacts")]
@@ -104,7 +104,7 @@ async fn inventory(
async fn impacts(
_config: &State<Config>,
aws_region: &str,
filter_tags: Vec<String>,
filter_tags: Option<Vec<String>>,
use_duration_hours: Option<f32>,
verbose_output: Option<bool>,
include_block_storage: Option<bool>,
@@ -118,7 +118,7 @@ async fn impacts(
warn!("Filtering on tags {:?}", filter_tags);
let res = crate::standard_scan(
&hours_use_time,
&filter_tags,
&filter_tags.unwrap_or_default(),
aws_region,
&_config.boavizta_url,
verbose_output.unwrap_or(false),

0 comments on commit 36bfbcb

Please sign in to comment.