Overview
TheCreateResourceAction class handles the creation of new resources directly in NetBird. It creates the resource via the NetBird API, stores a reference in the local database, and logs the action for audit purposes.
Constructor Dependencies
The action is instantiated with the following dependency:Service class for interacting with the NetBird API
Method Signature
Parameters
The name of the resource to create
The network address of the resource (e.g., IP address or hostname)
Optional description of the resource. Can be
nullWhether the resource should be enabled upon creation
The NetBird group ID to associate the resource with
The user performing the action (used for audit logging)
Return Value
Side Effects
This action performs the following side effects:- NetBird API Call: Creates a new resource in NetBird via
NetbirdService::createResource() - Database Insert: Creates a new
Resourcerecord with:netbird_id: The ID returned from NetBirduser_id: The ID of the user creating the resourcecreated_by: The name of the user creating the resource
- Audit Log: Creates a
ResourceLogentry with action typeCreatedand tracks all resource attributes
Example Usage
Error Scenarios
The action logs all resource attributes in the audit log, including the user who performed the action and when it occurred. This provides full traceability for compliance and debugging.
Source Reference
Implementation:/home/daytona/workspace/source/app/Actions/CreateResourceAction.php:24