azure-lite-rs 0.1.1

Lightweight HTTP client for Azure APIs
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
//! Types for the Azure Monitor API (v1).
//!
//! Auto-generated from the Azure ARM REST Specification.
//! **Do not edit manually** — modify the manifest and re-run codegen.

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Metric availability specifies the time grain.
///
/// **Azure API**: `monitor.v1.MetricAvailability`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricAvailability>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricAvailability {
    /// The time grain specifies the aggregation interval for the metric
    #[serde(skip_serializing_if = "Option::is_none")]
    pub time_grain: Option<String>,

    /// The retention period for the metric at the specified timegrain
    #[serde(skip_serializing_if = "Option::is_none")]
    pub retention: Option<String>,
}

impl MetricAvailability {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            time_grain: Some("test-time_grain".into()),
            retention: Some("test-retention".into()),
        }
    }
}

/// Metric definition class specifies the metadata for a metric.
///
/// **Azure API**: `monitor.v1.MetricDefinition`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricDefinition>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricDefinition {
    /// The resource identifier of the metric definition
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,

    /// The name and the display name of the metric
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

    /// The namespace the metric belongs to
    #[serde(skip_serializing_if = "Option::is_none")]
    pub namespace: Option<String>,

    /// The unit of the metric
    #[serde(skip_serializing_if = "Option::is_none")]
    pub unit: Option<String>,

    /// The primary aggregation type (None, Average, Count, Minimum, Maximum, Total)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub primary_aggregation_type: Option<String>,
}

impl MetricDefinition {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            id: Some("test-id".into()),
            name: Some("test-metric_definition".into()),
            namespace: Some("test-namespace".into()),
            unit: Some("test-unit".into()),
            primary_aggregation_type: Some("test-primary_aggregation_type".into()),
        }
    }
}

/// Represents collection of metric definitions.
///
/// **Azure API**: `monitor.v1.MetricDefinitionCollection`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricDefinitionCollection>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricDefinitionCollection {
    /// The values for the metric definitions
    #[serde(default)]
    pub value: Vec<MetricDefinition>,
}

impl MetricDefinitionCollection {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self { value: vec![] }
    }
}

/// Represents a metric value.
///
/// **Azure API**: `monitor.v1.MetricValue`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricValue>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricValue {
    /// The timestamp for the metric value
    pub time_stamp: String,

    /// The average value in the time range
    #[serde(skip_serializing_if = "Option::is_none")]
    pub average: Option<f64>,

    /// The minimum value in the time range
    #[serde(skip_serializing_if = "Option::is_none")]
    pub minimum: Option<f64>,

    /// The maximum value in the time range
    #[serde(skip_serializing_if = "Option::is_none")]
    pub maximum: Option<f64>,

    /// The sum of all values in the time range
    #[serde(skip_serializing_if = "Option::is_none")]
    pub total: Option<f64>,

    /// The number of samples in the time range
    #[serde(skip_serializing_if = "Option::is_none")]
    pub count: Option<f64>,
}

impl MetricValue {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            time_stamp: "test-time_stamp".into(),
            ..Default::default()
        }
    }
}

/// A time series result for a metric.
///
/// **Azure API**: `monitor.v1.TimeSeriesElement`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//TimeSeriesElement>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TimeSeriesElement {
    /// An array of data points representing the metric values
    #[serde(default)]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub data: Vec<MetricValue>,
}

impl TimeSeriesElement {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self { data: vec![] }
    }
}

/// The result data of a query.
///
/// **Azure API**: `monitor.v1.Metric`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//Metric>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct Metric {
    /// The metric Id
    pub id: String,

    /// The resource type of the metric resource
    #[serde(rename = "type")]
    pub r#type: String,

    /// The name and the display name of the metric
    pub name: String,

    /// The unit of the metric
    pub unit: String,

    /// The time series returned when a data query is performed
    #[serde(default)]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub timeseries: Vec<TimeSeriesElement>,
}

impl Metric {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            id: "test-id".into(),
            r#type: "test-type".into(),
            name: "test-metric".into(),
            unit: "test-unit".into(),
            timeseries: vec![],
        }
    }
}

