Skip to content

Commit 10e48f6

Browse files
authored
use TokenCredential in services (#59)
* use TokenCredential in services * azure_core::errors::AzureError * code gen * update examples * merged in nested-types & multi-value query params * overwrite conflicts
1 parent 64a118f commit 10e48f6

File tree

1,446 files changed

+367951
-36516
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,446 files changed

+367951
-36516
lines changed

sdk/core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async-trait = "0.1.36"
3434
oauth2 = { version = "4.0.0-alpha.2" }
3535

3636
[dev-dependencies]
37-
tokio = "0.3"
37+
tokio = "0.2"
3838
env_logger = "0.8"
3939

4040
[features]

services/mgmt/addons/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ version = "0.1.0"
55
edition = "2018"
66

77
[dependencies]
8+
azure_core = { path = "../../../sdk/core", version = "0.1.0" }
89
serde = { version = "1.0", features = ["derive"] }
910
serde_json = "1.0"
1011
reqwest = { version = "0.10", features = ["json"] }
1112
bytes = "0.5"
1213
snafu = "0.6"
1314

1415
[dev-dependencies]
16+
azure_identity = { path = "../../../sdk/identity", version = "0.1.0" }
1517
tokio = { version = "0.2", features = ["macros"] }
1618

1719
[features]

services/mgmt/addons/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@ pub struct OperationConfig {
1111
pub api_version: String,
1212
pub client: reqwest::Client,
1313
pub base_path: String,
14-
pub bearer_access_token: Option<String>,
14+
pub token_credential: Option<Box<dyn azure_core::TokenCredential>>,
15+
pub token_credential_resource: String,
1516
}
1617
impl OperationConfig {
17-
pub fn new(bearer_access_token: &str) -> Self {
18+
pub fn new(token_credential: Box<dyn azure_core::TokenCredential>) -> Self {
1819
Self {
19-
bearer_access_token: Some(bearer_access_token.to_owned()),
20+
token_credential: Some(token_credential),
2021
..Default::default()
2122
}
2223
}
@@ -27,7 +28,8 @@ impl Default for OperationConfig {
2728
api_version: API_VERSION.to_owned(),
2829
client: reqwest::Client::new(),
2930
base_path: "https://management.azure.com".to_owned(),
30-
bearer_access_token: None,
31+
token_credential: None,
32+
token_credential_resource: "https://management.azure.com/".to_owned(),
3133
}
3234
}
3335
}

services/mgmt/addons/src/package_2017_05/models.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct CanonicalSupportPlanProperties {
77
#[serde(rename = "provisioningState", skip_serializing_if = "Option::is_none")]
88
pub provisioning_state: Option<canonical_support_plan_properties::ProvisioningState>,
99
}
10-
mod canonical_support_plan_properties {
10+
pub mod canonical_support_plan_properties {
1111
use super::*;
1212
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1313
pub enum ProvisioningState {

services/mgmt/addons/src/package_2017_05/operations.rs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ pub mod operations {
1313
let client = &operation_config.client;
1414
let uri_str = &format!("{}/providers/Microsoft.Addons/operations", &operation_config.base_path,);
1515
let mut req_builder = client.get(uri_str);
16-
if let Some(token) = &operation_config.bearer_access_token {
17-
req_builder = req_builder.bearer_auth(token);
16+
if let Some(token_credential) = &operation_config.token_credential {
17+
let token_response = token_credential
18+
.get_token(&operation_config.token_credential_resource)
19+
.await
20+
.context(list::GetTokenError)?;
21+
req_builder = req_builder.bearer_auth(token_response.token.secret());
1822
}
1923
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
2024
let req = req_builder.build().context(list::BuildRequestError)?;
@@ -60,6 +64,9 @@ pub mod operations {
6064
source: serde_json::Error,
6165
body: bytes::Bytes,
6266
},
67+
GetTokenError {
68+
source: azure_core::errors::AzureError,
69+
},
6370
}
6471
}
6572
}
@@ -79,8 +86,12 @@ pub mod support_plan_types {
7986
&operation_config.base_path, subscription_id, provider_name, plan_type_name
8087
);
8188
let mut req_builder = client.get(uri_str);
82-
if let Some(token) = &operation_config.bearer_access_token {
83-
req_builder = req_builder.bearer_auth(token);
89+
if let Some(token_credential) = &operation_config.token_credential {
90+
let token_response = token_credential
91+
.get_token(&operation_config.token_credential_resource)
92+
.await
93+
.context(get::GetTokenError)?;
94+
req_builder = req_builder.bearer_auth(token_response.token.secret());
8495
}
8596
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
8697
let req = req_builder.build().context(get::BuildRequestError)?;
@@ -129,6 +140,9 @@ pub mod support_plan_types {
129140
source: serde_json::Error,
130141
body: bytes::Bytes,
131142
},
143+
GetTokenError {
144+
source: azure_core::errors::AzureError,
145+
},
132146
}
133147
}
134148
pub async fn create_or_update(
@@ -143,8 +157,12 @@ pub mod support_plan_types {
143157
&operation_config.base_path, subscription_id, provider_name, plan_type_name
144158
);
145159
let mut req_builder = client.put(uri_str);
146-
if let Some(token) = &operation_config.bearer_access_token {
147-
req_builder = req_builder.bearer_auth(token);
160+
if let Some(token_credential) = &operation_config.token_credential {
161+
let token_response = token_credential
162+
.get_token(&operation_config.token_credential_resource)
163+
.await
164+
.context(create_or_update::GetTokenError)?;
165+
req_builder = req_builder.bearer_auth(token_response.token.secret());
148166
}
149167
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
150168
let req = req_builder.build().context(create_or_update::BuildRequestError)?;
@@ -204,6 +222,9 @@ pub mod support_plan_types {
204222
source: serde_json::Error,
205223
body: bytes::Bytes,
206224
},
225+
GetTokenError {
226+
source: azure_core::errors::AzureError,
227+
},
207228
}
208229
}
209230
pub async fn delete(
@@ -218,8 +239,12 @@ pub mod support_plan_types {
218239
&operation_config.base_path, subscription_id, provider_name, plan_type_name
219240
);
220241
let mut req_builder = client.delete(uri_str);
221-
if let Some(token) = &operation_config.bearer_access_token {
222-
req_builder = req_builder.bearer_auth(token);
242+
if let Some(token_credential) = &operation_config.token_credential {
243+
let token_response = token_credential
244+
.get_token(&operation_config.token_credential_resource)
245+
.await
246+
.context(delete::GetTokenError)?;
247+
req_builder = req_builder.bearer_auth(token_response.token.secret());
223248
}
224249
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
225250
let req = req_builder.build().context(delete::BuildRequestError)?;
@@ -272,6 +297,9 @@ pub mod support_plan_types {
272297
source: serde_json::Error,
273298
body: bytes::Bytes,
274299
},
300+
GetTokenError {
301+
source: azure_core::errors::AzureError,
302+
},
275303
}
276304
}
277305
}
@@ -290,8 +318,12 @@ pub mod canonical_support_plan_types {
290318
&operation_config.base_path, subscription_id, provider_name
291319
);
292320
let mut req_builder = client.get(uri_str);
293-
if let Some(token) = &operation_config.bearer_access_token {
294-
req_builder = req_builder.bearer_auth(token);
321+
if let Some(token_credential) = &operation_config.token_credential {
322+
let token_response = token_credential
323+
.get_token(&operation_config.token_credential_resource)
324+
.await
325+
.context(get::GetTokenError)?;
326+
req_builder = req_builder.bearer_auth(token_response.token.secret());
295327
}
296328
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
297329
let req = req_builder.build().context(get::BuildRequestError)?;
@@ -337,6 +369,9 @@ pub mod canonical_support_plan_types {
337369
source: serde_json::Error,
338370
body: bytes::Bytes,
339371
},
372+
GetTokenError {
373+
source: azure_core::errors::AzureError,
374+
},
340375
}
341376
}
342377
}

