-
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added ConfigHistoryRevision model
- Loading branch information
1 parent
2e195fc
commit 7542f75
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
...ESTAPI/files/usr/local/pkg/RESTAPI/Endpoints/DiagnosticsConfigHistoryRevisionEndpoint.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace RESTAPI\Endpoints; | ||
|
||
require_once 'RESTAPI/autoloader.inc'; | ||
|
||
use RESTAPI\Core\Endpoint; | ||
|
||
/** | ||
* Defines an Endpoint for interacting with a single ConfigHistoryRevision Model at | ||
* /api/v2/diagnostics/config_history/revision. | ||
*/ | ||
class DiagnosticsConfigHistoryRevisionEndpoint extends Endpoint { | ||
public function __construct() { | ||
# Set Endpoint attributes | ||
$this->url = '/api/v2/diagnostics/config_history/revision'; | ||
$this->model_name = 'ConfigHistory'; | ||
$this->request_method_options = ['GET', 'DELETE']; | ||
$this->delete_help_text = "Deletes a configuration revision along with it's associated backup file."; | ||
|
||
# Construct the parent Endpoint object | ||
parent::__construct(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...STAPI/files/usr/local/pkg/RESTAPI/Endpoints/DiagnosticsConfigHistoryRevisionsEndpoint.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace RESTAPI\Endpoints; | ||
|
||
require_once 'RESTAPI/autoloader.inc'; | ||
|
||
use RESTAPI\Core\Endpoint; | ||
|
||
/** | ||
* Defines an Endpoint for interacting with many ConfigHistoryRevision Models at | ||
* /api/v2/diagnostics/config_history/revisions. | ||
*/ | ||
class DiagnosticsConfigHistoryRevisionsEndpoint extends Endpoint { | ||
public function __construct() { | ||
# Set Endpoint attributes | ||
$this->url = '/api/v2/diagnostics/config_history/revisions'; | ||
$this->model_name = 'ConfigHistory'; | ||
$this->request_method_options = ['GET']; | ||
$this->many = true; | ||
|
||
# Construct the parent Endpoint object | ||
parent::__construct(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
pfSense-pkg-RESTAPI/files/usr/local/pkg/RESTAPI/Models/ConfigHistoryRevision.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php | ||
|
||
namespace RESTAPI\Models; | ||
|
||
use RESTAPI\Core\Model; | ||
use RESTAPI\Fields\IntegerField; | ||
use RESTAPI\Fields\StringField; | ||
use RESTAPI\Fields\UnixTimeField; | ||
|
||
class ConfigHistoryRevision extends Model | ||
{ | ||
public UnixTimeField $time; | ||
public StringField $description; | ||
public StringField $version; | ||
public IntegerField $filesize; | ||
|
||
public function __construct(mixed $id = null, mixed $parent_id = null, mixed $data = [], ...$options) | ||
{ | ||
# Set model attributes | ||
$this->internal_callable = 'get_config_history'; | ||
$this->verbose_name = 'Configuration History Entry'; | ||
$this->many = true; | ||
|
||
# Set model fields | ||
$this->time = new UnixTimeField( | ||
required: true, | ||
help_text: "The time the configuration change was made." | ||
); | ||
$this->description = new StringField( | ||
default: '', | ||
help_text: "The description of the configuration change." | ||
); | ||
$this->version = new StringField( | ||
default: '', | ||
help_text: "The configuration version associated with this change." | ||
); | ||
$this->filesize = new IntegerField( | ||
default: 0, | ||
help_text: "The file size (in bytes) of the configuration file associated with this change." | ||
); | ||
|
||
parent::__construct($id, $parent_id, $data, ...$options); | ||
} | ||
|
||
/** | ||
* Deletes a configuration history entry. | ||
*/ | ||
public function _delete(): void { | ||
unlink("/cf/conf/backup/config-$this->time.xml"); | ||
} | ||
} |