Comments (2)
Hi @jmserra,
I've not run into this specific issue, but I have run into similar ones. My default strategy for these things would be to address this at the boundary level with Flysystem, of course this means such a boundary must be in place for this to have a good effect. Personally I think such cases illustrate nicely how software boundaries help you to deal with accidental complexity. But I'll make it a little more concrete.
For example, if our application was responsible for generating reports of some sort, there'd be a ReportingProcess, which has a Reporter and a ReportsStorage. The ReportStorage would be our boundary to Flysystem. It could look something like:
<?php
class ReportStorage
{
public function __construct(FilesystemInterface $filesystem)
{
$this->filesystem = $filesystem;
}
public function storeReport(User $reportIssuer, DateTime $reportedAt, string $report): bool
{
$path = "{$reportIssuer->uuid()}-{$reportedAt->format('Y-m-d').txt";
return $this->filesystem->write($path, $report);
}
}
If there'd be to be some retry mechanism with the $client->authenticate()
call, we could easily do that here. We could even do it pre-emptively.
For example, if we'd have a re-authenticator like this:
class ReAuthenticator
{
public function __construct($client, int $throttle)
{
$this->client = $client;
$this->throttle = $throttle;
$this->lastCall = time();
}
public function reAuthenticate()
{
if (time() > ($this->lastCall + $this->throttle)) {
$this->client->authenticate();
$this->lastCall = time();
}
}
}
and then our boundary could use that:
<?php
class ReportStorage
{
public function __construct(FilesystemInterface $filesystem, ReAuthenticator $reAuth)
{
$this->filesystem = $filesystem;
$this->reAuth = $reAuth;
}
public function storeReport(User $reportIssuer, DateTime $reportedAt, string $report): bool
{
$path = "{$reportIssuer->uuid()}-{$reportedAt->format('Y-m-d').txt";
$this->reAuth->reAuthenticate();
return $this->filesystem->write($path, $report);
}
}
In this case every time the throttle amount has passed we re-authenticate the client before trying to write with Flysystem.
Hope this help!
from flysystem-rackspace.
Hi @frankdejonge thanks for your extensive reply, it makes total sense, although doing this kind of implementation implies losing the beautiful abstraction Laravel is doing over Flysystem and its different providers through configuration.
So, looking again into the codebase and object structure i'm thinking that for simple scenarios would be easier accessing the client through the Disk object, what about this:
$client = $disk->getDriver()->getAdapter()->getContainer()->getService()->getClient();
if($client->hasExpired())
$client->authenticate();
Yeah, not the cleanest thing in the world, and it can easily get broken as soon as some of those layers change a little bit.
This would be more elaborated: (still not ideal)
function reAuthIfNeeded( FilesystemAdapter $disk )
{
$driver = $disk->getDriver();
if(!is_a($driver, \League\Flysystem\Filesystem::class))
return;
$adapter = $driver->getAdapter();
if(!is_a($adapter, \League\Flysystem\Rackspace\RackspaceAdapter::class))
return;
$client = $adapter->getContainer()->getService()->getClient();
if($client->hasExpired())
{
$client->authenticate();
}
}
At this point im wondering if that should be done transparently by the driver, as if the token is currently expired, shouldn't be its responsibility to update it without the caller even knowing ?
So, when any method of RackspaceAdapter is called, shouldn't first check if the token got expired ?
Thanks again!
from flysystem-rackspace.
Related Issues (19)
- How to use the snet endpoint? HOT 1
- V2 of the OpenCloud API HOT 16
- URL Encode filenames HOT 13
- readStream() returns empty string HOT 4
- Creating directories HOT 5
- Deleting Files HOT 1
- Instance of Closure given HOT 7
- readStream needs to be rewound before using HOT 5
- Get object URL HOT 4
- Can I use this package for softlayer object storage ?
- cloudvps
- Package guzzle/guzzle is abandoned HOT 3
- Infer Content-Type
- Is it alive? HOT 1
- Seems not to work with PHP8 - Guzzle issue?
- Rackspace has issued a new certificate and this is broken on PHP7
- Large Uploads HOT 1
- PHP Warning: fclose(): xx is not a valid stream resource HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flysystem-rackspace.