getCurrentOperatorApiKeyObject(); return $key ? $key->id : null; } public function getCurrentOperatorApiKeyString(): ?string { $key = $this->getCurrentOperatorApiKeyObject(); return $key ? $key->key : null; } public function getCurrentOperatorEnrichmentKeyString(): ?string { $key = $this->getCurrentOperatorApiKeyObject(); return $key ? $key->token : null; } public function getOperatorApiKeys(int $operatorId): array { $model = new \Models\ApiKeys(); $apiKeys = $model->getKeys($operatorId); $isOwner = true; if (!$apiKeys) { $coOwnerModel = new \Models\ApiKeyCoOwner(); $coOwnerModel->getCoOwnership($operatorId); if ($coOwnerModel->loaded()) { $isOwner = false; $apiKeys[] = $model->getKeyById($coOwnerModel->api); } } return [$isOwner, $apiKeys]; } // returns \Models\ApiKeys; in test mode returns object protected function getCurrentOperatorApiKeyObject(): object|null { $currentOperator = $this->f3->get('CURRENT_USER'); if (!$currentOperator) { return null; } $model = new \Models\ApiKeys(); //This key specified in the local configuration file and will not applied to the production environment $testId = $this->f3->get('TEST_API_KEY_ID'); if (isset($testId) && $testId !== '') { return (object) [ 'id' => $testId, 'key' => $model->getKeyById($testId)->key, 'skip_blacklist_sync' => true, 'token' => $model->getKeyById($testId)->token, ]; } $operatorId = $currentOperator->id; $key = $model->getKey($operatorId); if (!$key) { // Check if operator is co-owner of another API key when it has no own API key. $coOwnerModel = new \Models\ApiKeyCoOwner(); $coOwnerModel->getCoOwnership($operatorId); if ($coOwnerModel->loaded()) { $key = $model->getKeyById($coOwnerModel->api); } } return $key; } }