Skip to content

Commit

Permalink
feat: added ConfigHistoryRevision model
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredhendrickson13 committed May 6, 2024
1 parent 2e195fc commit 7542f75
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
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();
}
}
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();
}
}
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");
}
}

0 comments on commit 7542f75

Please sign in to comment.