/// The response to a metrics query.
///
/// **Azure API**: `monitor.v1.MetricsResponse`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricsResponse>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricsResponse {
    /// The value of the collection
    #[serde(default)]
    pub value: Vec<Metric>,

    /// The integer value representing the relative cost of the query
    #[serde(skip_serializing_if = "Option::is_none")]
    pub cost: Option<i32>,

    /// The timespan for which the data was retrieved
    #[serde(skip_serializing_if = "Option::is_none")]
    pub timespan: Option<String>,

    /// The interval (window size) for which the metric data was returned
    #[serde(skip_serializing_if = "Option::is_none")]
    pub interval: Option<String>,

    /// The namespace of the metrics been queried
    #[serde(skip_serializing_if = "Option::is_none")]
    pub namespace: Option<String>,
}

impl MetricsResponse {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            value: vec![],
            cost: Some(100),
            timespan: Some("test-timespan".into()),
            interval: Some("test-interval".into()),
            namespace: Some("test-namespace".into()),
        }
    }
}

/// An alert rule.
///
/// **Azure API**: `monitor.v1.MetricAlertProperties`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricAlertProperties>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricAlertProperties {
    /// The description of the alert rule
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,

    /// Alert severity (0-4, where 0 is critical)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub severity: Option<i32>,

    /// Whether the alert rule is enabled
    #[serde(skip_serializing_if = "Option::is_none")]
    pub enabled: Option<bool>,

    /// How often the alert rule is evaluated in ISO 8601 duration format
    #[serde(skip_serializing_if = "Option::is_none")]
    pub evaluation_frequency: Option<String>,

    /// The period of time in ISO 8601 duration format used to monitor alert activity
    #[serde(skip_serializing_if = "Option::is_none")]
    pub window_size: Option<String>,

    /// The provisioning state
    #[serde(skip_serializing_if = "Option::is_none")]
    pub provisioning_state: Option<String>,

    /// The resource type of the target resource(s) on which the alert is created/updated
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_resource_type: Option<String>,

    /// The region of the target resource(s) on which the alert is created/updated
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_resource_region: Option<String>,
}

impl MetricAlertProperties {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            description: Some("test-description".into()),
            severity: Some(100),
            enabled: Some(false),
            evaluation_frequency: Some("test-evaluation_frequency".into()),
            window_size: Some("test-window_size".into()),
            provisioning_state: Some("test-provisioning_state".into()),
            target_resource_type: Some("test-target_resource_type".into()),
            target_resource_region: Some("test-target_resource_region".into()),
        }
    }
}

/// The metric alert resource.
///
/// **Azure API**: `monitor.v1.MetricAlertResource`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricAlertResource>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricAlertResource {
    /// Azure resource Id
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,

    /// Azure resource name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub name: Option<String>,

    /// Azure resource type
    #[serde(rename = "type")]
    #[serde(skip_serializing_if = "Option::is_none")]
    pub r#type: Option<String>,

    /// Resource location
    pub location: String,

    /// Resource tags
    #[serde(default)]
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub tags: HashMap<String, String>,

    /// The alert rule properties
    #[serde(skip_serializing_if = "Option::is_none")]
    pub properties: Option<MetricAlertProperties>,
}

impl MetricAlertResource {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            id: Some("test-id".into()),
            name: Some("test-metric_alert_resource".into()),
            r#type: Some("test-type".into()),
            location: "test-location".into(),
            tags: Default::default(),
            properties: Some(MetricAlertProperties::fixture()),
        }
    }
}

/// Represents a collection of alert rule resources.
///
/// **Azure API**: `monitor.v1.MetricAlertResourceCollection`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricAlertResourceCollection>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricAlertResourceCollection {
    /// The values for the alert rule resources
    #[serde(default)]
    #[serde(skip_serializing_if = "Vec::is_empty")]
    pub value: Vec<MetricAlertResource>,
}

impl MetricAlertResourceCollection {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self { value: vec![] }
    }
}

