Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error on every function to access gcs storage #99

Open
juliano-aiqfome opened this issue Feb 11, 2025 · 1 comment
Open

Error on every function to access gcs storage #99

juliano-aiqfome opened this issue Feb 11, 2025 · 1 comment

Comments

@juliano-aiqfome
Copy link

juliano-aiqfome commented Feb 11, 2025

The error is: Unable to write file at location: uploads/driver-b54302ec-c772-11ea-b66f-06f3f99250a0/faces/1407502025021167ab59b6c8da0.png. Trying to access array offset on null.

but it happens when I try to read or update a file too, the error is thrown in the line 98 of google/auth/src/CacheTrait.php, $key = $this->cacheConfig['prefix'] . $key;

it happens because the value lifetime and prefix aren't being set on the credentials files, like google/auth/src/Credentials/ImpersonatedServiceAccountCredentials.php or google/auth/src/Credentials/GCECredentials.php, so the attribute cacheConfig is null on the CacheTrait.php, causing the exception, if I set them manually, it works fine.

the full function is

/**
* @param null|string $key
* @return null|string
*/
private function getFullCacheKey($key)
{
if (is_null($key)) {
return null;
}

    $key = $this->cacheConfig['prefix'] . $key;

    // ensure we do not have illegal characters
    $key = preg_replace('|[^a-zA-Z0-9_\.!]|', '', $key);

    // Hash keys if they exceed $maxKeyLength (defaults to 64)
    if ($this->maxKeyLength && strlen($key) > $this->maxKeyLength) {
        $key = substr(hash('sha256', $key), 0, $this->maxKeyLength);
    }

    return $key;
}

I would say that a possible solution is setting a default value right into the CacheTrait.php attribute, something like this:
private $cacheConfig = [
'lifetime' => 1500,
'prefix' => '',
];

@freekmurze
Copy link
Member

I'd be a happy to take a look at a PR that included tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants