nazara 0.2.0

A CLI application to create and update machines and VMs in NetBox.
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
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
//! # API Client Module
//!
//! This module's single responsibility is to take the payloads from the
//! [`publisher`](crate::publisher) module - which it created using the
//! [`translator`](crate::publisher::translator) module - and execute the individual API requests.
//!
//! Errors are escalated upwards.
extern crate thanix_client;

use crate::error::*;

use serde_json::Value;
use thanix_client::{
    paths::{
        DcimDevicesCreateResponse, DcimDevicesListQuery, DcimDevicesListResponse,
        DcimDevicesPartialUpdateResponse, DcimInterfacesCreateResponse, DcimInterfacesListQuery,
        DcimInterfacesListResponse, DcimInterfacesUpdateResponse, DcimMacAddressesListQuery,
        DcimMacAddressesListResponse, DcimMacAddressesUpdateResponse,
        IpamIpAddressesCreateResponse, IpamIpAddressesListQuery, IpamIpAddressesListResponse,
        IpamIpAddressesPartialUpdateResponse, VirtualizationInterfacesCreateResponse,
        VirtualizationInterfacesListQuery, VirtualizationInterfacesListResponse,
        VirtualizationInterfacesUpdateResponse, VirtualizationVirtualMachinesCreateResponse,
        VirtualizationVirtualMachinesListQuery, VirtualizationVirtualMachinesListResponse,
        VirtualizationVirtualMachinesPartialUpdateResponse, dcim_devices_create, dcim_devices_list,
        dcim_devices_partial_update, dcim_interfaces_create, dcim_interfaces_list,
        dcim_interfaces_update, dcim_mac_addresses_create, dcim_mac_addresses_list,
        dcim_mac_addresses_update, ipam_ip_addresses_create, ipam_ip_addresses_list,
        ipam_ip_addresses_partial_update, virtualization_interfaces_create,
        virtualization_interfaces_list, virtualization_interfaces_update,
        virtualization_virtual_machines_create, virtualization_virtual_machines_list,
        virtualization_virtual_machines_partial_update,
    },
    types::{
        Interface, MACAddressRequest, PatchedWritableDeviceWithConfigContextRequest,
        PatchedWritableIPAddressRequest, PatchedWritableVirtualMachineWithConfigContextRequest,
        WritableDeviceWithConfigContextRequest, WritableIPAddressRequest, WritableInterfaceRequest,
        WritableVMInterfaceRequest, WritableVirtualMachineWithConfigContextRequest,
    },
    util::ThanixClient,
};

/// Tests the connection to the NetBox API and verifies if your [`thanix_client`] version is compatible
/// with your NetBox version.
///
///	# Parameters
/// - `client`: The client instance to be used for communication.
///
/// # Returns
/// `Ok(())` if the connection to the API is successful and the [`thanix_client`] version is
/// compatible with the used NetBox version.
/// Otherwise an `Err` with [`NazaraError::NetBoxApiError`] if the connection fails or the
/// [`thanix_client`] version is not compatible with your NetBox version.
pub fn test_connection(client: &ThanixClient) -> Result<(), NazaraError> {
    let url: String = format!("{}/api/status/", client.base_url);

    let response = client
        .client
        .get(&url)
        .header(
            "Authorization",
            format!("Token {}", client.authentication_token),
        )
        .send()?;

    success!("Got response!");
    let json: Value = response.json::<Value>()?;

    if let Some(netbox_ver) = json.get("netbox-version").and_then(Value::as_str) {
        // Compare netbox version for compatibility
        if check_version_compatiblity(netbox_ver, thanix_client::version::VERSION) {
            info!("API client version compatible with NetBox version.");
            Ok(())
        } else {
            Err(NazaraError::VersionMismatch)
        }
    } else {
        Err(NazaraError::MissingVersion)
    }
}

