Skip to content

Commit

Permalink
remove client fully from the config object
Browse files Browse the repository at this point in the history
  • Loading branch information
nkzou committed Mar 19, 2024
1 parent 16d4937 commit e473676
Show file tree
Hide file tree
Showing 83 changed files with 221 additions and 183 deletions.
8 changes: 4 additions & 4 deletions .generator/src/generator/templates/api.j2
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ impl {{ structName }} {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder = reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let middleware_client_builder = reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self {config,client}
Self {config, client}
}

pub fn with_client_and_config(config: configuration::Configuration,client: reqwest_middleware::ClientWithMiddleware) -> Self {
Self {config,client}
pub fn with_client_and_config(config: configuration::Configuration, client: reqwest_middleware::ClientWithMiddleware) -> Self {
Self {config, client}
}

{% for path, method, operation in operations|sort(attribute="2.operationId", case_sensitive=true) %}
Expand Down
11 changes: 0 additions & 11 deletions .generator/src/generator/templates/configuration.j2
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ pub struct APIKey {
#[derive(Debug, Clone)]
pub struct Configuration {
pub(crate) user_agent: String,
pub(crate) client: reqwest_middleware::ClientWithMiddleware,
pub(crate) unstable_operations: HashMap<String, bool>,
pub(crate) auth_keys: HashMap<String, APIKey>,
pub server_index: usize,
Expand All @@ -57,14 +56,6 @@ impl Configuration {
Self::default()
}

pub fn client(&mut self, client: reqwest_middleware::ClientWithMiddleware) {
self.client = client;
}

pub fn get_client(&self) -> &reqwest_middleware::ClientWithMiddleware {
&self.client
}

pub fn get_operation_host(&self, operation_str: &str) -> String {
let operation = operation_str.to_string();
if let Some(servers) = OPERATION_SERVERS.get(&operation) {
Expand Down Expand Up @@ -127,7 +118,6 @@ impl Configuration {

impl Default for Configuration {
fn default() -> Self {
let http_client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new());
let user_agent = format!(
"datadog-api-client-rust/{} (rust {}; os {}; arch {})",
option_env!("CARGO_PKG_VERSION").unwrap_or("?"),
Expand Down Expand Up @@ -167,7 +157,6 @@ impl Default for Configuration {

Self {
user_agent,
client: http_client.build(),
unstable_operations,
auth_keys,
server_index: 0,
Expand Down
5 changes: 4 additions & 1 deletion .generator/src/generator/templates/function_mappings.j2
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ pub fn initialize_api_instance(world: &mut DatadogWorld, api: String) {
{%- set structName = name.replace(" ", "")+"API" %}
"{{name.replace(" ", "")}}" => {
{%- for version in versions %}
world.api_instances.{{version}}_{{fieldName}} = Some(datadog{{ version.upper() }}::api::{{fieldName}}::{{structName}}::with_client_and_config(world.config.clone(),world.config.get_client().clone(),));
world.api_instances.{{version}}_{{fieldName}} = Some(datadog{{ version.upper() }}::api::{{fieldName}}::{{structName}}::with_client_and_config(
world.config.clone(),
world.http_client.as_ref().unwrap().clone()
));
{%- endfor %}
},
{%- endfor %}
Expand Down
11 changes: 0 additions & 11 deletions src/datadog/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ pub struct APIKey {
#[derive(Debug, Clone)]
pub struct Configuration {
pub(crate) user_agent: String,
pub(crate) client: reqwest_middleware::ClientWithMiddleware,
pub(crate) unstable_operations: HashMap<String, bool>,
pub(crate) auth_keys: HashMap<String, APIKey>,
pub server_index: usize,
Expand All @@ -59,14 +58,6 @@ impl Configuration {
Self::default()
}

pub fn client(&mut self, client: reqwest_middleware::ClientWithMiddleware) {
self.client = client;
}

pub fn get_client(&self) -> &reqwest_middleware::ClientWithMiddleware {
&self.client
}

pub fn get_operation_host(&self, operation_str: &str) -> String {
let operation = operation_str.to_string();
if let Some(servers) = OPERATION_SERVERS.get(&operation) {
Expand Down Expand Up @@ -130,7 +121,6 @@ impl Configuration {

impl Default for Configuration {
fn default() -> Self {
let http_client = reqwest_middleware::ClientBuilder::new(reqwest::Client::new());
let user_agent = format!(
"datadog-api-client-rust/{} (rust {}; os {}; arch {})",
option_env!("CARGO_PKG_VERSION").unwrap_or("?"),
Expand Down Expand Up @@ -200,7 +190,6 @@ impl Default for Configuration {

Self {
user_agent,
client: http_client.build(),
unstable_operations,
auth_keys,
server_index: 0,
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl AuthenticationAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_aws_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ impl AWSIntegrationAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_aws_logs_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl AWSLogsIntegrationAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_azure_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl AzureIntegrationAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_dashboard_lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl DashboardListsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_dashboards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl DashboardsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_downtimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl DowntimesAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ impl EventsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_gcp_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl GCPIntegrationAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ impl HostsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_ip_ranges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl IPRangesAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_key_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ impl KeyManagementAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_logs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl LogsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_logs_indexes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl LogsIndexesAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_logs_pipelines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ impl LogsPipelinesAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ impl MetricsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_monitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ impl MonitorsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_notebooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl NotebooksAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_organizations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl OrganizationsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_pager_duty_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ impl PagerDutyIntegrationAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_security_monitoring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl SecurityMonitoringAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_service_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl ServiceChecksAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl ServiceLevelObjectiveCorrectionsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_service_level_objectives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ impl ServiceLevelObjectivesAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_slack_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl SlackIntegrationAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl SnapshotsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_synthetics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ impl SyntheticsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl TagsAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_usage_metering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,7 @@ impl UsageMeteringAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_users.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl UsersAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV1/api/api_webhooks_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl WebhooksIntegrationAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
2 changes: 1 addition & 1 deletion src/datadogV2/api/api_apm_retention_filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl APMRetentionFiltersAPI {
reqwest_client_builder = reqwest_client_builder.proxy(proxy);
}

let mut middleware_client_builder =
let middleware_client_builder =
reqwest_middleware::ClientBuilder::new(reqwest_client_builder.build().unwrap());
let client = middleware_client_builder.build();
Self { config, client }
Expand Down
Loading

0 comments on commit e473676

Please sign in to comment.