/// The metric alert resource for patch operations.
///
/// **Azure API**: `monitor.v1.MetricAlertResourcePatch`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricAlertResourcePatch>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricAlertResourcePatch {
    /// Resource tags
    #[serde(default)]
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub tags: HashMap<String, String>,

    /// The alert rule properties for an update operation
    #[serde(skip_serializing_if = "Option::is_none")]
    pub properties: Option<MetricAlertProperties>,
}

impl MetricAlertResourcePatch {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            tags: Default::default(),
            properties: Some(MetricAlertProperties::fixture()),
        }
    }
}

/// The metric alert resource.
///
/// **Azure API**: `monitor.v1.MetricAlertCreateRequest`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//MetricAlertCreateRequest>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct MetricAlertCreateRequest {
    /// Resource location
    pub location: String,

    /// Resource tags
    #[serde(default)]
    #[serde(skip_serializing_if = "HashMap::is_empty")]
    pub tags: HashMap<String, String>,

    /// The alert rule properties of the resource
    #[serde(skip_serializing_if = "Option::is_none")]
    pub properties: Option<MetricAlertProperties>,
}

impl MetricAlertCreateRequest {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            location: "test-location".into(),
            tags: Default::default(),
            properties: Some(MetricAlertProperties::fixture()),
        }
    }
}

/// The Azure event log entries are of type EventData.
///
/// **Azure API**: `monitor.v1.EventData`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//EventData>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EventData {
    /// The Id of this event as required by ARM for RBAC
    #[serde(skip_serializing_if = "Option::is_none")]
    pub id: Option<String>,

    /// The timestamp of when the event was generated by the Azure service
    #[serde(skip_serializing_if = "Option::is_none")]
    pub event_timestamp: Option<String>,

    /// The operation name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub operation_name: Option<String>,

    /// The Resource Group name
    #[serde(skip_serializing_if = "Option::is_none")]
    pub resource_group_name: Option<String>,

    /// The resource type
    #[serde(skip_serializing_if = "Option::is_none")]
    pub resource_type: Option<String>,

    /// The resource URI that has generated the event
    #[serde(skip_serializing_if = "Option::is_none")]
    pub resource_id: Option<String>,

    /// A string describing the status of the operation
    #[serde(skip_serializing_if = "Option::is_none")]
    pub status: Option<String>,

    /// The event sub status
    #[serde(skip_serializing_if = "Option::is_none")]
    pub sub_status: Option<String>,

    /// The event level (Critical, Error, Warning, Informational, Verbose)
    #[serde(skip_serializing_if = "Option::is_none")]
    pub level: Option<String>,

    /// The email address of the user who performed the operation
    #[serde(skip_serializing_if = "Option::is_none")]
    pub caller: Option<String>,

    /// The description of the event
    #[serde(skip_serializing_if = "Option::is_none")]
    pub description: Option<String>,
}

impl EventData {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            id: Some("test-id".into()),
            event_timestamp: Some("test-event_timestamp".into()),
            operation_name: Some("test-operation_name".into()),
            resource_group_name: Some("test-resource_group_name".into()),
            resource_type: Some("test-resource_type".into()),
            resource_id: Some("test-resource_id".into()),
            status: Some("test-status".into()),
            sub_status: Some("test-sub_status".into()),
            level: Some("test-level".into()),
            caller: Some("test-caller".into()),
            description: Some("test-description".into()),
        }
    }
}

/// Represents collection of events.
///
/// **Azure API**: `monitor.v1.EventDataCollection`
/// **Reference**: <https://learn.microsoft.com/en-us/rest/api/monitor//EventDataCollection>
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct EventDataCollection {
    /// This lists the events
    #[serde(default)]
    pub value: Vec<EventData>,

    /// Provides the link to retrieve the next set of events
    #[serde(skip_serializing_if = "Option::is_none")]
    pub next_link: Option<String>,
}

impl EventDataCollection {
    #[cfg(any(test, feature = "test-support"))]
    /// Create a fixture instance for testing.
    pub fn fixture() -> Self {
        Self {
            value: vec![],
            next_link: Some("test-next_link".into()),
        }
    }
}