Overview
TheDeleteResourceAction class handles the deletion of resources from NetBird. It removes the resource via the NetBird API, logs the deletion, and cleans up the local database reference.
Constructor Dependencies
The action is instantiated with the following dependency:Service class for interacting with the NetBird API
Method Signature
Parameters
The NetBird resource ID to delete
An array containing the resource data for logging purposes:
name(string, required): The resource nameaddress(string, required): The resource addressdescription(string|null, optional): The resource description
The user performing the deletion (used for audit logging)
Return Value
This action returnsvoid (no return value).
Side Effects
This action performs the following side effects:- NetBird API Call: Deletes the resource from NetBird via
NetbirdService::deleteResource() - Audit Log: Creates a
ResourceLogentry with action typeDeletedand records the resource details - Database Cleanup: Deletes the corresponding
Resourcerecord from the local database wherenetbird_idmatches
Example Usage
Operation Order
The action performs operations in this specific order:- Delete from NetBird API
- Log the deletion
- Clean up local database
The local database cleanup happens last to ensure the audit log is created successfully. If the NetBird API call fails, no database changes will occur.
Error Scenarios
The
resourceData parameter is required because the resource may not exist in the local database at deletion time. Passing the data explicitly ensures proper audit logging regardless of database state.Source Reference
Implementation:/home/daytona/workspace/source/app/Actions/DeleteResourceAction.php:24