Skip to content

Commit

Permalink
Improve handling of invalid plugins (NOJIRA)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benn Oshrin committed Jan 15, 2024
1 parent d231ff7 commit 4ff6d37
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
12 changes: 10 additions & 2 deletions app/src/Lib/Traits/PluggableModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,19 @@ protected function setPluginRelations() {
// once per instantiation.

$models = $this->find()
->select('plugin')
->select(['id', 'plugin'])
->distinct(['plugin'])
->all();

foreach($models as $m) {
if(empty($m->plugin) || !strstr($m->plugin, '.')) {
// This plugin is not valid. We could filter this in the find() using a
// where() clause, but checking here allows us to emit a warning.

$this->llog('error', "Ignoring invalid plugin found in " . $this->getTable() . " record " . $m->id);
continue;
}

// In general, a model with a "plugin" field has a 1-1 relation
// with the instantiated plugin configuration. eg: One instance
// of a Server has exactly one SqlServer associated with it.
Expand Down
7 changes: 5 additions & 2 deletions app/src/Model/Table/IdentifierAssignmentsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ public function initialize(array $config): void {
* Assign Identifiers for an Entity.
*
* @since COmanage Registry v5.0.0
* XXX Document params
* @param string $entityType Entity Table (eg: "People")
* @param int $entityId Entity ID
* @param bool $provision Whether or not to run provisioners after assignment
* @param int $actorPersonId Person ID of Actor assigning identifiers
*/

public function assign(
Expand Down Expand Up @@ -470,7 +473,7 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->notEmptyString('status');

$this->registerStringValidation($validator, $schema, 'plugin', false);
$this->registerStringValidation($validator, $schema, 'plugin', true);

$validator->add('context', [
'content' => ['rule' => ['inList', IdentifierAssignmentContextEnum::getConstValues()]]
Expand Down
2 changes: 1 addition & 1 deletion app/src/Model/Table/ServersTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function validationDefault(Validator $validator): Validator {
]);
$validator->notEmptyString('status');

$this->registerStringValidation($validator, $schema, 'plugin', false);
$this->registerStringValidation($validator, $schema, 'plugin', true);

return $validator;
}
Expand Down

0 comments on commit 4ff6d37

Please sign in to comment.