/// Compares the NetBox version with the thanix_client version for compatibility.
///
/// Given the drastic differences in NetBox's API between `v3.x` and `v4.x` there are two different
/// release tracks for these two versions.
///
/// Version `v1.x` is compatible for NetBox Version `v3.6.x` and above, while `thanix_client`
/// version `v2.x` will be compatible with NetBox version `v4.x` and above.
///
/// # Parameters
/// - `netbox_version`: The version of the NetBox instance extracted from the response.
/// - `thanix_version`: The version of the installed `thanix_client` dependency.
fn check_version_compatiblity(netbox_version: &str, thanix_version: &str) -> bool {
    status!("Checking API client compatibility with used NetBox version...");
    let netbox_major = get_major_verison(netbox_version);
    let thanix_major = get_major_verison(thanix_version);

    match netbox_major {
        Some(3) => thanix_major == Some(1),
        Some(4) => thanix_major == Some(2),
        _ => false, // Unsupported version
    }
}

/// Gets the major version from the given version String.
///
/// # Parameters
/// - `version`: String representation of the application version.
///
/// # Returns
/// `Some(u32)` if the version can be parsed to an `u32`.
fn get_major_verison(version: &str) -> Option<u32> {
    version.split('.').next()?.parse().ok()
}

/// Search a device by sending a `DcimDevicesListQuery` with given search parameters.
/// Returns the ID of the device if it exists.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `name`: The name of the machine to search for.
/// - `serial:` The serial number of the machine.
///
/// # Returns
/// The ID of the device, if it exists. Else `None`.
pub fn search_device(client: &ThanixClient, name: &str, serial: &str) -> NazaraResult<Option<i64>> {
    status!("Checking if device is already registered...");
    let payload = DcimDevicesListQuery {
        name: Some(vec![name.to_owned()]),
        serial: Some(vec![serial.to_owned()]),
        ..Default::default()
    };
    match dcim_devices_list(client, payload)? {
        DcimDevicesListResponse::Http200(device_list) => Ok(device_list
            .results
            .ok_or(NazaraError::NetBoxMissingField(
                "PaginatedDeviceWithConfigContextList".into(),
                "results".into(),
            ))?
            .first()
            .map(|x| x.id)),
        DcimDevicesListResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

pub fn search_vm(client: &ThanixClient, name: &str, serial: &str) -> NazaraResult<Option<i64>> {
    status!("Checking if virtual machine is already registered...");
    let payload = VirtualizationVirtualMachinesListQuery {
        name: Some(vec![name.to_owned()]),
        serial: Some(vec![serial.to_owned()]),
        ..Default::default()
    };
    match virtualization_virtual_machines_list(client, payload)? {
        VirtualizationVirtualMachinesListResponse::Http200(device_list) => Ok(device_list
            .results
            .ok_or(NazaraError::NetBoxMissingField(
                "PaginatedVirtualMachineWithConfigContextList".into(),
                "results".into(),
            ))?
            .first()
            .map(|x| x.id)),
        VirtualizationVirtualMachinesListResponse::Other(res) => {
            Err(NazaraError::UnexpectedResponse(res))
        }
    }
}

/// Send request to create a new device in NetBox.
/// Returns the ID of the newly created Device object.
///
/// # Parameters
/// - `client`: The [`ThanixClient`] instance to use for communication.
/// - `payload`: The information about the device serving as a request body.
pub fn create_device(
    client: &ThanixClient,
    payload: WritableDeviceWithConfigContextRequest,
) -> NazaraResult<i64> {
    status!("Creating device in NetBox...");

    match dcim_devices_create(client, payload)? {
        DcimDevicesCreateResponse::Http201(created_device) => {
            success!(
                "Device creation successful! New Device-ID: '{}'.",
                created_device.id
            );
            Ok(created_device.id)
        }
        DcimDevicesCreateResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

/// Updates a device with a given ID.
/// Will simply overwrite the given device object in NetBox with the collected information.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `payload`: The payload for the API request.
/// - `id`: The ID of the device to update.
///
/// # Returns
/// The ID of the updated device.
pub fn update_device(
    client: &ThanixClient,
    payload: PatchedWritableDeviceWithConfigContextRequest,
    id: i64,
) -> NazaraResult<i64> {
    status!("Updating device in NetBox...");
    match dcim_devices_partial_update(client, payload, id)? {
        DcimDevicesPartialUpdateResponse::Http200(updated_device) => {
            success!("Device updated successfully!");
            Ok(updated_device.id)
        }
        DcimDevicesPartialUpdateResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

/// Send request to create a new device in NetBox.
///
/// # Parameters
/// - `client`: The [`ThanixClient`] instance to use for communication.
/// - `payload`: The information about the device serving as a request body.
///
/// # Returns
/// Returns the ID of the newly created Device object.
pub fn create_vm(
    client: &ThanixClient,
    payload: WritableVirtualMachineWithConfigContextRequest,
) -> NazaraResult<i64> {
    status!("Creating virtual machine in NetBox...");
    match virtualization_virtual_machines_create(client, payload)? {
        VirtualizationVirtualMachinesCreateResponse::Http201(created_device) => {
            success!(
                " Virtual Machine creation successful! New ID: '{}'.",
                created_device.id
            );
            Ok(created_device.id)
        }
        VirtualizationVirtualMachinesCreateResponse::Other(res) => {
            Err(NazaraError::UnexpectedResponse(res))
        }
    }
}

/// Updates a device with a given ID.
/// Will simply overwrite the given device object in NetBox with the collected information.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `payload`: The payload for the API request.
/// - `id`: The ID of the device to update.
///
/// # Returns
/// Returns the ID of the updated device.
pub fn update_vm(
    client: &ThanixClient,
    payload: PatchedWritableVirtualMachineWithConfigContextRequest,
    id: i64,
) -> NazaraResult<i64> {
    status!("Updating Virtual machine in NetBox...");

    match virtualization_virtual_machines_partial_update(client, payload, id)? {
        VirtualizationVirtualMachinesPartialUpdateResponse::Http200(updated_device) => {
            success!("VM updated successfully!");
            Ok(updated_device.id)
        }
        VirtualizationVirtualMachinesPartialUpdateResponse::Other(res) => {
            Err(NazaraError::UnexpectedResponse(res))
        }
    }
}

/// Searches for a given MAC address object.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `mac_address`: The MAC address to search for.
///
/// # Returns
/// If it is found, the ID of the MAC address object in NetBox, else will return `None`.
pub fn search_mac_address(client: &ThanixClient, mac_address: &str) -> NazaraResult<Option<i64>> {
    status!("Searching for mac address...");

    let mut payload = DcimMacAddressesListQuery::default();
    payload.mac_address__ic = Some(vec![mac_address.to_string()]);

    match dcim_mac_addresses_list(client, payload)? {
        DcimMacAddressesListResponse::Http200(mac_addresses) => Ok(mac_addresses
            .results
            .ok_or(NazaraError::NetBoxMissingField(
                "PaginatedMACAddressList".into(),
                "results".into(),
            ))?
            .first()
            .map(|x| x.id)),
        DcimMacAddressesListResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

/// Creates new MAC address object.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `payload`: The API request payload.
///
/// # Returns
/// The ID of the newly created MAC address.
pub fn create_mac_address(client: &ThanixClient, payload: MACAddressRequest) -> NazaraResult<i64> {
    status!("Creating MAC address in NetBox...");
    match dcim_mac_addresses_create(client, payload)? {
        thanix_client::paths::DcimMacAddressesCreateResponse::Http201(result) => {
            success!(
                " MAC Address created successfully. New MAC Address-ID: '{}'",
                result.id
            );
            Ok(result.id)
        }
        thanix_client::paths::DcimMacAddressesCreateResponse::Other(res) => {
            Err(NazaraError::UnexpectedResponse(res))
        }
    }
}

/// Updates a MAC address object.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `payload`: The MAC address payload to update the MAC address with.
/// - `mac_address_id`: The ID of the MAC address to update.
#[allow(unused)]
pub fn update_mac_address(
    client: &ThanixClient,
    payload: MACAddressRequest,
    mac_address_id: i64,
) -> NazaraResult<i64> {
    match dcim_mac_addresses_update(client, payload, mac_address_id)? {
        DcimMacAddressesUpdateResponse::Http200(result) => {
            success!("MAC Address '{}' updated successfully.", result.id);
            Ok(result.id)
        }
        DcimMacAddressesUpdateResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

/// Searches for interfaces with a given search parameters.
///
/// # Parameters
/// - `client`: The `ThanixClient` instance to use for communication.
/// - `device_id`: The ID of the device this interface is linked to.
/// - `name`: The name of this interface.
///
/// # Returns
/// Returns the ID of the interface when it is found, else returns `None`.
pub fn search_interface(
    client: &ThanixClient,
    device_id: i64,
    name: &String,
) -> NazaraResult<Option<i64>> {
    status!("Searching for interface '{name}'...");

    let payload = DcimInterfacesListQuery {
        device_id: Some(vec![device_id]),
        name: Some(vec![name.clone()]),
        ..Default::default()
    };

    match dcim_interfaces_list(client, payload)? {
        DcimInterfacesListResponse::Http200(interfaces) => Ok(interfaces
            .results
            .ok_or(NazaraError::NetBoxMissingField(
                "PaginatedInterfaceList".into(),
                "results".into(),
            ))?
            .first()
            .map(|x| x.id)),
        DcimInterfacesListResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

pub fn search_vm_interface(
    client: &ThanixClient,
    vm_id: i64,
    name: &String,
) -> NazaraResult<Option<i64>> {
    status!("Searching for VM interface '{name}'...");

    let payload = VirtualizationInterfacesListQuery {
        virtual_machine_id: Some(vec![vm_id]),
        name: Some(vec![name.clone()]),
        ..Default::default()
    };

    match virtualization_interfaces_list(client, payload)? {
        VirtualizationInterfacesListResponse::Http200(interfaces) => Ok(interfaces
            .results
            .ok_or(NazaraError::NetBoxMissingField(
                "PaginatedVMInterfaceList".into(),
                "results".into(),
            ))?
            .first()
            .map(|x| x.id)),
        VirtualizationInterfacesListResponse::Other(res) => {
            Err(NazaraError::UnexpectedResponse(res))
        }
    }
}

/// Creates an interface object in NetBox.
///
/// # Parameters
/// - `client`: The client instance necessary for communication.
/// - `payload`: The payload for the API request.
///
/// # Returns
/// The ID of the interface object if the creation was successful.
pub fn create_interface(
    client: &ThanixClient,
    payload: WritableInterfaceRequest,
) -> NazaraResult<i64> {
    status!("Creating network interface in NetBox...");

    match dcim_interfaces_create(client, payload)? {
        DcimInterfacesCreateResponse::Http201(result) => {
            success!(
                " Interface created successfully. New Interface-ID: '{}'",
                result.id
            );
            Ok(result.id)
        }
        DcimInterfacesCreateResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

pub fn create_vm_interface(
    client: &ThanixClient,
    payload: WritableVMInterfaceRequest,
) -> NazaraResult<i64> {
    status!("Creating network interface in NetBox...");
    match virtualization_interfaces_create(client, payload)? {
        VirtualizationInterfacesCreateResponse::Http201(result) => {
            success!(
                " Interface created successfully. New Interface-ID: '{}'",
                result.id
            );
            Ok(result.id)
        }
        VirtualizationInterfacesCreateResponse::Other(res) => {
            Err(NazaraError::UnexpectedResponse(res))
        }
    }
}

/// Updates a given interface object.
/// Returns the ID of the updated interface.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `payload`: The API request payload to use.
/// - `interface_id`: The ID of the interface to update.
///
/// # Returns
/// The ID of the updated interface if the update was successful.
pub fn update_interface(
    client: &ThanixClient,
    payload: WritableInterfaceRequest,
    interface_id: i64,
) -> NazaraResult<i64> {
    match dcim_interfaces_update(client, payload, interface_id)? {
        DcimInterfacesUpdateResponse::Http200(result) => {
            success!("Interface '{}' updated successfully.", result.id);
            Ok(result.id)
        }
        DcimInterfacesUpdateResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

pub fn update_vm_interface(
    client: &ThanixClient,
    payload: WritableVMInterfaceRequest,
    interface_id: i64,
) -> NazaraResult<i64> {
    match virtualization_interfaces_update(client, payload, interface_id)? {
        VirtualizationInterfacesUpdateResponse::Http200(result) => {
            success!("Interface '{}' updated successfully.", result.id);
            Ok(result.id)
        }
        VirtualizationInterfacesUpdateResponse::Other(res) => {
            Err(NazaraError::UnexpectedResponse(res))
        }
    }
}

/// Search given IP Address.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `address`: The address to search for.
/// - `device_id`: The ID of the device this address is linked to, if any.
///
/// # Returns
/// The ID of the IP address if it was found, otherwise `None`.
pub fn search_ip(
    client: &ThanixClient,
    address: &String,
    device_id: Option<i64>,
) -> NazaraResult<Option<i64>> {
    status!("Searching for IP Address '{address}'...");
    let payload = IpamIpAddressesListQuery {
        address: Some(vec![address.clone()]),
        device_id: device_id.map(|x| vec![x]),
        ..Default::default()
    };
    submit_ip_query(client, payload)
}

pub fn search_vm_ip(
    client: &ThanixClient,
    address: &String,
    vm_ip: Option<i64>,
) -> NazaraResult<Option<i64>> {
    status!("Searching for IP Address '{address}'...");
    let payload = IpamIpAddressesListQuery {
        address: Some(vec![address.clone()]),
        virtual_machine_id: vm_ip.map(|x| vec![x]),
        ..Default::default()
    };
    submit_ip_query(client, payload)
}

fn submit_ip_query(
    client: &ThanixClient,
    payload: IpamIpAddressesListQuery,
) -> NazaraResult<Option<i64>> {
    match ipam_ip_addresses_list(client, payload)? {
        IpamIpAddressesListResponse::Http200(addresses) => Ok(addresses
            .results
            .ok_or(NazaraError::NetBoxMissingField(
                "PaginatedIPAddressList".into(),
                "results".into(),
            ))?
            .first()
            .map(|x| x.id)),
        IpamIpAddressesListResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

/// Creates new IP adress object.
///
/// # Parameters
/// - `client`: The client instance necessary for communication.
/// - `payload`: The payload to send.
///
/// # Returns
/// Returns the ID of the new IPAddress object if the creation of the IP address was successful.
pub fn create_ip(client: &ThanixClient, payload: WritableIPAddressRequest) -> NazaraResult<i64> {
    status!("Creating new IP address object...");
    match ipam_ip_addresses_create(client, payload)? {
        IpamIpAddressesCreateResponse::Http201(result) => {
            success!(
                " IP Address created successfully. New IP-ID: '{}'",
                result.id
            );
            Ok(result.id)
        }
        IpamIpAddressesCreateResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

/// Patches a given IP address object.
///
/// # Parameters
/// - `client`: The API client instance to use.
/// - `payload`: The API call payload.
/// - `id`: The ID of the IP Address to update.
///
/// # Returns
/// The ID of the patched IP address object, if successful.
pub fn patch_ip(
    client: &ThanixClient,
    payload: PatchedWritableIPAddressRequest,
    id: i64,
) -> NazaraResult<i64> {
    status!("Patching IPs for given interface...");

    match ipam_ip_addresses_partial_update(client, payload, id)? {
        IpamIpAddressesPartialUpdateResponse::Http200(result) => Ok(result.id),
        IpamIpAddressesPartialUpdateResponse::Other(res) => {
            Err(NazaraError::UnexpectedResponse(res))
        }
    }
}

/// Gets a list of Interfaces.
///
/// # Parameters
/// - `state`: The API client instance to use.
#[allow(unused)]
pub fn get_interface_list(state: &ThanixClient) -> NazaraResult<Vec<Interface>> {
    status!("Retrieving list of interfaces...");

    match dcim_interfaces_list(state, DcimInterfacesListQuery::default())? {
        DcimInterfacesListResponse::Http200(interfaces) => interfaces.results.ok_or(
            NazaraError::NetBoxMissingField("PaginatedInterfaceList".into(), "results".into()),
        ),
        DcimInterfacesListResponse::Other(res) => Err(NazaraError::UnexpectedResponse(res)),
    }
}

/// Attempts to retrieve an interface by its name.
///
/// # Parameters
/// - `state`: The API client instance to use.
/// - `payload`: The payload to send.
#[allow(unused)]
pub fn get_interface_by_name(
    state: &ThanixClient,
    payload: &WritableInterfaceRequest,
) -> NazaraResult<Interface> {
    status!(
        "Trying to retrieve interface by name '{}'...",
        &payload.name
    );
    get_interface_list(state)?
        .into_iter()
        .find(|x| x.name.clone().is_some_and(|n| n == payload.name))
        .ok_or(NazaraError::Other(format!(
            "No interface '{}' with name found. Creation possibly failed.",
            &payload.name
        )))
}