services/mgmt/addons/src/package_2018_03/models.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub struct CanonicalSupportPlanProperties {
77
#[serde(rename = "provisioningState", skip_serializing_if = "Option::is_none")]
88
pub provisioning_state: Option<canonical_support_plan_properties::ProvisioningState>,
99
}
10-
mod canonical_support_plan_properties {
10+
pub mod canonical_support_plan_properties {
1111
use super::*;
1212
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
1313
pub enum ProvisioningState {
@@ -40,7 +40,7 @@ pub struct CanonicalSupportPlanInfoDefinition {
4040
#[serde(rename = "oneTimeCharge", skip_serializing_if = "Option::is_none")]
4141
pub one_time_charge: Option<canonical_support_plan_info_definition::OneTimeCharge>,
4242
}
43-
mod canonical_support_plan_info_definition {
43+
pub mod canonical_support_plan_info_definition {
4444
use super::*;
4545
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
4646
pub enum SupportPlanType {

services/mgmt/addons/src/package_2018_03/operations.rs

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,12 @@ pub mod operations {
1313
let client = &operation_config.client;
1414
let uri_str = &format!("{}/providers/Microsoft.Addons/operations", &operation_config.base_path,);
1515
let mut req_builder = client.get(uri_str);
16-
if let Some(token) = &operation_config.bearer_access_token {
17-
req_builder = req_builder.bearer_auth(token);
16+
if let Some(token_credential) = &operation_config.token_credential {
17+
let token_response = token_credential
18+
.get_token(&operation_config.token_credential_resource)
19+
.await
20+
.context(list::GetTokenError)?;
21+
req_builder = req_builder.bearer_auth(token_response.token.secret());
1822
}
1923
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
2024
let req = req_builder.build().context(list::BuildRequestError)?;
@@ -60,6 +64,9 @@ pub mod operations {
6064
source: serde_json::Error,
6165
body: bytes::Bytes,
6266
},
67+
GetTokenError {
68+
source: azure_core::errors::AzureError,
69+
},
6370
}
6471
}
6572
}
@@ -79,8 +86,12 @@ pub mod support_plan_types {
7986
&operation_config.base_path, subscription_id, provider_name, plan_type_name
8087
);
8188
let mut req_builder = client.get(uri_str);
82-
if let Some(token) = &operation_config.bearer_access_token {
83-
req_builder = req_builder.bearer_auth(token);
89+
if let Some(token_credential) = &operation_config.token_credential {
90+
let token_response = token_credential
91+
.get_token(&operation_config.token_credential_resource)
92+
.await
93+
.context(get::GetTokenError)?;
94+
req_builder = req_builder.bearer_auth(token_response.token.secret());
8495
}
8596
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
8697
let req = req_builder.build().context(get::BuildRequestError)?;
@@ -129,6 +140,9 @@ pub mod support_plan_types {
129140
source: serde_json::Error,
130141
body: bytes::Bytes,
131142
},
143+
GetTokenError {
144+
source: azure_core::errors::AzureError,
145+
},
132146
}
133147
}
134148
pub async fn create_or_update(
@@ -143,8 +157,12 @@ pub mod support_plan_types {
143157
&operation_config.base_path, subscription_id, provider_name, plan_type_name
144158
);
145159
let mut req_builder = client.put(uri_str);
146-
if let Some(token) = &operation_config.bearer_access_token {
147-
req_builder = req_builder.bearer_auth(token);
160+
if let Some(token_credential) = &operation_config.token_credential {
161+
let token_response = token_credential
162+
.get_token(&operation_config.token_credential_resource)
163+
.await
164+
.context(create_or_update::GetTokenError)?;
165+
req_builder = req_builder.bearer_auth(token_response.token.secret());
148166
}
149167
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
150168
let req = req_builder.build().context(create_or_update::BuildRequestError)?;
@@ -204,6 +222,9 @@ pub mod support_plan_types {
204222
source: serde_json::Error,
205223
body: bytes::Bytes,
206224
},
225+
GetTokenError {
226+
source: azure_core::errors::AzureError,
227+
},
207228
}
208229
}
209230
pub async fn delete(
@@ -218,8 +239,12 @@ pub mod support_plan_types {
218239
&operation_config.base_path, subscription_id, provider_name, plan_type_name
219240
);
220241
let mut req_builder = client.delete(uri_str);
221-
if let Some(token) = &operation_config.bearer_access_token {
222-
req_builder = req_builder.bearer_auth(token);
242+
if let Some(token_credential) = &operation_config.token_credential {
243+
let token_response = token_credential
244+
.get_token(&operation_config.token_credential_resource)
245+
.await
246+
.context(delete::GetTokenError)?;
247+
req_builder = req_builder.bearer_auth(token_response.token.secret());
223248
}
224249
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
225250
let req = req_builder.build().context(delete::BuildRequestError)?;
@@ -272,6 +297,9 @@ pub mod support_plan_types {
272297
source: serde_json::Error,
273298
body: bytes::Bytes,
274299
},
300+
GetTokenError {
301+
source: azure_core::errors::AzureError,
302+
},
275303
}
276304
}
277305
pub async fn list_info(
@@ -284,8 +312,12 @@ pub mod support_plan_types {
284312
&operation_config.base_path, subscription_id
285313
);
286314
let mut req_builder = client.post(uri_str);
287-
if let Some(token) = &operation_config.bearer_access_token {
288-
req_builder = req_builder.bearer_auth(token);
315+
if let Some(token_credential) = &operation_config.token_credential {
316+
let token_response = token_credential
317+
.get_token(&operation_config.token_credential_resource)
318+
.await
319+
.context(list_info::GetTokenError)?;
320+
req_builder = req_builder.bearer_auth(token_response.token.secret());
289321
}
290322
req_builder = req_builder.query(&[("api-version", &operation_config.api_version)]);
291323
let req = req_builder.build().context(list_info::BuildRequestError)?;
@@ -333,6 +365,9 @@ pub mod support_plan_types {
333365
source: serde_json::Error,
334366
body: bytes::Bytes,
335367
},
368+
GetTokenError {
369+
source: azure_core::errors::AzureError,
370+
},
336371
}
337372
}
338373
}

services/mgmt/adp/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ version = "0.1.0"
55
edition = "2018"
66

77
[dependencies]
8+
azure_core = { path = "../../../sdk/core", version = "0.1.0" }
89
serde = { version = "1.0", features = ["derive"] }
910
serde_json = "1.0"
1011
reqwest = { version = "0.10", features = ["json"] }
1112
bytes = "0.5"
1213
snafu = "0.6"
1314

1415
[dev-dependencies]
16+
azure_identity = { path = "../../../sdk/identity", version = "0.1.0" }
1517
tokio = { version = "0.2", features = ["macros"] }
1618

1719
[features]

services/mgmt/adp/src/lib.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ pub struct OperationConfig {
77
pub api_version: String,
88
pub client: reqwest::Client,
99
pub base_path: String,
10-
pub bearer_access_token: Option<String>,
10+
pub token_credential: Option<Box<dyn azure_core::TokenCredential>>,
11+
pub token_credential_resource: String,
1112
}
1213
impl OperationConfig {
13-
pub fn new(bearer_access_token: &str) -> Self {
14+
pub fn new(token_credential: Box<dyn azure_core::TokenCredential>) -> Self {
1415
Self {
15-
bearer_access_token: Some(bearer_access_token.to_owned()),
16+
token_credential: Some(token_credential),
1617
..Default::default()
1718
}
1819
}
@@ -23,7 +24,8 @@ impl Default for OperationConfig {
2324
api_version: API_VERSION.to_owned(),
2425
client: reqwest::Client::new(),
2526
base_path: "https://management.azure.com".to_owned(),
26-
bearer_access_token: None,
27+
token_credential: None,
28+
token_credential_resource: "https://management.azure.com/".to_owned(),
2729
}
2830
}
2931
}

services/mgmt/adp/src/package_2020_07_01_preview/models.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ pub struct AccountProperties {
3030
#[serde(rename = "provisioningState", skip_serializing)]
3131
pub provisioning_state: Option<account_properties::ProvisioningState>,
3232
}
33-
mod account_properties {
33+
pub mod account_properties {
3434
use super::*;
3535
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
3636
pub enum ProvisioningState {
@@ -72,7 +72,7 @@ pub struct DataPoolBaseProperties {
7272
#[serde(skip_serializing_if = "Vec::is_empty")]
7373
pub locations: Vec<DataPoolLocation>,
7474
}
75-
mod data_pool_base_properties {
75+
pub mod data_pool_base_properties {
7676
use super::*;
7777
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
7878
pub enum ProvisioningState {
@@ -209,7 +209,7 @@ pub struct SystemData {
209209
#[serde(rename = "lastModifiedAt", skip_serializing_if = "Option::is_none")]
210210
pub last_modified_at: Option<String>,
211211
}
212-
mod system_data {
212+
pub mod system_data {
213213
use super::*;
214214
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
215215
pub enum CreatedByType {

0 commit comments

Comments
 (0)